org.usergrid.persistence.cassandra
Class CassandraService

java.lang.Object
  extended by org.usergrid.persistence.cassandra.CassandraService

public class CassandraService
extends Object


Field Summary
static int ALL_COUNT
           
static String APPLICATIONS_CF
           
static me.prettyprint.cassandra.serializers.BytesArraySerializer bae
           
static me.prettyprint.cassandra.serializers.ByteBufferSerializer be
           
static me.prettyprint.cassandra.serializers.DynamicCompositeSerializer dce
           
static String DEFAULT_APPLICATION
           
static UUID DEFAULT_APPLICATION_ID
           
static int DEFAULT_COUNT
           
static String DEFAULT_ORGANIZATION
           
static int DEFAULT_SEARCH_COUNT
           
static int INDEX_ENTRY_LIST_COUNT
           
static me.prettyprint.cassandra.serializers.LongSerializer le
           
static String MANAGEMENT_APPLICATION
           
static UUID MANAGEMENT_APPLICATION_ID
           
static UUID NULL_ID
           
static String PRINCIPAL_TOKEN_CF
           
static String PROPERTIES_CF
           
static int RETRY_COUNT
           
static me.prettyprint.cassandra.serializers.StringSerializer se
           
static String STATIC_APPLICATION_KEYSPACE
           
static String SYSTEM_KEYSPACE
           
static String TOKENS_CF
           
static me.prettyprint.cassandra.serializers.UUIDSerializer ue
           
static boolean USE_VIRTUAL_KEYSPACES
           
 
Constructor Summary
CassandraService(Properties properties, me.prettyprint.hector.api.Cluster cluster, me.prettyprint.cassandra.service.CassandraHostConfigurator cassandraHostConfigurator, LockManager lockManager)
           
 
Method Summary
 void checkKeyspaces()
           
 int countColumns(me.prettyprint.hector.api.Keyspace ko, Object columnFamily, Object key)
           
 void createKeyspace(String keyspace, List<me.prettyprint.hector.api.ddl.ColumnFamilyDefinition> cf_defs)
           
 long createTimestamp()
          Create a timestamp based on the TimeResolution set to the cluster.
 void deleteColumn(me.prettyprint.hector.api.Keyspace ko, Object columnFamily, Object key, Object column)
          Delete column.
 void deleteRow(me.prettyprint.hector.api.Keyspace ko, Object columnFamily, Object key)
          Delete row.
 void deleteRow(me.prettyprint.hector.api.Keyspace ko, Object columnFamily, Object key, long timestamp)
          Delete row.
 void deleteRow(me.prettyprint.hector.api.Keyspace ko, Object columnFamily, String key)
           
 Set<String> getAllColumnNames(me.prettyprint.hector.api.Keyspace ko, Object columnFamily, Object key)
           
 List<me.prettyprint.hector.api.beans.HColumn<String,ByteBuffer>> getAllColumns(me.prettyprint.hector.api.Keyspace ko, Object columnFamily, Object key)
           
<N,V> List<me.prettyprint.hector.api.beans.HColumn<N,V>>
getAllColumns(me.prettyprint.hector.api.Keyspace ko, Object columnFamily, Object key, me.prettyprint.hector.api.Serializer<N> nameSerializer, me.prettyprint.hector.api.Serializer<V> valueSerializer)
          Gets the columns.
 me.prettyprint.hector.api.Keyspace getApplicationKeyspace(UUID applicationId)
           
 me.prettyprint.cassandra.service.CassandraHostConfigurator getCassandraHostConfigurator()
           
 me.prettyprint.hector.api.Cluster getCluster()
           
<N,V> me.prettyprint.hector.api.beans.HColumn<N,V>
getColumn(me.prettyprint.hector.api.Keyspace ko, Object columnFamily, Object key, N column, me.prettyprint.hector.api.Serializer<N> nameSerializer, me.prettyprint.hector.api.Serializer<V> valueSerializer)
          Gets the column.
 me.prettyprint.hector.api.beans.HColumn<String,ByteBuffer> getColumn(me.prettyprint.hector.api.Keyspace ko, Object columnFamily, Object key, String column)
           
