Skip to main content

Easy-Cassandra= java ORM for Cassandra, now run with Maven

Posted by otaviojava on March 17, 2012 at 4:55 AM PDT

 

Running the new version of the Easy-Cassandra framework it main objective is making it easy the communication between Apache Cassandra and your application in java. With it you able create, update, retrieve, delete the java's objects in easy way and simple, for this you must add some annotation in Class and fields.

 

Characteristics

 

 

  • An ORM easy to use in Cassandra

  • Need only use some Annotations in a class to persist

  • Persists many Java Objects in way extremely easy (e.g: all primitives types, java.Lang.String, java.lang.BigDecimal, java.io.File, see here for more details).

  • Read and Write in Cassandra with Level Consistency.

  • The first framework ORM in Cassandra to compatives with version above 0.8.0.

  • The first to use CQL

  • The first to use invokedynamic instead to reflection

  • In the apache version 2.0 license

     

 

improvement in 1.0.8

 
  • Make of the Column Family and secondary index  in real time
  • CQL 2.0 Support
  • Support call key with 'in' command

 

 

 

For show the new version, we will do a simple application. This application has the objective persist information about average income of Brazil group by CEP. The objective is show how much is generated in cash and number of commercial entities by street. This way will be persist around 640 thousands information for each survey. Each request has the information below:

 

 

  • Lote code

  • how may commercial entities in CEP

  • value in cash

  • cite

  • street

  • district

  • Cep

  • type of street

  • Province

  • acronym of Province

For amazing the data will use the Cassandra, its features are:

 

Cassandra

     

    Proven

    Cassandra is in for many companies. that have large, active data sets. The largest known Cassandra cluster has over 300 TB of data in over 400 machines.

     

    Fault Tolerant

    Data is automatically replicated to multiple nodes for fault-tolerance. Replication across multiple data centers is supported. Failed nodes can be replaced with no downtime.

     

    Decentralized

    There are no single points of failure. There are no network bottlenecks. Every node in the cluster is identical.

     

    You're in Control

    Choose between synchronous or asynchronous replication for each update. Highly available asynchronous operations are optimized with features like Hinted Handoff and Read Repair.

     

    Rich Data Model

    Allows efficient use for many applications beyond simple key/value.

     

    Elastic

    Read and write throughput both increase linearly as new machines are added, with no downtime or interruption to applications.

     

    Durable

    Cassandra is suitable for applications that can't afford to lose data, even when an entire data center goes down.

     

    Professionally Supported

    Cassandra support contracts and services are available from third parties.

font:http://cassandra.apache.org/

 

 

For get developing more easy will used the Easy-Cassandra, It works like a layer above of the Thrift, facilitating call for Cassandra, increasing more productivity and leaving code more clean. For use it is necessary download the framework and its dependencies. You can manage this libs using the maven, for this add the repository like table 1.

 

table1: add repository and call the Easy-Cassandra

 

Each request will a line in Cassandra which might vary in size line by line. This way the class with annotations was like show table 2.

 

 

 

@ColumnFamilyValue(name = "controle")
public class ControleRenda implements Serializable {
 
@KeyValue(auto = true)
private Long id;
@EmbeddedValue
private Endereco endereco;
@ColumnValue(name = "valor")
private Double valor;
@ColumnValue(name = "quantidade")
private Long quantidade;
//getter and setter
}
 
public class Endereco implements Serializable {
 
@ColumnValue(name="cidade")
private String cidade;
 
@ColumnValue(name="logradouro")
private String logradouro;
 
@ColumnValue(name="bairro")
private String bairro;
 
@IndexValue
@ColumnValue(name="cep")
private String cep;
 
@ColumnValue(name="tp_logradouro")
private String tp_logradouro;
 
@ColumnValue(name="estado")
private String estado;
 
@ColumnValue(name="sigla")
private String sigla;
// getter and setter
}
 

Table 2: Mapping class with Easy-Cassandra

 

When you see the table 2, will seen the Address class with an annotation @IndexValue in cep's field, this annotation does the field be a secondary index( The secondary index is other field for search information beyond the key row).

For run our sample application needs Cassandra is running and make the keystore. The column family and secondary index will be created in run time thanks improvement in this version.

 

 

 

[prettifyclass="western"]create keyspace renda;[/prettify]

 

 

This way now only run the application and all information will persist in Cassandra. In this article was showed a practice example with 640 thousand requests. Was showed some improvements like create column family and secondary index in run time in this new version of the Easy-Cassandra.

 

 

References:

 

Easy-Cassandra: https://github.com/otaviojava/Easy-Cassandra

Documentation, lib e source (Maven_Example.rar): https://github.com/otaviojava/Easy-Cassandra/downloads

wiki: https://github.com/otaviojava/Easy-Cassandra/wiki

 

 

 

 

 

 

 

 

Comments

Can we use this in place of any relationl database ...

Can we use this in place of any relationl database ?

Regards
Javin

The NOSQL has something different than SQL and its objective ...

The NOSQL has something different than SQL and its objective is different.

See more in:
http://en.wikipedia.org/wiki/NoSQL