Class Database

All Implemented Interfaces:
CommandRunner

public class Database extends AbstractCommandRunner<DatabaseOptions>
Represents a Data API database, providing the primary entry point for database-level operations and interactions. This class enables Data Manipulation Language (DML) operations such as creating and deleting collections, as well as obtaining Collection objects for further operations on specific collections. It also provides access to operations for managing tables.

This class provides a synchronous interface, designed for straightforward and immediate execution of database commands. It is intended for use in scenarios where blocking calls are acceptable or desirable, such as in traditional server-side applications or command-line tools.

Each Database instance is associated with an "API Endpoint," which defines the specific region it connects to. This is particularly important for multi-region databases, where each instance of Database ensures connectivity to a specific regional endpoint for optimal performance and consistency.

Key Features:

  • Direct access to database-level operations, including collection management.
  • Region-specific connectivity for multi-region database configurations.
  • Built on AbstractCommandRunner, providing consistent command execution semantics.

Example usage:

 
 // Initialize the database object with endpoint and options
 DataAPIClient client = new DataAPIClient("token");
 client.getDatabase("https://<id>-<region>.apps.astra.datastax.com");

 // Perform database-level operations
 database.createCollection("myCollection");
 Collection collection = database.getCollection("myCollection");
 collection.insert(new Document("field1", "value1"));
 
 
