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

com.scalar.db.sql.statement.builder.CreateNamespaceStatementBuilder Maven / Gradle / Ivy

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

import com.google.common.collect.ImmutableMap;
import com.scalar.db.sql.statement.CreateNamespaceStatement;
import java.util.Map;

public class CreateNamespaceStatementBuilder {

  private CreateNamespaceStatementBuilder() {}

  public static class Start extends Buildable {
    Start(String namespaceName) {
      super(namespaceName, false);
    }

    /**
     * Specifies that the namespace should not be created if it already exists.
     *
     * @return a builder object
     */
    public Buildable ifNotExists() {
      return new Buildable(namespaceName, true);
    }

    /**
     * Specifies whether the namespace should not be created if it already exists.
     *
     * @param ifNotExists whether the namespace should not be created if it already exists
     * @return a builder object
     */
    public Buildable ifNotExists(boolean ifNotExists) {
      return new Buildable(namespaceName, ifNotExists);
    }
  }

  public static class Buildable {
    protected final String namespaceName;
    private final boolean ifNotExists;
    private ImmutableMap.Builder optionsBuilder;

    private Buildable(String namespaceName, boolean ifNotExists) {
      this.namespaceName = namespaceName;
      this.ifNotExists = ifNotExists;
    }

    /**
     * Adds a creation option.
     *
     * @param name an option name to add
     * @param value an option value to add
     * @return a builder object
     */
    public Buildable withOption(String name, String value) {
      if (optionsBuilder == null) {
        optionsBuilder = ImmutableMap.builder();
      }
      optionsBuilder.put(name, value);
      return this;
    }

    /**
     * Adds creation options.
     *
     * @param options options to add
     * @return a builder object
     */
    public Buildable withOptions(Map options) {
      if (optionsBuilder == null) {
        optionsBuilder = ImmutableMap.builder();
      }
      optionsBuilder.putAll(options);
      return this;
    }

    /**
     * Builds a CreateNamespaceStatement object.
     *
     * @return a CreateNamespaceStatement object
     */
    public CreateNamespaceStatement build() {
      return CreateNamespaceStatement.create(
          namespaceName,
          ifNotExists,
          optionsBuilder == null ? ImmutableMap.of() : optionsBuilder.build());
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy