congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
TableBuilder
Code IndexAdd Tabnine to your IDE (free)

How to use
TableBuilder
in
com.englishtown.vertx.cassandra.tablebuilder

Best Java code snippets using com.englishtown.vertx.cassandra.tablebuilder.TableBuilder (Showing top 16 results out of 315)

origin: com.englishtown/vertx-mod-cassandra

/**
 * Returns a {@link com.datastax.driver.core.BatchStatement} with all the alter statements necessary to modify an existing table.
 * <p>
 * Note: Columns will only be added or modified, not dropped.
 *
 * @param existing the existing table to be modified
 * @param desired  the desired end result
 * @return a set of statements to modify an existing table
 */
public static List<AlterTable> alter(TableMetadata existing, CreateTable desired) {
  List<AlterTable> results = new ArrayList<>();
  for (BuiltTableStatement.Column column : desired.getColumns()) {
    ColumnMetadata columnMetadata = existing.getColumn(column.getName());
    if (columnMetadata == null) {
      results.add(alter(desired.getKeyspace(), desired.getTable()).addColumn(column.getName(), column.getType()));
    } else if (!columnMetadata.getType().toString().equalsIgnoreCase(column.getType())) {
      if (columnMetadata.isStatic()) {
        throw new IllegalArgumentException("A static column cannot have its type modified");
      }
      results.add(alter(desired.getKeyspace(), desired.getTable()).alterColumn(column.getName(), column.getType()));
    }
  }
  return results;
}
origin: ef-labs/vertx-cassandra

@Test
public void testAlter() throws Exception {
  CreateTable desired = TableBuilder.create("test_keyspace", "test_table")
      .column("col1", "text")
      .column("col2", "bigint")
      .column("col3", "int")
      .column("col4", "text")
      .primaryKey("col1");
  List<AlterTable> statements = TableBuilder.alter(existing, desired);
  assertEquals(3, statements.size());
  assertEquals("ALTER TABLE test_keyspace.test_table ALTER col2 TYPE bigint", statements.get(0).toString());
  assertEquals("ALTER TABLE test_keyspace.test_table ADD col3 int", statements.get(1).toString());
  assertEquals("ALTER TABLE test_keyspace.test_table ADD col4 text", statements.get(2).toString());
}
origin: ef-labs/vertx-cassandra

@Test
public void testDropTable() throws Exception {
  DropTable table = TableBuilder.drop("test_keyspace", "test_table");
  String cql = table.getQueryString();
  assertEquals("DROP TABLE test_keyspace.test_table", cql);
}
origin: ef-labs/vertx-cassandra

statement = TableBuilder.create(keyspace, table)
    .column("col1", "text")
    .column("col2", "text")
statement = TableBuilder.create(keyspace, table)
    .ifNotExists()
    .column("col1", "text")
CreateTable createTable = TableBuilder.create(keyspace, table)
    .column("col1", "text")
    .column("col2", "text")
List<AlterTable> alterStatements = TableBuilder.alter(tableMetadata, createTable);
assertEquals(5, tableMetadata.getColumns().size());
statement = TableBuilder.drop(keyspace, table);
session.execute(statement);
statement = TableBuilder.drop(keyspace, table)
    .ifExists();
session.execute(statement);
  statement = TableBuilder.drop(keyspace, table);
  session.execute(statement);
  fail("Table should not exist, drop should have throw InvalidQueryException");
origin: ef-labs/vertx-cassandra

