Package com.datastax.astra.client.admin
Class DataAPIDatabaseAdmin
java.lang.Object
com.datastax.astra.internal.command.AbstractCommandRunner
com.datastax.astra.client.admin.DataAPIDatabaseAdmin
- All Implemented Interfaces:
DatabaseAdmin,CommandRunner
Implementation of Client.
-
Field Summary
FieldsFields inherited from class com.datastax.astra.internal.command.AbstractCommandRunner
commandOptions, httpClient -
Constructor Summary
ConstructorsConstructorDescriptionInitialize a database admin from token and database id.DataAPIDatabaseAdmin(String apiEndpoint, String token, DataAPIOptions options) Initialize a database admin from token and database id. -
Method Summary
Modifier and TypeMethodDescriptionvoidcreateKeyspace(String keyspace, boolean updateDBKeyspace) Create a Keyspace providing a name.voidcreateKeyspace(String keyspace, KeyspaceOptions options) Allow to create a keyspace with full-fledged definitionvoidcreateNamespace(String keyspace, boolean updateDBKeyspace) Deprecated.voidcreateNamespace(String namespace, NamespaceOptions options) Deprecated.voiddropKeyspace(String keyspace) Drops (deletes) the specified keyspace from the database.voiddropNamespace(String namespace) Deprecated.Retrieve the list of embedding providers available in the current database.protected StringThe subclass should provide the endpoint, url to post request.Access the Database associated with this admin class.getDatabase(String keyspace) Retrieves aDatabaseinstance that represents a specific database (or namespace) based on the provided namespace name.getDatabase(String keyspace, String userToken) Access the Database associated with this admin class.Retrieves a stream of keyspaces names available in the current database.Deprecated.voidregisterListener(String logger, CommandObserver commandObserver) Register a listener to execute commands on the collection.Methods inherited from class com.datastax.astra.internal.command.AbstractCommandRunner
mapAsDocument, runCommand, runCommandMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.datastax.astra.client.model.CommandRunner
runCommand, runCommandMethods inherited from interface com.datastax.astra.client.admin.DatabaseAdmin
createKeyspace, createKeyspaceAsync, createNamespace, createNamespaceAsync, dropKeyspaceAsync, dropNamespaceAsync, keyspaceExists, listKeyspacesNamesAsync, listNamespaceNamesAsync, namespaceExists
-
Field Details
-
db
Database if initialized from the DB.
-
-
Constructor Details
-
DataAPIDatabaseAdmin
Initialize a database admin from token and database id.- Parameters:
apiEndpoint- api endpoint.token- token valueoptions- list of options for the admin
-
DataAPIDatabaseAdmin
Initialize a database admin from token and database id.- Parameters:
db- current database instance
-
-
Method Details
-
listKeyspaceNames
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:
listKeyspaceNamesin interfaceDatabaseAdmin- Returns:
- A
Setcontaining 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.
-
listNamespaceNames
Deprecated.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:
listNamespaceNamesin interfaceDatabaseAdmin- Returns:
- A
Setcontaining 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
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 toEmbeddingProviderinstances, 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:
findEmbeddingProvidersin interfaceDatabaseAdmin- Returns:
- list of available providers
-
getDatabase
Access the Database associated with this admin class.- Specified by:
getDatabasein interfaceDatabaseAdmin- Returns:
- associated database
-
getDatabase
Retrieves aDatabaseinstance that represents a specific database (or namespace) based on the provided namespace name.Example usage:
This example illustrates how to obtain a// Assume 'client' is an instance of your data API client String keyspace = "exampleNamespace"; // Retrieve the namespace instance DataApiNamespace namespace = client.getNamespace(keyspace); // Now, 'namespace' can be used to perform operations within 'exampleNamespace'DataApiNamespaceinstance 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:
getDatabasein interfaceDatabaseAdmin- Parameters:
keyspace- The name of the keyspace to retrieve. This parameter should match the exact name of the namespace as it exists in the database.- Returns:
- A
DataApiNamespaceinstance that encapsulates the operations and information specific to the given keyspace.
-
getDatabase
Access the Database associated with this admin class.- Specified by:
getDatabasein interfaceDatabaseAdmin- Parameters:
keyspace- the destination keyspace for this databaseuserToken- the user token with DML access if different from admin.- Returns:
- instance of the database
-
createNamespace
Deprecated.Create a Keyspace providing a name.- Specified by:
createNamespacein interfaceDatabaseAdmin- Parameters:
keyspace- current keyspace.updateDBKeyspace- if the keyspace should be updated in the database.
-
createKeyspace
Create a Keyspace providing a name.- Specified by:
createKeyspacein interfaceDatabaseAdmin- Parameters:
keyspace- current keyspace.updateDBKeyspace- if the keyspace should be updated in the database.
-
createNamespace
Deprecated.usecreateKeyspace(String, KeyspaceOptions)insteadAllow to create a namespace with full-fledged definition- Parameters:
namespace- namespace nameoptions- options to create a namespace
-
createKeyspace
Allow to create a keyspace with full-fledged definition- Parameters:
keyspace- keyspace nameoptions- options to create a namespace
-
dropNamespace
Deprecated.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:
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.// 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- Specified by:
dropNamespacein interfaceDatabaseAdmin- 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
Description copied from interface:DatabaseAdminDrops (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:
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.// 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- Specified by:
dropKeyspacein interfaceDatabaseAdmin- Parameters:
keyspace- 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.
-
getApiEndpoint
The subclass should provide the endpoint, url to post request.- Specified by:
getApiEndpointin classAbstractCommandRunner- Returns:
- url on which to post the request
-
registerListener
Register a listener to execute commands on the collection. Please now useCommandOptions.- Parameters:
logger- name for the loggercommandObserver- class for the logger
-
createKeyspace(String, KeyspaceOptions)instead