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

com.scalar.db.sql.statement.builder.CreateCoordinatorTablesStatementBuilder 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.CreateCoordinatorTablesStatement;
import java.util.Map;

public class CreateCoordinatorTablesStatementBuilder {

  private CreateCoordinatorTablesStatementBuilder() {}

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

    /**
     * Specifies that the coordinator tables should not be created if they already exist.
     *
     * @return a builder object
     */
    public Buildable ifNotExist() {
      return new Buildable(true);
    }

    /**
     * Specifies whether the coordinator tables should not be created if they already exist.
     *
     * @param ifNotExist whether the coordinator tables should not be created if they already exist
     * @return a builder object
     */
    public Buildable ifNotExist(boolean ifNotExist) {
      return new Buildable(ifNotExist);
    }
  }

  public static class Buildable {
    private final boolean ifNotExist;
    private ImmutableMap.Builder optionsBuilder;

    private Buildable(boolean ifNotExist) {
      this.ifNotExist = ifNotExist;
    }

    /**
     * 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 CreateCoordinatorTablesStatement object.
     *
     * @return a CreateCoordinatorTablesStatement object
     */
    public CreateCoordinatorTablesStatement build() {
      return CreateCoordinatorTablesStatement.create(
          ifNotExist, optionsBuilder == null ? ImmutableMap.of() : optionsBuilder.build());
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy