Closeable
, AutoCloseable
Provides a client-side logical representation of the Azure Cosmos DB service. Calls to CosmosClient API's are blocked for completion.CosmosClient is thread-safe. It's recommended to maintain a single instance of CosmosClient per lifetime of the application which enables efficient connection management and performance. CosmosClient initialization is a heavy operation - don't use initialization CosmosClient instances as credentials or network connectivity validations.
Method Summary
All MethodsInstance MethodsConcrete Methods
void
Creates a Cosmos database.
Creates a database.
Creates a Cosmos database.
Creates a Cosmos database.
Creates a Cosmos database.
Creates a Cosmos database.
Create a Cosmos database if it does not already exist on the service.
Create a Cosmos database if it does not already exist on the service.
Gets the Cosmos database instance without making a service call.
Query a Cosmos database.
Query a Cosmos database.
Reads all Cosmos databases.
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Method Details
createDatabaseIfNotExists
Create a Cosmos database if it does not already exist on the service.ThroughputProperties throughputProperties = ThroughputProperties .createAutoscaledThroughput(autoScaleMaxThroughput); cosmosClient.createDatabaseIfNotExists(databaseName, throughputProperties);
The throughputProperties will only be used if the specified database does not exist and therefor a new database will be created with throughputProperties. Parameters:id
- the id of the database.throughputProperties
- the throughputProperties. Returns: theCosmosDatabaseResponse
with the created database.createDatabaseIfNotExists
Create a Cosmos database if it does not already exist on the service.CosmosDatabaseProperties databaseProperties = new CosmosDatabaseProperties(databaseName); cosmosClient.createDatabaseIfNotExists(databaseProperties);
Parameters:id
- the id of the database. Returns: theCosmosDatabaseResponse
with the created database.createDatabase
Creates a database.CosmosDatabaseProperties databaseProperties = new CosmosDatabaseProperties(databaseName); cosmosClient.createDatabase(databaseProperties);
Parameters:databaseProperties
-CosmosDatabaseProperties
the database properties.options
- the request options. Returns: theCosmosDatabaseResponse
with the created database. Throws:CosmosException
- if resource with specified id already existscreateDatabase
Creates a Cosmos database.CosmosDatabaseProperties databaseProperties = new CosmosDatabaseProperties(databaseName); cosmosClient.createDatabase(databaseProperties);
Parameters:databaseProperties
-CosmosDatabaseProperties
the database properties. Returns: theCosmosDatabaseResponse
with the created database. Throws:CosmosException
- if resource with specified id already existscreateDatabase
Creates a Cosmos database.CosmosDatabaseProperties databaseProperties = new CosmosDatabaseProperties(databaseName); cosmosClient.createDatabase(databaseProperties);
Parameters:id
- the id of the database. Returns: theCosmosDatabaseResponse
with the created database. Throws:CosmosException
- if resource with specified id already existscreateDatabase
Creates a Cosmos database.ThroughputProperties throughputProperties = ThroughputProperties .createAutoscaledThroughput(autoScaleMaxThroughput); cosmosClient.createDatabase(databaseName, throughputProperties);
Parameters:databaseProperties
-CosmosDatabaseProperties
the database properties.throughputProperties
- the throughput properties.options
-CosmosDatabaseRequestOptions
the request options. Returns: theCosmosDatabaseResponse
with the created database. Throws:CosmosException
- if resource with specified id already existscreateDatabase
Creates a Cosmos database.ThroughputProperties throughputProperties = ThroughputProperties .createAutoscaledThroughput(autoScaleMaxThroughput); cosmosClient.createDatabase(databaseName, throughputProperties);
Parameters:databaseProperties
-CosmosDatabaseProperties
the database properties.throughputProperties
- the throughput properties. Returns: theCosmosDatabaseResponse
with the created database. Throws:CosmosException
- if resource with specified id already existscreateDatabase
Creates a Cosmos database.ThroughputProperties throughputProperties = ThroughputProperties .createAutoscaledThroughput(autoScaleMaxThroughput); cosmosClient.createDatabase(databaseName, throughputProperties);
Parameters:id
- the id of the database.throughputProperties
- the throughput properties. Returns: theCosmosDatabaseResponse
with the created database. Throws:CosmosException
- if resource with specified id already existsreadAllDatabases
Reads all Cosmos databases.CosmosPagedIterable<CosmosDatabaseProperties> cosmosDatabaseProperties = cosmosClient.readAllDatabases(); cosmosDatabaseProperties.forEach(databaseProperties -> { System.out.println(databaseProperties); });
Returns: theCosmosPagedIterable
for feed response with the read databases.queryDatabases
Query a Cosmos database.CosmosQueryRequestOptions options = new CosmosQueryRequestOptions(); CosmosPagedIterable<CosmosDatabaseProperties> databaseProperties = cosmosClient.queryDatabases("select * from d", options); databaseProperties.forEach(properties -> { System.out.println(properties.getId()); });
Parameters:query
- the query.options
-CosmosQueryRequestOptions
the feed options. Returns: theCosmosPagedIterable
for feed response with the obtained databases.queryDatabases
Query a Cosmos database.CosmosQueryRequestOptions options = new CosmosQueryRequestOptions(); CosmosPagedIterable<CosmosDatabaseProperties> databaseProperties = cosmosClient.queryDatabases("select * from d", options); databaseProperties.forEach(properties -> { System.out.println(properties.getId()); });
Parameters:querySpec
-SqlQuerySpec
the query spec.options
- the query request options. Returns: theCosmosPagedIterable
for feed response with the obtained databases.getDatabase
Gets the Cosmos database instance without making a service call.
Parameters:id
- the id of the database. Returns:CosmosDatabase
the cosmos sync database.close
public void close()
Specified by:close
in interfaceAutoCloseable
Specified by:close
in interfaceCloseable
createGlobalThroughputControlConfigBuilder
Parameters:databaseId
- The database id of the control container.containerId
- The container id of the control container. Returns: AGlobalThroughputControlConfigBuilder
.
Visit the Azure for Java Developers site for more Java documentation, including quick starts, tutorials, and code samples.
ncG1vNJzZmiZqqq%2Fpr%2FDpJuom6Njr627wWeaqKqVY8SqusOorqxmnprBcHDWnploopGrrnCt2a6pnmWTpMCuu9Joa2dtZ2N9cK%2FOpmaasqWnsnCvzqykqKtfeLy0uc6seqWhlaPBb7TTpqM%3D