Class SchemaBuilder
- java.lang.Object
-
- com.datastax.driver.core.schemabuilder.SchemaBuilder
-
public final class SchemaBuilder extends Object
Static methods to build a CQL3 DDL statement.The provided builders perform very little validation of the built query. There is thus no guarantee that a built query is valid, and it is definitively possible to create invalid queries.
Note that it could be convenient to use an 'import static' to use the methods of this class.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSchemaBuilder.CachingCaching strategies, for use in a CREATE or ALTER TABLE statement.static classSchemaBuilder.DirectionThe direction used in clustering order declarations.static classSchemaBuilder.KeyCachingKey caching strategies for Cassandra 2.1, for use in a CREATE or ALTER TABLE statement.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static TableOptions.AdditionalWritePolicyValueadditionalWritePolicyAlways()static TableOptions.AdditionalWritePolicyValueadditionalWritePolicyMillisecs(int millisecs)static TableOptions.AdditionalWritePolicyValueadditionalWritePolicyNever()static TableOptions.AdditionalWritePolicyValueadditionalWritePolicyPercentile(int percentile)static TableOptions.CachingRowsPerPartitionallRows()Return the row caching strategy that caches all rows (all), to use in a CREATE or ALTER TABLE statement.static AlterKeyspacealterKeyspace(String keyspaceName)Start building a new ALTER KEYSPACE statement.static AlteralterTable(String tableName)Start building a new ALTER TABLE statement.static AlteralterTable(String keyspaceName, String tableName)Start building a new ALTER TABLE statement.static TableOptions.SpeculativeRetryValuealways()Create the speculative retry strategy that retries reads of all replicas, to use in a CREATE or ALTER TABLE statement.static CreateIndexcreateIndex(String indexName)Start building a new CREATE INDEX statement.static CreateKeyspacecreateKeyspace(String keyspaceName)Start building a new CREATE KEYSPACE statement.static CreatecreateTable(String tableName)Start building a new CREATE TABLE statement.static CreatecreateTable(String keyspaceName, String tableName)Start building a new CREATE TABLE statement.static CreateTypecreateType(String typeName)Start building a new CREATE TYPE statement.static CreateTypecreateType(String keyspaceName, String typeName)Start building a new CREATE TYPE statement.static TableOptions.CompactionOptions.DateTieredCompactionStrategyOptionsdateTieredStrategy()Create options for the date-tiered compaction strategy, to use in a CREATE or ALTER TABLE statement.static TableOptions.CompressionOptionsdeflate()Create options for the Deflate compression strategy, to use in a CREATE or ALTER TABLE statement.static DropdropIndex(String indexName)Start building a new DROP INDEX statement.static DropdropIndex(String keyspaceName, String indexName)Start building a new DROP INDEX statement.static DropKeyspacedropKeyspace(String keyspaceName)Start building a new DROP KEYSPACE statement.static DropdropTable(String tableName)Start building a new DROP TABLE statement.static DropdropTable(String keyspaceName, String tableName)Start building a new DROP TABLE statement.static DropdropType(String typeName)Start building a new DROP TYPE statement.static DropdropType(String keyspaceName, String typeName)Start building a new DROP TYPE statement.static UDTTypefrozen(String udtName)Build the datatype representation of a frozen UDT, to include in a schema builder statement.static TableOptions.CompactionOptions.LeveledCompactionStrategyOptionsleveledStrategy()Create options for the leveled compaction strategy, to use in a CREATE or ALTER TABLE statement.static TableOptions.CompressionOptionslz4()Create options for the LZ4 compression strategy, to use in a CREATE or ALTER TABLE statement.static TableOptions.SpeculativeRetryValuemillisecs(int millisecs)Create the speculative retry strategy that retries after a given delay, to use in a CREATE or ALTER TABLE statement.static TableOptions.CompressionOptionsnoCompression()Create options for theNONEcompression strategy, to use in a CREATE or ALTER TABLE statement.static TableOptions.CachingRowsPerPartitionnoRows()Return the row caching strategy that never caches rows (none, to use in a CREATE or ALTER TABLE statement.static TableOptions.SpeculativeRetryValuenoSpeculativeRetry()Create the speculative retry strategy that never retries reads, to use in a CREATE or ALTER TABLE statement.static TableOptions.SpeculativeRetryValuepercentile(int percentile)Create the speculative retry strategy that retries based on the effect on throughput and latency, to use in a CREATE or ALTER TABLE statement.static TableOptions.CachingRowsPerPartitionrows(int rowNumber)Return the row caching strategy that caches a given number of rows, to use in a CREATE or ALTER TABLE statement.static TableOptions.CompactionOptions.SizeTieredCompactionStrategyOptionssizedTieredStategy()Create options for the size-tiered compaction strategy, for use in a CREATE or ALTER TABLE statement.static TableOptions.CompressionOptionssnappy()Create options for the Snappy compression strategy, to use in a CREATE or ALTER TABLE statement.static TableOptions.CompactionOptions.TimeWindowCompactionStrategyOptionstimeWindowCompactionStrategy()Create options for the time window compaction strategy, to use in a CREATE or ALTER TABLE statement.static UDTTypeudtLiteral(String literal)Build the datatype representation of a complex UDT type, to include in a schema builder statement.
-
-
-
Method Detail
-
createKeyspace
public static CreateKeyspace createKeyspace(String keyspaceName)
Start building a new CREATE KEYSPACE statement.- Parameters:
keyspaceName- the name of the keyspace to create.- Returns:
- an in-construction CREATE KEYSPACE statement.
-
createTable
public static Create createTable(String tableName)
Start building a new CREATE TABLE statement.- Parameters:
tableName- the name of the table to create.- Returns:
- an in-construction CREATE TABLE statement.
-
createTable
public static Create createTable(String keyspaceName, String tableName)
Start building a new CREATE TABLE statement.- Parameters:
keyspaceName- the name of the keyspace to be used.tableName- the name of the table to create.- Returns:
- an in-construction CREATE TABLE statement.
-
alterKeyspace
public static AlterKeyspace alterKeyspace(String keyspaceName)
Start building a new ALTER KEYSPACE statement.- Parameters:
keyspaceName- the name of the keyspace to be altered.- Returns:
- an in-construction ALTER KEYSPACE statement.
-
alterTable
public static Alter alterTable(String tableName)
Start building a new ALTER TABLE statement.- Parameters:
tableName- the name of the table to be altered.- Returns:
- an in-construction ALTER TABLE statement.
-
alterTable
public static Alter alterTable(String keyspaceName, String tableName)
Start building a new ALTER TABLE statement.- Parameters:
keyspaceName- the name of the keyspace to be used.tableName- the name of the table to be altered.- Returns:
- an in-construction ALTER TABLE statement.
-
dropTable
public static Drop dropTable(String tableName)
Start building a new DROP TABLE statement.- Parameters:
tableName- the name of the table to be dropped.- Returns:
- an in-construction DROP TABLE statement.
-
dropKeyspace
public static DropKeyspace dropKeyspace(String keyspaceName)
Start building a new DROP KEYSPACE statement.- Parameters:
keyspaceName- the name of the keyspace to be dropped.- Returns:
- an in-construction DROP KEYSPACE statement.
-
dropTable
public static Drop dropTable(String keyspaceName, String tableName)
Start building a new DROP TABLE statement.- Parameters:
keyspaceName- the name of the keyspace to be used.tableName- the name of the table to be dropped.- Returns:
- an in-construction DROP TABLE statement.
-
createIndex
public static CreateIndex createIndex(String indexName)
Start building a new CREATE INDEX statement.- Parameters:
indexName- the name of the table to create.- Returns:
- an in-construction CREATE INDEX statement.
-
dropIndex
public static Drop dropIndex(String indexName)
Start building a new DROP INDEX statement.- Parameters:
indexName- the name of the index to be dropped.- Returns:
- an in-construction DROP INDEX statement.
-
dropIndex
public static Drop dropIndex(String keyspaceName, String indexName)
Start building a new DROP INDEX statement.- Parameters:
keyspaceName- the name of the keyspace to be used.indexName- the name of the index to be dropped.- Returns:
- an in-construction DROP INDEX statement.
-
createType
public static CreateType createType(String typeName)
Start building a new CREATE TYPE statement.- Parameters:
typeName- the name of the custom type to create.- Returns:
- an in-construction CREATE TYPE statement.
-
createType
public static CreateType createType(String keyspaceName, String typeName)
Start building a new CREATE TYPE statement.- Parameters:
keyspaceName- the name of the keyspace to be used.typeName- the name of the custom type to create.- Returns:
- an in-construction CREATE TYPE statement.
-
dropType
public static Drop dropType(String typeName)
Start building a new DROP TYPE statement.- Parameters:
typeName- the name of the type to be dropped.- Returns:
- an in-construction DROP TYPE statement.
-
dropType
public static Drop dropType(String keyspaceName, String typeName)
Start building a new DROP TYPE statement.- Parameters:
keyspaceName- the name of the keyspace to be used.typeName- the name of the type to be dropped.- Returns:
- an in-construction DROP TYPE statement.
-
frozen
public static UDTType frozen(String udtName)
Build the datatype representation of a frozen UDT, to include in a schema builder statement.frozen("foo")will producefrozen<foo>.- Parameters:
udtName- the name of the UDT.- Returns:
- the type.
-
udtLiteral
public static UDTType udtLiteral(String literal)
Build the datatype representation of a complex UDT type, to include in a schema builder statement.As of Cassandra 2.1, this method is not strictly necessary because
CreateandAlterprovide specialized methods to express simple collections of UDTs, but future versions will make it possible to use types such asmap<text, map<text, frozen<user>>>.- Parameters:
literal- the type literal as it will appear in the final CQL statement.- Returns:
- the type.
-
sizedTieredStategy
public static TableOptions.CompactionOptions.SizeTieredCompactionStrategyOptions sizedTieredStategy()
Create options for the size-tiered compaction strategy, for use in a CREATE or ALTER TABLE statement.- Returns:
- the options.
-
leveledStrategy
public static TableOptions.CompactionOptions.LeveledCompactionStrategyOptions leveledStrategy()
Create options for the leveled compaction strategy, to use in a CREATE or ALTER TABLE statement.- Returns:
- the options.
-
dateTieredStrategy
public static TableOptions.CompactionOptions.DateTieredCompactionStrategyOptions dateTieredStrategy()
Create options for the date-tiered compaction strategy, to use in a CREATE or ALTER TABLE statement.This strategy was introduced in Cassandra 2.1.1.
- Returns:
- the options.
-
timeWindowCompactionStrategy
public static TableOptions.CompactionOptions.TimeWindowCompactionStrategyOptions timeWindowCompactionStrategy()
Create options for the time window compaction strategy, to use in a CREATE or ALTER TABLE statement.This strategy was introduced in Cassandra 3.0.8 and 3.9.
- Returns:
- the options.
-
noCompression
public static TableOptions.CompressionOptions noCompression()
Create options for theNONEcompression strategy, to use in a CREATE or ALTER TABLE statement.- Returns:
- the options.
-
lz4
public static TableOptions.CompressionOptions lz4()
Create options for the LZ4 compression strategy, to use in a CREATE or ALTER TABLE statement.- Returns:
- the options.
-
snappy
public static TableOptions.CompressionOptions snappy()
Create options for the Snappy compression strategy, to use in a CREATE or ALTER TABLE statement.- Returns:
- the options.
-
deflate
public static TableOptions.CompressionOptions deflate()
Create options for the Deflate compression strategy, to use in a CREATE or ALTER TABLE statement.- Returns:
- the options.
-
noSpeculativeRetry
public static TableOptions.SpeculativeRetryValue noSpeculativeRetry()
Create the speculative retry strategy that never retries reads, to use in a CREATE or ALTER TABLE statement.- Returns:
- the strategy.
-
always
public static TableOptions.SpeculativeRetryValue always()
Create the speculative retry strategy that retries reads of all replicas, to use in a CREATE or ALTER TABLE statement.- Returns:
- the strategy.
-
percentile
public static TableOptions.SpeculativeRetryValue percentile(int percentile)
Create the speculative retry strategy that retries based on the effect on throughput and latency, to use in a CREATE or ALTER TABLE statement.- Returns:
- the strategy.
-
millisecs
public static TableOptions.SpeculativeRetryValue millisecs(int millisecs)
Create the speculative retry strategy that retries after a given delay, to use in a CREATE or ALTER TABLE statement.- Returns:
- the strategy.
-
noRows
public static TableOptions.CachingRowsPerPartition noRows()
Return the row caching strategy that never caches rows (none, to use in a CREATE or ALTER TABLE statement.- Returns:
- the strategy.
-
allRows
public static TableOptions.CachingRowsPerPartition allRows()
Return the row caching strategy that caches all rows (all), to use in a CREATE or ALTER TABLE statement.Be careful when choosing this option, you can starve Cassandra memory quickly if your partition is very large.
- Returns:
- the strategy.
-
rows
public static TableOptions.CachingRowsPerPartition rows(int rowNumber)
Return the row caching strategy that caches a given number of rows, to use in a CREATE or ALTER TABLE statement.- Parameters:
rowNumber- the number of rows to cache.- Returns:
- the strategy.
-
additionalWritePolicyNever
public static TableOptions.AdditionalWritePolicyValue additionalWritePolicyNever()
-
additionalWritePolicyAlways
public static TableOptions.AdditionalWritePolicyValue additionalWritePolicyAlways()
-
additionalWritePolicyPercentile
public static TableOptions.AdditionalWritePolicyValue additionalWritePolicyPercentile(int percentile)
-
additionalWritePolicyMillisecs
public static TableOptions.AdditionalWritePolicyValue additionalWritePolicyMillisecs(int millisecs)
-
-