• No results found

Easy-Cassandra User Guide

N/A
N/A
Protected

Academic year: 2021

Share "Easy-Cassandra User Guide"

Copied!
32
0
0

Loading.... (view fulltext now)

Full text

(1)
(2)

Summary

About Easy-Cassandra...5

Features...5

Java Objects Supported...5

About Versions...6 Version: 1.1.0...6 Version: 1.0.9...6 Version: 1.0.8...6 Version: 1.0.7...6 Version: 1.0.6...6 Version: 1.0.5...6 Version: 1.0.4...6 Version: 1.0.3...7 Version: 1.0.2...7 Version: 1.0.1...7 Beyond version...7

For use the Easy-Cassandra is necessary: ...7

The Thrift's dependence: ...7

Maven:...8 Annotations...10 Used in Class...10 Entity: ...10 MappedSuperclass: ...10 Used in Field...11 Column: ...11 Embedded: ...11 Enumerated: ...11 Version...12 Index: ...12 Id: ...12

Complete Example with Annotation...13

Commands...13 Consistency Level...13 Enum Options:...13 ONE:...13 QUORUM ...14 ALL...14 DCQUORUM...14 DCQUORUMSYNC...15

The class org.easycassandra.persistence.EasyCassandraManager...16

Client getClient(String keySpace, String host, int port)...16

Persistence getPersistence(String keySpace, String host, int port)...16

boolean addFamilyObject(Class<?> classColumnFamily)...16

The class org.easycassandra.persistence.Persistence...17

Insert Commands...18

insert(Object object, ConsistencyLevelCQL consistencyLevel)...18

insert(Object object)...18

Remove Commands...18

(3)

deleteById(Object Id, Class objectClass)...18

Update Commands...18

update(Object object, ConsistencyLevel consistencyLevel)...19

update(Object object, ConsistencyLevel consistencyLevel)...19

List Commands...19

findAll(Class persistenceClass, ConsistencyLevelCQL consistencyLevel, int limit)...19

findAll(Class persistenceClass, ConsistencyLevelCQL consistencyLevel)...19

findAll(Class persistenceClass, int limit)...19

findAll(Class persistenceClass)...20

findByIndex(Object index, Class objectClass, ConsistencyLevelCQL consistencyLevelCQL, int limit)...20

findByIndex(Class persistenceClass, ConsistencyLevelCQL consistencyLevel)...20

findByIndex(Class persistenceClass, int limit)...20

findByIndex(Class persistenceClass)...20

Retrieve from Key row Commands...21

findByKey(Object key, Class persistenceClass, ConsistencyLevelCQL consistencyLevel)...21

findByKey(Object key, Class persistenceClass)...21

findByKeyIn(Class baseClass,ConsistencyLevelCQL consistencyLevel,Object... keys) ...21

findByKeyIn(Class baseClass, Object... keys)...21

Count Commands...21

count(Class<?> clazz,ConsistencyLevelCQL consistencyLevel)...21

count(Class clazz)...22

Sample Abstract DAO...23

Native Commands...25

Get Thrift Client...25

Get Thrift Client in Current Persistence...25

Execute Cassandra Query Language...25

executeUpdateCql(String query)...25

executeCql(String query)...25

The class org.easycassandra.persistence.JCassandra...26

Add Class for Easy-Cassandra to manager...26

EasyCassandraManager.addFamilyObject(Class<?> classColumnFamily)...26 Persistence.createJCassandra(String cql)...26 List getResultList()...26 setFirstResult(int startPosition);...27 int getFirstResult();...27 setMaxResults(int maxResult);...27 int getMaxResults();...27

setParameter(String name, Object value);...27

Set<Parameter<?>> getParameters();...28

Parameter<?> getParameter(int position);...28

Parameter<?> getParameter(String name);...28

Object getSingleResult();...28

boolean executeUpdate();...28

JPQL in Cassandra Commands...29

Retrieve Objects...29

Select the Object...29

(4)

Count number of row in Object...29

Delete Objects...30

remove the Object...30

remove some fields in the Object...30

Update Objects...31

update some fields in the Object...31

How to Contribute with this project...32

(5)

About Easy-Cassandra

