Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
JNoSQL/Artemis/Couchbase
Contents
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.
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 Document Repository
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. 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 CouchbaseDocumentRepository repository;
public void sample() {
JsonObject params = JsonObject.create().put("name", "Ada");
List<Person> people = repository.n1qlQuery("select * from Person where name = $name", params);
}
The similar thing happens with the CouchbaseDocumentRepositoryAsync just produces the CouchbaseDocumentCollectionManagerAsync.
@Produces
public CouchbaseDocumentCollectionManagerAsync getManagerAsync() {
//code
return managerFactory.get(KEY_SPACE);
}
Crud repository
Beyond the document repository, Couchbase Extension also has the CrudRepository specialization to both sync and async works. These specializations allow querying with n1ql.
Sample Code
public interface PersonRepository extends CouchbaseCrudRepository<Person> {
@N1QL("select * from Person")
List<Person> findAll();
@N1QL("select * from Person where name = $name")
List<Person> findByName(JsonObject params);
}
public interface PersonRepository extends CouchbaseCrudRepository<Person> {
@N1QL("select * from Person")
List<Person> findAll();
@N1QL("select * from Person where name = $name")
List<Person> findByName(JsonObject params);
}
public interface PersonAsyncRepository extends CrudRepositoryAsync<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);
}