Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Supported Client Libraries


Supported Operations (2.x)

Operation

Methods Supported

Insert
  • insert
  • upsert
Select
  • getAndTouch
  • getAndLock
  • exists
  • get
Delete
  • remove
Update
  • replace
  • prepend
  • append

Supported Operations (3.x)

Operation

Methods Supported

Insert
  • insert
  • upsert
Select
  • getAndTouch
  • getAndLock
  • exists
  • get
Delete
  • remove
Update
  • replace

Objects (2.x)

Icon 

Description

Java Couchbase Cluster

Java Couchbase Bucket

Java Couchbase Unknown Cluster

 

Java Couchbase Unknown Bucket 

...

Objects (3.x)

IconDescription

Image Added

Java Couchbase Cluster

Image Added

Java Couchbase Bucket

Image Added

Java Couchbase Collection

Image Added

Java Couchbase Unknown Cluster

 Image Added

Java Couchbase Unknown Bucket 

Image Added

Java Couchbase Unknown Collection

Links (2.x)

Links are created for transaction and function point needs:

Link typeSource and destination of linkMethods supported
parentLinkBetween Couchbase Cluster object and Couchbase Bucket belongsTo

From Java Couchbase Collection object to Java Couchbase Bucket object and Java Couchbase Bucket object to Java Couchbase Cluster object


useLinkBetween the caller Couchbase Java Method objects and and Java Couchbase Buckets/Collection objects
  • Upsert
  • N1QL.parameterized
  • N1QL.simple

useSelectLink

  • get()
  • async().get()
  • getAndTouch()
  • async().getAndTouch()
  • getAndLock()
  • async().getAndLock()
  • exists()
  • async().exists()
useUpdateLink
  • replace()
  • async().replace()
  • append()
  • async().append()
  • prepend()
  • async.prepend()
useDeleteLink
  • remove()
  • async().remove()
useInsertLink
  • insert
  • async().insert()

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.

Cluster Object

Code Block
languagejava
public class App 
{
    public static void main( String[] args )
    {
    	
        System.out.println("Create connection");
	   	final Cluster cluster = CouchbaseCluster.create("127.0.0.1");
    	cluster.authenticate("Administrator", "Password");
	}
}

Image Removed

...

Links (3.x)

Link typeSource and destination of linkMethods supported
parentLink
  • Between Couchbase Connection object and Bucket object
  • Between Couchbase bucket object and Collection object



useLinkBetween the caller Couchbase Java Method objects and Couchbase Buckets objects
  • Upsert

useSelectLink

  • get()
  • async().get()
  • getAndTouch()
  • async().getAndTouch()
  • getAndLock()
  • async().getAndLock()
  • exists()
  • async().exists()
useUpdateLink
  • replace()
  • async().replace()
useDeleteLink
  • remove()
  • async().remove()
useInsertLink
  • insert
  • async().insert()

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.

Cluster and Bucket Object 

Expand
titleCluster and Bucket (2.x)


Code Block
public class App 
{
    public static void main( String[] args )
    {
    	
        System.out.println("Create connection");
	   	final Cluster cluster = CouchbaseCluster.create("127.0.0.1");
    	cluster.authenticate("Administrator", "Password");
	}
}

Image Added

Code Block
public class App 
{
    public static void main( String[] args )
    {
    	
        System.out.println("Create connection");
    	final Cluster cluster = CouchbaseCluster.create("127.0.0.1");
    	cluster.authenticate("Administrator", "Password");
    	Bucket myBucket1 = cluster.openBucket("example1");
    }
}

Image Added


Expand
titleConnection,bucket and collection objects(3.x)

Connection, Bucket and Cluster object