Easy-Cassandra is a framework ORM API and a high client for Apache Cassandra in java, with this is possible persist information from the Java Object in easy way. For this is only necessary add some annotations in some fields and your class. It works like an abstraction's tier in the Thrift, doing call for Cassandra.

The Easy-Cassandra uses the Thrift implementation and has like the main objective be one simple ORM (Object relational manager). It need the jdk 7 for run, because some parts in your code was replaced

reflection for invoke dynamic. So will have a behavior faster than other framework. The Easy-Cassandra was the first framework compatible with Cassandra version above 0.8 and the first one to use CQL (Cassandra Query Language). For read a class, it use the invokedynamic, fifteen time faster than reflection.

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

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

Features

• An ORM easy to use in Cassandra • Use the JPQL

• 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, etc.).

• Read and Write in Cassandra with Level Consistency.

• The first framework ORM in Cassandra to compatibles with version above 0.8.0. • The first to use CQL

• compatible with CQL 2.0

• The first to use invokedynamic instead to reflection • In the Apache version 2.0 license

• Supporting JPA 2.0 annotation

• Supporting Java Query Language in Cassandra

Java Objects Supported

The Easy-Cassandra has support for the Object java bellow:

• all primitives types (int, long, float, double, short, byte, boolean) • java.lang.Boolean • java.util.Date • java.lang.Double • java.lang.Float • java.lang.Integer • java.lang.Long • java.lang.String • java.lang.Boolean • java.lang.Byte

(6)

• java.lang.Short • java.lang.Character • java.io.File

• java.nio.file.Path

About Versions

The current and stable version is 1.1.0 Version: 1.1.0

• Client for many Client in sequencial mode • Client for many Client in sequencial random • DownGrade to java 6

• create keyspace automatically • do single client

Version: 1.0.9

• Supporting at jpa 2.0 annotation • Query with objects

• Version to retrieve the timestamp of the object • Using the JPQL

• now supported inheritance

Version: 1.0.8

• Select Key from 'in' CQL command

• Create automatically the ColumnFamily in Run Time • Create automatically the Index in Run Time

• Support with cql 2.0

• Now, it not necessary create Column Family or Secondary Index. The Easy-Cassandra will create that in run time.

Version: 1.0.7

• update cassandra-thrift to 1.0.7 Version: 1.0.6

• Fixes bug with File

• Support Calendar interface Version: 1.0.5

• Can now store files

• Support java.io.File and java.nio.file.Path Version: 1.0.4

(7)

• Less memory

• Now is supported all primitives types

• Now is supported Byte, character, Short, BigInteger and BigDecimal Version: 1.0.3

• Fixes bug with result • update for Thrift 1.0.6

• Log now using java.util.loggin Version: 1.0.2

• Fixes bug with Boolean's Object

• Now the Cassandra's lib is supported this way is possible use every Cassandra above of the version 0.8.0

Version: 1.0.1

• Allowed use Column and ColumnFamilyValue in default mode this way its get the field's name • Fixes bug in Reflection

Beyond version

For use the Easy-Cassandra is necessary:

• JDK 7 or above • JPA 2.0 annotation lib

• Apache Cassandra is running • Create the Keystore

• Do annotations in the class Annotations

• Realize call for save the object in Cassandra Here

• Add Easy-Cassandra's Lib https://github.com/otaviojava/Easy-Cassandra/downloads

• Add Thrift Dependence: Easy Cassandra with Thrift dependencies

The Thrift's dependence:

• cassandra-thrift-1.0.7.jar • commons-codec-1.3.jar • commons-lang-2.4.jar • commons-logging-1.1.1.jar • httpclient-4.0.1.jar • httpcore-4.0.1.jar • junit-4.4.jar • libthrift-0.6.1.jar • servlet-api-2.5.jar • slf4j-api-1.6.1.jar

(8)

Maven:

For use Easy-Cassandra with maven you must add in your maven application the repository and then add the tag of the project.

(9)

<project>

….

<dependencies>

<dependency>

<groupId>org.easycassandra</groupId>

<artifactId>EasyCassandra</artifactId>

<version>1.0.9</version>

</dependency>

<dependency>

<groupId>org.ow2.spec.ee</groupId>

<artifactId>ow2-jpa-2.0-spec</artifactId>

<version>1.0.11</version>

</dependency>

<!-- other dependencies -->

</dependencies>

<repositories>

<!-- other repositories -->

<repository>

<id>easycassandra</id>

<url>http://otaviojava.googlecode.com/svn/repository/</url>

</repository>

</repositories>

</project>

(10)

Annotations

The annotations are for mapping of the object, then persist and retrieve the information in Cassandra. In current version are used jpa annotations

Used in Class

Entity:

Annotations for identify the family column name. E.g:

@Entity(name = "Person")

public class Person implements Serializable {...}

@Entity

public class Person implements Serializable {...}

If this no used the 'name' value, the default value is the Class's name

MappedSuperclass:

You can use inheritance for this you need the @MappedSuperclass annotations in father's class and the subclass allow persist the objects of the super class.

@MappedSuperclass

public class Worker implements Serializable {

@Column

private String name;

@Column

private Double salary; //getter and setter

}

@Entity

public class Engineer extends Worker {

@Id

private String nickName;

@Column

private String type;

@Column

private String especialization; //getter and setter

(11)

Used in Field

Column:

For identify the column in the Family Column, the classes can be used are:

• all primitives types (int, long, short, byte, float, double, boolean) • java.lang.Boolean • java.util.Date • java.lang.Double • java.lang.Float • java.lang.Integer • java.lang.Long • java.lang.String • java.lang.Boolean • java.lang.Byte • java.lang.Short • java.lang.Character • java.io.File • java.nio.file.Path

@Column(name = "year") private Integer year; @Column

private Integer year;

If this no used the 'name' value, the default value is the Field's name

Embedded:

The class with this is annotation has fields with Column inside itself, but the persistence way continues in the same Family of the Column. This annotation is to do the object’s modeling easily.

@Embedded

private MyObject myObject;

Enumerated:

For be used in Enums @Enumerated

@Column(name="sex") private EnumClass enumClass;

(12)

@Enumerated

private EnumClass enumClass;

If this no used the 'name' value, the default value is the Field's name

Version

The version annotation is used for know the time that Object was persisted in Cassandra dataBase. It uses the timestamp in column, in other words, this annotation doesn't persist nothing in Cassandra, but retrieves the timestamp from line.

This annotation might be java.lang.Long, java.lang.String, java.util.Date, java.util.Calendar.

@Version

private Date timeStampDate; Index:

The field with this annotation is an index secundary, can search and retrieve information from the row like Id, need also use the Column together with this annotation.

@Index

@Column(name = "name") private String name;

@Index

@Column

private String name; Id:

The field with this annotation is a Key of the Row. If the auto value is true will generate auto increment, each new Key in the FamilyColumn there are a new value auto numeric.

@Id

private String id;

@Id

@GeneratedValue

private Long id;

When you use the auto increment resource the kind of key field must be: java.lang.String, java.lang.Long, java.lang.Integer, java.lang.Byte, java.lang.Short, java.math.BigInteger

The default value for auto equals false, in other words Easy-Cassandra will not generate an auto increment value, when the auto is false can use all type supported by framework and when is auto is true must use Long object. Each Class with FamilyColumn annotation must be this annotation in some field.

(13)

Complete Example with Annotation

@Entity(name = "person")

public class Person implements Serializable { private static final long serialVersionUID = 3L; @Id

private Long id;

@Column(name = "name") private String name; @Column(name = "born") private Integer year; //getter and setter }

//Embedded class

public class Address implements Serializable { private static final long serialVersionUID = 1L; @Column(name="state")

private String state; @Column(name="cyte") private String city; @Column(name="street") private String street; @Column(name="cep") private String cep; //getter and setter }

Commands

Consistency Level

The org.easycassandra.ConsistencyLevel is an enum that controls both read and write, in Easy-Cassandra, the behavior based on the ReplicationFactor of the keyspace.

Enum Options: ONE:

Read

Will return the record returned by the first replica to respond. A consistency check is always done in a background thread to fix any consistency issues when ConsistencyLevel.ONE is used. This means subsequent calls will have correct data even if the initial read gets an older value. (This is called ReadRepair).

(14)

Write

Ensure that the write has been written to at least 1 replica's commit log and memory table before responding to the client.

QUORUM Read

Will query all replicas and return the record with the most recent timestamp once it has at least a majority of replicas (N 2 + 1) reported. Again, the remaining replicas will be checked in the background.

Write

Ensure that the write has been written to N 2 + 1 replicas before responding to the client. ALL Read

Will query all replicas and return the record with the most recent timestamp once all replicas have replied. Any unresponsive replicas will fail the operation.

Write

Ensure that the write is written to all N replicas before responding to the client. Any unresponsive replicas will fail the operation.

DCQUORUM

Read

Returns the record with the most recent timestamp once a majority of replicas within the local datacenter have replied.

Write

Ensure that the write has been written to <ReplicationFactor> 2 + 1 nodes, within the local datacenter (requires NetworkTopologyStrategy) .

(15)

DCQUORUMSYNC

Read

Returns the record with the most recent timestamp once a majority of replicas within each datacenter have replied.

Write

Ensure that the write has been written to <ReplicationFactor> 2 + 1 nodes in each datacenter (requires NetworkTopologyStrategy).

(16)

The class org.easycassandra.persistence.EasyCassandraManager

This class has objective does connections for Cassandra and manages them, also is it that all information is contained in common between the all objects of the connections, the class Persistence.

Client getClient(String keySpace, String host, int port)

Method for create the Cassandra's Client native. That: keySpace- name of keySpace in Cassandra

host- host that Cassandra be

port – number of port to communication with Cassandra DataBase

EasyCassandraManager.getClient("keyspace", "host", 9160);

Persistence getPersistence(String keySpace, String host, int port)

Method for create the Easy-Cassandra's Client. That:

keySpace- name of keySpace in Cassandra host- host that Cassandra be

port – number of port to communication with Cassandra Data Base

Persistence getPersistence(String keySpace, String host, int port)

boolean addFamilyObject(Class<?> classColumnFamily)

This command is for add some Class for use in JPQL in Cassandra, so you need add class before its use. EasyCassandraManager.addFamilyObject(Object1.class);

(17)

The class org.easycassandra.persistence.Persistence

The class Persistence is the main Class for do call to Cassandra, for created this class you must inform the host, port and Keystore where is Cassandra.

Persistence persistence= EasyCassandraManager.getPersistence("javabahia", "localhost", 9160);

In current version you can use one or more nodes with easy-cassandra. Using multi-node you have two choice: random or sequential way and both you should add nodes before use the client.

For random way, access the client in randomly, use the class PersistenceRandom and for the sequential way, use the client sequentially, use the class PersistenceSequencial. Both are son of Persistence, in other word, it's possible change single node, sequential node and random node in real time.

Adding nodes EasyCassandraManager.getPersistence("javabahia", "node1", 9160); EasyCassandraManager.getPersistence("javabahia", "node2", 9160); EasyCassandraManager.getPersistence("javabahia", "node3", 9160); Random Persistence persistence=EasyCassandraManager.getPersistenceRandom("javabahia"); Sequential Persistence persistence=EasyCassandraManager.getPersistenceSequencial("javabahia"); Single

(18)

Insert Commands

This are command for persist class in Cassandra.

insert(Object object, ConsistencyLevelCQL consistencyLevel)

Insert the object with a consistency level defined, it return true if executed with success. boolean success=persistence.insert(bean,ConsistencyLevelCQL.ALL);

insert(Object object)

Insert the object with a consistency level equal ConsistencyLevelCQL.ONE, it return true if executed with success.

boolean success=persistence.insert(bean);

Remove Commands

delete(Object object)

Remove all row from key inside of the Object, the key value must be not empty or null. It return true if executed with success.

boolean success=persistence.delete(bean);

deleteById(Object Id, Class objectClass)

Remove all row with key value and use the Class for search the respective Column Family. It return true if executed with success.

boolean success=persistence.deleteById(rowKey, baseClass); Update Commands

(19)

update(Object object, ConsistencyLevel consistencyLevel)

Update all row with information present in the object with Consistency level sectioned, this command do an override in values in the row, the key value must be not empty or null. It return true if executed with success.

boolean success=persistence.update(bean,ConsistencyLevelCQL.DCQUORUM);

update(Object object, ConsistencyLevel consistencyLevel)

Update all row with information present in the object consistency level equal ConsistencyLevelCQL.ONE this command do an override in values in the row, the key value must be not empty or null. It return true if

executed with success.

boolean success=persistence.update(bean); List Commands

findAll(Class persistenceClass, ConsistencyLevelCQL consistencyLevel, int limit)

Return all objects in the Column Family, recovered by class, with consistency level selected and with a limit number defined.

List<BaseObject> list =persistence.findAll(baseClass, ConsistencyLevelCQL.DCQUORUMSYNC, 15000); findAll(Class persistenceClass, ConsistencyLevelCQL consistencyLevel)

Return all objects in the Column Family, recovered by class, with consistency level selected and with a limit number 10000.

List<BaseObject> list =persistence.findAll(baseClass, ConsistencyLevelCQL.DCQUORUMSYNC); findAll(Class persistenceClass, int limit)

Return all objects in the Column Family, recovered by class, with consistency level equal ConsistencyLevelCQL.ONE and with a limit number defined.

(20)

findAll(Class persistenceClass)

Return all objects in the Column Family, recovered by class, with consistency level equal ConsistencyLevelCQL.ONE and with a limit number 10000.

List<BaseObject> list =persistence.findAll(baseClass);

findByIndex(Object index, Class objectClass, ConsistencyLevelCQL consistencyLevelCQL, int limit) Return all objects from secondary index in the Column Family, recovered by class, with consistency level selected and with a limit number defined. The class must be some field with Index annotations.

List<BaseObject> list =persistence.findByIndex(Index,baseClass, ConsistencyLevelCQL.DCQUORUMSYNC, 15000);

findByIndex(Class persistenceClass, ConsistencyLevelCQL consistencyLevel)

Return all objects from secondary index in the Column Family, recovered by class, with consistency level selected and with a limit number 10000. The class must be some field with Index annotations.

List<BaseObject> list =persistence.findByIndex(Index,baseClass, ConsistencyLevelCQL.DCQUORUMSYNC);

findByIndex(Class persistenceClass, int limit)

Return all objects from secondary index in the Column Family, recovered by class, with consistency level equal ConsistencyLevelCQL.ONE and with a limit number defined. The class must be some field with Index annotations.

List<BaseObject> list =persistence.findAll(Index,baseClass, 5000); findByIndex(Class persistenceClass)

Return all objects from secondary index in the Column Family, recovered by class, with consistency level equal ConsistencyLevelCQL.ONE and with a limit number 10000. The class must be some field with Index annotations.

(21)

Retrieve from Key row Commands

findByKey(Object key, Class persistenceClass, ConsistencyLevelCQL consistencyLevel)

Return the object from key row with the value passed in parameter, recovered by class, with the consistency level selectioned.

BaseObject base=(BaseObject)persistence.findByKey(idValue, baseClass,ConsistencyLevelCQL.ALL);

findByKey(Object key, Class persistenceClass)

Return the object from key row with the value passed in parameter, recovered by class, with the consistency level selected.

BaseObject base=(BaseObject)persistence.findByKey(idValue, baseClass);

findByKeyIn(Class baseClass,ConsistencyLevelCQL consistencyLevel,Object... keys)

Return the object from key row with N value passed in parameter, recovered by class, with the consistency level selected.

List<BaseObject> list=persistence.findByKeyIn(

baseClass,ConsistencyLevelCQL.ALL,param1,param2,param3);

findByKeyIn(Class baseClass, Object... keys)

Return the object from key row with N value passed in parameter, recovered by class, with the consistency level equal ConsistencyLevelCQL.ONE.

List<BaseObject> list=persistence.findByKeyIn( baseClass,param1,param2,param3); Count Commands

count(Class<?> clazz,ConsistencyLevelCQL consistencyLevel)

Return the number of rows in Column Family with the consistency level selected.

(22)

count(Class clazz)

Return the number of rows in Column Family with consistency level equal ConsistencyLevel. Long numberOfRow=persistence.count(baseClass);

(23)

Sample Abstract DAO

Bellow a simple example DAO using Easy-Cassandra.

public abstract class AbstractDao<T> { private Persistence persistence;

private Class baseClass;

public AbstractDao(Class<T> baseClass) { this.baseClass=baseClass;

persistence = EasyCassandraManager.getPersistence("javabahia", "localhost", 9160); }

public boolean insert(T bean) {

return persistence.insert(bean,ConsistencyLevelCQL.ONE); }

public boolean remove(T bean) { return persistence.delete(bean); }

public boolean removeFromRowKey(Object rowKey) { return persistence.deleteById(rowKey, baseClass); }

public boolean update(T bean) { return persistence.update(bean); }

@SuppressWarnings("unchecked") public T retrieve(Object id) {

return (T) persistence.findByKey(id, baseClass); }

@SuppressWarnings("unchecked") public List<T> listAll() {

return persistence.findAll(baseClass); }

(24)

@SuppressWarnings("unchecked") public List<T> listByIndex(Object index) {

return persistence.findByIndex(index, baseClass); }

public Long count() {

return persistence.count(baseClass); }

public List<T> findKeyIn(Object... key) {

return persistence.findByKeyIn( baseClass,key); }

}

(25)

Native Commands

Get Thrift Client

If necessary you can call Thrift functions for it, it is necessary inform the host, port, and keystore for the Class EasyCassandraManager.

Client client=EasyCassandraManager.getClient("javabahia", "localhost", 9160);

Get Thrift Client in Current Persistence

Also is allowed get Thrift's client, used by Persistence.

Client client=persistence.getClient();

Execute Cassandra Query Language

executeUpdateCql(String query)

This Command execute the query in String if there was success return true otherwise false

boolean success=persistence.executeUpdateCql("DELETE columnName FROM COLUMNFAMILY WHERE KEY = keyname1");

executeCql(String query)

Retrieve values from Query command and return The values from query like List of the Map<String, String>: Each List is a row.

Each Map<String, String>: a key in the map is equal a column's name and the value in the map is the column's value.

(26)

The class org.easycassandra.persistence.JCassandra

The interface JCassandra is look like javax.persistence.Query in JPA, its main objective is be Java Persistence Query Language, in other words, translate Java's object to Cassandra Data Base. But before talk about that call, is very important say that there are some different features between NOSQL Column Family and SQL. The first on is there aren't relationship between Column family. So you might not do relationship. Like one to one, one to many or many to many. The second one the Cassandra is case sensitive, then Person, peRson and person are different names in Cassandra.

Add Class for Easy-Cassandra to manager

The first thing to do for use JPQL in Easy-Cassandra is add Class, for this you don't need use XML, that's it without XML.

EasyCassandraManager.addFamilyObject(Class<?> classColumnFamily)

This command is for add some Class for use in JPQL in Cassandra, so you need add class before its use.

EasyCassandraManager.addFamilyObject(Object1.class); EasyCassandraManager.addFamilyObject(Object2.class);

Persistence.createJCassandra(String cql)

Method for create the interface JCassandra that is for used to control query execution.

JCassandra query=persistence.createJCassandra("select * from Object"); List getResultList()

Execute a CQL and return the result results as a List.

JCassandra query=persistence.createJCassandra("select * from Object"); List<Person> persons=jCassandra.getResultList();

(27)

setFirstResult(int startPosition);

Set the position of the first result to retrieve.

JCassandra query=persistence.createJCassandra("select * from Object"); jCassandra.setFirstResult(2);

List<Person> persons=jCassandra.getResultList();

int getFirstResult();

Get the parameter objects corresponding to the declared parameters of the query. Returns empty set if the query has no parameters. This method is not required to be supported for native queries.

JCassandra query=persistence.createJCassandra("select * from Object"); jCassandra.getFirstResult();

setMaxResults(int maxResult);

Set the maximum number of results to retrieve.

JCassandra query=persistence.createJCassandra("select * from Object"); jCassandra.setMaxResults(2);

List<Person> persons=jCassandra.getResultList();

int getMaxResults();

The position of the first result the query object was set to retrieve. Returns 0 if setFirstResult was not applied to the query object.

JCassandra query=persistence.createJCassandra("select * from Object"); jCassandra.getMaxResults();

setParameter(String name, Object value);

Bind an argument to a named parameter.

JCassandra jCassandra=persistence.createJCassandra("select * from Person where id =:id ");

(28)

Set<Parameter<?>> getParameters();

Get the parameter objects corresponding to the declared parameters of the query. Returns empty set if the query has no parameters. This method is not required to be supported for native queries.

JCassandra jCassandra=persistence.createJCassandra("select * from Person where id =:id and name =:name");

Set<Parameter<?>> setParameters=jCassandra.getParameters();

Parameter<?> getParameter(int position);

Get the parameter object corresponding to the declared positional parameter with the given position. This method is not required to be supported for native queries.

JCassandra jCassandra=persistence.createJCassandra("select * from Person where id =:id and name =:name");

Parameter<?> parameter=jCassandra.getParameter(0); Parameter<?> getParameter(String name);

Get the parameter object corresponding to the declared parameter of the given name. This method is not required to be supported for native queries.

JCassandra jCassandra=persistence.createJCassandra("select * from Person where id =:id and name =:name");

Parameter<?> parameter=jCassandra.getParameter(“name”);

Object getSingleResult();

Execute a cql that returns a single result.

JCassandra jCassandra=persistence.createJCassandra("select * from Person where id = '31' ");

Person person=(Person)jCassandra.getSingleResult();

boolean executeUpdate(); Execute an update or delete statement.

JCassandra jCassandra=persistence.createJCassandra("delete from Person where id =:id ");

jCassandra.setParameter("id", 1l); jCassandra.executeUpdate();

(29)

JPQL in Cassandra Commands

Retrieve Objects

Select the Object

For retrieve the object in CQL command, you should use the '*' character. You might use the “where” condition in select, for this the field should be index secondary and key.

JCassandra jCassandra=persistence.createJCassandra("select * from Person"); List<Person> persons=jCassandra.getResultList();

Select some fields in the Object

You are able select some fields, for this separate the fields with comma. You might use the “where” condition in select, for this the field should be index secondary and key.

JCassandra jCassandra=persistence.createJCassandra("select name, id, year from Person");

List<Map<String, Object>> list=jCassandra.getResultList();

Count number of row in Object

Count number of row in Column Family use the “count(*)” command. You might use the “where” condition in select, for this the field should be index secondary and key.

JCassandra jCassandra=persistence.createJCassandra("select count(*) from Person ");

(30)

Delete Objects remove the Object

For remove the object in Cassandra, you need know the key and use this in 'where' condition.

JCassandra jCassandra=persistence.createJCassandra("delete from Person where id =:id ");

jCassandra.setParameter("id", 1l); jCassandra.executeUpdate();

remove some fields in the Object

You are able remove some fields, for this separate the fields with comma, you need know the key use that in 'where' condition.

JCassandra jCassandra=persistence.createJCassandra("delete name from Person where id =:id ");

jCassandra.setParameter("id", 10l); jCassandra.executeUpdate();

(31)

Update Objects

update some fields in the Object

You are able update some fields, for this separate the fields with comma, you need know the key use that in 'where' condition.

JCassandra jCassandra=persistence.createJCassandra("update Person set name =:name where id =:id ");

jCassandra.setParameter("id", 4l);

jCassandra.setParameter("name", "Otavio Santana"); jCassandra.executeUpdate();

(32)

How to Contribute with this project

If you would like help the project, report software error, fix bug in the document you can send email for:

otaviojava@java.net or participate in Google Groups: https://groups.google.com/group/easy-cassandra

Article:

http://weblogs.java.net/blog/otaviojava/archive/2012/01/24/persisting-information-cassandra-java-simple-exa mple

References

Related documents

Oral and written responses force interpretation of appropriateness and/or meaning Attempts to translate or use English; avoids using or speaking in the target language. Poor command

Preferred over the cassandra dynamic column family example later databases, since columns this model that the object, you need to work in this make your implementation?. Current

So, although relational coordination is most desirable with nurses, other prison officers and social workers when prison officers need to find support to manage a mentally

Berries without lesions harvested from symp- tomatic vines at maturity yielded musts with very similar quality characteristics in both the control and the treated plot at

To remove objects, select the object and press DELETE or click and drag an object from the Result Objects pane back to the Data Manager pane.. Class: Curriculum Courses

void add(int index, E element) Inserts the specified element at the position index in this list. Object set(int index, E element) Replaces the element at position index with

This thesis examines the pedestal structure, edge transport, linear MHD stability and inter-ELM edge current evolution in a series of JET-ILW Hydrogen (H) and Deuterium (D) type I

overall Object of class ovl.kmeans for the overall means clustering rows Object of class row.kmeans for the row means clustering columns Object of class col.kmeans for the column