Class TransformingCqlFactory<T extends java.io.Serializable>
- java.lang.Object
-
- cz.o2.proxima.direct.io.cassandra.CacheableCqlFactory
-
- cz.o2.proxima.direct.io.cassandra.TransformingCqlFactory<T>
-
- All Implemented Interfaces:
CqlFactory,java.io.Serializable
public class TransformingCqlFactory<T extends java.io.Serializable> extends CacheableCqlFactory
A CQL factory that stores data in other fields than what would suggest the model itself. The factory extracts column names and values from ingest by provided extractors. The ingest is first modified by provided parser.- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface cz.o2.proxima.direct.io.cassandra.CqlFactory
CqlFactory.KvIterable<T>
-
-
Field Summary
-
Fields inherited from class cz.o2.proxima.direct.io.cassandra.CacheableCqlFactory
ttl
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedTransformingCqlFactory(UnaryFunction<StreamElement,T> parser, java.util.List<java.lang.String> columns, java.util.List<UnaryFunction<Pair<java.lang.String,T>,java.lang.Object>> extractors)protectedTransformingCqlFactory(UnaryFunction<StreamElement,T> parser, java.util.List<java.lang.String> columns, java.util.List<UnaryFunction<Pair<java.lang.String,T>,java.lang.Object>> extractors, UnaryFunction<T,java.lang.Boolean> filter)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.StringcreateDeleteStatement(StreamElement ingest)Create statement to be prepared for given ingest when deleting attribute.protected java.lang.StringcreateDeleteWildcardStatement(StreamElement what)Create statement to delete wildcard attribute.protected java.lang.StringcreateFetchTokenStatement()Create statement to fetch token for primary key.protected java.lang.StringcreateGetStatement(java.lang.String attribute, AttributeDescriptor desc)Create get statement for key-attribute pair.protected java.lang.StringcreateInsertStatement(StreamElement element)Create statement to be prepared for given ingest.protected java.lang.StringcreateListAllStatement(com.datastax.oss.driver.api.core.CqlSession session)Create statement to list all attributes of this entity.protected java.lang.StringcreateListEntitiesStatement()Create list statement for entity keys.protected java.lang.StringcreateListStatement(AttributeDescriptor wildcard)Create list statement for key-wildcardAttribute pair.<T> CqlFactory.KvIterable<T>getListAllStatement(java.lang.String key, Offsets.Raw offset, int limit, com.datastax.oss.driver.api.core.CqlSession session)Retrieve wrapped statement to execute to list all attributes of given key.com.datastax.oss.driver.api.core.cql.BoundStatementgetListStatement(java.lang.String key, AttributeDescriptor wildcard, Offsets.Raw offset, int limit, com.datastax.oss.driver.api.core.CqlSession session)Retrieve a CQL query to execute in order to list wildcard attributes.com.datastax.oss.driver.api.core.cql.BoundStatementgetReadStatement(java.lang.String key, java.lang.String attribute, AttributeDescriptor desc, com.datastax.oss.driver.api.core.CqlSession session)Retrieve a CQL query to execute in order to read data.java.util.Optional<com.datastax.oss.driver.api.core.cql.BoundStatement>getWriteStatement(StreamElement element, com.datastax.oss.driver.api.core.CqlSession session)Retrieve a CQL query to execute in order to ingest the request.com.datastax.oss.driver.api.core.cql.StatementscanPartition(java.util.List<AttributeDescriptor<?>> attributes, CassandraPartition partition, com.datastax.oss.driver.api.core.CqlSession session)Retrieve a bound statement to scan data for given attribute and partition.<V> KeyValue<V>toKeyValue(EntityDescriptor entityDescriptor, AttributeDescriptor<V> attributeDescriptor, java.lang.String key, java.lang.String attribute, long stamp, RandomOffset offset, byte[] serializedValue)Convert the byte[] stored in the database intoKeyValue.-
Methods inherited from class cz.o2.proxima.direct.io.cassandra.CacheableCqlFactory
clearCache, getFetchTokenStatement, getListEntitiesStatement, getPreparedGetStatement, getPreparedListAllStatement, getPreparedListStatement, getPreparedStatement, setup, setup
-
-
-
-
Constructor Detail
-
TransformingCqlFactory
protected TransformingCqlFactory(UnaryFunction<StreamElement,T> parser, java.util.List<java.lang.String> columns, java.util.List<UnaryFunction<Pair<java.lang.String,T>,java.lang.Object>> extractors)
-
TransformingCqlFactory
protected TransformingCqlFactory(UnaryFunction<StreamElement,T> parser, java.util.List<java.lang.String> columns, java.util.List<UnaryFunction<Pair<java.lang.String,T>,java.lang.Object>> extractors, UnaryFunction<T,java.lang.Boolean> filter)
-
-
Method Detail
-
createDeleteStatement
protected java.lang.String createDeleteStatement(StreamElement ingest)
Description copied from class:CacheableCqlFactoryCreate statement to be prepared for given ingest when deleting attribute.- Specified by:
createDeleteStatementin classCacheableCqlFactory- Parameters:
ingest- the input element to create statement for- Returns:
- string representation of the CQL
-
createDeleteWildcardStatement
protected java.lang.String createDeleteWildcardStatement(StreamElement what)
Description copied from class:CacheableCqlFactoryCreate statement to delete wildcard attribute.- Specified by:
createDeleteWildcardStatementin classCacheableCqlFactory- Parameters:
what- the input element to create statement for- Returns:
- string representation of the CQL
-
createInsertStatement
protected java.lang.String createInsertStatement(StreamElement element)
Description copied from class:CacheableCqlFactoryCreate statement to be prepared for given ingest. This will be then stored in cache after call toprepare.- Specified by:
createInsertStatementin classCacheableCqlFactory- Parameters:
element- the input element to create statement for- Returns:
- string representation of the CQL
-
getWriteStatement
public java.util.Optional<com.datastax.oss.driver.api.core.cql.BoundStatement> getWriteStatement(StreamElement element, com.datastax.oss.driver.api.core.CqlSession session)
Description copied from interface:CqlFactoryRetrieve a CQL query to execute in order to ingest the request.- Parameters:
element- input datasession- current session- Returns:
- the statement to execute. When empty, the ingest is silently discarded.
-
createGetStatement
protected java.lang.String createGetStatement(java.lang.String attribute, AttributeDescriptor desc)Description copied from class:CacheableCqlFactoryCreate get statement for key-attribute pair. The statement must return only single field with value.- Specified by:
createGetStatementin classCacheableCqlFactory- Parameters:
attribute- the input attribute to create get fordesc- the descriptor of the attribute- Returns:
- string representation of the CQL
-
createListStatement
protected java.lang.String createListStatement(AttributeDescriptor wildcard)
Description copied from class:CacheableCqlFactoryCreate list statement for key-wildcardAttribute pair. The statement must return two fields - attribute, value.- Specified by:
createListStatementin classCacheableCqlFactory- Parameters:
wildcard- the descriptor of the attribute- Returns:
- string representation of the CQL
-
getReadStatement
public com.datastax.oss.driver.api.core.cql.BoundStatement getReadStatement(java.lang.String key, java.lang.String attribute, AttributeDescriptor desc, com.datastax.oss.driver.api.core.CqlSession session)Description copied from interface:CqlFactoryRetrieve a CQL query to execute in order to read data.- Parameters:
key- the primary key whose attribute to returnattribute- the attribute to fetchdesc- descriptor of the attributesession- the connection session- Returns:
- the statement to execute
-
getListStatement
public com.datastax.oss.driver.api.core.cql.BoundStatement getListStatement(java.lang.String key, AttributeDescriptor wildcard, Offsets.Raw offset, int limit, com.datastax.oss.driver.api.core.CqlSession session)Description copied from interface:CqlFactoryRetrieve a CQL query to execute in order to list wildcard attributes. The prefix is name of wildcard attribute shortened by two last characters (.*).- Parameters:
key- the primary key value (first part of the composite key)wildcard- the wildcard attribute to listoffset- the offset to start from this might be null (start from beginning)limit- maximal number of elements to list (-1 for all)session- the connection session- Returns:
- the statement to execute
-
createListEntitiesStatement
protected java.lang.String createListEntitiesStatement()
Description copied from class:CacheableCqlFactoryCreate list statement for entity keys. The statement must return single field - the entity key.- Specified by:
createListEntitiesStatementin classCacheableCqlFactory- Returns:
- string representation of the CQL
-
createFetchTokenStatement
protected java.lang.String createFetchTokenStatement()
Description copied from class:CacheableCqlFactoryCreate statement to fetch token for primary key. The statement must return only the token as single field in single row.- Specified by:
createFetchTokenStatementin classCacheableCqlFactory- Returns:
- string representation of the CQL
-
scanPartition
public com.datastax.oss.driver.api.core.cql.Statement scanPartition(java.util.List<AttributeDescriptor<?>> attributes, CassandraPartition partition, com.datastax.oss.driver.api.core.CqlSession session)
Description copied from interface:CqlFactoryRetrieve a bound statement to scan data for given attribute and partition.- Parameters:
attributes- list of attributes to scanpartition- the partition to scansession- connection session- Returns:
- the statement to execute
-
toKeyValue
public <V> KeyValue<V> toKeyValue(EntityDescriptor entityDescriptor, AttributeDescriptor<V> attributeDescriptor, java.lang.String key, java.lang.String attribute, long stamp, RandomOffset offset, byte[] serializedValue)
Description copied from interface:CqlFactoryConvert the byte[] stored in the database intoKeyValue.
-
createListAllStatement
protected java.lang.String createListAllStatement(com.datastax.oss.driver.api.core.CqlSession session)
Description copied from class:CacheableCqlFactoryCreate statement to list all attributes of this entity.- Specified by:
createListAllStatementin classCacheableCqlFactory- Parameters:
session- the connection session- Returns:
- string representation of the CQL
-
getListAllStatement
public <T> CqlFactory.KvIterable<T> getListAllStatement(java.lang.String key, Offsets.Raw offset, int limit, com.datastax.oss.driver.api.core.CqlSession session)
Description copied from interface:CqlFactoryRetrieve wrapped statement to execute to list all attributes of given key.- Type Parameters:
T- type ofCqlFactory.KvIterable- Parameters:
key- key to list attributes ofoffset- offset to start from (return next attribute)limit- maximum number of items to returnsession- the connection session- Returns:
- iterable over keyvalues
-
-