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

com.scalar.db.sql.common.ColumnDefinitionsBuilder Maven / Gradle / Ivy

The newest version!
package com.scalar.db.sql.common;

import com.scalar.db.sql.ColumnDefinition;
import com.scalar.db.sql.ColumnDefinitions;
import com.scalar.db.sql.DataType;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nullable;

public class ColumnDefinitionsBuilder {

  private final List columnDefinitions = new ArrayList<>();

  private ColumnDefinitionsBuilder() {}

  public ColumnDefinitionsBuilder add(String columnName, DataType dataType) {
    return add(null, null, columnName, dataType);
  }

  public ColumnDefinitionsBuilder add(
      @Nullable String tableName, String columnName, DataType dataType) {
    return add(null, tableName, columnName, dataType);
  }

  public ColumnDefinitionsBuilder add(
      @Nullable String namespaceName,
      @Nullable String tableName,
      String columnName,
      DataType dataType) {
    if (namespaceName != null && tableName == null) {
      throw new IllegalArgumentException(
          "tableName must be specified if namespaceName is specified");
    }
    return add(new ColumnDefinitionImpl(namespaceName, tableName, columnName, dataType));
  }

  public ColumnDefinitionsBuilder add(ColumnDefinition columnDefinition) {
    columnDefinitions.add(columnDefinition);
    return this;
  }

  public ColumnDefinitions build() {
    return new ColumnDefinitionsImpl(columnDefinitions);
  }

  public static ColumnDefinitionsBuilder builder() {
    return new ColumnDefinitionsBuilder();
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy