Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

README.md

dbapi-java

Database API for Java is a lightweight JPA provider implementation for Cassandra. It can also be extended with pluggable modules for other NoSQL document-oriented databases as well.

Overview

The NoSQL field is repidly evolving and changing nowadays. It isn't mature enough and neither standardized yet. This project may help to separate business logic and object model from the database interaction layer. So that it's relatively easy to switch from one vendor to another or support both if any. It becomes possible at certain abstraction overhead though.

Requirements

Build Instructions

The standard build process with Maven is supported.

To build the project from sources and run tests please perform:

$ mvn package

To generate eclipse project files please do:

$ mvn eclipse:eclipse

Usage

The dbapi.api.DBAPI class is an entry point to the system. It provides access to the factory that can issue JPA entity managers. To create a factory you need to specify a map with configuration parameters and the list of persistent entity classes to be managed:

        Map<String, String> config = new HashMap<String, String>();
        config.put("db.type", "cassandra");
        config.put("plugins.cassandra.keyspace", "tests");
        config.put("plugins.cassandra.host", "localhost");
        config.put("plugins.cassandra.port", "9160");


        Set<Class<?>> entities = new HashSet<Class<?>>();
        entities.add(User.class);

        EntityManagerFactory factory = DBAPI.getFactory(config, entities);

        EntityManager em = factory.createEntityManager();

Please see dbapi.test.system.CRUDTest for more details on Create/Find/Delete commands that are currently supported. In order to play with this test you will need data structures to be pre-created in Cassandra. Use the following script for that:

create keyspace tests;
use tests;

create column family user with
  comparator = UTF8Type and
  column_metadata =
  [
    {column_name: username, validation_class: UTF8Type},
    {column_name: displayName, validation_class: UTF8Type},
    {column_name: bio, validation_class: UTF8Type},
    {column_name: password, validation_class: UTF8Type}
  ];

Something went wrong with that request. Please try again.