Overview

This is the main documentation for the gora-cassandra module which enables Apache Cassandra backend support for Gora.

gora.properties

Property Key Property Value Required Description
gora.datastore.default= org.apache.gora.cassandra.store.CassandraStore Yes Implementation of the persistent Java storage class
gora.cassandrastore.mapping.file= /path/to/gora-cassandra-mapping.xml No The XML mapping file to be used. If no value is used this defaults to gora-cassandra-mapping.xml
gora.cassandrastore.cassandraServers= localhost Yes This value should specify the host for a running Cassandra server or node. In this case the server happens to be running on localhost which is the default Cassandra server configuration.
gora.cassandrastore.port= 9042 Yes This value should specify the cql port for a running Cassandra server or node. In this case the server happens to be running on 9042 port which is the default Cassandra server configuration.
gora.cassandrastore.clusterName= Test Cluster No This value should specify the cassandra cluster name for a running Cassandra server or node. In this case the server has configured to run with Cassandra cluster name as 'Test Cluster' which is the default Cassandra server configuration.
gora.cassandrastore.username= ${username} No The authentication details for passing a username to the CassandraHostConfigurator. This will be required if security is required for Cassandra reads and writes.
gora.cassandrastore.password= ${password} No The authentication details for passing a password to the CassandraHostConfigurator. This will be required if security is required for Cassandra reads and writes.
gora.cassandrastore.cassandraSerializationType= AVRO/NATIVE No The serialization type for persist into the cassandra data store. default value is Native serialization type

Gora Cassandra mappings

Say we wished to map some CassandraRecord data and store it into the CassandraStore.

<gora-otd>

    <keyspace name="RecordKeySpace" durableWrite="false">
        <placementStrategy name="SimpleStrategy" replication_factor="1"/>
    </keyspace>

    <class name="org.apache.gora.cassandra.example.generated.AvroSerialization.CassandraRecord"
           keyClass="org.apache.gora.cassandra.example.generated.AvroSerialization.CassandraKey"
           keyspace="RecordKeySpace"
           table="CassandraRecord" allowFiltering="true" id="5a1c395e-b41f-11e5-9f22-ba0be0483c18">
        <field name="name" column="name" type="text"/>
        <field name="dataInt" column="age" type="int"/>
        <field name="salary" column="salary" type="bigint"/>
        <field name="dataDouble" column="testDouble" type="double"/>
        <field name="dataBytes" column="quotes" type="blob"/>
        <field name="arrayInt" column="listInt" type="list(int)"/>
        <field name="arrayString" column="listString" type="list(text)"/>
        <field name="arrayLong" column="listLong" type="list(bigint)"/>
        <field name="arrayDouble" column="listDouble" type="list(double)"/>
        <field name="mapInt" column="mapInt" type="map(text,int)"/>
        <field name="mapString" column="mapString" type="map(text,text)"/>
        <field name="mapLong" column="mapLong" type="map(text,bigint)"/>
        <field name="mapDouble" column="mapDouble" type="map(text,double)"/>
    </class>

    <cassandraKey name="org.apache.gora.cassandra.example.generated.AvroSerialization.CassandraKey">
        <partitionKey>
            <field name="url" column="urlData" type="text"/>
            <field name="timestamp" column="timestampData" type="bigint"/>
        </partitionKey>
        <clusterKey>
            <key column="timestampData" order="desc"/>
        </clusterKey>
    </cassandraKey>

</gora-otd>

Here you can see that we require the definition of two child elements within the gora-otd mapping configuration, namely;

The keyspace element; where we specify:

  1. a parameter containing the Cassandra keyspace schema name e.g. RecordKeySpace,

  2. a parameter containing the durable write enabled property in the Cassandra keyspace e.g. false, More about durable write can be found here.

  3. the child element placementStrategy containing the Cassandra placementStrategy details, a parameter containing the Cassandra placement strategy name, e.g. SimpleStrategy, gora-cassandra will use SimpleStrategy by default if no value for this attribute is specified. More about placement strategies can be found here.

  4. a parameter containing a replicationFactor attribute with value integer. Again the replicationFactor value associated with the Keyspace tag will only apply if Gora creates the Keyspace and will have no effect if this is being used against an existing keyspace. the default value for 'replicationFactor' is '1'.

The class element specifying persistent fields which values should map to. This element contains;

  1. a parameter containing the Persistent class name e.g. org.apache.gora.cassandra.example.generated.AvroSerialization.CassandraRecord,

  2. a parameter containing the keyClass e.g. org.apache.gora.cassandra.example.generated.AvroSerialization.CassandraKey which specifies the keys which map to the field values,

  3. a parameter containing the keyspace e.g. RecordKeySpace which matches to the above keyspace definition,

  4. a parameter containing the table name e.g. CassandraRecord,

  5. a parameter containing the allow filtering e.g. true, More about allow filtering can be found here.

  6. a child element(s) field which represent fields which are to be persisted into Cassandra. These need to be configured such that they receive the following;

    finally a parameter name e.g. (name, dateOfBirth, ssn and salary respectively) which map to Gora field name,

    a parameter containing the column name e.g. name,

    a parameter containing the data type of the column e.g. text,

    an optional parameter primarykey, which indicates the primary key.

The cassandraKey element specifying composite key fields which is used in keyClass, This is optional, this element should be added only when composite keys are available;

  1. a child element(s) partitionKey which represent cassandra partition key

    a child element(s) compositeKey which represent cassandra composite partition key

    a child element(s) field which represent partition key fields which are to be persisted into Cassandra. These need to be configured such that they receive the following;

    a parameter name e.g. (name, dateOfBirth, ssn and salary respectively) which map to Gora field name,

    a parameter containing the column name e.g. name,

    a parameter containing the data type of the column text,

  2. a child element(s) clusterKey which represent cassandra cluster key

    a child element(s) key which represents column key fields which needs to be add clustered key.

    a parameter containing the column name e.g. name,

    a parameter containing the Order type of the column to be applied e.g. desc,