<N,V> me.prettyprint.hector.api.beans.ColumnSlice<N,V>
getColumns(me.prettyprint.hector.api.Keyspace ko, Object columnFamily, Object key, N[] columns, me.prettyprint.hector.api.Serializer<N> nameSerializer, me.prettyprint.hector.api.Serializer<V> valueSerializer)
           
 List<me.prettyprint.hector.api.beans.HColumn<ByteBuffer,ByteBuffer>> getColumns(me.prettyprint.hector.api.Keyspace ko, Object columnFamily, Object key, Object start, Object finish, int count, boolean reversed)
          Gets the columns.
<N,V> List<me.prettyprint.hector.api.beans.HColumn<N,V>>
getColumns(me.prettyprint.hector.api.Keyspace ko, Object columnFamily, Object key, Set<String> columnNames, me.prettyprint.hector.api.Serializer<N> nameSerializer, me.prettyprint.hector.api.Serializer<V> valueSerializer)
          Gets the columns.
 me.prettyprint.hector.api.ConsistencyLevelPolicy getConsistencyLevelPolicy()
           
 List<UUID> getIdList(me.prettyprint.hector.api.Keyspace ko, Object key, Object start, Object finish, int count, boolean reversed, IndexBucketLocator locator, UUID applicationId, String collectionName)
          Gets the id list.
 me.prettyprint.hector.api.Keyspace getKeyspace(String keyspace, UUID prefix)
           
 LockManager getLockManager()
           
 Properties getProperties()
           
 Map<String,String> getPropertiesMap()
           
<K> List<K>
getRowKeyList(me.prettyprint.hector.api.Keyspace ko, Object columnFamily, me.prettyprint.hector.api.Serializer<K> keySerializer)
          Gets the row keys as uui ds.
<K> Set<K>
getRowKeySet(me.prettyprint.hector.api.Keyspace ko, Object columnFamily, me.prettyprint.hector.api.Serializer<K> keySerializer)
          Gets the row keys.
<K,N,V> me.prettyprint.hector.api.beans.Rows<K,N,V>
getRows(me.prettyprint.hector.api.Keyspace ko, Object columnFamily, List<K> keys, me.prettyprint.hector.api.Serializer<K> keySerializer, me.prettyprint.hector.api.Serializer<N> nameSerializer, me.prettyprint.hector.api.Serializer<V> valueSerializer)
          Gets the columns.
<K,N,V> me.prettyprint.hector.api.beans.Rows<K,N,V>
getRows(me.prettyprint.hector.api.Keyspace ko, Object columnFamily, List<K> keys, Set<String> columnNames, me.prettyprint.hector.api.Serializer<K> keySerializer, me.prettyprint.hector.api.Serializer<N> nameSerializer, me.prettyprint.hector.api.Serializer<V> valueSerializer)
          Gets the columns.
 me.prettyprint.hector.api.Keyspace getSystemKeyspace()
           
 me.prettyprint.hector.api.Keyspace getUsergridApplicationKeyspace()
          The Usergrid_Applications keyspace directly
 void init()
           
static String keyspaceForApplication(UUID applicationId)
           
 void logKeyspaces()
           
 Map<ByteBuffer,List<me.prettyprint.hector.api.beans.HColumn<ByteBuffer,ByteBuffer>>> multiGetColumns(me.prettyprint.hector.api.Keyspace ko, Object columnFamily, List<?> keys, Object start, Object finish, int count, boolean reversed)
           
