Class DefaultCqlFactory

  • All Implemented Interfaces:
    CqlFactory, java.io.Serializable

    public class DefaultCqlFactory
    extends CacheableCqlFactory
    A CqlFactory used by default. The default behavior is to take name of the attribute and change it from camelCase to underscore_case. The cassandra URI looks like this:
    
     cassandra://<authority>/<table>/?primary=<primaryField>
         &secondary=<secondaryKeyField>&data=<dataField>&reversed=true*
     
    where: * primaryField is the column where primary key (or first part of composite key) is stored * secondaryField is the second part of composite key (optional) * dataField is the name of data field for wildcard attributes (optional) * reversed might by true if the composite key is sorted in descending order
    See Also:
    Serialized Form
    • Constructor Detail

      • DefaultCqlFactory

        public DefaultCqlFactory()
    • Method Detail

      • setup

        protected void setup​(java.util.Map<java.lang.String,​java.lang.String> query,
                             StringConverter<?> converter)
        Description copied from class: CacheableCqlFactory
        Setup the factory from URI parameters passed in.
        Overrides:
        setup in class CacheableCqlFactory
        Parameters:
        query - the parsed URI query parameters
        converter - converter of payload to string
      • getWriteStatement

        public java.util.Optional<com.datastax.driver.core.BoundStatement> getWriteStatement​(StreamElement element,
                                                                                             com.datastax.driver.core.Session session)
        Description copied from interface: CqlFactory
        Retrieve a CQL query to execute in order to ingest the request.
        Parameters:
        element - input data
        session - current session
        Returns:
        the statement to execute. When empty, the ingest is silently discarded.
      • getReadStatement

        public com.datastax.driver.core.BoundStatement getReadStatement​(java.lang.String key,
                                                                        java.lang.String attribute,
                                                                        AttributeDescriptor<?> desc,
                                                                        com.datastax.driver.core.Session session)
        Description copied from interface: CqlFactory
        Retrieve a CQL query to execute in order to read data.
        Parameters:
        key - the primary key whose attribute to return
        attribute - the attribute to fetch
        desc - descriptor of the attribute
        session - the connection session
        Returns:
        the statement to execute
      • getListStatement

        public com.datastax.driver.core.BoundStatement getListStatement​(java.lang.String key,
                                                                        AttributeDescriptor<?> wildcard,
                                                                        @Nullable
                                                                        Offsets.Raw offset,
                                                                        int limit,
                                                                        com.datastax.driver.core.Session session)
        Description copied from interface: CqlFactory
        Retrieve 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 list
        offset - 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
      • createInsertStatement

        protected java.lang.String createInsertStatement​(StreamElement element)
        Description copied from class: CacheableCqlFactory
        Create statement to be prepared for given ingest. This will be then stored in cache after call to prepare.
        Specified by:
        createInsertStatement in class CacheableCqlFactory
        Parameters:
        element - the input element to create statement for
        Returns:
        string representation of the CQL
      • createDeleteStatement

        protected java.lang.String createDeleteStatement​(StreamElement element)
        Description copied from class: CacheableCqlFactory
        Create statement to be prepared for given ingest when deleting attribute.
        Specified by:
        createDeleteStatement in class CacheableCqlFactory
        Parameters:
        element - the input element to create statement for
        Returns:
        string representation of the CQL
      • createGetStatement

        protected java.lang.String createGetStatement​(java.lang.String attribute,
                                                      AttributeDescriptor<?> desc)
        Description copied from class: CacheableCqlFactory
        Create get statement for key-attribute pair. The statement must return only single field with value.
        Specified by:
        createGetStatement in class CacheableCqlFactory
        Parameters:
        attribute - the input attribute to create get for
        desc - the descriptor of the attribute
        Returns:
        string representation of the CQL
      • createListStatement

        protected java.lang.String createListStatement​(AttributeDescriptor<?> attr)
        Description copied from class: CacheableCqlFactory
        Create list statement for key-wildcardAttribute pair. The statement must return two fields - attribute, value.
        Specified by:
        createListStatement in class CacheableCqlFactory
        Parameters:
        attr - the descriptor of the attribute
        Returns:
        string representation of the CQL
      • createListEntitiesStatement

        protected java.lang.String createListEntitiesStatement()
        Description copied from class: CacheableCqlFactory
        Create list statement for entity keys. The statement must return single field - the entity key.
        Specified by:
        createListEntitiesStatement in class CacheableCqlFactory
        Returns:
        string representation of the CQL
      • createFetchTokenStatement

        protected java.lang.String createFetchTokenStatement()
        Description copied from class: CacheableCqlFactory
        Create statement to fetch token for primary key. The statement must return only the token as single field in single row.
        Specified by:
        createFetchTokenStatement in class CacheableCqlFactory
        Returns:
        string representation of the CQL
      • createListAllStatement

        protected java.lang.String createListAllStatement​(com.datastax.driver.core.Session session)
        Description copied from class: CacheableCqlFactory
        Create statement to list all attributes of this entity.
        Specified by:
        createListAllStatement in class CacheableCqlFactory
        Parameters:
        session - the connection session
        Returns:
        string representation of the CQL
      • scanPartition

        public com.datastax.driver.core.Statement scanPartition​(java.util.List<AttributeDescriptor<?>> attributes,
                                                                CassandraPartition partition,
                                                                com.datastax.driver.core.Session session)
        Description copied from interface: CqlFactory
        Retrieve a bound statement to scan data for given attribute and partition.
        Parameters:
        attributes - list of attributes to scan
        partition - the partition to scan
        session - connection session
        Returns:
        the statement to execute
      • getListAllStatement

        public <T> CqlFactory.KvIterable<T> getListAllStatement​(java.lang.String key,
                                                                Offsets.Raw offset,
                                                                int limit,
                                                                com.datastax.driver.core.Session session)
        Description copied from interface: CqlFactory
        Retrieve wrapped statement to execute to list all attributes of given key.
        Type Parameters:
        T - type of CqlFactory.KvIterable
        Parameters:
        key - key to list attributes of
        offset - offset to start from (return next attribute)
        limit - maximum number of items to return
        session - the connection session
        Returns:
        iterable over keyvalues