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

CAST supports Azure Cosmos DB via its NoSQL for .NET extension. Details about how this support is provided for .NET source code is discussed below.

Supported Client Libraries

Supported Operations

OperationMethods Supported
Create
  • CreateDocumentCollectionAsync
  • CreateDocumentCollectionIfNotExistsAsync
Insert
  • CreateDocumentAsync
Update
  • ReplaceDocumentAsync
  • ReplaceDocumentCollectionAsync
Select
  • ReadDocumentAsync
  • ReadDocumentCollectionAsync
  • CreateDocumentQuery
Delete
  • DeleteDocumentAsync
  • DeleteDocumentCollectionAsync

Objects

IconDescription

DotNet CosmosDB Database

DotNet CosmosDB Collection

 

DotNet CosmosDB Unknown Database 

 

DotNet CosmosDB Unknown Collection 

Links are created for transaction and function point needs:

Link typeWhen is this created? Methods Supported
parentLink

Between Azure CosmosDB database object and Azure CosmosDB collection object


useLinkBetween the caller .NET Method objects and Azure CosmosDB collection object


  • CreateDocumentCollectionAsync
  • CreateDocumentCollectionIfNotExistsAsync

useInsertLink

  •  CreateDocumentAsync
useUpdateLink
  • ReplaceDocumentAsync
  • ReplaceDocumentCollectionAsync
useSelectLink
  • ReadDocumentAsync
  • ReadDocumentCollectionAsync
  • CreateDocumentQuery
useDeletetLink
  • DeleteDocumentAsync
  • DeleteDocumentCollectionAsync

What results can you expect?

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

Azure Cosmos DB Database and Table Creation

public class CosmosDBApplication 
{
	private const string EndpointUrl = .......;
	private const string PrimaryKey = .........;
	private DocumentClient client ;
	private string databaseName = "FamilyDatabase";
	private string collName = "FamilyCollection";

	public static void Main()
	 {
		this.client = new DocumentClient(new Uri(EndpointUrl), PrimaryKey);
	}
	private async Task CreateDatabase()
        {
            Database db1 = await this.client.CreateDatabaseIfNotExistsAsync(new Database { Id = databaseName }).Result;
            Database db2 = this.client.CreateDatabaseIfNotExistsAsync(new Database { Id = "FamilyDatabase2" }).Result;
        }
        private async Task CreateCollection()
        {
            //Creating DocumentCollection using UriFactory
            await this.client.CreateDocumentCollectionIfNotExistsAsync(UriFactory.CreateDatabaseUri("FamilyDatabase"), new DocumentCollection {Id = 
                   "FamilyCollection"});
             // Creating Document Collection using string Link
            await this.client.CreateDocumentCollectionIfNotExistsAsync("dbs/FamilyDatabase", new DocumentCollection {Id = "FamilyCollection2"});
            // Creating DatabaseUri
            var databaseUri = UriFactory.CreateDatabaseUri("FamilyDatabase2");
            this.client.CreateDocumentCollectionIfNotExistsAsync(databaseUri, new DocumentCollection {Id = "FamilyCollectionNewWay"});
        }
}

Insert Operation

PutItem
private async InsertDocument(Family family){
            await this.client.CreateDocumentAsync(UriFactory.CreateDocumentCollectionUri(databaseName, collName), family);
}

Select Operation

ReadDocumentAsync
private async Task ReadDocument(Family family){
            await this.client.ReadDocumentAsync(UriFactory.CreateDocumentUri(databaseName, collName, family.Id));
}

ReadDocumentCollectionAsync
private async Task ReadCollection()
{
            // Using UriFactory object
            await this.client.ReadDocumentCollectionAsync(UriFactory.CreateDocumentCollectionUri(databaseName, collName));
            //Using stringLink
            await this.client.ReadDocumentCollectionAsync("dbs/FamilyDatabase/colls/FamilyCollection2");
           //Creating DocumentCollectionUri
            var collLink = UriFactory.CreateDocumentCollectionUri("FamilyDatabase2", "FamilyCollectionNewWay");
            await this.client.ReadDocumentCollectionAsync(collLink);
}

CreateDocumentQuery
private async Task QueryData()
{
	FeedOptions queryOptions = new FeedOptions { MaxItemCount = -1 };
	IQueryable<Family> familyQuery = this.client.CreateDocumentQuery<Family>(
				  		 UriFactory.CreateDocumentCollectionUri(databaseName, collName), queryOptions)	
					        .Where(f => f.LastName == "Andersen");
}

Update Operation

ReplaceDocumentAsync
private async Task ReplaceDocument(Family updatedFamily)
{            
	await this.client.ReplaceDocumentAsync("dbs/FamilyDatabase/colls/FamilyCollection/docs/familyName", updatedFamily);
}		

ReplaceDocumentCollectionAsync
private async Task ReplaceCollection(DocumentCollection updatedColl1, DocumentCollection updatedColl2)
{            
          await this.client.ReplaceDocumentCollectionAsync(UriFactory.CreateDocumentCollectionUri(databaseName, collName), updatedColl1);
          // Creating DocumentCollectionUri
          var collectionLink = UriFactory.CreateDocumentCollectionUri("FamilyDatabase2", "FamilyCollectionNewWay");
          await this.client.ReplaceDocumentCollectionAsync(collectionLink, updatedColl2);
}

Delete Operation

DeleteDocumentAsync
private async Task DeleteDocument(string documentName)
{
            await this.client.DeleteDocumentAsync(UriFactory.CreateDocumentUri(databaseName, collName, documentName));
            Console.WriteLine("Deleted Family {0}", documentName);
}

DeleteDocumentCollectionAsync
private async Task DeleteCollection()
{
            await this.client.DeleteDocumentCollectionAsync(UriFactory.CreateDocumentCollectionUri(databaseName, collName));
            await this.client.DeleteDocumentCollectionAsync("dbs/FamilyDatabase/colls/FamilyCollection2");
}

Evolution

  • Previously, only  files consisting of relevant Azure CosmosDB imports were processed further for analysing.
  • Support has been evolved to process a  file when it does not contain Azure CosmosDB import but makes use of its methods (APIs). Assumption here is file makes use of same namespace as used in the file containing Azure CosmosDB imports.

Limitations

  • Database and collection names are resolved as known objects only in the following situations:
    • Name is hardcoded
    • Name is defined in the variable in the local method
    • Name is defined as C# field
    • Name is provided in the App.config file
    • Database object is used while creating the database
    • DocumentCollection object is used while creating the collection

Future development

  • Resolving the database/collection name when passed as arguments in methods
  • No labels