static UUID prefixForApplication(UUID applicationId)
           
 void setCassandraHostConfigurator(me.prettyprint.cassandra.service.CassandraHostConfigurator chc)
           
 void setCluster(me.prettyprint.hector.api.Cluster cluster)
           
 void setColumn(me.prettyprint.hector.api.Keyspace ko, Object columnFamily, Object key, Object columnName, Object columnValue)
           
 void setColumn(me.prettyprint.hector.api.Keyspace ko, Object columnFamily, Object key, Object columnName, Object columnValue, int ttl)
           
 void setColumns(me.prettyprint.hector.api.Keyspace ko, Object columnFamily, byte[] key, Map<?,?> map)
          Sets the columns.
 void setColumns(me.prettyprint.hector.api.Keyspace ko, Object columnFamily, byte[] key, Map<?,?> map, int ttl)
           
 void setConsistencyLevelPolicy(me.prettyprint.hector.api.ConsistencyLevelPolicy consistencyLevelPolicy)
           
 void setIdList(me.prettyprint.hector.api.Keyspace ko, UUID targetId, String keyPrefix, String keySuffix, List<UUID> keyIds)
          Sets the id list.
 void setLockManager(LockManager lockManager)
           
 void setProperties(Properties properties)
           
 void startClusterHealthCheck()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SYSTEM_KEYSPACE

public static String SYSTEM_KEYSPACE

STATIC_APPLICATION_KEYSPACE

public static String STATIC_APPLICATION_KEYSPACE

USE_VIRTUAL_KEYSPACES

public static final boolean USE_VIRTUAL_KEYSPACES
See Also:
Constant Field Values

APPLICATIONS_CF

public static final String APPLICATIONS_CF
See Also:
Constant Field Values

PROPERTIES_CF

public static final String PROPERTIES_CF
See Also:
Constant Field Values

TOKENS_CF

public static final String TOKENS_CF
See Also:
Constant Field Values

PRINCIPAL_TOKEN_CF

public static final String PRINCIPAL_TOKEN_CF
See Also:
Constant Field Values

DEFAULT_COUNT

public static final int DEFAULT_COUNT
See Also:
Constant Field Values

ALL_COUNT

public static final int ALL_COUNT
See Also:
Constant Field Values

INDEX_ENTRY_LIST_COUNT

public static final int INDEX_ENTRY_LIST_COUNT
See Also:
Constant Field Values

DEFAULT_SEARCH_COUNT

public static final int DEFAULT_SEARCH_COUNT
See Also:
Constant Field Values

RETRY_COUNT

public static final int RETRY_COUNT
See Also:
Constant Field Values

DEFAULT_APPLICATION

public static final String DEFAULT_APPLICATION
See Also:
Constant Field Values

DEFAULT_ORGANIZATION

public static final String DEFAULT_ORGANIZATION
See Also:
Constant Field Values

MANAGEMENT_APPLICATION

public static final String MANAGEMENT_APPLICATION
See Also:
Constant Field Values

MANAGEMENT_APPLICATION_ID

public static final UUID MANAGEMENT_APPLICATION_ID

DEFAULT_APPLICATION_ID

public static final UUID DEFAULT_APPLICATION_ID

se

public static final me.prettyprint.cassandra.serializers.StringSerializer se

be

public static final me.prettyprint.cassandra.serializers.ByteBufferSerializer be

ue

public static final me.prettyprint.cassandra.serializers.UUIDSerializer ue

bae

public static final me.prettyprint.cassandra.serializers.BytesArraySerializer bae

dce

public static final me.prettyprint.cassandra.serializers.DynamicCompositeSerializer dce

le

public static final me.prettyprint.cassandra.serializers.LongSerializer le

NULL_ID

public static final UUID NULL_ID
Constructor Detail

CassandraService

public CassandraService(Properties properties,
                        me.prettyprint.hector.api.Cluster cluster,
                        me.prettyprint.cassandra.service.CassandraHostConfigurator cassandraHostConfigurator,
                        LockManager lockManager)
Method Detail

init

public void init()
          throws Exception
Throws:
Exception

getCluster

public me.prettyprint.hector.api.Cluster getCluster()

setCluster

public void setCluster(me.prettyprint.hector.api.Cluster cluster)

getCassandraHostConfigurator

