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

CAST supports DynamoDB 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
  • CreateTable
Insert
  • PutItem
  • WriteBatchItem
Update
  • UpdateTable
  • UpdateItem
Select 
  • Query
  • Scan
  • GetItem
  • BatchGetItem
  • DescribeTable
Delete 
  • DeleteItem
  • DeleteTable

Objects

IconDescription

.NET DynamoDB Client

.NET DynamoDB Table

.NET Unknown DynamoDB Client

 

.NET Unknown DynamoDB Table 

Links are created for transaction and function point needs:

Link typeSource and destination of link Methods Supported
parentLink

Between DynamoDB client object and DynamoDB Table


useLinkBetween the caller .NET Method objects and DynamoDB tables
  •  CreateTable

useInsertink

  • PutItem
  • BatchWriteItem
useUpdateLink
  • UpdateTable
  • UpdateItem
useSelectLink
  • Query
  • Scan
  • DescribeTable
  • GetItem
  • BatchGetItem
useDeleteLink
  • DeleteItem
  • DeleteTable

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.

AmazonDynamoDB Client and Table Creation

Client and Table Creation
public partial class Program
    {
        private static string table1 = "BookDatabase";
        private static AmazonDynamoDBClient client = new AmazonDynamoDBClient();

        private static void CreateTable()
        {
            ProvisionedThroughput throughput = new ProvisionedThroughput
            {
                ReadCapacityUnits = 50,
                WriteCapacityUnits = 50
            };
            // Configure the CreateTable request
            var createTableRequest = new CreateTableRequest
            {
                TableName = table1,
                AttributeDefinitions = new List<AttributeDefinition>()
                {
                    new AttributeDefinition
                    {
                        AttributeName = "Author",
                        AttributeType = "S"
                    },
                    new AttributeDefinition
                    {
                        AttributeName = "Title",
                        AttributeType = "S"
                    }
                },
                KeySchema = new List<KeySchemaElement>()
                {
                    new KeySchemaElement
                    {
                        AttributeName = "Author",
                        KeyType = "HASH"  //Partition key
                    },
                     new KeySchemaElement
                    {
                        AttributeName = "Title",
                        KeyType = "RANGE"  //Partition key
                    }
                },
                ProvisionedThroughput = throughput
            };
            var response = client.CreateTable(createTableRequest);
        }
}

Insert Data Operation

PutItem
private static void InsertData()
{            
	    Dictionary<string, AttributeValue> attributes4 = new Dictionary<string, AttributeValue>();
            attributes4["Author"] = new AttributeValue { S = "D J Munro" };
            attributes4["Title"] = new AttributeValue { S = "Slave to Fortune" };
            attributes4["Years"] = new AttributeValue { N = "2015" };
            attributes4["Setting"] = new AttributeValue { S = "Ukraine" };
            attributes4["Pages"] = new AttributeValue { N = "364" };
            attributes4["Genres"] = new AttributeValue { SS = new List<string> { "Emotions" } };


            PutItemRequest insertRequest = new PutItemRequest
            {              
			TableName = table1,
	                Item = attributes1
            };
            client.PutItem(insertRequest);
}

Select Operation

Query
QueryRequest queryRequest = new QueryRequest
{ 
	TableName = table1, 
	KeyConditionExpression = "Author = :Author", 
	ExpressionAttributeValues = new Dictionary<string, AttributeValue> { 
				    { ":Author", new AttributeValue { S = "P G Wodehouse"} } } 
}; 
var queryResponse = client.Query(queryRequest);

Scan
var scanRequest = new ScanRequest 
{ 
	TableName = table1, 
	ExpressionAttributeValues = new Dictionary<string, AttributeValue> {
								{":years", new AttributeValue { N = "2000" }} },
	FilterExpression = "Years > :years" 
}; 
var scanResponse = client.Scan(scanRequest);

Describe
DescribeTableRequest describeRequest = new DescribeTableRequest 
{ 
	TableName = table1 
}; 
var describeResponse = client.DescribeTable(describeRequest).Table;

GetItem
GetItemRequest getRequest = new GetItemRequest 
{ 
	TableName = table1, 
	Key = keys, 
}; 
GetItemResponse r = client.GetItem(getRequest);

Update Operation

Update
var updateRequest = new UpdateTableRequest
{
	TableName = table1,
        ProvisionedThroughput = new ProvisionedThroughput()
        {
		// Provide new values.
                ReadCapacityUnits = 100,
                WriteCapacityUnits = 100
         }
};
var updateResponse = client.UpdateTable(updateRequest);        

UpdateItem
UpdateItemRequest updateRequest = new UpdateItemRequest 
{ 
	TableName = table1, 
	Key = keys, 
	AttributeUpdates = updates 
};
clientUpdate.UpdateItem(updateRequest);

 

Delete Operation

Delete
var deleteRequest = new DeleteTableRequest
{
    TableName = table1
};
var responseDelete = clientDelete.DeleteTable(deleteRequest);

DeleteItem
DeleteItemRequest deleteRequest = new DeleteItemRequest
{
    TableName = table1,
    Key = keys
};client.DeleteItem(deleteRequest);

Batch Operations

BatchWriteItem
BatchWriteItemRequest request = new BatchWriteItemRequest
{
    RequestItems = new Dictionary<string, List<WriteRequest>>
        {        {   table1, sampleTableItems1 },
                {   "StudentDatabase", sampleTableItems2 }
        }
};
BatchWriteItemResponse response = client.BatchWriteItem(request);

BatchReadItem
var request = new BatchGetItemRequest
{
    RequestItems = new Dictionary<string, KeysAndAttributes>()
        {
        {            table1, sampleTableItems2
                 },
                 { 
                       "StudentDatabase", new KeysAndAttributes
                        {
                            Keys = new List<Dictionary<string, AttributeValue> >()
                            {
                                new Dictionary<string, AttributeValue>()
                                {
                                    { "RollNo", new AttributeValue { N = "67" } }
                                },
                                new Dictionary<string, AttributeValue>()
                                {
                                    { "RollNo", new AttributeValue { N = "1310" } }
                                }
                            }
                        }
                    }
        }
};
response = client.BatchGetItem(request);

Evolution

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

Limitations

  • Client and table names are resolved as known tables only in the following situations:
    • Name is hardcoded
    • Name is defined in the variable in the local method
    • Name is defined as C# field
  • The AWS SDK For .Net provides three models for communicating with DynamoDB:

    Communication ModelNamespaceSupport
    Low-levelAmazon.DynamoDBv2Yes
    DocumentAmazon.DynamoDBv2.DocumentModelNo
    Object PersistenceAmazon.DynamoDBv2.DataModelNo

Future development

  • Resolving the client/table name when passed as arguments in methods
  • No labels