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

JNoSQL/Artemis/Couchbase

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