CosmosAsyncDatabase Class
- java.
lang. Object - com.
azure. cosmos. CosmosAsyncDatabase
- com.
public class CosmosAsyncDatabase
Perform read and delete databases, update database throughput, and perform operations on child resources
Method Summary
Methods inherited from java.lang.Object
Method Details
createClientEncryptionKey
public Mono
Creates a client encryption key after subscription the operation will be performed. The Mono upon successful completion will contain a single resource response with the created client encryption key. In case of failure the Mono will error.
Parameters:
Returns:
createContainer
public Mono
Creates a Cosmos container.
CosmosContainerProperties containerProperties =
new CosmosContainerProperties(containerId, partitionKeyDefinition);
cosmosAsyncDatabase.createContainer(containerProperties)
.subscribe(
cosmosContainerResponse -> System.out.println(cosmosContainerResponse),
throwable -> System.out.println("Failed to create container: " + throwable)
);
After subscription the operation will be performed. The Mono upon successful completion will contain a cosmos container response with the created container. In case of failure the Mono will error.
Parameters:
Returns:
createContainer
public Mono
Creates a Cosmos container.
CosmosContainerProperties containerProperties =
new CosmosContainerProperties(containerId, partitionKeyDefinition);
cosmosAsyncDatabase.createContainer(containerProperties)
.subscribe(
cosmosContainerResponse -> System.out.println(cosmosContainerResponse),
throwable -> System.out.println("Failed to create container: " + throwable)
);
After subscription the operation will be performed. The Mono upon successful completion will contain a cosmos container response with the created container. In case of failure the Mono will error.
Parameters:
Returns:
createContainer
public Mono
Creates a Cosmos container with custom throughput properties.
CosmosContainerProperties containerProperties =
new CosmosContainerProperties(containerId, partitionKeyDefinition);
ThroughputProperties throughputProperties =
ThroughputProperties.createAutoscaledThroughput(autoScaleMaxThroughput);
cosmosAsyncDatabase.createContainer(containerProperties, throughputProperties)
.subscribe(
cosmosContainerResponse -> System.out.println(cosmosContainerResponse),
throwable -> System.out.println("Failed to create container: " + throwable)
);
After subscription the operation will be performed. The Mono upon successful completion will contain a cosmos container response with the created container. In case of failure the Mono will error.
Parameters:
Returns:
createContainer
public Mono
Creates a container.
CosmosContainerProperties containerProperties =
new CosmosContainerProperties(containerId, partitionKeyDefinition);
cosmosAsyncDatabase.createContainer(
containerProperties,
throughput,
options
)
.subscribe(
cosmosContainerResponse -> System.out.println(cosmosContainerResponse),
throwable -> System.out.println("Failed to create container: " + throwable)
);
Parameters:
Returns:
createContainer
public Mono
Creates a Cosmos container.
ThroughputProperties throughputProperties =
ThroughputProperties.createAutoscaledThroughput(autoscaledThroughput);
cosmosAsyncDatabase.createContainer(
containerId,
partitionKeyPath,
throughputProperties
)
.subscribe(
cosmosContainerResponse -> System.out.println(cosmosContainerResponse),
throwable -> System.out.println("Failed to create container: " + throwable)
);
After subscription the operation will be performed. The Mono upon successful completion will contain a cosmos container response with the created container. In case of failure the Mono will error.
Parameters:
Returns:
createContainer
public Mono
Creates a Cosmos container.
ThroughputProperties throughputProperties =
ThroughputProperties.createAutoscaledThroughput(autoscaledThroughput);
cosmosAsyncDatabase.createContainer(
containerId,
partitionKeyPath,
throughputProperties
)
.subscribe(
cosmosContainerResponse -> System.out.println(cosmosContainerResponse),
throwable -> System.out.println("Failed to create container: " + throwable)
);
After subscription the operation will be performed. The Mono upon successful completion will contain a cosmos container response with the created container. In case of failure the Mono will error.
Parameters:
Returns:
createContainerIfNotExists
public Mono
Creates a Cosmos container if it does not exist on the service.
CosmosContainerProperties containerProperties =
new CosmosContainerProperties(containerId, partitionKeyDefinition);
cosmosAsyncDatabase.createContainerIfNotExists(containerProperties)
.subscribe(
cosmosContainerResponse -> System.out.println(cosmosContainerResponse),
throwable -> System.out.println("Failed to create container: " + throwable)
);
After subscription the operation will be performed. The Mono upon successful completion will contain a cosmos container response with the created or existing container. In case of failure the Mono will error.
Parameters:
Returns:
createContainerIfNotExists
public Mono
Creates a Cosmos container if it does not exist on the service.
CosmosContainerProperties containerProperties =
new CosmosContainerProperties(containerId, partitionKeyDefinition);
cosmosAsyncDatabase.createContainerIfNotExists(containerProperties, throughputProperties)
.subscribe(
cosmosContainerResponse -> System.out.println(cosmosContainerResponse),
throwable -> System.out.println("Failed to create container: " + throwable)
);
The throughput properties will only be used if the specified container does not exist and therefor a new container will be created.
After subscription the operation will be performed. The Mono upon successful completion will contain a cosmos container response with the created or existing container. In case of failure the Mono will error.
Parameters:
Returns:
createContainerIfNotExists
public Mono
Creates a Cosmos container if it does not exist on the service.
CosmosContainerProperties containerProperties =
new CosmosContainerProperties(containerId, partitionKeyDefinition);
cosmosAsyncDatabase.createContainerIfNotExists(containerProperties)
.subscribe(
cosmosContainerResponse -> System.out.println(cosmosContainerResponse),
throwable -> System.out.println("Failed to create container: " + throwable)
);
After subscription the operation will be performed. The Mono upon successful completion will contain a cosmos container response with the created container. In case of failure the Mono will error.
Parameters:
Returns:
createContainerIfNotExists
public Mono
Creates a Cosmos container if it does not exist on the service.
CosmosContainerProperties containerProperties =
new CosmosContainerProperties(containerId, partitionKeyDefinition);
cosmosAsyncDatabase.createContainerIfNotExists(containerProperties, throughputProperties)
.subscribe(
cosmosContainerResponse -> System.out.println(cosmosContainerResponse),
throwable -> System.out.println("Failed to create container: " + throwable)
);
The throughput properties will only be used if the specified container does not exist and therefor a new container will be created.
After subscription the operation will be performed. The Mono upon successful completion will contain a cosmos container response with the created container. In case of failure the Mono will error.
Parameters:
Returns:
createUser
public Mono
Creates a user After subscription the operation will be performed. The Mono upon successful completion will contain a single resource response with the created user. In case of failure the Mono will error.
String userId = "userId";
CosmosUserProperties userProperties = new CosmosUserProperties();
userProperties.setId(userId);
cosmosAsyncDatabase.createUser(userProperties)
.subscribe(
userResponse -> System.out.println(userResponse),
throwable -> System.out.println("Failed to create user: " + throwable)
);
Parameters:
Returns:
delete
public Mono
Deletes the current Cosmos database.
CosmosAsyncDatabase database = cosmosAsyncClient
.getDatabase("<YOUR DATABASE NAME>");
database.delete().subscribe(databaseResponse -> {
System.out.println(databaseResponse);
},
throwable -> {
throwable.printStackTrace();
});
After subscription the operation will be performed. The Mono upon successful completion will contain a cosmos database response with the deleted database. In case of failure the Mono will error.
Returns:
delete
public Mono
Deletes the current Cosmos database while specifying additional request options.
CosmosAsyncDatabase database = cosmosAsyncClient
.getDatabase("<YOUR DATABASE NAME>");
database.delete().subscribe(databaseResponse -> {
System.out.println(databaseResponse);
},
throwable -> {
throwable.printStackTrace();
});
After subscription the operation will be performed. The Mono upon successful completion will contain a cosmos database response with the deleted database. In case of failure the Mono will error.
Parameters:
Returns:
getClientEncryptionKey
public CosmosAsyncClientEncryptionKey getClientEncryptionKey(String id)
Gets a CosmosAsyncClientEncryptionKey object without making a service call
Parameters:
Returns:
getContainer
public CosmosAsyncContainer getContainer(String id)
Gets a CosmosAsyncContainer object without making a service call
Parameters:
Returns:
getId
public String getId()
Get the id of the CosmosAsyncDatabase.
Returns:
getUser
public CosmosAsyncUser getUser(String id)
Gets user.
Parameters:
Returns:
queryClientEncryptionKeys
public CosmosPagedFlux
Query for cosmos client encryption keys in a database.
After subscription the operation will be performed. The CosmosPagedFlux<T> will contain one or several feed response of the obtained client encryption keys. In case of failure the CosmosPagedFlux<T> will error.
Parameters:
Returns:
queryClientEncryptionKeys
public CosmosPagedFlux
Query for cosmos client encryption keys in a database.
After subscription the operation will be performed. The CosmosPagedFlux<T> will contain one or several feed response of the obtained client encryption keys. In case of failure the CosmosPagedFlux<T> will error.
Parameters:
Returns:
queryClientEncryptionKeys
public CosmosPagedFlux
Query for cosmos client encryption keys in a database.
After subscription the operation will be performed. The CosmosPagedFlux<T> will contain one or several feed response of the obtained client encryption keys. In case of failure the CosmosPagedFlux<T> will error.
Parameters:
Returns:
queryClientEncryptionKeys
public CosmosPagedFlux
Query for cosmos client encryption keys in a database.
After subscription the operation will be performed. The CosmosPagedFlux<T> will contain one or several feed response of the obtained client encryption keys. In case of failure the CosmosPagedFlux<T> will error.
Parameters:
Returns:
queryContainers
public CosmosPagedFlux
Query for cosmos containers in a cosmos database.
cosmosAsyncDatabase.queryContainers("SELECT * FROM DB_NAME")
.byPage()
.flatMap(containerPropertiesFeedResponse -> {
for (CosmosContainerProperties properties : containerPropertiesFeedResponse.getResults()) {
System.out.println(properties);
}
return Flux.empty();
})
.subscribe();
After subscription the operation will be performed. The CosmosPagedFlux<T> will contain one or several feed response of the obtained containers. In case of failure the CosmosPagedFlux<T> will error.
Parameters:
Returns:
queryContainers
public CosmosPagedFlux
Query for cosmos containers in a cosmos database.
cosmosAsyncDatabase.queryContainers("SELECT * FROM DB_NAME")
.byPage()
.flatMap(containerPropertiesFeedResponse -> {
for (CosmosContainerProperties properties : containerPropertiesFeedResponse.getResults()) {
System.out.println(properties);
}
return Flux.empty();
})
.subscribe();
After subscription the operation will be performed. The CosmosPagedFlux<T> will contain one or several feed response of the obtained containers. In case of failure the CosmosPagedFlux<T> will error.
Parameters:
Returns:
queryContainers
public CosmosPagedFlux
Query for cosmos containers in a cosmos database.
cosmosAsyncDatabase.queryContainers("SELECT * FROM DB_NAME")
.byPage()
.flatMap(containerPropertiesFeedResponse -> {
for (CosmosContainerProperties properties : containerPropertiesFeedResponse.getResults()) {
System.out.println(properties);
}
return Flux.empty();
})
.subscribe();
After subscription the operation will be performed. The CosmosPagedFlux<T> will contain one or several feed response of the obtained containers. In case of failure the CosmosPagedFlux<T> will error.
Parameters:
Returns:
queryContainers
public CosmosPagedFlux
Query for cosmos containers in a cosmos database.
cosmosAsyncDatabase.queryContainers("SELECT * FROM DB_NAME")
.byPage()
.flatMap(containerPropertiesFeedResponse -> {
for (CosmosContainerProperties properties : containerPropertiesFeedResponse.getResults()) {
System.out.println(properties);
}
return Flux.empty();
})
.subscribe();
After subscription the operation will be performed. The CosmosPagedFlux<T> will contain one or several feed response of the obtained containers. In case of failure the CosmosPagedFlux<T> will error.
Parameters:
Returns:
queryUsers
public CosmosPagedFlux
Query for cosmos users in a database.
After subscription the operation will be performed. The CosmosPagedFlux<T> will contain one or several feed response of the obtained users. In case of failure the CosmosPagedFlux<T> will error.
Parameters:
Returns:
queryUsers
public CosmosPagedFlux
Query for cosmos users in a database.
After subscription the operation will be performed. The CosmosPagedFlux<T> will contain one or several feed response of the obtained users. In case of failure the CosmosPagedFlux<T> will error.
Parameters:
Returns:
queryUsers
public CosmosPagedFlux
Query for cosmos users in a database.
After subscription the operation will be performed. The CosmosPagedFlux<T> will contain one or several feed response of the obtained users. In case of failure the CosmosPagedFlux<T> will error.
Parameters:
Returns:
queryUsers
public CosmosPagedFlux
Query for cosmos users in a database.
After subscription the operation will be performed. The CosmosPagedFlux<T> will contain one or several feed response of the obtained users. In case of failure the CosmosPagedFlux<T> will error.
Parameters:
Returns:
read
public Mono
Reads a database. Fetch the details and properties of a database based on its unique identifier.
CosmosAsyncDatabase database = cosmosAsyncClient
.getDatabase("<YOUR DATABASE NAME>");
database.read().subscribe(databaseResponse -> {
System.out.println(databaseResponse);
},
throwable -> {
throwable.printStackTrace();
});
After subscription the operation will be performed. The Mono upon successful completion will contain a single cosmos database response with the read database. In case of failure the Mono will error.
Returns:
read
public Mono
Reads a database. Fetch the details and properties of a database based on its unique identifier.
CosmosAsyncDatabase database = cosmosAsyncClient
.getDatabase("<YOUR DATABASE NAME>");
database.read().subscribe(databaseResponse -> {
System.out.println(databaseResponse);
},
throwable -> {
throwable.printStackTrace();
});
After subscription the operation will be performed. The Mono upon successful completion will contain a cosmos database response with the read database. In case of failure the Mono will error.
Parameters:
Returns:
readAllClientEncryptionKeys
public CosmosPagedFlux
Reads all cosmos client encryption keys in a database.
After subscription the operation will be performed. The CosmosPagedFlux<T> will contain one or several feed response of the read cosmos client encryption keys. In case of failure the CosmosPagedFlux<T> will error.
Returns:
readAllClientEncryptionKeys
public CosmosPagedFlux
Reads all cosmos client encryption keys in a database.
After subscription the operation will be performed. The CosmosPagedFlux<T> will contain one or several feed response of the read cosmos client encryption keys. In case of failure the CosmosPagedFlux<T> will error.
Parameters:
Returns:
readAllContainers
public CosmosPagedFlux
Reads all cosmos containers.
cosmosAsyncDatabase.readAllContainers()
.byPage()
.flatMap(containerPropertiesFeedResponse -> {
for (CosmosContainerProperties properties : containerPropertiesFeedResponse.getResults()) {
System.out.println(properties);
}
return Flux.empty();
})
.subscribe();
After subscription the operation will be performed. The CosmosPagedFlux<T> will contain one or several feed response of the read containers. In case of failure the CosmosPagedFlux<T> will error.
Returns:
readAllContainers
public CosmosPagedFlux
Reads all cosmos containers.
cosmosAsyncDatabase.readAllContainers()
.byPage()
.flatMap(containerPropertiesFeedResponse -> {
for (CosmosContainerProperties properties : containerPropertiesFeedResponse.getResults()) {
System.out.println(properties);
}
return Flux.empty();
})
.subscribe();
After subscription the operation will be performed. The CosmosPagedFlux<T> will contain one or several feed response of the read containers. In case of failure the CosmosPagedFlux<T> will error.
Parameters:
Returns:
readAllUsers
public CosmosPagedFlux
Reads all cosmos users in a database.
cosmosAsyncDatabase.readAllUsers()
.byPage()
.flatMap(userPropertiesFeedResponse -> {
for (CosmosUserProperties properties : userPropertiesFeedResponse.getResults()) {
System.out.println(properties);
}
return Flux.empty();
})
.subscribe();
After subscription the operation will be performed. The CosmosPagedFlux<T> will contain one or several feed response of the read cosmos users. In case of failure the CosmosPagedFlux<T> will error.
Returns:
readThroughput
public Mono
Gets the throughput of the database.
cosmosAsyncDatabase.readThroughput()
.subscribe(throughputResponse -> {
System.out.println(throughputResponse);
},
throwable -> {
throwable.printStackTrace();
});
Returns:
replaceThroughput
public Mono
Sets throughput provisioned for a container in measurement of Requests-per-Unit in the Azure Cosmos service.
ThroughputProperties autoscaledThroughput = ThroughputProperties
.createAutoscaledThroughput(autoScaleMaxThroughput);
cosmosAsyncDatabase.replaceThroughput(autoscaledThroughput)
.subscribe(throughputResponse -> {
System.out.println(throughputResponse);
},
throwable -> {
throwable.printStackTrace();
});
Parameters:
Returns:
upsertUser
public Mono
Upsert a user. Upsert will create a new user if it doesn't exist, or replace the existing one if it does. After subscription the operation will be performed. The Mono upon successful completion will contain a single resource response with the created user. In case of failure the Mono will error.
String userId = "userId";
CosmosUserProperties userProperties = new CosmosUserProperties();
userProperties.setId(userId);
cosmosAsyncDatabase.upsertUser(userProperties)
.subscribe(
userResponse -> System.out.println(userResponse),
throwable -> System.out.println("Failed to upsert user: " + throwable)
);
Parameters:
Returns: