Skip to content

Cassandra Specific Features

xamry edited this page Jul 25, 2012 · 20 revisions

Kundera allows you to specify data-store specific hooks into a configuration file. You need to add below property into persistence.xml for your persistence unit. Here kundera-cassandra.properties is the name of configuration file that must be in classpath of your application:

<property name="kundera.client.property" value="kundera-cassandra.properties" />

You specify properties in this file as key-value pairs.

Replication Factor

In order to set replication factor, just add below line into kundera-cassandra.properties:

replication_factor=n

where 'n' is an integer number, e.g. 3

Placement Strategy

For setting placement strategy, add below line into kundera-cassandra.properties:

placement_strategy=org.apache.cassandra.locator.SimpleStrategy

OR

placement_strategy=org.apache.cassandra.locator.NetworkTopologyStrategy

Counter Column Family

Counter column families, available starting with Cassandra 0.8.0, are supported in Kundera. They are specified in kundera-cassandra.properties file as comma separated list:

cf_defs=<Counter column family Name>|<Default Validation Class>|<Comparator Type>

An example entry is:

cf_defs=MyCounterColumnFamily1|CounterColumnType|UTF8Type,MyCounterColumnFamily2|CounterColumnType|UTF8Type

Please note that should be same as the table name specified at entity class definition, like this:

@Entity
@Table(name = "MyCounterColumnFamily1", schema = "KunderaExamples@cassandra_pu")
public class WebPageHitCounter
{
    @Id
    private String id;

    @Column
    private int counter;

    //getters and setters
}

A sample property file is available here.

For example on how to use this feature, refer to test class CountersTest and SuperCountersTest.

Inverted Indexing

As a default behavior, Kundera uses Cassandra's secondary indexing mechanism for querying on columns in a column family. A limitation of secondary indexing is that it doesn't support querying on columns within super columns.

To overcome this limitation, users have an option to use Lucene Indexing, which can be switched on by specifying "index.home.dir" property in persistence.xml. It enables users to run queries in column families as well as super column families.

For those who don't want to use Lucene indexing because of performance or other reasons, inverted indexing is an alternative. You can turn it on via specifying below property in kundera-cassandra.properties:

inverted.indexing.enabled=true

It enables insertion of records in inverted index column family when user inserts records in the original column family. When you run JPA query for searching a column within a super column, Kundera searches in inverted index first, retrieves Row key, and then finds records from original column family.

For an example: See TwissandraTest.

Home

Clone this wiki locally