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, options, OPTIONS_HYBRID_LIMITS, OPTIONS_INCLUDE_SCORES, OPTIONS_INCLUDE_SIMILARITY, OPTIONS_INCLUDE_SORT_VECTOR, OPTIONS_LIMIT, OPTIONS_ORDERED, OPTIONS_PAGE_STATE, OPTIONS_RERANK_ON, OPTIONS_RERANK_QUERY, OPTIONS_RETURN_DOCUMENT, OPTIONS_RETURN_DOCUMENT_RESPONSES, OPTIONS_UPSERT, RESULT_COUNT, RESULT_DELETED_COUNT, RESULT_INSERTED_IDS, RESULT_MATCHED_COUNT, RESULT_MODIFIED_COUNT, RESULT_MORE_DATA, RESULT_UPSERTED_ID -
Constructor Summary
ConstructorsConstructorDescriptionAstraDBDatabaseAdmin(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 TypeMethodDescriptionvoidcreateKeyspace(KeyspaceDefinition keyspace, CreateKeyspaceOptions options) Create a Keyspace providing a name.voidcreateKeyspace(String keyspace) Syntax Sugar, retro compatible.voiddropKeyspace(String keyspace) Drops (deletes) the specified keyspace from the database.voiddropKeyspace(String keyspace, DropKeyspaceOptions options) Drops (deletes) the specified keyspace from the database.Retrieve the list of embedding providers available in the current database.Retrieve the list of reranking 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) 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.getDatabase(String keyspace, String userToken, DatabaseOptions options) Access the Database associated with this admin class providing extra optionscom.dtsx.astra.sdk.db.domain.DatabaseFind 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, unmarshallMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.datastax.astra.client.core.commands.CommandRunner
runCommand, runCommandMethods inherited from interface com.datastax.astra.client.admin.DatabaseAdmin
createKeyspace, createKeyspaceAsync, dropKeyspaceAsync, dropKeyspaceAsync, findEmbeddingProviders, findRerankingProviders, keyspaceExists, listKeyspaceNamesAsync
-
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:
getApiEndpointin classAbstractCommandRunner<AdminOptions>- Returns:
- the endpoint as an url.
-
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
Description copied from interface:DatabaseAdminAccess the Database associated with this admin class providing extra options- Specified by:
getDatabasein interfaceDatabaseAdmin- Returns:
- associated database
-
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
-
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.
-
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.- Specified by:
findEmbeddingProvidersin interfaceDatabaseAdmin- Parameters:
options- Defines options for the operation, such as filtering by model status or other criteria.Example usage:
// Assuming 'client' is an instance of DataApiClient Map<String, EmbeddingProvider> providers = client.findEmbeddingProvidersAsMap());- Returns:
- list of available providers
-
findRerankingProviders
Retrieve the list of reranking providers available in the current database. Reranking providers are services that sort a list of record based on a algorithm (eg bm25) . This method returns a map of provider names toRerankProviderinstances, allowing applications to access and utilize the reranking services.Example usage:
// Assuming 'client' is an instance of DataApiClient Map<String, EmbeddingProvider> providers = client.findEmbeddingProvidersAsMap());- Specified by:
findRerankingProvidersin interfaceDatabaseAdmin- Parameters:
options- options to perform a reranking operation- Returns:
- list of available providers
-
createKeyspace
Syntax Sugar, retro compatible.- Specified by:
createKeyspacein interfaceDatabaseAdmin- Parameters:
keyspace- current namespace.
-
createKeyspace
Description copied from interface:DatabaseAdminCreate a Keyspace providing a name.- Specified by:
createKeyspacein interfaceDatabaseAdmin- Parameters:
keyspace- keyspace definitionoptions- options to create the keyspace
-
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:
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 keyspace client.dropKeyspace(keyspace); // The keyspace '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.
-
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:
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 keyspace client.dropKeyspace(keyspace); // The keyspace '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.options- The options to use for the operation.
-