See Also:
  • Constructor Details

    • Database

      public Database(String rootEndpoint, DatabaseOptions options)
      Initializes a Database instance with the specified API endpoint and connection options. This constructor configures the database client to interact with the Data API at the provided root endpoint, setting up necessary parameters and constructing the API endpoint based on the deployment environment and options.

      The API endpoint is automatically adjusted for Astra deployments (e.g., ASTRA, ASTRA_TEST, ASTRA_DEV), appending the required JSON API path if the root endpoint ends with ".com". For local or on-premise deployments, no adjustments are made to the root endpoint.

      The constructed API endpoint includes:

      Parameters:
      rootEndpoint - The root API endpoint for connecting to the database. This is the base URL that determines the target deployment environment (e.g., Astra or local).
      options - The DatabaseOptions containing all attributes required to connect to the database, including authentication details, keyspace configuration, and client options.
  • Method Details

    • getKeyspace

      public String getKeyspace()
      Retrieves the name of the currently selected keyspace.
      Returns:
      The name of the keyspace currently in use by this Database instance.
    • getRegion

      public String getRegion()
      Retrieves the region of the database if it is deployed in Astra. This method ensures that the database is an Astra deployment before returning the region. If the database is not deployed in Astra, an assertion error is raised.
      Returns:
      The region where the Astra database is deployed.
      Throws:
      IllegalStateException - if the database is not deployed in Astra.
    • getId

      public UUID getId()
      Retrieves the unique database identifier (UUID) of the database if it is deployed in Astra. This method ensures that the database is an Astra deployment before returning the identifier. If the database is not deployed in Astra, an assertion error is raised.
      Returns:
      The unique identifier (UUID) of the Astra database.
      Throws:
      IllegalStateException - if the database is not deployed in Astra.
    • getInfo

      public DatabaseInfo getInfo()
      Retrieves information about the current database, including metadata and configuration details.

      This method interacts with the devops API to fetch database information. To optimize performance, the database information is cached after the first retrieval. Subsequent calls to this method return the cached DatabaseInfo object unless the cache is invalidated externally.

      Example usage:

       
       DatabaseInfo info = database.getInfo();
       System.out.println("Database Name: " + info.getName());
       System.out.println("Database Version: " + info.getVersion());
       
       
      Returns:
      A DatabaseInfo object containing details about the current database.
      Throws:
      IllegalStateException - if the database information cannot be retrieved or if the database is not properly configured for administration operations.
    • getName

      public String getName()
      Retrieves the name of the current database.

      This method provides a convenient way to access the database name from the DatabaseInfo object returned by getInfo(). It encapsulates the process of fetching and extracting the database name.

      Example usage:

       
       String dbName = database.getName();
       System.out.println("Database Name: " + dbName);
       
       
      Returns:
      The name of the current database as a String.
      Throws:
      IllegalStateException - if the database information cannot be retrieved or is unavailable.
    • useKeyspace

      public Database useKeyspace(String keyspace)
      Sets the active keyspace for the database. This method allows switching the current keyspace context used for database operations.
      Parameters:
      keyspace - The name of the keyspace to set as the current keyspace. This must not be null or empty.
      Returns:
      The database instance with the specified keyspace set as active, allowing for method chaining.
      Throws:
      IllegalArgumentException - If the provided keyspace is null or empty.

      Example usage:

       
       Database database = new Database();
       database.useKeyspace("my_keyspace");
       
       
    • getAdmin

      public AstraDBAdmin getAdmin(AdminOptions adminOptions)
      Retrieves an administration client for Astra deployments using detailed administrative options.

      This method provides fine-grained control over the client configuration by allowing explicit specification of both the token and additional options.

      Parameters:
      adminOptions - The AdminOptions object containing authentication and configuration details.
      Returns:
      An AstraDBAdmin instance configured with the provided administrative options.
      Throws:
      IllegalStateException - if the database is not deployed in Astra.
    • getAdmin

      public AstraDBAdmin getAdmin()
      Retrieves an administration client specifically for Astra deployments using the default authentication token.

      This client allows execution of administrative tasks such as creating databases and managing Astra configurations.

      Returns:
      An AstraDBAdmin instance configured with the default token for administrative operations.
      Throws:
      IllegalStateException - if the database is not deployed in Astra.
    • getAdmin

      public AstraDBAdmin getAdmin(String superUserToken)
      Retrieves an administration client specifically for Astra deployments using a provided super-user token.

      This method allows overriding the default token with a custom super-user token for enhanced privileges.

      Parameters:
      superUserToken - A token with elevated privileges for administrative operations.
      Returns:
      An AstraDBAdmin instance configured with the provided token.
      Throws:
      IllegalStateException - if the database is not deployed in Astra.
    • getDatabaseAdmin

      public DatabaseAdmin getDatabaseAdmin(AdminOptions adminOptions)
      Retrieves a database administration client using detailed administrative options.

      Depending on the deployment type (Astra or non-Astra), this method returns an appropriate implementation of DatabaseAdmin, either AstraDBDatabaseAdmin or DataAPIDatabaseAdmin. The provided AdminOptions object determines the authentication and configuration used for the client.

      Key behaviors:

      • If no adminOptions are provided, a default configuration is derived from the current options.
      • If the deployment is Astra, an AstraDBDatabaseAdmin instance is returned.
      • For non-Astra deployments, a DataAPIDatabaseAdmin instance is returned.
      Parameters:
      adminOptions - The AdminOptions object containing authentication and configuration details.
      Returns:
      A DatabaseAdmin instance tailored for the current deployment type and configured with the provided options.
    • getDatabaseAdmin

      public DatabaseAdmin getDatabaseAdmin()
      Retrieves a database administration client using the default authentication token.

      The client enables management of database-level configurations, such as keyspaces, collections, and other database settings.

      Returns:
      A DatabaseAdmin instance configured with the default token for database-level operations.
    • getDatabaseAdmin

      public DatabaseAdmin getDatabaseAdmin(String superUserToken)
      Retrieves a database administration client using a provided super-user token.

      This method allows overriding the default token with a custom super-user token for privileged database management operations.

      Parameters:
      superUserToken - A token with elevated privileges for database administration tasks.
      Returns:
      A DatabaseAdmin instance configured with the provided token.
    • listCollectionNames

      public List<String> listCollectionNames()
      Retrieves the names of all the collections present in this database.

      This method provides a list of collection names, allowing developers to explore or iterate over the available collections in the database. It is particularly useful for dynamic scenarios where the collections within a database might not be predetermined or when you need to inspect the database's current state programmatically.

      Example usage:

       
       Database database = new DataAPIClient("token").getDatabase("endpoint);
       List<String> collectionNames = database.listCollectionNames();
       collectionNames.forEach(System.out::println);
       
       
      Returns:
      A List containing the names of all collections in this database.
      Throws:
      DataAPIException - if an error occurs while retrieving the collection names.
    • listCollectionNames

      public List<String> listCollectionNames(ListCollectionOptions listCollectionOptions)
      Retrieves the names of all the collections present in this database, with the ability to customize the listing behavior using the specified ListCollectionOptions.

      This method provides a list of collection names, allowing developers to explore or iterate over the collections in the database. The behavior of this operation can be tailored by providing ListCollectionOptions, enabling filtering or additional configuration as needed.

      Parameters:

      • listCollectionOptions - The options to customize the collection listing operation, such as filtering criteria or additional query parameters.

      Example usage:

       
       // Create list collection options
       ListCollectionOptions options = new ListCollectionOptions()
          .timeout(Duration.ofMillis(1000));
      
       // Retrieve collection names based on options
       Database database = new DataAPIClient("token").getDatabase("endpoint);
       List<String> collectionNames = database.listCollectionNames(options);
      
       // Print the collection names
       collectionNames.forEach(System.out::println);
       
       
      Parameters:
      listCollectionOptions - The ListCollectionOptions to customize the collection listing behavior.
      Returns:
      A List containing the names of all collections in this database, filtered or modified according to the provided options.
    • listCollections

      public List<CollectionDescriptor> listCollections()
      Retrieves all collections in this database along with their definitions.

      This method returns a list of CollectionDescriptor objects, providing detailed metadata about each collection, such as its name, schema, or other relevant attributes. It acts as a convenient entry point for obtaining all collection definitions without any filtering or additional options.

      Example usage:

       
       Database database = new DataAPIClient("token").getDatabase("endpoint);
       List<CollectionDescriptor> collections = database.listCollections();
       
       
      Returns:
      A List of CollectionDescriptor objects representing all collections in this database.
    • listCollections

      public List<CollectionDescriptor> listCollections(ListCollectionOptions listCollectionOptions)
      Retrieves all collections in this database along with their definitions, customized by the specified ListCollectionOptions.

      This method allows for more fine-grained control over the collection retrieval process, enabling options such as filtering, limiting the number of results, or specifying additional query parameters. The returned list includes CollectionDescriptor objects, which provide detailed metadata for each collection that matches the provided options.

      Parameters:

      • listCollectionOptions - The ListCollectionOptions to customize the listing behavior, such as filtering criteria or additional query parameters. If null, all collections are returned.

      Example usage:

       
       // Create options for listing collections with a specific prefix
       ListCollectionOptions options = new ListCollectionOptions()
          .timeout(Duration.ofMillis(1000));
      
       // Retrieve matching collections
       Database database = new DataAPIClient("token").getDatabase("endpoint);
       List<CollectionDescriptor> collections = database.listCollections(options);
       
       
      Parameters:
      listCollectionOptions - The ListCollectionOptions to customize the collection retrieval process. If null, no filtering or additional options are applied.
      Returns:
      A List of CollectionDescriptor objects representing the collections that match the criteria.
    • collectionExists

      public boolean collectionExists(String collectionName)
      Checks if a specified collection exists in this database.

      This method evaluates whether a collection with the given name is present in the database. It is useful for verifying the existence of a collection before performing operations such as querying, inserting, or updating data.

      Example usage:

       
       Database database = new DataAPIClient("token").getDatabase("endpoint");
       boolean exists = database.collectionExists("my_collection");
       if (exists) {
           System.out.println("Collection exists!");
       } else {
           System.out.println("Collection does not exist.");
       }
       
       
      Parameters:
      collectionName - The name of the collection to check.
      Returns:
      true if the collection exists, false otherwise.
      Throws:
      IllegalArgumentException - if the collection name is null or empty.
    • getCollection

      public Collection<Document> getCollection(String collectionName)
      Retrieves a Collection object for the specified collection name.

      This method provides a convenient way to obtain a Collection instance for a specific collection in the database. The returned object allows for further operations on the collection, such as querying, inserting, or updating documents.

      Parameters:

      • collectionName - The name of the collection to retrieve. This must not be null or empty.

      Example usage:

       
       Database database = new DataAPIClient("token").getDatabase("endpoint");
       Collection collection = database.getCollection("my_collection");
       
       
      Parameters:
      collectionName - The name of the collection to retrieve.
      Returns:
      A Collection object representing the specified collection.
      Throws:
      IllegalArgumentException - if the collection name is null or empty.
    • getCollection

      public <T> Collection<T> getCollection(String collectionName, Class<T> documentClass)
      Retrieves a Collection object for the specified collection name, with the ability to customize the collection behavior using the specified CollectionOptions.

      This method provides a way to obtain a Collection instance for a specific collection in the database, with additional options for configuring the collection's behavior. The returned object allows for further operations on the collection, such as querying, inserting, or updating documents.

      Parameters:

      • collectionName - The name of the collection to retrieve. This must not be null or empty.
      • collectionOptions - The CollectionOptions to customize the collection behavior, such as setting a custom serializer or specifying additional options. If null, default options are used.

      Example usage:

       
       // Create custom collection options
       CollectionOptions options = new CollectionOptions()
          .serializer(new MyCustomSerializer());
      
       // Retrieve the collection with custom options
       Database database = new DataAPIClient("token").getDatabase("endpoint");
       Collection collection = database.getCollection("my_collection", options);
       
       
      Type Parameters:
      T - The type of the documents stored in the collection.
      Parameters:
      collectionName - The name of the collection to retrieve.
      documentClass - The class type of the documents stored in the collection.
      Returns:
      A Collection object representing the specified collection, configured with the provided options.
    • getCollection

      public Collection<Document> getCollection(String collectionName, CollectionOptions collectionOptions)
      Retrieves a Collection object for the specified collection name with the ability to specify custom options.

      This method provides a flexible way to obtain a Collection instance by allowing the caller to specify CollectionOptions to customize the behavior of the collection.

      Parameters:

      • collectionName - The name of the collection to retrieve. This must not be null or empty.
      • collectionOptions - A CollectionOptions object that specifies custom behaviors for the collection. If null, default options will be used.

      Example usage:

       
      
       CollectionOptions options = new CollectionOptions()
        .timeout(Duration.ofMillis(1000))
        .dataAPIClientOptions(new DataAPIClientOptions())
        .embeddingAuthProvider(new EmbeddingAPIKeyHeaderProvider("api-key"));
      
       Database database = new DataAPIClient("token").getDatabase("endpoint");
       Collection collection = database.getCollection("my_collection", options);
       
       
      Parameters:
      collectionName - The name of the collection to retrieve.
      collectionOptions - The CollectionOptions to customize the collection behavior.
      Returns:
      A Collection object representing the specified collection.
      Throws:
      IllegalArgumentException - if collectionName is null or empty.
    • getCollection

      public <T> Collection<T> getCollection(String collectionName, Class<T> documentClass, CollectionOptions options)
      Retrieves a Collection object for the specified collection name with custom options and document type.

      This method provides the most flexible way to obtain a Collection instance, allowing clients to specify custom options and the type of documents in the collection.

      Parameters:

      • collectionName - The name of the collection to retrieve. This must not be null or empty.
      • options - The CollectionOptions to customize the collection behavior. Must not be null.
      • documentClass - The Class type of the documents stored in the collection. This enables type safety when working with the collection's documents. Must not be null.

      Example usage:

       
       CollectionOptions options = new CollectionOptions()
        .timeout(Duration.ofMillis(1000))
        .dataAPIClientOptions(new DataAPIClientOptions())
        .embeddingAuthProvider(new EmbeddingAPIKeyHeaderProvider("api-key"));
       Collection<MyDocument> collection = database.getCollection("my_collection", options, MyDocument.class);
       
       
      Type Parameters:
      T - The type of the documents stored in the collection.
      Parameters:
      collectionName - The name of the collection to retrieve.
      documentClass - The class type of the documents in the collection.
      options - The CollectionOptions for customizing the collection behavior.
      Returns:
      A Collection object representing the specified collection.
      Throws:
      IllegalArgumentException - if collectionName, options, or documentClass is null.
    • createCollection

      public <T> Collection<T> createCollection(String collectionName, CollectionDefinition collectionDefinition, Class<T> documentClass, CreateCollectionOptions createCollectionOptions)
      Creates a new collection in the database.
      Type Parameters:
      T - The type of the documents stored in the collection.
      Parameters:
      collectionName - The name of the collection to be created.
      collectionDefinition - An optional CollectionDefinition object defining the schema and other properties of the collection.
      documentClass - The class of the documents stored in the collection.
      createCollectionOptions - Additional options for creating the collection, such as timeouts or retry policies.
      Returns:
      The created collection as a Collection of the specified document type.
      Throws:
      IllegalArgumentException - If any required argument is null or invalid.

      Example usage:

       
       Collection<MyDocument> collection = db.createCollection(
           "myCollection",
           new CollectionDefinition(),
           new CollectionOptions(token, dataAPIClientOptions),
           new CreateCollectionOptions(),
           MyDocument.class
       );
       
       
    • createCollection

      public Collection<Document> createCollection(String collectionName)
      Creates a new collection with the default document type Document.
      Parameters:
      collectionName - The name of the collection to be created.
      Returns:
      The created collection as a Collection of Document.

      Example usage:

       
       Collection<Document> collection = db.createCollection("myDefaultCollection");
       
       
    • createCollection

      public <T> Collection<T> createCollection(String collectionName, Class<T> documentClass)
      Creates a new collection with the specified document class.
      Type Parameters:
      T - The type of the documents stored in the collection.
      Parameters:
      collectionName - The name of the collection to be created.
      documentClass - The class of the documents stored in the collection.
      Returns:
      The created collection as a Collection of the specified document type.

      Example usage:

       
       Collection<MyDocument> collection = db.createCollection("myTypedCollection", MyDocument.class);
       
       
    • createCollection

      public Collection<Document> createCollection(String name, CollectionDefinition def)
      Creates a new collection with a specified definition and the default document type Document.
      Parameters:
      name - The name of the collection to be created.
      def - The CollectionDefinition specifying the schema and other properties of the collection.
      Returns:
      The created collection as a Collection of Document.

      Example usage:

       
       Collection<Document> collection = createCollection("myDefinedCollection", new CollectionDefinition());
       
       
    • createCollection

      public <T> Collection<T> createCollection(String name, CollectionDefinition def, Class<T> documentClass)
      Creates a new collection with a specified definition and the specified document class.
      Type Parameters:
      T - The type of the documents stored in the collection.
      Parameters:
      name - The name of the collection to be created.
      def - The CollectionDefinition specifying the schema and other properties of the collection.
      documentClass - The class of the documents stored in the collection.
      Returns:
      The created collection as a Collection of the specified document type.

      Example usage:

       
       Collection<MyDocument> collection = createCollection("myDefinedCollection",
        new CollectionDefinition(), MyDocument.class);
       
       
    • createCollection

      public Collection<Document> createCollection(String collectionName, CollectionDefinition collectionDefinition, CreateCollectionOptions createCollectionOptions)
      Creates a new collection with a specified definition, options, and the default document type Document.
      Parameters:
      collectionName - The name of the collection to be created.
      collectionDefinition - The CollectionDefinition specifying the schema and other properties of the collection.
      createCollectionOptions - Additional options for creating the collection, such as timeouts or retry policies.
      Returns:
      The created collection as a Collection of Document.

      Example usage:

       
       Collection<Document> collection = createCollection(
           "myComplexCollection",
           new CollectionDefinition(),
           new CollectionOptions(token, dataAPIClientOptions),
           new CreateCollectionOptions()
       );
       
       
    • dropCollection

      public void dropCollection(String collectionName, DropCollectionOptions dropCollectionOptions)
      Deletes a collection from the database.
      Parameters:
      collectionName - The name of the collection to be deleted. Must not be null or empty.
      dropCollectionOptions - Additional options for dropping the collection, such as timeout or retry policies.

      Example usage:

       
       db.dropCollection("myCollection", new DropCollectionOptions().timeout(Duration.ofMillis(1000)));
       
       
    • dropCollection

      public void dropCollection(String collectionName)
      Deletes a collection from the database with default options.
      Parameters:
      collectionName - The name of the collection to be deleted. Must not be null or empty.

      Example usage:

       
       dropCollection("myCollection");
       
       
    • listTableNames

      public List<String> listTableNames()
      Retrieves the names of all tables in the database with default options.
      Returns:
      A list of all table names in the database.

      Example usage:

       
       List<String> tableNames = listTableNames();
       
       
    • listTableNames

      public List<String> listTableNames(ListTablesOptions listTablesOptions)
      Retrieves the names of all tables in the database.
      Parameters:
      listTablesOptions - Options for filtering or configuring the table listing operation.
      Returns:
      A list of all table names in the database.

      Example usage:

       
       ListTablesOptions options = new ListTablesOptions();
       List<String> tableNames = listTableNames(options);
       
       
    • listTables

      public List<TableDescriptor> listTables()
      Retrieves the details of all tables in the database with default options.
      Returns:
      A list of TableDescriptor objects representing all tables in the database.

      Example usage:

       
       List<TableDescriptor> tables = listTables();
       
       
    • listTables

      public List<TableDescriptor> listTables(ListTablesOptions listTableOptions)
      Retrieves the details of all tables in the database.
      Parameters:
      listTableOptions - Options for filtering or configuring the table listing operation.
      Returns:
      A list of TableDescriptor objects representing all tables in the database.

      Example usage:

       
       ListTablesOptions options = new ListTablesOptions();
       List<TableDescriptor> tables = listTables(options);
       
       
    • tableExists

      public boolean tableExists(String tableName)
      Checks if a table exists in the database by its name.
      Parameters:
      tableName - The name of the table to check. Must not be null or empty.
      Returns:
      true if the table exists, false otherwise.
      Throws:
      IllegalArgumentException - if tableName is null or empty.

      Example usage:

       
       boolean exists = tableExists("myTable");
       if (exists) {
           System.out.println("The table exists.");
       } else {
           System.out.println("The table does not exist.");
       }
       
       
    • getTable

      public <T> Table<T> getTable(String tableName, Class<T> rowClass, TableOptions tableOptions)
      Retrieves a table representation for the specified table name, table options, and row class type. This is the primary method to obtain a typed table instance.
      Type Parameters:
      T - the type of the row objects
      Parameters:
      tableName - the name of the table (must not be null or empty)
      rowClass - the class representing the type of rows in the table (must not be null)
      tableOptions - options used to configure the table (e.g., connection options)
      Returns:
      a Table<T> instance for the specified configuration

      Example usage:

       
       Table<MyRowType> table = db.getTable("my_table", new TableOptions(...), MyRowType.class);
       
       
    • getTable

      public Table<Row> getTable(String tableName)
      Retrieves a table representation for the specified table name with default TableOptions.
      Parameters:
      tableName - the name of the table (must not be null or empty)
      Returns:
      a Table<Row> instance representing a generic table with Row type rows
      Throws:
      IllegalArgumentException - if tableName is null or empty

      Example usage:

       
       Table<Row> table = db.getTable("my_table");
       
       
    • getTable

      public <T> Table<T> getTable(String tableName, Class<T> rowClass)
      Retrieves a table representation for the specified table name and row class type with default TableOptions.
      Type Parameters:
      T - the type of the row objects
      Parameters:
      tableName - the name of the table (must not be null or empty)
      rowClass - the class representing the type of rows in the table (must not be null)
      Returns:
      a Table<T> instance for the specified configuration
      Throws:
      IllegalArgumentException - if tableName is null or empty
      NullPointerException - if rowClass is null

      Example usage:

       
       Table<MyRowType> table = myFramework.getTable("my_table", MyRowType.class);
       
       
    • getTable

      public Table<Row> getTable(String tableName, TableOptions tableOptions)
      Retrieves a table representation for the specified table name and TableOptions, defaulting to Row type rows.
      Parameters:
      tableName - the name of the table (must not be null or empty)
      tableOptions - options used to configure the table (e.g., connection options)
      Returns:
      a Table<Row> instance representing a generic table with Row type rows
      Throws:
      IllegalArgumentException - if tableName is null or empty
      NullPointerException - if tableOptions is null

      Example usage:

       
       Table<Row> table = myFramework.getTable("my_table", new TableOptions(...));
       
       
    • getTable

      public <T> Table<T> getTable(Class<T> rowClass)
      Retrieves a table representation for a row class annotated with EntityTable. The table name is inferred from the value attribute of the EntityTable annotation.
      Type Parameters:
      T - the type of the row objects
      Parameters:
      rowClass - the class representing the type of rows in the table (must be annotated with EntityTable)
      Returns:
      a Table<T> instance for the inferred table name and row type
      Throws:
      InvalidConfigurationException - if the provided class is not annotated with EntityTable

      Example usage:

       
       @EntityTable("my_table")
       public class MyRowType { ... }
      
       Table<MyRowType> table = myFramework.getTable(MyRowType.class);
       
       
    • createTable

      public <T> Table<T> createTable(String tableName, TableDefinition tableDefinition, Class<T> rowClass, CreateTableOptions createTableOptions)
      Creates a table in the system with the specified parameters.
      Type Parameters:
      T - the type of the row objects that the table will hold
      Parameters:
      tableName - the name of the table to be created; must not be null or empty
      tableDefinition - the schema definition of the table; must not be null
      rowClass - the class representing the row type; must not be null
      createTableOptions - additional options for creating the table; optional, can be null
      Returns:
      the created table object
      Throws:
      IllegalArgumentException - if any mandatory argument is null or invalid

      Example usage:

       
       TableDefinition tableDefinition = new TableDefinition()
        .addColumnText("match_id")
        .addColumnInt("round")
        .addColumnVector("m_vector", new ColumnDefinitionVector().dimension(3).metric(COSINE))
        .addColumn("score", ColumnTypes.INT)
        .addColumn("when", ColumnTypes.TIMESTAMP)
        .addColumn("winner", ColumnTypes.TEXT)
        .addColumnSet("fighters", ColumnTypes.UUID)
        .addPartitionBy("match_id")
        .addPartitionSort(Sort.ascending("round"));
      
       // Optional
       CreateTableOptions createTableOptions =
            new CreateTableOptions().timeout(Duration.ofMillis(1000));
      
       Table<Row> tableSimple2 = db.createTable("TABLE_SIMPLE", tableDefinition,
        Row.class, createTableOptions);
       
       
    • createTable

      public <T> Table<T> createTable(String tableName, TableDefinition tableDefinition, Class<T> rowClass)
      Creates a table using default options and runtime configurations.
      Type Parameters:
      T - the type of the row objects that the table will hold
      Parameters:
      tableName - the name of the table to be created; must not be null or empty
      tableDefinition - the schema definition of the table; must not be null
      rowClass - the class representing the row type; must not be null
      Returns:
      the created table object
    • createTable

      public Table<Row> createTable(String tableName, TableDefinition tableDefinition, CreateTableOptions options)
      Creates a table using default options and runtime configurations.
      Parameters:
      tableName - the name of the table to be created; must not be null or empty
      tableDefinition - the schema definition of the table; must not be null
      options - the option to initialize the class.
      Returns:
      the created table object
    • createTable

      public Table<Row> createTable(String tableName, TableDefinition tableDefinition)
      Creates a table with a default row type of Row.
      Parameters:
      tableName - the name of the table to be created; must not be null or empty
      tableDefinition - the schema definition of the table; must not be null
      Returns:
      the created table object with rows of type Row
    • createTable

      public <T> Table<T> createTable(Class<T> rowClass)
      Creates a table using default options and the inferred table name from the row class.
      Type Parameters:
      T - the type of the row objects that the table will hold
      Parameters:
      rowClass - the class representing the row type; must not be null
      Returns:
      the created table object
    • createTable

      public <T> Table<T> createTable(Class<T> rowClass, CreateTableOptions createTableOptions)
      Creates a table using default options and the inferred table name from the row class.
      Type Parameters:
      T - the type of the row objects that the table will hold
      Parameters:
      rowClass - the class representing the row type; must not be null
      createTableOptions - additional options for creating the table; optional, can be null
      Returns:
      the created table object
    • createTable

      public <T> Table<T> createTable(String tableName, Class<T> rowClass, CreateTableOptions createTableOptions)
      Creates a table using default options and runtime configurations.
      Type Parameters:
      T - the type of the row objects that the table will hold
      Parameters:
      tableName - the name of the table to be created; must not be null or empty
      rowClass - the class representing the row type; must not be null
      createTableOptions - additional options for creating the table; optional, can be null
      Returns:
      the created table object
    • getTableName

      public <T> String getTableName(Class<T> rowClass)
      Creates a table using default options and runtime configurations.
      Type Parameters:
      T - the type of the row objects that the table will hold
      Parameters:
      rowClass - the class representing the row type; must not be null
      Returns:
      the created table object
    • dropTable

      public void dropTable(String tableName)
      Deletes a collection (table) from the database. This method delegates to dropTable(String, DropTableOptions) with default options.
      Parameters:
      tableName - the name of the table to be deleted; must not be null or empty.
      Throws:
      IllegalArgumentException - if tableName is null or empty.

      Example usage:

       
       database.dropTable("exampleTable");
       
       
    • dropTable

      public void dropTable(String tableName, DropTableOptions dropTableOptions)
      Deletes a collection (table) from the database with specific options.
      Parameters:
      tableName - the name of the table to be deleted; must not be null or empty.
      dropTableOptions - the options to configure the table deletion operation; can be null.
      Throws:
      IllegalArgumentException - if tableName is null or empty.

      Example usage:

       
       DropTableOptions options = new DropTableOptions();
       database.dropTable("exampleTable", options);
       
       
    • dropTableIndex

      public void dropTableIndex(String indexName)
      Delete an index by name.
      Parameters:
      indexName - index name
    • dropTableIndex

      public void dropTableIndex(String indexName, DropTableIndexOptions dropIndexOptions)
      Delete an index by name.
      Parameters:
      indexName - index name
      dropIndexOptions - flag to drop index
    • getApiEndpoint

      public String getApiEndpoint()
      Gets apiEndpoint
      Overrides:
      getApiEndpoint in class AbstractCommandRunner<DatabaseOptions>
      Returns:
      value of apiEndpoint