public me.prettyprint.cassandra.service.CassandraHostConfigurator getCassandraHostConfigurator()

setCassandraHostConfigurator

public void setCassandraHostConfigurator(me.prettyprint.cassandra.service.CassandraHostConfigurator chc)

getProperties

public Properties getProperties()

setProperties

public void setProperties(Properties properties)

getPropertiesMap

public Map<String,String> getPropertiesMap()

getLockManager

public LockManager getLockManager()

setLockManager

public void setLockManager(LockManager lockManager)

getConsistencyLevelPolicy

public me.prettyprint.hector.api.ConsistencyLevelPolicy getConsistencyLevelPolicy()

setConsistencyLevelPolicy

public void setConsistencyLevelPolicy(me.prettyprint.hector.api.ConsistencyLevelPolicy consistencyLevelPolicy)

keyspaceForApplication

public static String keyspaceForApplication(UUID applicationId)
Parameters:
applicationId -
Returns:
keyspace for application UUID

prefixForApplication

public static UUID prefixForApplication(UUID applicationId)

getKeyspace

public me.prettyprint.hector.api.Keyspace getKeyspace(String keyspace,
                                                      UUID prefix)

getApplicationKeyspace

public me.prettyprint.hector.api.Keyspace getApplicationKeyspace(UUID applicationId)

getUsergridApplicationKeyspace

public me.prettyprint.hector.api.Keyspace getUsergridApplicationKeyspace()
The Usergrid_Applications keyspace directly

Returns:

getSystemKeyspace

public me.prettyprint.hector.api.Keyspace getSystemKeyspace()

createKeyspace

public void createKeyspace(String keyspace,
                           List<me.prettyprint.hector.api.ddl.ColumnFamilyDefinition> cf_defs)

checkKeyspaces

public void checkKeyspaces()

logKeyspaces

public void logKeyspaces()

getAllColumns

public <N,V> List<me.prettyprint.hector.api.beans.HColumn<N,V>> getAllColumns(me.prettyprint.hector.api.Keyspace ko,
                                                                              Object columnFamily,
                                                                              Object key,
                                                                              me.prettyprint.hector.api.Serializer<N> nameSerializer,
                                                                              me.prettyprint.hector.api.Serializer<V> valueSerializer)
                                                                 throws Exception
Gets the columns.

Parameters:
keyspace - the keyspace
columnFamily - the column family
key - the key
Returns:
columns
Throws:
Exception - the exception

getAllColumns

public List<me.prettyprint.hector.api.beans.HColumn<String,ByteBuffer>> getAllColumns(me.prettyprint.hector.api.Keyspace ko,
                                                                                      Object columnFamily,
                                                                                      Object key)
                                                                               throws Exception
Throws:
Exception

getAllColumnNames

public Set<String> getAllColumnNames(me.prettyprint.hector.api.Keyspace ko,
                                     Object columnFamily,
                                     Object key)
                              throws Exception
Throws:
Exception

getColumns

public List<me.prettyprint.hector.api.beans.HColumn<ByteBuffer,ByteBuffer>> getColumns(me.prettyprint.hector.api.Keyspace ko,
                                                                                       Object columnFamily,
                                                                                       Object key,
                                                                                       Object start,
                                                                                       Object finish,
                                                                                       int count,
                                                                                       boolean reversed)
                                                                                throws Exception
Gets the columns.

Parameters:
keyspace - the keyspace
columnFamily - the column family
key - the key
start - the start
finish - the finish
count - the count
reversed - the reversed
Returns:
columns
Throws:
Exception - the exception

multiGetColumns

public Map<ByteBuffer,List<me.prettyprint.hector.api.beans.HColumn<ByteBuffer,ByteBuffer>>> multiGetColumns(me.prettyprint.hector.api.Keyspace ko,
                                                                                                            Object columnFamily,
                                                                                                            List<?> keys,
                                                                                                            Object start,
                                                                                                            Object finish,
                                                                                                            int count,
                                                                                                            boolean reversed)
                                                                                                     throws Exception
