Page tree
Skip to end of metadata
Go to start of metadata

CAST supports Azure Cosmos DB via its NoSQL for Java extension. Details about the support provided for Java source code is explained below.

Supported Client Libraries

Supported Operations

OperationsMethod Supported
Insert
  • CreateDocument
Update
  • ReplaceDocument
Select
  • ReadDocument
  • ReadDocuments
  • QueryDocuments
  • ReadCollection
Delete
  • DeleteDocument
  • DeleteCollection

Above mentioned methods are supported for both Synchronous and Asynchronous clients.

Objects

Icon

Description

Java CosmosDB Database

Java CosmosDB Collection

Java Unknown CosmosDB Database

Java Unknown CosmosDB Collection

Links are created for transaction and function point needs:

Link typeSource and destination of linkMethods Supported
parentLink

Between CosmosDB Database object and CosmosDB Collection


useLinkBetween the caller Java Method objects and CosmosDB Collection
  • CreateCollection
useInsertLink
  • CreateDocument
useUpdateLink
  • ReplaceDocument

useSelectLink

  • ReadDocument
  • ReadDocuments
  • QueryDocuments
  • ReadCollection
useDeleteLink
  • DeleteDocument
  • DeleteCollection

What results can you expect?

Once the analysis/snapshot generation is completed, you can view the results in the normal manner (for example via CAST Enlighten). Some examples are shown below.

Cosmos DB Client Creation

Cosmos DB Client Creation
private static final String HOST = "[YOUR_ENDPOINT_HERE]";
 private static final String MASTER_KEY = "[YOUR_KEY_HERE]";
 
 private static DocumentClient documentClient = new DocumentClient(HOST, MASTER_KEY,
                 ConnectionPolicy.GetDefault(), ConsistencyLevel.Session);
 
 public static DocumentClient getDocumentClient() {
     return documentClient;
 }

Insert Data Operation

CreateDocument
	public static Family andersenFamily = new Family();

	public void TestCreateDocument() throws DocumentClientException {
		// Insert your Java objects as documents
		System.out.println("Creating doc");

		andersenFamily.setId("Andersen.1");
		andersenFamily.setLastName("Andersen");

		this.client.createDocument("/dbs/familydb/colls/familycoll", andersenFamily, new RequestOptions(), true);

		System.out.println("Done Creating doc");
	}

Select Operation

QueryDocuments
public void TestQueryDocuments() {

		System.out.println("Querying db...");
		FeedResponse<Document> queryResults = this.client.queryDocuments("/dbs/familydb/colls/familycoll",
				"SELECT * FROM Family WHERE Family.id = 'Andersen.1'", null);

		System.out.println("Running SQL query...");
		for (Document family : queryResults.getQueryIterable()) {
			System.out.println(String.format("\tRead %s", family));
		}

	}

Read Document
	public void TestReadDocument() throws DocumentClientException {
		this.client.readDocument("/dbs/familydb/colls/familycoll/docs/Andersen.1", null);
	}

ReadDocuments
public void TestReadDocuments() throws DocumentClientException {
		this.client.readDocuments("/dbs/familydb", null);
	}

Update Operation

ReplaceDocument
public void TestReplaceDocument() throws DocumentClientException {
		// Update a property
		andersenFamily.setLastName("Petersons");
		this.client.replaceDocument("/dbs/familydb/colls/familycoll/docs/Andersen.1", andersenFamily, null);
	}

Delete Operation

DeleteDocument
public void TestDeleteDocument() throws DocumentClientException {
		this.client.deleteDocument("", null);
	}

Support for Collection based methods are provided, for example:

  • createCollection
  • deleteCollection
  • readCollection

Asynchronous API

All corresponding methods are represented and results are very similar to its Synchronous counterpart:

Async Client creation
import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient;
    
public AsyncDocumentClient client = new AsyncDocumentClient.Builder()
            .withServiceEndpoint(AccountSettings.HOST)
            .withMasterKeyOrResourceToken(AccountSettings.MASTER_KEY)
            .withConnectionPolicy(ConnectionPolicy.GetDefault())
            .withConsistencyLevel(ConsistencyLevel.Eventual)
            .build();

Limitations

Major limitations

No support for Cassandra API, MongoDB API, Gremlin API, Table API or other APIs built by Microsoft for accessing an Azure Cosmos DB service. See the API reference here:

Minor limitations     

  • Database and collection names are resolved as known objects when a connection string is passed to the client directly

    • Example: This connection string is passed to client - "/dbs/familydb/colls/familycoll" 

  • Database and collection are marked as Unknown when Database Collection and document objects are passed as an argument in CRUD methods.

  • Runtime Ambiguities are not resolved

    • Example: Different databases are accessed in if/else cases based on some conditions

  • No labels