-
Notifications
You must be signed in to change notification settings - Fork 233
Kundera with Couchbase
This is an experimental feature. We encourage the community to contribute to the development and testing of it.
Couchbase Server is an open source, distributed, NoSQL document-oriented database. It exposes a fast key-value store with managed cache for submillisecond data operations, purpose-built indexers for fast queries and a query engine for executing SQL-like queries.
Being a JPA provider, Kundera provides support for Couchbase.
Records from all the tables of a database will be stored in a couchbase bucket.
Java Object | Couchbase |
---|---|
Database | Bucket |
Table | No separate entity |
Columns | Keys of document |
Object | Document |
Consider this Person
entity in TEST_DB
database.
@Entity
public class Person
{
@Id
private String id;
@Column
private String name;
@Column
private int age;
// setters and getters.
}
Sample Java object
Person person = new Person();
person.setId("101");
person.setName("Dev");
person.setAge(25);
Corresponding Couchbase document
{
"id": "101",
"name": "Dev",
"age": 25,
"kundera_enity": "Person"
}
with primary key person_101
in TEST_DB
bucket.
Did you observe an extra key kundera_enity
?
This key is used while JPA querying.
For example, this JPA query
select p from Person p where p.age >= 30
will get converted into
select * from couchbase_db where kundera_enity = 'Person' AND age > 30
To use it, user needs to add the following dependency in pom.xml:
<dependency>
<groupId>com.impetus.kundera.client</groupId>
<artifactId>kundera-couchbase</artifactId>
<version>${kundera.version}</version>
</dependency>
<persistence-unit name="couchbase_pu">
<provider>com.impetus.kundera.KunderaPersistence</provider>
<class>com.impetus.client.couchbase.entities.Person</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="kundera.nodes" value="localhost" />
<property name="kundera.client" value="couchbase" />
<property name="kundera.keyspace" value="test_db" />
<property name="kundera.username" value="admin" />
<property name="kundera.password" value="password" />
<property name="kundera.ddl.auto.prepare" value="update" />
<property name="kundera.client.lookup.class"
value="com.impetus.client.couchbase.CouchbaseClientFactory" />
<property name="kundera.client.property" value="kunderaCouchbaseTest.xml" />
</properties>
</persistence-unit>
kundera.username
and kundera.password
are credentials for cluster-wide operations.
-
CRUD
- User can Create, Read, Update and Delete data in Couchbase Buckets using Kundera. Refer test-case.
-
Basic Select Queries
- User can perform basic SELECT queries with
WHERE
clause. Refer test-case.
- User can perform basic SELECT queries with
-
Native Queries
- Native queries can also be performed using
entityManager.createNativeQuery()
method. Refer test-case.
- Native queries can also be performed using
-
Schema Generation
- User can automatically generate schema by using
kundera.ddl.auto.prepare
property in Persistence Unit. Check Schema Generation for more details.
- User can automatically generate schema by using
- CRUD on simple entities (without embeddables, relationships and inheritance) is possible.
- Only queries with
WHERE
clause are allowed.
- Externalize different ports and timeouts.
- Support secondary indexes.