Class AstraDBDatabaseAdmin

java.lang.Object
com.datastax.astra.client.admin.AstraDBDatabaseAdmin
All Implemented Interfaces:
DatabaseAdmin

public class AstraDBDatabaseAdmin extends Object implements DatabaseAdmin
Implementation of the DatabaseAdmin interface for Astra. To create the namespace the devops APi is leverage. To use this class a higher token permission is required.
  • Field Details

    • db

      protected Database db
      Database if initialized from the DB.
  • Constructor Details

    • AstraDBDatabaseAdmin

      public AstraDBDatabaseAdmin(Database db)
      Initialize a database admin from token and database id.
      Parameters:
      db - target database
    • AstraDBDatabaseAdmin

      public AstraDBDatabaseAdmin(String token, UUID databaseId, com.dtsx.astra.sdk.utils.AstraEnvironment env, DataAPIOptions options)
      Initialize a database admin from token and database id.
      Parameters:
      token - token value
      databaseId - database identifier
      env - working environment
      options - options used to initialize the http client
  • Method Details

    • getDatabaseInformations

      public com.dtsx.astra.sdk.db.domain.Database getDatabaseInformations()
      Find a database from its id.
      Returns:
      list of db matching the criteria
    • getDatabase

      public Database getDatabase(String keyspace)
      Access teh database with the default token.
      Specified by:
      getDatabase in interface DatabaseAdmin
      Parameters:
      keyspace - The name of the namespace (or keyspace) to retrieve. This parameter should match the exact name of the namespace as it exists in the database.
      Returns:
      client to interact with database DML.
    • getDatabase

      public Database getDatabase(String keyspace, String tokenUser)
      Access teh database with the specialized token.
      Specified by:
      getDatabase in interface DatabaseAdmin
      Parameters:
      keyspace - The name of the namespace (or keyspace) to retrieve. This parameter should match the exact name of the namespace as it exists in the database.
      tokenUser - token with reduce privileges compared to admin token in order to do dml options (CRUD).
      Returns:
      client to interact with database DML.
    • listNamespaceNames

      public Set<String> listNamespaceNames()
      Retrieves a stream of namespace names available in the current database. This method is essential for applications that need to enumerate all namespaces to perform operations such as displaying available namespaces to users, managing namespaces programmatically, or executing specific tasks within each namespace. The returned Stream facilitates efficient processing of namespace names, enabling operations like filtering, sorting, and mapping without the need for preloading all names into memory.

      Example usage:

       
       // Assuming 'client' is an instance of DataApiClient
       Stream<String> namespaceNames = client.listNamespaceNames());
       // Display names in the console
       namespaceNames.forEach(System.out::println);
       
       
      Specified by:
      listNamespaceNames in interface DatabaseAdmin
      Returns:
      A Set containing the names of all namespaces within the current database. The stream provides a flexible and efficient means to process the namespace names according to the application's needs.
    • listKeyspaceNames

      public Set<String> listKeyspaceNames()
      Description copied from interface: DatabaseAdmin
      Retrieves a stream of keyspaces names available in the current database. This method is essential for applications that need to enumerate all namespaces to perform operations such as displaying available namespaces to users, managing keyspaces programmatically, or executing specific tasks within each keyspace. The returned Stream facilitates efficient processing of keyspace names, enabling operations like filtering, sorting, and mapping without the need for preloading all names into memory.

      Example usage:

       
       // Assuming 'client' is an instance of DataApiClient
       Stream<String> keyspacesNames = client.listKeyspacesNames());
       // Display names in the console
       keyspacesNames.forEach(System.out::println);
       
       
      Specified by:
      listKeyspaceNames in interface DatabaseAdmin
      Returns:
      A Set containing the names of all namespaces within the current database. The stream provides a flexible and efficient means to process the namespace names according to the application's needs.
    • findEmbeddingProviders

      public FindEmbeddingProvidersResult findEmbeddingProviders()
      Retrieve the list of embedding providers available in the current database. Embedding providers are services that provide embeddings for text, images, or other data types. This method returns a map of provider names to EmbeddingProvider instances, allowing applications to access and utilize the embedding services.

      Example usage:

       
       // Assuming 'client' is an instance of DataApiClient
       Map<String, EmbeddingProvider> providers = client.findEmbeddingProvidersAsMap());
       
       
      Specified by:
      findEmbeddingProviders in interface DatabaseAdmin
      Returns:
      list of available providers
    • createNamespace

      public void createNamespace(String namespace)
      Syntax Sugar, retro compatible.
      Specified by:
      createNamespace in interface DatabaseAdmin
      Parameters:
      namespace - current namespace.
    • createNamespace

      public void createNamespace(String keyspace, boolean updateDBKeyspace)
      Create a Keyspace providing a name.
      Specified by:
      createNamespace in interface DatabaseAdmin
      Parameters:
      keyspace - current keyspace.
      updateDBKeyspace - if the keyspace should be updated in the database.
    • createKeyspace

      public void createKeyspace(String keyspace, boolean updateDBKeyspace)
      Description copied from interface: DatabaseAdmin
      Create a Keyspace providing a name.
      Specified by:
      createKeyspace in interface DatabaseAdmin
      Parameters:
      keyspace - current keyspace.
      updateDBKeyspace - if the keyspace should be updated in the database.
    • dropNamespace

      public void dropNamespace(String namespace)
      Drops (deletes) the specified namespace from the database. This operation is idempotent; it will not produce an error if the namespace does not exist. This method is useful for cleaning up data or removing entire keyspaces as part of database maintenance or restructuring. Caution should be exercised when using this method, as dropping a namespace will remove all the data, collections, or tables contained within it, and this action cannot be undone.

      Example usage:

       
       // Assume 'client' is an instance of your data API client
       String namespace = "targetNamespace";
      
       // Drop the namespace
       client.dropNamespace(namespace);
      
       // The namespace 'targetNamespace' is now deleted, along with all its contained data
       
       
      This example demonstrates how to safely drop a namespace by name. The operation ensures that even if the namespace does not exist, the method call will not interrupt the flow of the application, thereby allowing for flexible and error-tolerant code design.
      Specified by:
      dropNamespace in interface DatabaseAdmin
      Parameters:
      namespace - The name of the namespace to be dropped. This parameter specifies the target namespace that should be deleted. The operation will proceed silently and without error even if the namespace does not exist, ensuring consistent behavior.
    • dropKeyspace

      public void dropKeyspace(String namespace)
      Description copied from interface: DatabaseAdmin
      Drops (deletes) the specified keyspace from the database. This operation is idempotent; it will not produce an error if the keyspace does not exist. This method is useful for cleaning up data or removing entire keyspaces as part of database maintenance or restructuring. Caution should be exercised when using this method, as dropping a keyspace will remove all the data, collections, or tables contained within it, and this action cannot be undone.

      Example usage:

       
       // Assume 'client' is an instance of your data API client
       String keyspace = "targetKeyspace";
      
       // Drop the namespace
       client.dropKeyspace(keyspace);
      
       // The namespace 'targetKeyspace' is now deleted, along with all its contained data
       
       
      This example demonstrates how to safely drop a keyspace by name. The operation ensures that even if the keyspace does not exist, the method call will not interrupt the flow of the application, thereby allowing for flexible and error-tolerant code design.
      Specified by:
      dropKeyspace in interface DatabaseAdmin
      Parameters:
      namespace - The name of the keyspace to be dropped. This parameter specifies the target keyspace that should be deleted. The operation will proceed silently and without error even if the keyspace does not exist, ensuring consistent behavior.
    • getDatabase

      public Database getDatabase()
      Access the Database associated with this admin class.
      Specified by:
      getDatabase in interface DatabaseAdmin
      Returns:
      associated database