Throws:
Exception

getRows

public <K,N,V> me.prettyprint.hector.api.beans.Rows<K,N,V> getRows(me.prettyprint.hector.api.Keyspace ko,
                                                                   Object columnFamily,
                                                                   List<K> keys,
                                                                   me.prettyprint.hector.api.Serializer<K> keySerializer,
                                                                   me.prettyprint.hector.api.Serializer<N> nameSerializer,
                                                                   me.prettyprint.hector.api.Serializer<V> valueSerializer)
                                                    throws Exception
Gets the columns.

Parameters:
keyspace - the keyspace
columnFamily - the column family
keys - the keys
Returns:
map of keys to columns
Throws:
Exception - the exception

getColumns

public <N,V> List<me.prettyprint.hector.api.beans.HColumn<N,V>> getColumns(me.prettyprint.hector.api.Keyspace ko,
                                                                           Object columnFamily,
                                                                           Object key,
                                                                           Set<String> columnNames,
                                                                           me.prettyprint.hector.api.Serializer<N> nameSerializer,
                                                                           me.prettyprint.hector.api.Serializer<V> valueSerializer)
                                                              throws Exception
Gets the columns.

Parameters:
keyspace - the keyspace
columnFamily - the column family
key - the key
columnNames - the column names
Returns:
columns
Throws:
Exception - the exception

getRows

public <K,N,V> me.prettyprint.hector.api.beans.Rows<K,N,V> getRows(me.prettyprint.hector.api.Keyspace ko,
                                                                   Object columnFamily,
                                                                   List<K> keys,
                                                                   Set<String> columnNames,
                                                                   me.prettyprint.hector.api.Serializer<K> keySerializer,
                                                                   me.prettyprint.hector.api.Serializer<N> nameSerializer,
                                                                   me.prettyprint.hector.api.Serializer<V> valueSerializer)
                                                    throws Exception
Gets the columns.

Parameters:
keyspace - the keyspace
columnFamily - the column family
keys - the keys
columnNames - the column names
Returns:
map of keys to columns
Throws:
Exception - the exception

getColumn

public <N,V> me.prettyprint.hector.api.beans.HColumn<N,V> getColumn(me.prettyprint.hector.api.Keyspace ko,
                                                                    Object columnFamily,
                                                                    Object key,
                                                                    N column,
                                                                    me.prettyprint.hector.api.Serializer<N> nameSerializer,
                                                                    me.prettyprint.hector.api.Serializer<V> valueSerializer)
                                                       throws Exception
Gets the column.

Parameters:
keyspace - the keyspace
columnFamily - the column family
key - the key
column - the column
Returns:
column
Throws:
Exception - the exception

getColumns

public <N,V> me.prettyprint.hector.api.beans.ColumnSlice<N,V> getColumns(me.prettyprint.hector.api.Keyspace ko,
                                                                         Object columnFamily,
                                                                         Object key,
                                                                         N[] columns,
                                                                         me.prettyprint.hector.api.Serializer<N> nameSerializer,
                                                                         me.prettyprint.hector.api.Serializer<V> valueSerializer)
                                                            throws Exception
Throws:
Exception

getColumn

public me.prettyprint.hector.api.beans.HColumn<String,ByteBuffer> getColumn(me.prettyprint.hector.api.Keyspace ko,
                                                                            Object columnFamily,
                                                                            Object key,
                                                                            String column)
                                                                     throws Exception
Throws:
Exception

setColumn

public void setColumn(me.prettyprint.hector.api.Keyspace ko,
                      Object columnFamily,
                      Object key,
                      Object columnName,
                      Object columnValue)
               throws Exception
Throws:
Exception

setColumn

public void setColumn(me.prettyprint.hector.api.Keyspace ko,
                      Object columnFamily,
                      Object key,
                      Object columnName,
                      Object columnValue,
                      int ttl)
               throws Exception
Throws:
Exception

setColumns