Code Block
  public static void main(String... args) {

    Cluster cluster = Cluster.connect("localhost", "Administrator", "password");

    Bucket bucket = cluster.bucket("travel-sample");
    Scope scope = bucket.scope("_default");
    Collection collection = scope.collection("_default");

Image Added



Insert operations

Expand
titleInsert link(2.x)


Code Block
languagejava
public class App 
{
    public static void main( String[] args )
    {
    	
        System.out.println("Create connection");
    	final Cluster cluster = CouchbaseCluster.create("127.0.0.1");
    	cluster.authenticate("Administrator", "Password");
    	Bucket myBucket = cluster.openBucket("example");
    	JsonObject content = JsonObject.empty()
    			  .put("name", "John Doe")
    			  .put("type", "Person")
    			  .put("email", "john.doe@mydomain.com")
    			  .put("homeTown", "Chicago");
		String id = UUID.randomUUID().toString();
    	JsonDocument document = JsonDocument.create(id, content);
		JsonDocument inserted = myBucket.insert(document);
	}
}

Image Added


Expand
titleInsert link(3.x)


Code Block
public void insert()
{
      System.out.println("\nExample: [insert]");
      // tag::insert[]
      try {
        JsonObject content = JsonObject.create().put("title", "My Blog Post 2");
        MutationResult insertResult = collection.insert("document-key2", content);
      } catch (DocumentExistsException ex) {
        System.err.println("The document already exists!");
      } catch (CouchbaseException ex) {
        System.err.println("Something else happened: " + ex);
      }
      // end::insert[]
    }


Image Added

Select operations

Expand
titleSelect link(2.x)
  • get()


    Code Block
    languagejava
    public class App 
    {
        public static void main( String[] args )
        {
        	
            System.out.println("Create connection");
        	final Cluster cluster = CouchbaseCluster.create("127.0.0.1");
        	cluster.authenticate("Administrator", "Password");
        	Bucket myBucket = cluster.openBucket("example");
        	JsonObject content = JsonObject.empty()
        			  .put("name", "John Doe")
        			  .put("type", "Person")
        			  .put("email", "john.doe@mydomain.com")
        			  .put("homeTown", "Chicago");
    		String id = UUID.randomUUID().toString();
        	JsonDocument document = JsonDocument.create(id, content);
    		JsonDocument inserted = myBucket.insert(document);
    		JsonDocument document1 = JsonDocument.create(id, content1);
    
    
    		JsonDocument gets = myBucket.get(document);
    		System.out.println(gets);
    
    	}
    }


  • getAndTouch()


    Code Block
    languagejava
    public class App 
    {
        public static void main( String[] args )
        {
        	
            System.out.println("Create connection");
        	final Cluster cluster = CouchbaseCluster.create("127.0.0.1");
        	cluster.authenticate("Administrator", "
Password
  • password");
        	Bucket 
myBucket1
  • myBucket = cluster.openBucket("
example1
  • example");
        
} }

Image Removed

Operations which create useInsertlink:

  • insert()
Code Block
languagejava
public class App {
  • 	JsonObject content = JsonObject.empty()
        			  .put("name", "John Doe")
       
public
  •  
static
  • 			 
void
  •  
main( String[] args ) {
  • .put("type", "Person")
        			  .put("email", "john.doe@mydomain.com")
        			  
System.out.println("Create connection"
  • .put("homeTown", "Chicago");
    		String id = UUID.randomUUID().toString();
        	
final
  • JsonDocument 
Cluster
  • document 
cluster
  • = 
CouchbaseCluster
  • JsonDocument.create(
"127.0.0.1"
  • id, content);
    		JsonDocument inserted = myBucket.insert(document);
    
cluster.authenticate("Administrator", "Password"); Bucket myBucket = cluster.openBucket("example"); JsonObject content = JsonObject.empty() .put("name", "John Doe") .put("type", "Person") .put("email", "john.doe@mydomain.com") .put("homeTown", "Chicago"); String id = UUID.randomUUID().toString(
  • 		JsonDocument document1 = JsonDocument.create(id, content1);
    
    		JsonDocument getandtouch = myBucket.getAndTouch(document);
    		System.out.println(getandtouch);
    	}
    }


  • getAndLock()


    Code Block
    languagejava
    public class App 
    {
        public static void main( String[] args )
        {
        	
            System.out.println("Create connection");
        	final Cluster cluster = CouchbaseCluster.create("127.0.0.1");
        	
JsonDocument document = JsonDocument.create(id, content
  • cluster.authenticate("Administrator", "Password");
    
JsonDocument inserted
  •     	Bucket myBucket = 
myBucket
  • cluster.
insert
  • openBucket(
document); } }

Image Removed

Operations which create useSelectlink:

  • get()
Code Block
languagejava
public class App {
  • "example");
        
public
  • 	JsonObject 
static
  • content 
void
  • = 
main( String[] args
  • JsonObject.empty()
        
{
  • 			  .put("name", "John Doe")
    
  •     			  
System.out.println
  • .put("
Create connection
  • type", "Person")
;
  • 
        		
final
  • 	 
Cluster
  •  
cluster = CouchbaseCluster
  • .
create
  • put("
127.0.0.1");
  • email", "john.doe@mydomain.com")
        	
cluster.authenticate
  • 		  .put("
Administrator
  • homeTown", "
Password
  • Chicago");
    
Bucket myBucket
  • 		String id = 
cluster.openBucket("example"
  • UUID.randomUUID().toString();
        	
JsonObject
  • JsonDocument 
content
  • document = 
JsonObject
  • JsonDocument.
empty
  • create(
)
  • id, content);
    		
  • JsonDocument inserted = myBucket.
put("name", "John Doe")
  • insert(document);
    		
  • JsonDocument document1 = JsonDocument.
put
  • create(
"type"
  • id, 
"Person"
  • content1);
    
    
  • 		
  • JsonDocument getandlock = myBucket.
put
  • getAndLock(
"email"
  • document, 
"john.doe@mydomain.com") .put("homeTown", "Chicago"); String id = UUID.randomUUID().toString();
  • 10);
    		System.out.println(getandlock);
    	}
    }


  • exists()


    Code Block
    languagejava
    public class App 
    {
        public static void main( String[] args )
        
JsonDocument
  • {
    
document
  •  
=
  •  
JsonDocument.create(id,
  •  
content);
  •  	
JsonDocument
  • 
      
inserted
  •  
=
  •  
myBucket.insert(document);
  •  
JsonDocument
  •  
document1
  •  
=
  •  
JsonDocument
  • System.out.
create
  • println(
id, content1
  • "Create connection");
      
JsonDocument gets
  •   	final Cluster cluster = 
myBucket
  • CouchbaseCluster.
get(document); System.out.println(gets
  • create("127.0.0.1");
     
} }
  • getAndTouch()
Code Block
languagejava
public
  •  
class
  •  
App {
  •  	cluster.authenticate("Administrator", "Password");
        
public
  • 	Bucket 
static
  • myBucket 
void
  • = 
main( String[] args ) {
  • cluster.openBucket("example");
        	JsonObject content = JsonObject.empty()
        			  .put("name", "John Doe")
        			  
System
  • .
out.println
  • put("type"
Create
  • , 
connection
  • "Person")
;
  • 
      
final
  •  
Cluster
  •  
cluster
  • 			 
=
  •  
CouchbaseCluster
  • .
create
  • put("
127.0.0.1");
  • email", "john.doe@mydomain.com")
        	
cluster.authenticate
  • 		  .put("
Administrator
  • homeTown", "
password
  • Chicago");
    		String id = UUID.randomUUID().toString();
        	
Bucket
  • JsonDocument 
myBucket
  • document = 
cluster
  • JsonDocument.
openBucket("example"
  • create(id, content);
    
JsonObject content
  • 		JsonDocument inserted = 
JsonObject
  • myBucket.
empty
  • insert(document);
    
  • 		
  • JsonDocument document1 = JsonDocument.
put
  • create(
"name"
  • id, 
"John Doe"
  • content1);
    		
    		Boolean exists = myBucket.exists(document);
    		System.out.println(exists);
    	
.put("type", "Person") .put("email", "john.doe@mydomain.com")
  • }
    }


Image Added



Expand
titleSelect Link(3.x)


Code Block

public void get()
{
    
  System.out.
put
println("
homeTown", "Chicago"
\nExample: [get-simple]");
String
 
id
 
=
 
UUID.randomUUID().toString();
   // 
JsonDocument document = JsonDocument.create(id, content); JsonDocument inserted = myBucket.insert(document); JsonDocument document1 = JsonDocument.create(id, content1); JsonDocument getandtouch = myBucket.getAndTouch(document); System.out.println(getandtouch); } }
  • getAndLock()
Code Block
languagejava
public class App { public static void main( String[] args ) {
tag::get-simple[]
      try {
        GetResult getResult = collection.get("document-key");
        String title = getResult.contentAsObject().getString("title");
        System.out.println(title); // title == "My Blog Post"
      } catch 
System.out.println("Create connection");
(DocumentNotFoundException ex) {
    
final
 
Cluster
 
cluster
 
=
 
CouchbaseCluster
System.out.
create
println("
127.0.0.1
Document not found!");
    
cluster.authenticate("Administrator", "Password");
  }
    
Bucket
 
myBucket
 
= cluster.openBucket("example");
// end::get-simple[]
    
JsonObject
}
content
public 
=
void 
JsonObject.empty
getAndTouch()
    
{
 
.put("name",
 
"John
 
Doe")
   
.put("type", "Person")
System.out.println("\nExample: [expiry-touch]");
   
.put("email", "john.doe@mydomain.com")
   // tag::expiry-touch[]
      GetResult 
result = collection.
put
getAndTouch("
homeTown
my-document3", 
"Chicago"); String id = UUID.randomUUID().toString();
Duration.ofDays(1));
      
JsonDocument document = JsonDocument.create(id, content); JsonDocument inserted = myBucket.insert(document); JsonDocument document1 = JsonDocument.create(id, content1); JsonDocument getandlock = myBucket.getAndLock(document, 10); System.out.println(getandlock); } }

...

// end::expiry-touch[]

      System.out.println("cas value: " + result.cas());
    }

Image Added


Update Operations

Expand
titleUpdate link(2.x)
  • replace()


    Code Block
    languagejava
    public class App 
    {
        public static void main( String[] args )
        {
        	
            System.out.println("Create connection");
        	final Cluster cluster = CouchbaseCluster.create("127.0.
0.1");
  • 0.1");
        	cluster.authenticate("Administrator", "Password");
        	Bucket myBucket = cluster.openBucket("example");
        	JsonObject content = JsonObject.empty()
        	
cluster.authenticate
  • 		  .put("
Administrator
  • name", "
Password
  • John Doe")
;
  • 
        	
Bucket
  • 		 
myBucket
  •  
= cluster
  • .
openBucket
  • put("
example
  • type", "Person")
;
  • 
        	
JsonObject
  • 		 
content = JsonObject.empty(
  •  .put("email", "john.doe@mydomain.com")
        			  .put("
name", "John Doe"
  • homeTown", "Chicago");
    
    		JsonObject content3 = JsonObject.empty()
        			
  • .put("
type
  • Emp_Trigram", "
Person
  • ABC")
        			
  • .put("
email
  • Emp_id", "
john.doe@mydomain.com
  • 001");
    
  • 		
  • JsonDocument document1 = JsonDocument.
put
  • create(
"homeTown"
  • id, 
"Chicago"
  • content1);
    
    		String id = UUID.randomUUID().toString();
        	JsonDocument document = JsonDocument.create(id, content);
    		JsonDocument inserted = myBucket.insert(document);
    		JsonDocument document1 = JsonDocument.create(id, content1);
    		
    		
Boolean
  • JsonDocument 
exists
  • removed = myBucket.
exists
  • replace(
document
  • document1);
    		System.out.println(
exists
  • myBucket);
} }

Image Removed

Operations which create useUpdatelink:

...

  • 
    	}
    }


  • prepend()


    Code Block
    languagejava
    public class App 
    {
        public static void main( String[] args )
        {
        	
            System.out.println("Create connection");
        	final Cluster cluster = CouchbaseCluster.create("127.0.0.1");
        	cluster.authenticate("Administrator", "Password");
        	Bucket myBucket = cluster.openBucket("example");
        	JsonObject content = JsonObject.empty()
        			  .put("name", "John Doe")
        			  .put("type", "Person
") .put("email", "john.doe@mydomain.com") .put("homeTown", "Chicago"); JsonObject content3 = JsonObject.empty(
  • ")
        			  .put("
Emp_Trigram
  • email", "
ABC
  • john.doe@mydomain.com")
        			  .put("
Emp_id
  • homeTown", "
001
  • Chicago");
    		String id = UUID.randomUUID().toString();
        	JsonDocument 
document1
  • document = JsonDocument.create(id, 
content1
  • content);
    
  • 		
String
  • JsonDocument 
id
  • inserted = 
UUID
  • myBucket.
randomUUID
  • insert(document)
.toString
  • ;
    		JsonObject content3 = JsonObject.empty()
;
  • 
        
JsonDocument document = JsonDocument.create(id, content); JsonDocument inserted = myBucket.insert(document
  • 			.put("Emp_Trigram", "ABC")
        			.put("Emp_id", "001");
    		JsonDocument document1 = JsonDocument.create(id, content1);
    
  • 
    		JsonDocument 
removed
  • prepended = myBucket.
replace
  • prepend(document1);
    
System.out.println(myBucket);
  • 
    	}
    }

...


  • append()


    Code Block
    languagejava
    public class App 
    {
        public static void main( String[] args )
        {
        	
            System.out.println("Create connection");
        	final Cluster cluster = CouchbaseCluster.create("127.0.0.1");
        	cluster.authenticate("Administrator", "Password");
        	Bucket myBucket = cluster.openBucket("example");
        	JsonObject content = JsonObject.empty()
        			  .put("name", "John Doe")
        			  .put("type", "Person")
        			  .put("email", "john.doe@mydomain.com")
        			  .put("homeTown", "Chicago");
    		String id = UUID.randomUUID().toString();
        	JsonDocument document = JsonDocument.create(id, content);
    		JsonDocument inserted = myBucket.insert(document);
    		JsonObject content3 = JsonObject.empty()
        			.put("Emp_Trigram", "ABC")
        			.put("Emp_id", "001");
    		JsonDocument document1 = JsonDocument.create(id, content1);
    
    		JsonDocument prepended = myBucket.
prepend
  • append(document1);
    
    	}
    }

...

  • Image Added


language
Expand
titleUpdate link(3.x)


Code Block
java
public 
class
void 
App
get()
{
    
public
 
static void main( String[] args )
 System.out.println("\nExample: [expiry-replace]");
    
{
  
System.out.println("Create connection");
// tag::expiry-replace[]
     
final
 
Cluster
GetResult 
cluster
found = 
CouchbaseCluster
collection.
create
get("
127.0.0.1"
my-document3", getOptions().withExpiry(true));

   
cluster.authenticate("Administrator", "Password");
   MutationResult result = collection.replace("my-document3", json,
        
Bucket
 
myBucket = cluster.openBucket("example"
 replaceOptions().expiry(found.expiryTime().get()));
    
JsonObject
  
content = JsonObject.empty()
// end::expiry-replace[]

    
  System.
put
out.println("
name
cas value: "
,
 
"John Doe")
+ result.cas());
    
.put("type", "Person") .put("email", "john.doe@mydomain.com") .put("homeTown", "Chicago"); String id = UUID.randomUUID().toString();
}

Image Added

Delete Operations

Expand
titleDelete link(2.x)
  • remove()

       

Code Block
languagejava
public class App 
{
    public static void main( String[] args )
    {
    	
JsonDocument document = JsonDocument.create(id, content); JsonDocument inserted = myBucket.insert(document); JsonObject content3 = JsonObject.empty()

        System.out.println("Create connection");
    	final Cluster cluster = CouchbaseCluster.create("127.0.0.1");
    	
cluster.
put
authenticate("
Emp_Trigram
Administrator", "
ABC
Password");
    	
.put("Emp_id", "001"
Bucket myBucket = cluster.openBucket("example");
JsonDocument document1
    	JsonObject content = 
JsonDocument
JsonObject.
create(id, content1);
empty()
    		
JsonDocument
	 
prepended = myBucket.append(document1); } }

Image Removed

Operations which create useDeletelink:

  • remove()
Code Block
languagejava
public class App { public static void main( String[] args
 .put("name", "John Doe")
    			  .put("type", "Person")
    			  .put("email", "john.doe@mydomain.com")
    
{
			  .put("homeTown", "Chicago");
		String id 
System.out.println("Create connection"
= UUID.randomUUID().toString();
    	
final
JsonDocument 
Cluster cluster
document = 
CouchbaseCluster
JsonDocument.create(
"127.0.0.1"
id, content);
		JsonDocument inserted = myBucket.insert(document);
		JsonDocument document1 = 
cluster
JsonDocument.
authenticate
create(
"Administrator"
id, 
"Password"
content1);
		
		
Bucket
JsonDocument 
myBucket
removed = 
cluster
myBucket.
openBucket
remove(
"example"
document);
		System.out.println(myBucket);
JsonObject content = JsonObject.empty
	}
}

Image Added


Expand
titleDelete link(3.x)


Code Block
public void remove()

{
  
    System.
put
out.println("
name", "John Doe")
\nExample: [remove]");
      
.put("type", "Person")
// tag::remove[]
      
try {
.put("email",
 
"john.doe@mydomain.com")
     
  collection.
put
remove("
homeTown", "Chicago"); String id = UUID.randomUUID().toString();
my-document");
      } catch (DocumentNotFoundException ex) {
     
JsonDocument
 
document
 
=
 
JsonDocument
System.out.
create(id, content); JsonDocument inserted = myBucket.insert(document); JsonDocument document1 = JsonDocument.create(id, content1); JsonDocument removed = myBucket.remove(document); System.out.println(myBucket); } }

Image Removed

...

println("Document did not exist when trying to remove");
      }
      // end::remove[]
    }

Image Added


Batch Operations


Expand
titleBatch Operations(2.x)


Code Block
languagejava
int docsToCreate = 100;
List<JsonDocument> documents = new ArrayList<JsonDocument>();
for (int i = 0; i < docsToCreate; i++) {
    JsonObject content = JsonObject.create()
        .put("counter", i)
        .put("name", "Foo Bar");
    documents.add(JsonDocument.create("doc-"+i, content));
}

// Insert them in one batch, waiting until the last one is done.
Observable
    .from(documents)
    .flatMap(new Func1<JsonDocument, Observable<JsonDocument>>() {
        @Override
        public Observable<JsonDocument> call(final JsonDocument docToInsert) {
            return bucket.async().insert(docToInsert);
        }
    })
    .last()
    .toBlocking()
    .single();



N1QL Queries


Expand
titleLinks Snippet

Image Removed

Image Removed

Image Removed

Image Removed

...

N1QL(2.x)


Code Block
languagejava
protected static N1qlQuery buildQuery(Statement statement, JsonValue queryPlaceholderValues, ScanConsistency scanConsistency) {
		Cluster cluster = CouchbaseCluster.create("localhost");  
		N1qlParams n1qlParams = N1qlParams.build().consistency(scanConsistency);
		 N1qlQuery query;
		 if (queryPlaceholderValues instanceof JsonObject && !((JsonObject) queryPlaceholderValues).isEmpty()) {
		  query = N1qlQuery.parameterized(statement, (JsonObject) queryPlaceholderValues, n1qlParams);
		 } else if (queryPlaceholderValues instanceof JsonArray && !((JsonArray) queryPlaceholderValues).isEmpty()) {
		  query = N1qlQuery.parameterized(statement, (JsonArray) queryPlaceholderValues, n1qlParams);
		 } else {
		  query = N1qlQuery.simple(statement, n1qlParams);
		 }
		 return query;
		}

Image Modified


Evolutions

  • Collections are supported for SDK 3.x
  • Better resolution for client and bucket


Limitations

  •  Only CRUD operations are supported for Java 3.x

Future

  • N1QL query support in Java SDK 3.x