@Override public String getQueryString(CodecRegistry codecRegistry) { if (cache == null) { cache = buildInternal(); } return cache; }
/** * Specify the column to create the index on. * * @param columnName the column name. * @return the final CREATE INDEX statement. */ public SchemaStatement andColumn(String columnName) { validateNotEmpty(columnName, "Column name"); validateNotKeyWord( columnName, String.format( "The column name '%s' is not allowed because it is a reserved keyword", columnName)); CreateIndex.this.columnName = columnName; return SchemaStatement.fromQueryString(buildInternal()); }
@Test(groups = "unit") public void should_drop_table() throws Exception { // When SchemaStatement statement = dropTable("test"); // Then assertThat(statement.getQueryString()).isEqualTo("DROP TABLE test"); }
Alter(String tableName) { validateNotEmpty(tableName, "Table name"); validateNotKeyWord( tableName, String.format( "The table name '%s' is not allowed because it is a reserved keyword", tableName)); this.tableName = tableName; }
/** * Define the new type of the altered column. * * @param type the new type of the altered column. * @return the final statement. */ public SchemaStatement type(DataType type) { return SchemaStatement.fromQueryString( alter.buildInternal() + " ALTER " + columnName + " TYPE " + type.toString()); }
ClusteringOrder(String clusteringColumnName, SchemaBuilder.Direction direction) { validateNotEmpty(clusteringColumnName, "Column name for clustering order"); this.clusteringColumnName = clusteringColumnName; this.direction = direction; }
@Test(groups = "unit") public void should_create_simple_table_with_set_keyspace() throws Exception { // When SchemaStatement statement = createTable("test") .addPartitionKey("id", DataType.bigint()) .addColumn("name", DataType.text()) .setKeyspace("ks"); // Then assertThat(statement.getKeyspace()).isEqualTo("ks"); }
CreateIndex(String indexName) { validateNotEmpty(indexName, "Index name"); validateNotKeyWord( indexName, String.format( "The index name '%s' is not allowed because it is a reserved keyword", indexName)); this.indexName = indexName; }
/** * Define the type of the added column. * * @param type the type of the added column. * @return the final statement. */ public SchemaStatement type(DataType type) { return SchemaStatement.fromQueryString( alter.buildInternal() + " ADD " + columnName + " " + type.toString() + (staticColumn ? " static" : "")); }
static UDTType literal(String literal) { SchemaStatement.validateNotEmpty(literal, "UDT type literal"); return new UDTType(literal); } }
/** * Create an index on the keys of the given map column. * * @param columnName the column name. * @return the final CREATE INDEX statement. */ public SchemaStatement andKeysOfColumn(String columnName) { validateNotEmpty(columnName, "Column name"); validateNotKeyWord( columnName, String.format( "The column name '%s' is not allowed because it is a reserved keyword", columnName)); CreateIndex.this.columnName = columnName; CreateIndex.this.keys = true; return SchemaStatement.fromQueryString(buildInternal()); } }
Alter(String keyspaceName, String tableName) { validateNotEmpty(keyspaceName, "Keyspace name"); validateNotEmpty(tableName, "Table name"); validateNotKeyWord( keyspaceName, String.format( "The keyspace name '%s' is not allowed because it is a reserved keyword", keyspaceName)); validateNotKeyWord( tableName, String.format( "The table name '%s' is not allowed because it is a reserved keyword", tableName)); this.tableName = tableName; this.keyspaceName = Optional.fromNullable(keyspaceName); }
/** * Define the new type of the altered column, when that type contains a UDT. * * @param udtType the UDT type. Use {@link SchemaBuilder#frozen(String)} or {@link * SchemaBuilder#udtLiteral(String)}. * @return the final statement. */ public SchemaStatement udtType(UDTType udtType) { return SchemaStatement.fromQueryString( alter.buildInternal() + " ALTER " + columnName + " TYPE " + udtType.asCQLString()); } }
@Override public String buildInternal() { return SchemaStatement.this.buildInternal(); } };
@Test(groups = "unit") public void should_drop_type() throws Exception { // When SchemaStatement statement = dropType("test"); // Then assertThat(statement.getQueryString()).isEqualTo("DROP TYPE test"); }
static UDTType frozen(String udtName) { SchemaStatement.validateNotEmpty(udtName, "UDT name"); return new UDTType("frozen<" + udtName + ">"); }
/** * Add a new DROP column clause to this ALTER TABLE statement. * * <p>Note that you cannot drop a column that is part of the primary key. * * @param columnName the name of the column to be dropped. * @return the final ALTER TABLE DROP COLUMN statement. */ public SchemaStatement dropColumn(String columnName) { validateNotEmpty(columnName, "Column to be dropped"); validateNotKeyWord( columnName, String.format( "The dropped column name '%s' is not allowed because it is a reserved keyword", columnName)); return SchemaStatement.fromQueryString(buildInternal() + " DROP " + columnName); }
/** * Specify the table to create the index on. * * @param tableName the table name. * @return a {@link CreateIndexOn} that will allow the specification of the column. */ public CreateIndexOn onTable(String tableName) { validateNotEmpty(tableName, "Table name"); validateNotKeyWord( tableName, String.format( "The table name '%s' is not allowed because it is a reserved keyword", tableName)); this.tableName = tableName; return new CreateIndexOn(); }
/** * Define the type of the added column, when that type contains a UDT. * * @param udtType the UDT type of the added column. * @return the final statement. */ public SchemaStatement udtType(UDTType udtType) { return SchemaStatement.fromQueryString( alter.buildInternal() + " ADD " + columnName + " " + udtType.asCQLString() + (staticColumn ? " static" : "")); } }
@Override public String buildInternal() { return SchemaStatement.this.buildInternal(); } };