forked from Impetus/kundera
-
Notifications
You must be signed in to change notification settings - Fork 0
Kundera with Couchdb
chhavigangwal edited this page Jun 5, 2015
·
11 revisions
Couchdb is an open source database that enables easy access of data over web. It uses JavaScript Object Notation (JSON) for data storage, a lightweight format based on a subset of JavaScript syntax. Couchdb can be easily downloaded and installed with help of instructions available on its site.
Being a JPA provider, Kundera provides support for Couchdb. It allows to perform CRUD and query operation over Couchdb using JPA specifications. Let's look into how to use Kundera over Couchdb as database.
- Entity
*/
@Entity
public class PersonCouchDB
{
/** The person id. */
@Id
@Column(name = "PERSON_ID")
private String personId;
/** The person name. */
@Column(name = "PERSON_NAME")
private String personName;
/** The age. */
@Column(name = "AGE")
private Integer age;
// setters and getters.
}
<persistence-unit name="couchdb_pu">
<provider>com.impetus.kundera.KunderaPersistence</provider>
<properties>
<property name="kundera.nodes" value="localhost" />
<property name="kundera.port" value="5984" />
<property name="kundera.keyspace" value="couchdatabase" />
<property name="kundera.dialect" value="couchdb" />
<property name="kundera.client" value="couchdb" />
<property name="kundera.ddl.auto.prepare" value="create" />
<property name="kundera.client.lookup.class"
value="com.impetus.client.couchdb.CouchDBClientFactory" />
<property name="kundera.cache.provider.class"
value="com.impetus.kundera.cache.ehcache.EhCacheProvider" />
<property name="kundera.cache.config.resource" value="/ehcache-test.xml" />
</properties>
</persistence-unit>
final String nodeId = "node1";
final String originalName = "vivek";
PersonCouchDB object = new PersonCouchDB();
object.setAge(32);
object.setPersonId(ROW_KEY);
object.setPersonName(originalName);
object.setDay(Day.TUESDAY);
object.setMonth(Month.JAN);
Node node = new Node(nodeId, PersonCouchDB.class, new TransientState(), null, ROW_KEY);
node.setData(object);
client.persist(node);
PersonCouchDB result = (PersonCouchDB) client.find(PersonCouchDB.class, ROW_KEY);
```
```
// Find by key and now row key
String findByIdAndAge = "Select p from PersonCouchDB p where p.personId=:personId AND p.age=:age";
query = em.createQuery(findByIdAndAge);
query.setParameter("personId", ROW_KEY);
query.setParameter("age", 32);
```
* **Range**
```
// Find by greater than and less than clause over non row key
String findAgeByGTELTEClause = "Select p from PersonCouchDB p where p.age <=:max AND p.age>=:min";
query = em.createQuery(findAgeByGTELTEClause);
query.setParameter("min", 32);
query.setParameter("max", 35);
```
* **Between clause**
```
// find by between over non rowkey
String findAgeByBetween = "Select p from PersonCouchDB p where p.age between :min AND :max";
query = em.createQuery(findAgeByBetween);
query.setParameter("min", 32);
query.setParameter("max", 35);
```
* **Select specific field (without where clause)**
```
// select specific field AGE
String findAge = "Select p.age from PersonCouchDB p";
query = em.createQuery(findAge);
```
* **Perform aggregations (without where clause)**
Kundera supports COUNT MAX MIN SUM and AVG aggregation queries with CouchDB. Currently the support is enabled for queries without WHERE clause only.
```
// run aggregation like MIN SUM COUNT etc
String findMinAge = "Select MIN(p.age) from PersonCouchDB p";
query = em.createQuery(findMinAge);
String findSumAge = "Select SUM(p.age) from PersonCouchDB p";
query = em.createQuery(findSumAge);
String findCountAge = "Select COUNT(p.age) from PersonCouchDB p";
query = em.createQuery(findCountAge);
```
* Please refer [CouchDBQueryTest](https://github.com/impetus-opensource/Kundera/tree/trunk/src/kundera-couchdb/src/test/java/com/impetus/client/couchdb/query) for more details over JPA query support.
**_You may also refer [junits](https://github.com/impetus-opensource/Kundera/tree/trunk/src/kundera-couchdb/src/test/java/com/impetus/client/couchdb) for more examples._**
### To-do
* Enable SELECT query on a particular column with WHERE clause
* Nested AND clause support
-
Datastores Supported
- Releases
-
Architecture
-
Concepts
-
Getting Started in 5 minutes
-
Features
- Object Mapper
- Polyglot Persistence
- Queries Support
- JPQL (JPA Query Language)
- Native Queries
- Batch insert update
- Schema Generation
- Primary Key Auto generation
- Transaction Management
- REST Based Access
- Geospatial Persistence and Queries
- Graph Database Support
-
Composite Keys
-
No hard annotation for schema
-
Support for Mapped superclass
-
Object to NoSQL Data Mapping
-
Cassandra's User Defined Types and Indexes on Collections
-
Support for aggregation
- Scalar Queries over Cassandra
- Connection pooling using Kundera Cassandra
- Configuration
- [Kundera with Couchdb] (https://github.com/impetus-opensource/Kundera/wiki/Kundera-with--Couchdb)
- [Kundera with Elasticsearch] (https://github.com/impetus-opensource/Kundera/wiki/Kundera-with-Elasticsearch)
- [Kundera with HBase] (https://github.com/impetus-opensource/Kundera/wiki/Kundera-with-HBase)
- [Kundera with Kudu] (https://github.com/impetus-opensource/Kundera/wiki/Kundera-with-Kudu)
- [Kundera with MongoDB] (https://github.com/impetus-opensource/Kundera/wiki/Kundera-with-MongoDB)
- [Kundera with OracleNoSQL] (https://github.com/impetus-opensource/Kundera/wiki/Kundera-OracleNoSQL)
- [Kundera with Redis] (https://github.com/impetus-opensource/Kundera/wiki/Kundera-over-Redis)
- [Kundera with Spark] (https://github.com/impetus-opensource/Kundera/wiki/Kundera-with-Spark)
-
Extend Kundera
- Sample Codes and Examples
- [Blogs and Articles] (https://github.com/impetus-opensource/Kundera/wiki/Blogs--and-Articles)
-
Tutorials
* Kundera with Openshift
* Kundera with Play Framework
* Kundera with GWT
* Kundera with JBoss
* Kundera with Spring
-
Performance
-
Troubleshooting
-
FAQ
- Production deployments
- Feedback