public void setColumns(me.prettyprint.hector.api.Keyspace ko,
                       Object columnFamily,
                       byte[] key,
                       Map<?,?> map)
                throws Exception
Sets the columns.

Parameters:
keyspace - the keyspace
columnFamily - the column family
key - the key
map - the map
Throws:
Exception - the exception

setColumns

public void setColumns(me.prettyprint.hector.api.Keyspace ko,
                       Object columnFamily,
                       byte[] key,
                       Map<?,?> map,
                       int ttl)
                throws Exception
Throws:
Exception

createTimestamp

public long createTimestamp()
Create a timestamp based on the TimeResolution set to the cluster.

Returns:
a timestamp

deleteColumn

public void deleteColumn(me.prettyprint.hector.api.Keyspace ko,
                         Object columnFamily,
                         Object key,
                         Object column)
                  throws Exception
Delete column.

Parameters:
keyspace - the keyspace
columnFamily - the column family
key - the key
column - the column
Throws:
Exception - the exception

getRowKeySet

public <K> Set<K> getRowKeySet(me.prettyprint.hector.api.Keyspace ko,
                               Object columnFamily,
                               me.prettyprint.hector.api.Serializer<K> keySerializer)
                    throws Exception
Gets the row keys.

Parameters:
keyspace - the keyspace
columnFamily - the column family
Returns:
set of keys
Throws:
Exception - the exception

getRowKeyList

public <K> List<K> getRowKeyList(me.prettyprint.hector.api.Keyspace ko,
                                 Object columnFamily,
                                 me.prettyprint.hector.api.Serializer<K> keySerializer)
                      throws Exception
Gets the row keys as uui ds.

Parameters:
keyspace - the keyspace
columnFamily - the column family
Returns:
list of row key UUIDs
Throws:
Exception - the exception

deleteRow

public void deleteRow(me.prettyprint.hector.api.Keyspace ko,
                      Object columnFamily,
                      Object key)
               throws Exception
Delete row.

Parameters:
keyspace - the keyspace
columnFamily - the column family
key - the key
Throws:
Exception - the exception

deleteRow

public void deleteRow(me.prettyprint.hector.api.Keyspace ko,
                      Object columnFamily,
                      String key)
               throws Exception
Throws:
Exception

deleteRow

public void deleteRow(me.prettyprint.hector.api.Keyspace ko,
                      Object columnFamily,
                      Object key,
                      long timestamp)
               throws Exception
Delete row.

Parameters:
keyspace - the keyspace
columnFamily - the column family
key - the key
timestamp - the timestamp
Throws:
Exception - the exception

getIdList

public List<UUID> getIdList(me.prettyprint.hector.api.Keyspace ko,
                            Object key,
                            Object start,
                            Object finish,
                            int count,
                            boolean reversed,
                            IndexBucketLocator locator,
                            UUID applicationId,
                            String collectionName)
                     throws Exception
Gets the id list.

Parameters:
ko - the keyspace
key - the key
start - the start
finish - the finish
count - the count
reversed - True if the scan should be reversed
locator - The index locator instance
applicationId - The applicationId
collectionName - The name of the collection to get the Ids for
Returns:
list of columns as UUIDs
Throws:
Exception - the exception

countColumns

public int countColumns(me.prettyprint.hector.api.Keyspace ko,
                        Object columnFamily,
                        Object key)
                 throws Exception
Throws:
Exception

setIdList

public void setIdList(me.prettyprint.hector.api.Keyspace ko,
                      UUID targetId,
                      String keyPrefix,
                      String keySuffix,
                      List<UUID> keyIds)
               throws Exception
Sets the id list.

Parameters:
keyspace - the keyspace
targetId - the target id
columnFamily - the column family
keyPrefix - the key prefix
keySuffix - the key suffix
keyIds - the key ids
setColumnValue - the set column value
Throws:
Exception - the exception

startClusterHealthCheck

public void startClusterHealthCheck()


Copyright © 2013. All Rights Reserved.