if (keyspaceMetadata != null) {
  for (TableMetadata tableMetadata : keyspaceMetadata.getTables()) {
    session.execute(TableBuilder.drop(keyspace, tableMetadata.getName()).ifExists());
createTestTableStatement = TableBuilder.create(keyspace, "test")
    .ifNotExists()
    .column("id", "text")
origin: ef-labs/vertx-cassandra

@Test
public void testColumns() throws Exception {
  CreateTable table = TableBuilder.create("test_keyspace", "test_table")
      .columns(new String[]{"col1", "col2", "col3"}, new String[]{"text", "int", "blob"})
      .column("col4", "text")
      .column("col3", "text")
      .column("col1", "int")
      .primaryKey("col1");
  String cql = table.getQueryString();
  assertEquals("CREATE TABLE test_keyspace.test_table (col1 int, col2 int, col3 text, col4 text, PRIMARY KEY(col1))", cql);
}
origin: ef-labs/vertx-cassandra

@Test
public void testCreateTable() throws Exception {
  CreateTable table = TableBuilder.create("test_keyspace", "test_table")
      .ifNotExists()
      .column("col1", "text")
      .column("col2", "int")
      .staticColumn("col3", "blob")
      .primaryKeys("col1", "col2");
  String cql = table.getQueryString();
  assertEquals("CREATE TABLE IF NOT EXISTS test_keyspace.test_table (col1 text, col2 int, col3 blob STATIC, PRIMARY KEY(col1, col2))", cql);
}
origin: com.englishtown.vertx/vertx-cassandra

/**
 * Returns a {@link com.datastax.driver.core.BatchStatement} with all the alter statements necessary to modify an existing table.
 * <p>
 * Note: Columns will only be added or modified, not dropped.
 *
 * @param existing the existing table to be modified
 * @param desired  the desired end result
 * @return a set of statements to modify an existing table
 */
public static List<AlterTable> alter(AbstractTableMetadata existing, CreateTable desired) {
  List<AlterTable> results = new ArrayList<>();
  for (BuiltTableStatement.Column column : desired.getColumns()) {
    ColumnMetadata columnMetadata = existing.getColumn(column.getName());
    if (columnMetadata == null) {
      results.add(alter(desired.getKeyspace(), desired.getTable()).addColumn(column.getName(), column.getType()));
    } else if (!columnMetadata.getType().toString().equalsIgnoreCase(column.getType())) {
      if (columnMetadata.isStatic()) {
        throw new IllegalArgumentException("A static column cannot have its type modified");
      }
      results.add(alter(desired.getKeyspace(), desired.getTable()).alterColumn(column.getName(), column.getType()));
    }
  }
  return results;
}
origin: ef-labs/vertx-cassandra

@Test
public void testCreateTable_Composite_Partition_Key() throws Exception {
  CreateTable table = TableBuilder.create("test_keyspace", "test_table")
      .column("col1", "text")
      .column("col2", "int")
      .column("col3", "blob")
      .column("col4", "uuid")
      .primaryKey("col1", PrimaryKeyType.PARTITIONING)
      .primaryKey("col2", PrimaryKeyType.PARTITIONING)
      .primaryKey("col3", PrimaryKeyType.CLUSTERING)
      .primaryKey("col4");
  String cql = table.getQueryString();
  assertEquals("CREATE TABLE test_keyspace.test_table (col1 text, col2 int, col3 blob, col4 uuid, PRIMARY KEY((col1, col2), col3, col4))", cql);
}
origin: ef-labs/vertx-cassandra

@Test
public void testIfExists() throws Exception {
  DropTable table = TableBuilder.drop("test_keyspace", "test_table").ifExists();
  String cql = table.getQueryString();
  assertEquals("DROP TABLE IF EXISTS test_keyspace.test_table", cql);
}
origin: ef-labs/vertx-cassandra

/**
 * Returns a {@link com.datastax.driver.core.BatchStatement} with all the alter statements necessary to modify an existing table.
 * <p>
 * Note: Columns will only be added or modified, not dropped.
 *
 * @param existing the existing table to be modified
 * @param desired  the desired end result
 * @return a set of statements to modify an existing table
 */
public static List<AlterTable> alter(AbstractTableMetadata existing, CreateTable desired) {
  List<AlterTable> results = new ArrayList<>();
  for (BuiltTableStatement.Column column : desired.getColumns()) {
    ColumnMetadata columnMetadata = existing.getColumn(column.getName());
    if (columnMetadata == null) {
      results.add(alter(desired.getKeyspace(), desired.getTable()).addColumn(column.getName(), column.getType()));
    } else if (!columnMetadata.getType().toString().equalsIgnoreCase(column.getType())) {
      if (columnMetadata.isStatic()) {
        throw new IllegalArgumentException("A static column cannot have its type modified");
      }
      results.add(alter(desired.getKeyspace(), desired.getTable()).alterColumn(column.getName(), column.getType()));
    }
  }
  return results;
}
origin: ef-labs/vertx-cassandra

assertNotNull(value);
Statement statement = TableBuilder.create(keyspace, "test")
    .column("id", "text")
    .primaryKey("id");
origin: ef-labs/vertx-cassandra

@Test
public void testAdd() throws Exception {
  AlterTable alter = TableBuilder.alter("test_keyspace", "test_table")
      .addColumn("col1", "text");
  String cql = alter.getQueryString();
  assertEquals("ALTER TABLE test_keyspace.test_table ADD col1 text", cql);
}
origin: ef-labs/vertx-cassandra

  @Test
  public void testRename() throws Exception {
    AlterTable alter = TableBuilder.alter("test_keyspace", "test_table")
        .renameColumn("col1", "col2");

    String cql = alter.getQueryString();
    assertEquals("ALTER TABLE test_keyspace.test_table RENAME col1 TO col2", cql);
  }
}
origin: ef-labs/vertx-cassandra

@Test
public void testAlter() throws Exception {
  AlterTable alter = TableBuilder.alter("test_keyspace", "test_table")
      .alterColumn("col1", "text");
  String cql = alter.getQueryString();
  assertEquals("ALTER TABLE test_keyspace.test_table ALTER col1 TYPE text", cql);
}
origin: ef-labs/vertx-cassandra

@Test
public void testDrop() throws Exception {
  AlterTable alter = TableBuilder.alter("test_keyspace", "test_table")
      .dropColumn("col1");
  String cql = alter.getQueryString();
  assertEquals("ALTER TABLE test_keyspace.test_table DROP col1", cql);
}
com.englishtown.vertx.cassandra.tablebuilderTableBuilder

Javadoc

Static methods to build a CQL3 table statement

Most used methods

  • alter
    Returns a com.englishtown.vertx.cassandra.tablebuilder.AlterTable builder
  • create
    Returns a com.englishtown.vertx.cassandra.tablebuilder.CreateTable builder
  • drop
    Returns a com.englishtown.vertx.cassandra.tablebuilder.DropTable statement

Popular in Java

  • Reading from database using SQL prepared statement
  • onRequestPermissionsResult (Fragment)
  • onCreateOptionsMenu (Activity)
  • getResourceAsStream (ClassLoader)
  • StringTokenizer (java.util)
    Breaks a string into tokens; new code should probably use String#split.> // Legacy code: StringTo
  • AtomicInteger (java.util.concurrent.atomic)
    An int value that may be updated atomically. See the java.util.concurrent.atomic package specificati
  • Response (javax.ws.rs.core)
    Defines the contract between a returned instance and the runtime when an application needs to provid
  • Project (org.apache.tools.ant)
    Central representation of an Ant project. This class defines an Ant project with all of its targets,
  • Join (org.hibernate.mapping)
  • DateTimeFormat (org.joda.time.format)
    Factory that creates instances of DateTimeFormatter from patterns and styles. Datetime formatting i
  • Top 12 Jupyter Notebook extensions
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now