Search in sources :

Example 6 with CosmosDatabaseResponse

use of com.azure.cosmos.models.CosmosDatabaseResponse in project azure-cosmos-java-sql-api-samples by Azure-Samples.

the class SamplePatchQuickstart method createDatabaseIfNotExists.

private void createDatabaseIfNotExists() throws Exception {
    logger.info("Create database {} if not exists.", databaseName);
    // Create database if not exists
    // <CreateDatabaseIfNotExists>
    CosmosDatabaseResponse databaseResponse = client.createDatabaseIfNotExists(databaseName);
    database = client.getDatabase(databaseResponse.getProperties().getId());
    // </CreateDatabaseIfNotExists>
    logger.info("Checking database {} completed!\n", database.getId());
}
Also used : CosmosDatabaseResponse(com.azure.cosmos.models.CosmosDatabaseResponse)

Example 7 with CosmosDatabaseResponse

use of com.azure.cosmos.models.CosmosDatabaseResponse in project azure-cosmos-java-sql-api-samples by Azure-Samples.

the class QueriesQuickstart method createDatabaseIfNotExists.

// Database Create
private void createDatabaseIfNotExists() throws Exception {
    logger.info("Create database " + databaseName + " if not exists...");
    // Create database if not exists
    CosmosDatabaseResponse databaseResponse = client.createDatabaseIfNotExists(databaseName);
    database = client.getDatabase(databaseResponse.getProperties().getId());
    logger.info("Done.");
}
Also used : CosmosDatabaseResponse(com.azure.cosmos.models.CosmosDatabaseResponse)

Example 8 with CosmosDatabaseResponse

use of com.azure.cosmos.models.CosmosDatabaseResponse in project azure-cosmos-java-sql-api-samples by Azure-Samples.

the class SampleCRUDQuickstart method createDatabaseIfNotExists.

private void createDatabaseIfNotExists() throws Exception {
    logger.info("Create database " + databaseName + " if not exists.");
    // Create database if not exists
    // <CreateDatabaseIfNotExists>
    CosmosDatabaseResponse databaseResponse = client.createDatabaseIfNotExists(databaseName);
    database = client.getDatabase(databaseResponse.getProperties().getId());
    // </CreateDatabaseIfNotExists>
    logger.info("Checking database " + database.getId() + " completed!\n");
}
Also used : CosmosDatabaseResponse(com.azure.cosmos.models.CosmosDatabaseResponse)

Example 9 with CosmosDatabaseResponse

use of com.azure.cosmos.models.CosmosDatabaseResponse in project testcontainers-java by testcontainers.

the class CosmosDBEmulatorContainerTest method testWithCosmosClient.

// }
@Test
public void testWithCosmosClient() throws Exception {
    // buildAndSaveNewKeyStore {
    Path keyStoreFile = tempFolder.newFile("azure-cosmos-emulator.keystore").toPath();
    KeyStore keyStore = emulator.buildNewKeyStore();
    keyStore.store(new FileOutputStream(keyStoreFile.toFile()), emulator.getEmulatorKey().toCharArray());
    // }
    // setSystemTrustStoreParameters {
    System.setProperty("javax.net.ssl.trustStore", keyStoreFile.toString());
    System.setProperty("javax.net.ssl.trustStorePassword", emulator.getEmulatorKey());
    System.setProperty("javax.net.ssl.trustStoreType", "PKCS12");
    // }
    // buildClient {
    CosmosAsyncClient client = new CosmosClientBuilder().gatewayMode().endpointDiscoveryEnabled(false).endpoint(emulator.getEmulatorEndpoint()).key(emulator.getEmulatorKey()).buildAsyncClient();
    // }
    // testWithClientAgainstEmulatorContainer {
    CosmosDatabaseResponse databaseResponse = client.createDatabaseIfNotExists("Azure").block();
    Assertions.assertThat(databaseResponse.getStatusCode()).isEqualTo(201);
    CosmosContainerResponse containerResponse = client.getDatabase("Azure").createContainerIfNotExists("ServiceContainer", "/name").block();
    Assertions.assertThat(containerResponse.getStatusCode()).isEqualTo(201);
// }
}
Also used : Path(java.nio.file.Path) CosmosClientBuilder(com.azure.cosmos.CosmosClientBuilder) CosmosDatabaseResponse(com.azure.cosmos.models.CosmosDatabaseResponse) FileOutputStream(java.io.FileOutputStream) CosmosAsyncClient(com.azure.cosmos.CosmosAsyncClient) KeyStore(java.security.KeyStore) CosmosContainerResponse(com.azure.cosmos.models.CosmosContainerResponse) Test(org.junit.Test)

Example 10 with CosmosDatabaseResponse

use of com.azure.cosmos.models.CosmosDatabaseResponse in project DataSpaceConnector by eclipse-dataspaceconnector.

the class CosmosContractDefinitionStoreIntegrationTest method deleteDatabase.

@AfterAll
static void deleteDatabase() {
    if (database != null) {
        CosmosDatabaseResponse delete = database.delete();
        assertThat(delete.getStatusCode()).isGreaterThanOrEqualTo(200).isLessThan(300);
    }
}
Also used : CosmosDatabaseResponse(com.azure.cosmos.models.CosmosDatabaseResponse) AfterAll(org.junit.jupiter.api.AfterAll)

Aggregations

CosmosDatabaseResponse (com.azure.cosmos.models.CosmosDatabaseResponse)31 CosmosDatabaseRequestOptions (com.azure.cosmos.models.CosmosDatabaseRequestOptions)8 AfterAll (org.junit.jupiter.api.AfterAll)5 BeforeAll (org.junit.jupiter.api.BeforeAll)4 CosmosClientBuilder (com.azure.cosmos.CosmosClientBuilder)3 CosmosContainerResponse (com.azure.cosmos.models.CosmosContainerResponse)3 ThroughputProperties (com.azure.cosmos.models.ThroughputProperties)3 CosmosDiagnostics (com.azure.cosmos.CosmosDiagnostics)2 CosmosContainerProperties (com.azure.cosmos.models.CosmosContainerProperties)2 ArrayList (java.util.ArrayList)2 TypeManager (org.eclipse.dataspaceconnector.spi.types.TypeManager)2 ConsistencyLevel (com.azure.cosmos.ConsistencyLevel)1 CosmosAsyncClient (com.azure.cosmos.CosmosAsyncClient)1 CosmosClient (com.azure.cosmos.CosmosClient)1 CosmosContainer (com.azure.cosmos.CosmosContainer)1 CosmosDatabase (com.azure.cosmos.CosmosDatabase)1 AccountSettings (com.azure.cosmos.examples.common.AccountSettings)1 Profile (com.azure.cosmos.examples.common.Profile)1 CosmosItemResponse (com.azure.cosmos.models.CosmosItemResponse)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1