Class CacheableCqlFactory
- java.lang.Object
-
- cz.o2.proxima.direct.io.cassandra.CacheableCqlFactory
-
- All Implemented Interfaces:
CqlFactory
,java.io.Serializable
- Direct Known Subclasses:
DefaultCqlFactory
,TransformingCqlFactory
public abstract class CacheableCqlFactory extends java.lang.Object implements CqlFactory
A cache for prepared CQL statements.- 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 Modifier and Type Field Description protected long
ttl
A TTL value in seconds associated with each update or insert.
-
Constructor Summary
Constructors Modifier Constructor Description protected
CacheableCqlFactory()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
clearCache()
Clear the cache (e.g.protected abstract java.lang.String
createDeleteStatement(StreamElement element)
Create statement to be prepared for given ingest when deleting attribute.protected abstract java.lang.String
createDeleteWildcardStatement(StreamElement element)
Create statement to delete wildcard attribute.protected abstract java.lang.String
createFetchTokenStatement()
Create statement to fetch token for primary key.protected abstract java.lang.String
createGetStatement(java.lang.String attribute, AttributeDescriptor<?> desc)
Create get statement for key-attribute pair.protected abstract java.lang.String
createInsertStatement(StreamElement element)
Create statement to be prepared for given ingest.protected abstract java.lang.String
createListAllStatement(com.datastax.driver.core.Session session)
Create statement to list all attributes of this entity.protected abstract java.lang.String
createListEntitiesStatement()
Create list statement for entity keys.protected abstract java.lang.String
createListStatement(AttributeDescriptor<?> desc)
Create list statement for key-wildcardAttribute pair.com.datastax.driver.core.BoundStatement
getFetchTokenStatement(java.lang.String key, com.datastax.driver.core.Session session)
Retrieve a bound statement to fetch a token for given entity.com.datastax.driver.core.BoundStatement
getListEntitiesStatement(Offsets.Token offset, int limit, com.datastax.driver.core.Session session)
Get statement for listing entities.protected com.datastax.driver.core.PreparedStatement
getPreparedGetStatement(com.datastax.driver.core.Session session, java.lang.String attribute, AttributeDescriptor<?> desc)
Retrieve cached prepared statement for getting data from cassandra for given attribute.protected com.datastax.driver.core.PreparedStatement
getPreparedListAllStatement(com.datastax.driver.core.Session session)
protected com.datastax.driver.core.PreparedStatement
getPreparedListStatement(com.datastax.driver.core.Session session, AttributeDescriptor<?> wildcardAttribute)
Retrieve cached prepared statement for listing data by attribute prefix (for wildcard attributes).protected com.datastax.driver.core.PreparedStatement
getPreparedStatement(com.datastax.driver.core.Session session, StreamElement what)
Retrieve cached prepared statement for writing given data.void
setup(EntityDescriptor entity, java.net.URI uri, StringConverter<?> converter)
Setup the factory from URI and given string converter.protected void
setup(java.util.Map<java.lang.String,java.lang.String> query, StringConverter<?> converter)
Setup the factory from URI parameters passed in.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface cz.o2.proxima.direct.io.cassandra.CqlFactory
getListAllStatement, getListStatement, getReadStatement, getWriteStatement, scanPartition, toKeyValue
-
-
-
-
Method Detail
-
setup
public final void setup(EntityDescriptor entity, java.net.URI uri, StringConverter<?> converter)
Description copied from interface:CqlFactory
Setup the factory from URI and given string converter.- Specified by:
setup
in interfaceCqlFactory
- Parameters:
entity
- descriptor of entityuri
- URI of the sourceconverter
- payload to string converter
-
setup
protected void setup(java.util.Map<java.lang.String,java.lang.String> query, StringConverter<?> converter)
Setup the factory from URI parameters passed in.- Parameters:
query
- the parsed URI query parametersconverter
- converter of payload to string
-
getPreparedStatement
protected com.datastax.driver.core.PreparedStatement getPreparedStatement(com.datastax.driver.core.Session session, StreamElement what)
Retrieve cached prepared statement for writing given data.- Parameters:
session
- the connection sessionwhat
- data to ingest- Returns:
- the statement to use in order to store the data
-
getPreparedGetStatement
protected com.datastax.driver.core.PreparedStatement getPreparedGetStatement(com.datastax.driver.core.Session session, java.lang.String attribute, AttributeDescriptor<?> desc)
Retrieve cached prepared statement for getting data from cassandra for given attribute.- Parameters:
session
- the connection sessionattribute
- the attribute to fetchdesc
- descriptor of the attribute- Returns:
- the statement to use in order to read the data
-
getPreparedListStatement
protected com.datastax.driver.core.PreparedStatement getPreparedListStatement(com.datastax.driver.core.Session session, AttributeDescriptor<?> wildcardAttribute)
Retrieve cached prepared statement for listing data by attribute prefix (for wildcard attributes).- Parameters:
session
- the connection sessionwildcardAttribute
- the wildcard attribute to list- Returns:
- the statement to use in order to read the data
-
getPreparedListAllStatement
protected com.datastax.driver.core.PreparedStatement getPreparedListAllStatement(com.datastax.driver.core.Session session)
-
createInsertStatement
protected abstract java.lang.String createInsertStatement(StreamElement element)
Create statement to be prepared for given ingest. This will be then stored in cache after call toprepare
.- Parameters:
element
- the input element to create statement for- Returns:
- string representation of the CQL
-
createDeleteStatement
protected abstract java.lang.String createDeleteStatement(StreamElement element)
Create statement to be prepared for given ingest when deleting attribute.- Parameters:
element
- the input element to create statement for- Returns:
- string representation of the CQL
-
createDeleteWildcardStatement
protected abstract java.lang.String createDeleteWildcardStatement(StreamElement element)
Create statement to delete wildcard attribute.- Parameters:
element
- the input element to create statement for- Returns:
- string representation of the CQL
-
createGetStatement
protected abstract java.lang.String createGetStatement(java.lang.String attribute, AttributeDescriptor<?> desc)
Create get statement for key-attribute pair. The statement must return only single field with value.- Parameters:
attribute
- the input attribute to create get fordesc
- the descriptor of the attribute- Returns:
- string representation of the CQL
-
createListStatement
protected abstract java.lang.String createListStatement(AttributeDescriptor<?> desc)
Create list statement for key-wildcardAttribute pair. The statement must return two fields - attribute, value.- Parameters:
desc
- the descriptor of the attribute- Returns:
- string representation of the CQL
-
createListEntitiesStatement
protected abstract java.lang.String createListEntitiesStatement()
Create list statement for entity keys. The statement must return single field - the entity key.- Returns:
- string representation of the CQL
-
createFetchTokenStatement
protected abstract java.lang.String createFetchTokenStatement()
Create statement to fetch token for primary key. The statement must return only the token as single field in single row.- Returns:
- string representation of the CQL
-
createListAllStatement
protected abstract java.lang.String createListAllStatement(com.datastax.driver.core.Session session)
Create statement to list all attributes of this entity.- Parameters:
session
- the connection session- Returns:
- string representation of the CQL
-
clearCache
protected void clearCache()
Clear the cache (e.g. on reconnects).
-
getListEntitiesStatement
public com.datastax.driver.core.BoundStatement getListEntitiesStatement(Offsets.Token offset, int limit, com.datastax.driver.core.Session session)
Description copied from interface:CqlFactory
Get statement for listing entities.- Specified by:
getListEntitiesStatement
in interfaceCqlFactory
- Parameters:
offset
- offset of the querylimit
- maximal number of elements to list (-1 for all)session
- connection session- Returns:
- the statement to execute
-
getFetchTokenStatement
public com.datastax.driver.core.BoundStatement getFetchTokenStatement(java.lang.String key, com.datastax.driver.core.Session session)
Description copied from interface:CqlFactory
Retrieve a bound statement to fetch a token for given entity.- Specified by:
getFetchTokenStatement
in interfaceCqlFactory
- Parameters:
key
- key to fetch token forsession
- connection session- Returns:
- the statement to execute
-
-