All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.scalar.db.sql.statement.CreateNamespaceStatement Maven / Gradle / Ivy

There is a newer version: 3.14.0
Show newest version
package com.scalar.db.sql.statement;

import com.google.common.collect.ImmutableMap;
import java.util.Objects;
import javax.annotation.concurrent.Immutable;

@Immutable
public class CreateNamespaceStatement implements DdlStatement {

  public final String namespaceName;
  public final boolean ifNotExists;
  public final ImmutableMap options;

  private CreateNamespaceStatement(
      String namespaceName, boolean ifNotExists, ImmutableMap options) {
    this.namespaceName = Objects.requireNonNull(namespaceName);
    this.ifNotExists = ifNotExists;
    this.options = Objects.requireNonNull(options);
  }

  @Override
  public String toSql() {
    StringBuilder builder = new StringBuilder("CREATE NAMESPACE ");
    if (ifNotExists) {
      builder.append("IF NOT EXISTS ");
    }
    StatementUtils.appendObjectName(builder, namespaceName);
    if (!options.isEmpty()) {
      builder.append(" WITH ");
      StatementUtils.appendOptions(builder, options);
    }
    return builder.toString();
  }

  @Override
  public  R accept(StatementVisitor visitor, C context) {
    return visitor.visit(this, context);
  }

  @Override
  public  R accept(DdlStatementVisitor visitor, C context) {
    return visitor.visit(this, context);
  }

  @Override
  public String toString() {
    return toSql();
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (!(o instanceof CreateNamespaceStatement)) {
      return false;
    }
    CreateNamespaceStatement that = (CreateNamespaceStatement) o;
    return ifNotExists == that.ifNotExists
        && Objects.equals(namespaceName, that.namespaceName)
        && Objects.equals(options, that.options);
  }

  @Override
  public int hashCode() {
    return Objects.hash(namespaceName, ifNotExists, options);
  }

  public static CreateNamespaceStatement create(
      String namespaceName, boolean ifNotExists, ImmutableMap options) {
    return new CreateNamespaceStatement(namespaceName, ifNotExists, options);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy