Package com.datastax.astra.client.admin
Class AstraDBDatabaseAdmin
java.lang.Object
com.datastax.astra.internal.command.AbstractCommandRunner<AdminOptions>
com.datastax.astra.client.admin.AstraDBDatabaseAdmin
- All Implemented Interfaces:
DatabaseAdmin
,CommandRunner
public class AstraDBDatabaseAdmin
extends AbstractCommandRunner<AdminOptions>
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 Summary
Fields inherited from class com.datastax.astra.internal.command.AbstractCommandRunner
apiEndpoint, ARG_CLAZZ, ARG_DATABASE, ARG_OPTIONS, ARG_UPDATE, httpClient, INPUT_INCLUDE_SIMILARITY, INPUT_INCLUDE_SORT_VECTOR, INPUT_ORDERED, INPUT_PAGE_STATE, INPUT_RETURN_DOCUMENT, INPUT_RETURN_DOCUMENT_RESPONSES, INPUT_UPSERT, options, RESULT_COUNT, RESULT_DELETED_COUNT, RESULT_INSERTED_IDS, RESULT_MATCHED_COUNT, RESULT_MODIFIED_COUNT, RESULT_MORE_DATA, RESULT_UPSERTED_ID
-
Constructor Summary
ConstructorDescriptionAstraDBDatabaseAdmin
(Database db, AdminOptions adminOptions) Initialize a database admin from token and database id.AstraDBDatabaseAdmin
(String token, UUID databaseId, DataAPIClientOptions clientOptions) Initialize a database admin from token and database id. -
Method Summary
Modifier and TypeMethodDescriptionvoid
createKeyspace
(String keyspace, boolean updateDBKeyspace) Create a Keyspace providing a name.void
dropKeyspace
(String keyspace) Drops (deletes) the specified keyspace from the database.void
dropKeyspace
(String keyspace, BaseOptions<?> options) Drops (deletes) the specified keyspace from the database.Retrieve the list of embedding providers available in the current database.Get the API endpoint for the current database.Access the Database associated with this admin class.getDatabase
(String keyspace) Access teh database with the default token.getDatabase
(String keyspace, String tokenUser) Access teh database with the specialized token.com.dtsx.astra.sdk.db.domain.Database
Find a database from its id.Retrieves a stream of keyspaces names available in the current database.Methods inherited from class com.datastax.astra.internal.command.AbstractCommandRunner
assertIsAstra, getOptions, getSerializer, runCommand, runCommand, unmarshall
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.datastax.astra.client.core.commands.CommandRunner
runCommand, runCommand
Methods inherited from interface com.datastax.astra.client.admin.DatabaseAdmin
createKeyspace, createKeyspaceAsync, dropKeyspaceAsync, keyspaceExists, listKeyspacesNamesAsync
-
Constructor Details
-
AstraDBDatabaseAdmin
Initialize a database admin from token and database id.- Parameters:
db
- target databaseadminOptions
- options to use for the admin operations like timeouts
-
AstraDBDatabaseAdmin
Initialize a database admin from token and database id.- Parameters:
token
- token valuedatabaseId
- database identifierclientOptions
- 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
-
getApiEndpoint
Get the API endpoint for the current database.- Overrides:
getApiEndpoint
in classAbstractCommandRunner<AdminOptions>
- Returns:
- the endpoint as an url.
-
getDatabase
Access teh database with the default token.- Specified by:
getDatabase
in interfaceDatabaseAdmin
- 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
Access teh database with the specialized token.- Specified by:
getDatabase
in interfaceDatabaseAdmin
- 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.
-
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:
listKeyspaceNames
in interfaceDatabaseAdmin
- 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
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 toEmbeddingProvider
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 interfaceDatabaseAdmin
- Returns:
- list of available providers
-
createKeyspace
Create a Keyspace providing a name.- Specified by:
createKeyspace
in interfaceDatabaseAdmin
- Parameters:
keyspace
- current keyspace.updateDBKeyspace
- if the keyspace should be updated in the database.
-
dropKeyspace
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 keyspace client.dropKeyspace(keyspace); // The keyspace 'targetKeyspace' is now deleted, along with all its contained data
- Specified by:
dropKeyspace
in 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.
-
dropKeyspace
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 keyspace client.dropKeyspace(keyspace); // The keyspace 'targetKeyspace' is now deleted, along with all its contained data
- Specified by:
dropKeyspace
in 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.options
- The options to use for the operation.
-
getDatabase
Access the Database associated with this admin class.- Specified by:
getDatabase
in interfaceDatabaseAdmin
- Returns:
- associated database
-