public abstract class CassandraClientBase extends ClientBase implements ClientPropertiesSetter
| Modifier and Type | Class and Description |
|---|---|
protected class |
CassandraClientBase.CQLClient
Use CqlClient class for crud when cql enable.
|
| Modifier and Type | Field and Description |
|---|---|
protected org.apache.cassandra.thrift.ConsistencyLevel |
consistencyLevel
The consistency level.
|
protected CassandraClientBase.CQLClient |
cqlClient
The cql client.
|
protected TimestampGenerator |
generator
The generator.
|
clientMetadata, externalProperties, indexManager, isUpdate, kunderaMetadata, persistenceUnit, showQuery| Modifier | Constructor and Description |
|---|---|
protected |
CassandraClientBase(String persistenceUnit,
Map<String,Object> externalProperties,
EntityManagerFactoryImpl.KunderaMetadata kunderaMetadata,
TimestampGenerator generator)
constructor using fields.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addBatch(Node node)
Adds the batch.
|
protected void |
addRelationsToThriftRow(EntityMetadata metadata,
ThriftRow tf,
List<RelationHolder> relations)
Adds relation foreign key values as thrift column/ value to thrift row.
|
void |
clear()
Clear.
|
void |
close()
Close.
|
protected void |
computeEntityViaColumns(EntityMetadata m,
boolean isRelation,
List<String> relations,
List<Object> entities,
Map<ByteBuffer,List<org.apache.cassandra.thrift.Column>> qResults)
Compute entity via columns.
|
protected void |
computeEntityViaSuperColumns(EntityMetadata m,
boolean isRelation,
List<String> relations,
List<Object> entities,
Map<ByteBuffer,List<org.apache.cassandra.thrift.SuperColumn>> qResults)
Compute entity via super columns.
|
protected void |
createIndexesOnColumns(EntityMetadata m,
String tableName,
List<org.apache.cassandra.thrift.Column> columns,
Class columnType)
Creates secondary indexes on columns if not already created.
|
protected List<String> |
createInsertQuery(EntityMetadata entityMetadata,
Object entity,
org.apache.cassandra.thrift.Cassandra.Client cassandra_client,
List<RelationHolder> rlHolders,
Object ttlColumns)
Return insert query string for given entity.
|
protected List<String> |
createUpdateQueryForCounter(EntityMetadata entityMetadata,
Object entity,
org.apache.cassandra.thrift.Cassandra.Client cassandra_client,
List<RelationHolder> rlHolders)
Return update query string for given entity intended for counter column
family.
|
protected abstract void |
delete(Object entity,
Object pKey)
Delete.
|
protected void |
deleteRecordFromCounterColumnFamily(Object pKey,
String tableName,
EntityMetadata metadata,
org.apache.cassandra.thrift.ConsistencyLevel consistencyLevel)
Deletes record for given primary key from counter column family.
|
<T> T |
execute(String query,
Object connection)
Execute.
|
int |
executeBatch()
Execute batch.
|
protected Object |
executeCQLQuery(String cqlQuery,
boolean isCql3Enabled)
Executes query string using cql3.
|
abstract List |
executeQuery(Class clazz,
List<String> relationalField,
boolean isNative,
String cqlQuery)
Query related methods.
|
List |
executeScalarQuery(String cqlQuery)
Execute scalar query.
|
List |
executeSelectQuery(Class clazz,
List<String> relationalField,
CassandraDataHandler dataHandler,
boolean isNative,
String cqlQuery)
Executes Select CQL Query.
|
int |
executeUpdateDeleteQuery(String cqlQuery)
Executes Update/ Delete CQL query.
|
<E> List<E> |
find(Class<E> entityClass,
Map<String,String> superColumnMap,
CassandraDataHandler dataHandler)
Find.
|
abstract List |
find(Class entityClass,
List<String> relationNames,
boolean isWrapReq,
EntityMetadata metadata,
Object... rowIds)
Find.
|
Object |
find(Class entityClass,
Object rowId)
Finds an entiry from database.
|
abstract List<EnhanceEntity> |
find(EntityMetadata m,
List<String> relationNames,
List<org.apache.cassandra.thrift.IndexClause> conditions,
int maxResult,
List<String> columns)
Find.
|
abstract List |
find(List<org.apache.cassandra.thrift.IndexClause> ixClause,
EntityMetadata m,
boolean isRelation,
List<String> relations,
int maxResult,
List<String> columns)
Find.
|
<E> List<E> |
findAll(Class<E> entityClass,
String[] columnsToSelect,
Object... rowIds)
Finds a
List of entities from database. |
abstract List |
findByRange(byte[] muinVal,
byte[] maxVal,
EntityMetadata m,
boolean isWrapReq,
List<String> relations,
List<String> columns,
List<org.apache.cassandra.thrift.IndexExpression> conditions,
int maxResults)
Find by range.
|
protected List<Object> |
findByRelationQuery(EntityMetadata m,
String columnName,
Object columnValue,
Class clazz,
CassandraDataHandler dataHandler)
Find List of objects based on value of column
.
|
List |
findByRowKeys(Class entityClass,
List<String> relationNames,
boolean isWrapReq,
EntityMetadata metadata,
Object... rowIds)
Finds a
List of entities from database. |
protected <E> List<E> |
findIdsByColumnUsingCql(String schemaName,
String tableName,
String pKeyName,
String columnName,
Object columnValue,
Class entityClazz)
Find join column values for inverse join column.
|
int |
getBatchSize()
Gets the batch size.
|
protected <E> List<E> |
getColumnsByIdUsingCql(String schemaName,
String tableName,
String pKeyColumnName,
String columnName,
Object pKeyColumnValue,
Class columnJavaType)
Find inverse join column values for join column.
|
protected abstract Object |
getConnection()
Gets the connection.
|
protected abstract Object |
getConnection(Object connection)
Gets the connection.
|
org.apache.cassandra.thrift.ConsistencyLevel |
getConsistencyLevel()
Gets the consistency level.
|
org.apache.cassandra.thrift.CqlMetadata |
getCqlMetadata()
Gets the cql metadata.
|
protected String |
getCqlVersion()
Gets the cql version.
|
protected abstract CassandraDataHandler |
getDataHandler()
Gets the data handler.
|
Map<String,Object> |
getExternalProperties()
Gets the external properties.
|
org.apache.cassandra.thrift.Cassandra.Client |
getRawClient(String schema)
Returns raw cassandra client from thrift connection pool.
|
Map<String,Object> |
getTtlValues()
Gets the ttl values.
|
boolean |
isCql3Enabled()
Returns true in case of, composite Id and if cql3 opted and not a
embedded entity.
|
boolean |
isCql3Enabled(EntityMetadata metadata)
Returns true in case of, composite Id and if cql3 opted and not a
embedded entity.
|
protected boolean |
isOpen()
Checks if is open.
|
boolean |
isTtlPerRequest()
Checks if is ttl per request.
|
boolean |
isTtlPerSession()
Checks if is ttl per session.
|
protected abstract List<org.apache.cassandra.thrift.SuperColumn> |
loadSuperColumns(String keyspace,
String columnFamily,
String rowId,
String... superColumnNames)
Load super columns.
|
protected void |
onColumn(EntityMetadata m,
boolean isRelation,
List<String> relations,
List<Object> entities,
List<org.apache.cassandra.thrift.Column> columns,
List<AbstractManagedType> subManagedType,
ByteBuffer key)
On column.
|
protected List<Object> |
onCounterColumn(EntityMetadata m,
boolean isRelation,
List<String> relations,
List<org.apache.cassandra.thrift.KeySlice> ks)
On counter column.
|
protected String |
onDeleteQuery(EntityMetadata metadata,
String tableName,
MetamodelImpl metaModel,
Object keyObject)
On delete query.
|
protected void |
onSuperColumn(EntityMetadata m,
boolean isRelation,
List<String> relations,
List<Object> entities,
List<org.apache.cassandra.thrift.SuperColumn> superColumns,
ByteBuffer key)
On super column.
|
protected void |
onWhereClause(EntityMetadata metadata,
Object key,
CQLTranslator translator,
StringBuilder queryBuilder,
MetamodelImpl metaModel,
javax.persistence.metamodel.SingularAttribute attribute)
On where clause.
|
protected void |
persistJoinTableByCql(JoinTableData joinTableData,
org.apache.cassandra.thrift.Cassandra.Client conn)
Persist join table by cql.
|
void |
populateClientProperties(Client client,
Map<String,Object> properties) |
protected List |
populateEntitiesFromKeySlices(EntityMetadata m,
boolean isWrapReq,
List<String> relations,
List<org.apache.cassandra.thrift.KeySlice> keys,
CassandraDataHandler dataHandler)
Populate entities from key slices.
|
protected org.apache.cassandra.thrift.Column |
populateFkey(String rlName,
Object rlValue,
long timestamp)
Populates foreign key as column.
|
protected Map<ByteBuffer,Map<String,List<org.apache.cassandra.thrift.Mutation>>> |
prepareMutation(EntityMetadata entityMetadata,
Object entity,
Object id,
List<RelationHolder> relationHolders,
Map<ByteBuffer,Map<String,List<org.apache.cassandra.thrift.Mutation>>> mutationMap)
Prepare mutation.
|
protected abstract void |
releaseConnection(Object conn)
Release connection.
|
abstract List<SearchResult> |
searchInInvertedIndex(String columnFamilyName,
EntityMetadata m,
Map<Boolean,List<org.apache.cassandra.thrift.IndexClause>> indexClauseMap)
Search in inverted index.
|
void |
setConsistencyLevel(org.apache.cassandra.thrift.ConsistencyLevel cLevel)
Sets the consistency level.
|
void |
setCqlMetadata(org.apache.cassandra.thrift.CqlMetadata cqlMetadata)
Sets the cql metadata.
|
void |
setCqlVersion(String cqlVersion)
Sets the cql version.
|
void |
setTtlPerRequest(boolean ttlPerRequest)
Sets the ttl per request.
|
void |
setTtlPerSession(boolean ttlPerSession)
Sets the ttl per session.
|
void |
setTtlValues(Map<String,Object> ttlValues)
Sets the ttl values.
|
executeScript, getClientMetadata, getIndexManager, getPersistenceUnit, getRelationHolders, indexNode, onPersist, persist, remove, unIndexNode, useSecondryIndexprotected org.apache.cassandra.thrift.ConsistencyLevel consistencyLevel
protected final CassandraClientBase.CQLClient cqlClient
protected final TimestampGenerator generator
protected CassandraClientBase(String persistenceUnit, Map<String,Object> externalProperties, EntityManagerFactoryImpl.KunderaMetadata kunderaMetadata, TimestampGenerator generator)
persistenceUnit - the persistence unitexternalProperties - the external propertieskunderaMetadata - the kundera metadatagenerator - the generatorprotected org.apache.cassandra.thrift.Column populateFkey(String rlName, Object rlValue, long timestamp) throws PropertyAccessException
rlName - relation namerlValue - relation valuetimestamp - the timestampPropertyAccessException - the property access exceptionprotected List<Object> onCounterColumn(EntityMetadata m, boolean isRelation, List<String> relations, List<org.apache.cassandra.thrift.KeySlice> ks)
m - the misRelation - the is relationrelations - the relationsks - the ksprotected void computeEntityViaColumns(EntityMetadata m, boolean isRelation, List<String> relations, List<Object> entities, Map<ByteBuffer,List<org.apache.cassandra.thrift.Column>> qResults)
m - the misRelation - the is relationrelations - the relationsentities - the entitiesqResults - the q resultsprotected void onColumn(EntityMetadata m, boolean isRelation, List<String> relations, List<Object> entities, List<org.apache.cassandra.thrift.Column> columns, List<AbstractManagedType> subManagedType, ByteBuffer key)
m - the misRelation - the is relationrelations - the relationsentities - the entitiescolumns - the columnssubManagedType - the sub managed typekey - the keyprotected void computeEntityViaSuperColumns(EntityMetadata m, boolean isRelation, List<String> relations, List<Object> entities, Map<ByteBuffer,List<org.apache.cassandra.thrift.SuperColumn>> qResults)
m - the misRelation - the is relationrelations - the relationsentities - the entitiesqResults - the q resultsprotected void onSuperColumn(EntityMetadata m, boolean isRelation, List<String> relations, List<Object> entities, List<org.apache.cassandra.thrift.SuperColumn> superColumns, ByteBuffer key)
m - the misRelation - the is relationrelations - the relationsentities - the entitiessuperColumns - the super columnskey - the keyprotected void addRelationsToThriftRow(EntityMetadata metadata, ThriftRow tf, List<RelationHolder> relations)
metadata - the metadatatf - the tfrelations - the relationsprotected void deleteRecordFromCounterColumnFamily(Object pKey, String tableName, EntityMetadata metadata, org.apache.cassandra.thrift.ConsistencyLevel consistencyLevel)
pKey - the keytableName - the table namemetadata - the metadataconsistencyLevel - the consistency levelprotected void createIndexesOnColumns(EntityMetadata m, String tableName, List<org.apache.cassandra.thrift.Column> columns, Class columnType)
m - the mtableName - Column family namecolumns - List of columnscolumnType - the column typepublic Object find(Class entityClass, Object rowId)
entityClass - the entity classrowId - the row idpublic <E> List<E> findAll(Class<E> entityClass, String[] columnsToSelect, Object... rowIds)
List of entities from database.E - the element typeentityClass - the entity classcolumnsToSelect - TODOrowIds - the row idspublic boolean isCql3Enabled(EntityMetadata metadata)
metadata - the metadatapublic boolean isCql3Enabled()
public <E> List<E> find(Class<E> entityClass, Map<String,String> superColumnMap, CassandraDataHandler dataHandler)
E - the element typeentityClass - the entity classsuperColumnMap - the super column mapdataHandler - the data handlerpublic List executeSelectQuery(Class clazz, List<String> relationalField, CassandraDataHandler dataHandler, boolean isNative, String cqlQuery)
clazz - the clazzrelationalField - the relational fielddataHandler - the data handlerisNative - the is nativecqlQuery - the cql querypublic List executeScalarQuery(String cqlQuery)
dataHandler - the data handlercqlQuery - the cql querypublic int executeUpdateDeleteQuery(String cqlQuery)
cqlQuery - the cql querypublic Map<String,Object> getExternalProperties()
protected List populateEntitiesFromKeySlices(EntityMetadata m, boolean isWrapReq, List<String> relations, List<org.apache.cassandra.thrift.KeySlice> keys, CassandraDataHandler dataHandler) throws Exception
m - the misWrapReq - the is wrap reqrelations - the relationskeys - the keysdataHandler - the data handlerException - the exceptionprotected List<String> createInsertQuery(EntityMetadata entityMetadata, Object entity, org.apache.cassandra.thrift.Cassandra.Client cassandra_client, List<RelationHolder> rlHolders, Object ttlColumns)
entityMetadata - the entity metadataentity - the entitycassandra_client - the cassandra_clientrlHolders - the rl holdersttlColumns - TTL values for each columnsprotected List<String> createUpdateQueryForCounter(EntityMetadata entityMetadata, Object entity, org.apache.cassandra.thrift.Cassandra.Client cassandra_client, List<RelationHolder> rlHolders)
entityMetadata - the entity metadataentity - the entitycassandra_client - the cassandra_clientrlHolders - the rl holdersprotected String getCqlVersion()
public void setCqlVersion(String cqlVersion)
cqlVersion - the cqlVersion to setpublic void setConsistencyLevel(org.apache.cassandra.thrift.ConsistencyLevel cLevel)
cLevel - the new consistency levelpublic void close()
protected final boolean isOpen()
public org.apache.cassandra.thrift.ConsistencyLevel getConsistencyLevel()
protected String onDeleteQuery(EntityMetadata metadata, String tableName, MetamodelImpl metaModel, Object keyObject)
metadata - the metadatatableName - TODOmetaModel - the meta modelkeyObject - the compound key objectprotected void onWhereClause(EntityMetadata metadata, Object key, CQLTranslator translator, StringBuilder queryBuilder, MetamodelImpl metaModel, javax.persistence.metamodel.SingularAttribute attribute)
metadata - the metadatakey - the compound key objecttranslator - the translatorqueryBuilder - the query buildermetaModel - the meta modelattribute - the attributepublic abstract List find(Class entityClass, List<String> relationNames, boolean isWrapReq, EntityMetadata metadata, Object... rowIds)
entityClass - the entity classrelationNames - the relation namesisWrapReq - the is wrap reqmetadata - the metadatarowIds - the row idsprotected abstract List<org.apache.cassandra.thrift.SuperColumn> loadSuperColumns(String keyspace, String columnFamily, String rowId, String... superColumnNames)
keyspace - the keyspacecolumnFamily - the column familyrowId - the row idsuperColumnNames - the super column namespublic abstract List executeQuery(Class clazz, List<String> relationalField, boolean isNative, String cqlQuery)
clazz - the clazzrelationalField - the relational fieldisNative - the is nativecqlQuery - the cql querypublic abstract List find(List<org.apache.cassandra.thrift.IndexClause> ixClause, EntityMetadata m, boolean isRelation, List<String> relations, int maxResult, List<String> columns)
ixClause - the ix clausem - the misRelation - the is relationrelations - the relationsmaxResult - the max resultcolumns - the columnspublic abstract List findByRange(byte[] muinVal, byte[] maxVal, EntityMetadata m, boolean isWrapReq, List<String> relations, List<String> columns, List<org.apache.cassandra.thrift.IndexExpression> conditions, int maxResults) throws Exception
muinVal - the muin valmaxVal - the max valm - the misWrapReq - the is wrap reqrelations - the relationscolumns - the columnsconditions - the conditionsmaxResults - the max resultsException - the exceptionpublic abstract List<SearchResult> searchInInvertedIndex(String columnFamilyName, EntityMetadata m, Map<Boolean,List<org.apache.cassandra.thrift.IndexClause>> indexClauseMap)
columnFamilyName - the column family namem - the mindexClauseMap - the index clause mappublic abstract List<EnhanceEntity> find(EntityMetadata m, List<String> relationNames, List<org.apache.cassandra.thrift.IndexClause> conditions, int maxResult, List<String> columns)
m - the mrelationNames - the relation namesconditions - the conditionsmaxResult - the max resultcolumns - the columnsprotected abstract CassandraDataHandler getDataHandler()
protected abstract void delete(Object entity, Object pKey)
delete in class ClientBaseentity - the entitypKey - the keypublic void addBatch(Node node)
node - the nodepublic int getBatchSize()
public void clear()
public int executeBatch()
protected Map<ByteBuffer,Map<String,List<org.apache.cassandra.thrift.Mutation>>> prepareMutation(EntityMetadata entityMetadata, Object entity, Object id, List<RelationHolder> relationHolders, Map<ByteBuffer,Map<String,List<org.apache.cassandra.thrift.Mutation>>> mutationMap)
entityMetadata - the entity metadataentity - the entityid - the idrelationHolders - the relation holdersmutationMap - the mutation mappublic void populateClientProperties(Client client, Map<String,Object> properties)
populateClientProperties in interface ClientPropertiesSetterpublic org.apache.cassandra.thrift.Cassandra.Client getRawClient(String schema)
schema - schema or keyspace.protected Object executeCQLQuery(String cqlQuery, boolean isCql3Enabled)
cqlQuery - the cql queryisCql3Enabled - the is cql3 enabledprotected List<Object> findByRelationQuery(EntityMetadata m, String columnName, Object columnValue, Class clazz, CassandraDataHandler dataHandler)
m - the mcolumnName - the column namecolumnValue - the column valueclazz - the clazzdataHandler - the data handlerprotected abstract Object getConnection()
protected abstract Object getConnection(Object connection)
connection - the connectionprotected abstract void releaseConnection(Object conn)
conn - the connpublic boolean isTtlPerRequest()
public void setTtlPerRequest(boolean ttlPerRequest)
ttlPerRequest - the ttlPerRequest to setpublic boolean isTtlPerSession()
public void setTtlPerSession(boolean ttlPerSession)
ttlPerSession - the ttlPerSession to setpublic void setTtlValues(Map<String,Object> ttlValues)
ttlValues - the ttlValues to setpublic final List findByRowKeys(Class entityClass, List<String> relationNames, boolean isWrapReq, EntityMetadata metadata, Object... rowIds)
List of entities from database.entityClass - the entity classrelationNames - the relation namesisWrapReq - the is wrap reqmetadata - the metadatarowIds - the row idspublic <T> T execute(String query, Object connection)
T - the generic typequery - the queryconnection - the connectionprotected void persistJoinTableByCql(JoinTableData joinTableData, org.apache.cassandra.thrift.Cassandra.Client conn)
joinTableData - the join table dataconn - the connprotected <E> List<E> getColumnsByIdUsingCql(String schemaName, String tableName, String pKeyColumnName, String columnName, Object pKeyColumnValue, Class columnJavaType)
E - the element typeschemaName - the schema nametableName - the table namepKeyColumnName - the key column namecolumnName - the column namepKeyColumnValue - the key column valuecolumnJavaType - the column java typeprotected <E> List<E> findIdsByColumnUsingCql(String schemaName, String tableName, String pKeyName, String columnName, Object columnValue, Class entityClazz)
E - the element typeschemaName - the schema nametableName - the table namepKeyName - the key namecolumnName - the column namecolumnValue - the column valueentityClazz - the entity clazzpublic org.apache.cassandra.thrift.CqlMetadata getCqlMetadata()
public void setCqlMetadata(org.apache.cassandra.thrift.CqlMetadata cqlMetadata)
cqlMetadata - the new cql metadataCopyright © 2015. All Rights Reserved.