Class DataAPIDatabaseAdmin

java.lang.Object
com.datastax.astra.internal.command.AbstractCommandRunner
com.datastax.astra.client.admin.DataAPIDatabaseAdmin
All Implemented Interfaces:
DatabaseAdmin, CommandRunner

public class DataAPIDatabaseAdmin extends AbstractCommandRunner implements DatabaseAdmin
Implementation of Client.
  • Field Details

    • options

      protected final DataAPIOptions options
      Version of the API.
    • apiEndPoint

      protected final String apiEndPoint
      Version of the API.
    • token

      protected final String token
      Version of the API.
  • Constructor Details

    • DataAPIDatabaseAdmin

      public DataAPIDatabaseAdmin(String apiEndpoint, String token, DataAPIOptions options)
      Initialize a database admin from token and database id.
      Parameters:
      apiEndpoint - api endpoint.
      token - token value
      options - list of options for the admin
  • Method Details

    • 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.
    • 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
    • getDatabase

      public Database getDatabase(String namespaceName)
      Retrieves a Database instance that represents a specific database (or namespace) based on the provided namespace name.

      Example usage:

       
       // Assume 'client' is an instance of your data API client
       String namespaceName = "exampleNamespace";
      
       // Retrieve the namespace instance
       DataApiNamespace namespace = client.getNamespace(namespaceName);
      
       // Now, 'namespace' can be used to perform operations within 'exampleNamespace'
       
       
      This example illustrates how to obtain a DataApiNamespace instance for a specified namespace name, which then enables the execution of various database operations within that namespace. It highlights the method's role in facilitating direct interaction with different parts of the database.
      Specified by:
      getDatabase in interface DatabaseAdmin
      Parameters:
      namespaceName - 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:
      A DataApiNamespace instance that encapsulates the operations and information specific to the given namespace.
    • getDatabase

      public Database getDatabase(String namespaceName, String userToken)
      Access the Database associated with this admin class.
      Specified by:
      getDatabase in interface DatabaseAdmin
      Parameters:
      namespaceName - the destination namespace for this database
      userToken - the user token with DML access if different from admin.
      Returns:
      instance of the database
    • createNamespace

      public void createNamespace(String namespace)
      Create a Namespace providing a name.
      Specified by:
      createNamespace in interface DatabaseAdmin
      Parameters:
      namespace - current namespace.
    • createNamespace

      public void createNamespace(String namespace, NamespaceOptions options)
      Allow to create a namespace with full-fledged definition
      Parameters:
      namespace - namespace name
      options - options to create a namespace
    • 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.
    • getApiEndpoint

      protected String getApiEndpoint()
      The subclass should provide the endpoint, url to post request.
      Specified by:
      getApiEndpoint in class AbstractCommandRunner
      Returns:
      url on which to post the request
    • registerListener

      public void registerListener(String logger, CommandObserver commandObserver)
      Register a listener to execute commands on the collection. Please now use CommandOptions.
      Parameters:
      logger - name for the logger
      commandObserver - class for the logger