Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "JNoSQL/Artemis/Couchbase"

(Created page with "== Couchbase Extension == The goal of an extension goes beyond the Artemis API-core, and with Couchbase Extensions, it does not look different. Couchbase Extension has classe...")
 
 
Line 1: Line 1:
 
== Couchbase Extension ==
 
== Couchbase Extension ==
  
The goal of an extension goes beyond the Artemis API-core, and with Couchbase Extensions, it does not look different. Couchbase Extension has classes such as CouchbaseDocumentRepository and CouchbaseDocumentRepositoryAsync whose have support to Couchbase particular behavior as n1ql.
+
The goal of an extension goes beyond the Artemis API-core, and with Couchbase Extensions, it does not look different. Couchbase Extension has classes such as CouchbaseTemplate and CouchbaseTemplateAsync whose have support to Couchbase particular behavior as n1ql.
  
 
== Maven Dependency ==
 
== Maven Dependency ==
Line 25: Line 25:
 
</pre>
 
</pre>
  
== Couchbase Document Repository ==
+
== Couchbase Template ==
  
  
CouchbaseDocumentRepositoryAsync and CouchbaseDocumentRepository are specialized classes from DocumentRepository and DocumentRepositoryAsync respectively, so they have all methods plus the Couchbase methods whose has in Couchbase driver such as n1ql.
+
CouchbaseTemplateAsync and CouchbaseTemplate are specialized classes from DocumentTemplate and DocumentTemplateAsync respectively, so they have all methods plus the Couchbase methods whose has in Couchbase driver such as n1ql.
 
To active, this resource just needs to produce a CouchbaseDocumentCollectionManager in a CDI context.
 
To active, this resource just needs to produce a CouchbaseDocumentCollectionManager in a CDI context.
  
Line 46: Line 46:
 
<pre lang="java">
 
<pre lang="java">
 
@Inject
 
@Inject
private CouchbaseDocumentRepository repository;
+
private CouchbaseTemplate template;
  
 
public void sample() {
 
public void sample() {
 
         JsonObject params = JsonObject.create().put("name", "Ada");
 
         JsonObject params = JsonObject.create().put("name", "Ada");
         List<Person> people = repository.n1qlQuery("select * from Person where name = $name", params);
+
         List<Person> people = template.n1qlQuery("select * from Person where name = $name", params);
 
}
 
}
 
</pre>
 
</pre>
  
  
The similar thing happens with the CouchbaseDocumentRepositoryAsync just produces the CouchbaseDocumentCollectionManagerAsync.
+
The similar thing happens with the CouchbaseTemplateAsync just produces the CouchbaseDocumentCollectionManagerAsync.
  
 
<pre lang="java">
 
<pre lang="java">
Line 67: Line 67:
  
  
==== Crud repository ====
+
==== Repository ====
  
  
Beyond the document repository, Couchbase Extension also has the CrudRepository specialization to both sync and async works. These specializations allow querying with n1ql.
+
Beyond the document repository, Couchbase Extension also has the Repository specialization to both sync and async works. These specializations allow querying with n1ql.
  
  
Line 76: Line 76:
  
 
<pre lang="java">
 
<pre lang="java">
     public interface PersonRepository extends CouchbaseCrudRepository<Person> {
+
     public interface PersonRepository extends CouchbaseRepository<Person> {
  
 
         @N1QL("select * from Person")
 
         @N1QL("select * from Person")
Line 88: Line 88:
  
 
<pre lang="java">
 
<pre lang="java">
     public interface PersonRepository extends CouchbaseCrudRepository<Person> {
+
     public interface PersonRepository extends CouchbaseRepository<Person> {
  
 
         @N1QL("select * from Person")
 
         @N1QL("select * from Person")
Line 100: Line 100:
  
 
<pre lang="java">
 
<pre lang="java">
   public interface PersonAsyncRepository extends CrudRepositoryAsync<Person> {
+
   public interface PersonAsyncRepository extends CouchbaseRepositoryAsync<Person> {
  
 
         Person findByName(String name);
 
         Person findByName(String name);

Latest revision as of 07:53, 1 May 2017

Couchbase Extension

The goal of an extension goes beyond the Artemis API-core, and with Couchbase Extensions, it does not look different. Couchbase Extension has classes such as CouchbaseTemplate and CouchbaseTemplateAsync whose have support to Couchbase particular behavior as n1ql.

Maven Dependency

To use the Couchbase extension to Artemis:

 
  <dependency>
    <groupId>org.jnosql.artemis</groupId>
    <artifactId>couchbase-extension</artifactId>
    <version>version</version>
  </dependency>

E.g:

 
  <dependency>
    <groupId>org.jnosql.artemis</groupId>
    <artifactId>couchbase-extension</artifactId>
    <version>0.0.1</version>
  </dependency>

Couchbase Template

CouchbaseTemplateAsync and CouchbaseTemplate are specialized classes from DocumentTemplate and DocumentTemplateAsync respectively, so they have all methods plus the Couchbase methods whose has in Couchbase driver such as n1ql. To active, this resource just needs to produce a CouchbaseDocumentCollectionManager in a CDI context.

  @Produces
    public CouchbaseDocumentCollectionManager getManager() {
	//code
        return managerFactory.get(KEY_SPACE);
    }


Done, the Artemis will take and manage the bean to you.


@Inject
private CouchbaseTemplate template;

public void sample() {
        JsonObject params = JsonObject.create().put("name", "Ada");
        List<Person> people = template.n1qlQuery("select * from Person where name = $name", params);
}


The similar thing happens with the CouchbaseTemplateAsync just produces the CouchbaseDocumentCollectionManagerAsync.

  @Produces
    public CouchbaseDocumentCollectionManagerAsync getManagerAsync() {
	//code
        return managerFactory.get(KEY_SPACE);
    }


Repository

Beyond the document repository, Couchbase Extension also has the Repository specialization to both sync and async works. These specializations allow querying with n1ql.


Sample Code
    public interface PersonRepository extends CouchbaseRepository<Person> {

        @N1QL("select * from Person")
        List<Person> findAll();

        @N1QL("select * from Person where name = $name")
        List<Person> findByName(JsonObject params);
    }


    public interface PersonRepository extends CouchbaseRepository<Person> {

        @N1QL("select * from Person")
        List<Person> findAll();

        @N1QL("select * from Person where name = $name")
        List<Person> findByName(JsonObject params);
    }


   public interface PersonAsyncRepository extends CouchbaseRepositoryAsync<Person> {

        Person findByName(String name);

        Person findByName(String name, ConsistencyLevel level, Consumer<List<Person>> callBack);

        void deleteByName(String name, ConsistencyLevel level, Consumer<Void> callBack);

        @CQL("select * from Person where name= ?")
        void queryName(String name, Consumer<List<Person>> callBack);
    }

Links

Back to the top