Class 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.

    • 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 produce frozen<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 Create and Alter provide specialized methods to express simple collections of UDTs, but future versions will make it possible to use types such as map<text, map<text, frozen<user>>>.

        Parameters:
        literal - the type literal as it will appear in the final CQL statement.
        Returns:
        the type.
      • noCompression

        public static TableOptions.CompressionOptions noCompression()
        Create options for the NONE compression 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.