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

CAST supports Couchbase 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
  • OpenBucket
  • OpenBucketAsync
  • GetBucket
Insert
  • Insert
  • InsertAsync
Update
 Update Methods Supported
  • Replace
  • Upsert
  • Append
  • Prepend
  • Increment
  • Decrement
  • MutateIn
  • ReplaceAsync
  • UpsertAsync
  • AppendAsync
  • PrependAsync
  • IncrementAsync
  • DecrementAsync
Select
 Select Methods Supported
  • Get
  • GetAndTouch
  • GetAndLock
  • GetWithLock
  • GetFromReplica
  • GetDocument
  • GetAndTouchDocument
  • GetDocumentFromReplica
  • LookupIn
  • GetAsync
  • GetAndLockAsync
  • GetAndTouchAsync
  • GetWithLockAsync
  • GetFromReplicaAsync
  • GetDocumentAsync
  • GetAndTouchDocumentAsync
  • GetDocumentFromReplicaAsync
Delete 
  • Remove
  • RemoveAsync

Objects

Icon Description

DotNet Couchbase Cluster

DotNet Couchbase Bucket

DotNet Unknown Cluster

 

DotNet Unknown Couchbase Bucket 

Links are created for transaction and function point needs:

Link typeSource and destination of link Methods supported
parentLink

Between Couchbase Cluster object and Couchbase Bucket object


useLinkBetween the caller .NET Class / Method objects and Couchbase Buckets objects


  • OpenBucket
  • OpenBucketAsync
  • GetBucket
 useInsertLink
  • Insert
  • InsertAsync
 useDeleteLink
  • Remove
  • RemoveAsync

useSelectLink


 Select methods supported
  • Get
  • GetAndTouch
  • GetAndLock
  • GetWithLock
  • GetFromReplica
  • GetDocument
  • GetAndTouchDocument
  • GetDocumentFromReplica
  • LookupIn
  • GetAsync
  • GetAndLockAsync
  • GetAndTouchAsync
  • GetWithLockAsync
  • GetFromReplicaAsync
  • GetDocumentAsync
  • GetAndTouchDocumentAsync
  • GetDocumentFromReplicaAsync
useUpdateLink
 Update methods supported
  • Replace
  • Upsert
  • Append
  • Prepend
  • Increment
  • Decrement
  • MutateIn
  • ReplaceAsync
  • UpsertAsync
  • AppendAsync
  • PrependAsync
  • IncrementAsync
  • DecrementAsync

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.

Cluster Creation and Bucket Opening

Cluster Creation and Bucket Opening
class Program
{        
	private static Cluster cluster_1 = new Cluster();
        private const string bucket_name = "GeoBucket";
        private static IBucket geobucket;
        static void Main(string[] args)
        {	    
			AuthenticateCluster();
			CreateBucket();
			CouchbaseOpenBucket();
	}
        private static void AuthenticateCluster()
        {            
			Console.WriteLine("Cluster Created - Localhost");
			var authenticator = new PasswordAuthenticator("Administrator", "123456");
			cluster_1.Authenticate(authenticator);
	           
        }
        private static void CreateBucket()
        {            
			var cm = cluster_1.CreateManager();
			cm.CreateBucket(bucket_name);
	}
        private static void CouchbaseOpenBucket()
        {            
			geobucket = cluster_1.OpenBucket(bucket_name);
            	     	return;
        }
}

Using ClusterHelper for cluster and bucket

CLUSTERHELPER
private static void TestClusterHelper4()        
{
            var config = new ClientConfiguration {
            Servers = new List<Uri>{
			new Uri("http://192.168.56.101:8091"),
			new Uri("http://192.168.56.102:8091")
            }  };
            ClusterHelper.Initialize(config);
            var chbucket = ClusterHelper.GetBucket("defaultWayt");        
}

Insert Operation

InsertDocumentInBucket
private static void InsertDocumentInBucket()        
{
	geobucket.Insert(SetKarDoc());
	geobucket.Insert(SetGoaDoc());
	geobucket.Insert(SetBengaluruDoc());
	geobucket.Insert(SetChandigarhDoc());
}

Update Operation

ReplaceDocumentInBucket
private static void ReplaceDocumentInBucket()        
{
	geobucket.Replace(ModifyChandigarhDoc());        
}

UpsertDocumentInBucket
private static void UpsertDocumentInBucket()        
{
	geobucket.Upsert(MysuruDoc());        
}

Decrement

Append/Prepend

Increment

Select Operation 

GetDocumentFromBucket
private static void GetDocumentsFromBucket()        
{
	var result = geobucket.GetDocument<dynamic>("Goa").Content;
}

Delete Operation

RemoveDocumentFromBucket
private static void DeleteDocumentInBucket()        
{
	geobucket.Remove(MysuruDoc());
}        

N1QL Query

Using N1QL
private static void QueryBucketUsingN1QL()        
{
	var create_index = "CREATE PRIMARY INDEX ON " + bucket_name;
	geobucket.Query<dynamic>(create_index);
	var queryResult = geobucket.Query<dynamic>("SELECT name, state FROM GeoBucket WHERE type = \'city\' and capital=\'Yes\'"); 
	foreach (var row in queryResult.Rows)
		Console.WriteLine(row);
 }

Sub-Document Operations

The following methods sub-document operations are supported:

  • LookupIn
  • MutateIn
    • ArrayInsert
    • ArrayAppend
    • ArrayPrepend
    • ArrayAddUnique
    • Remove
    • Replace
    • Insert
    • Upsert

LookupIn

LOOKUPIN
public static void LookupInMethod2( string id)
{           var builder = geobucket.LookupIn<dynamic>(id).
                Get("type").
                Get("country").
                Exists("notfound");       
}

MutateIn

MUTATEIN
public static void SubDocMisc(string id, string path, string replace_path, object value)
{
	geobucket.MutateIn<dynamic>(id).
		Remove(path).
		Replace(replace_path, value).
		Execute();
}

Asynchronous API

  • OpenBucketAsync
  • InsertAsync
  • ReplaceAsync
  • UpsertAsync
  • AppendAsync
  • PrependAsync
  • IncrementAsync
  • DecrementAsync
  • QueryAsync
  • GetAsync
  • GetAndLockAsync
  • GetAndTouchAsync
  • GetWithLockAsync
  • GetFromReplicaAsync
  • GetDocumentAsync
  • GetAndTouchDocumentAsync
  • GetDocumentFromReplicaAsync

Evolution

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

Limitations

  • Cluster and bucket names are resolved as known only in the following situations:
    • Cluster/Bucket name is hardcoded
    • Cluster/Bucket name  is defined in the variable in the local method
    • Cluster/Bucket name  is defined as C# field
    • Cluster/Bucket name information is present in App.config
  • Version .NET SDK 2.1 to 2.7 are supported

Future development

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