Class CassandraUtils


  • public class CassandraUtils
    extends Object
    Utility methods for handling Cassandra datastores.
    • Method Detail

      • getJavaTypeForCassandraType

        public static Class getJavaTypeForCassandraType​(String cassandraType)
      • getCassandraTypeForDatastoreType

        public static String getCassandraTypeForDatastoreType​(String javaType)
      • getMemberValueForColumnWithConverter

        public static Object getMemberValueForColumnWithConverter​(com.datastax.oss.driver.api.core.cql.Row row,
                                                                  org.datanucleus.store.schema.table.Column column,
                                                                  org.datanucleus.store.types.converters.TypeConverter typeConv)
      • getJavaValueForDatastoreValue

        public static Object getJavaValueForDatastoreValue​(Object datastoreValue,
                                                           String cassandraType,
                                                           Class javaType,
                                                           org.datanucleus.ExecutionContext ec)
      • getCassandraTypeForNonPersistableType

        public static String getCassandraTypeForNonPersistableType​(Class type,
                                                                   boolean serialised,
                                                                   org.datanucleus.store.types.TypeManager typeMgr,
                                                                   String jdbcType,
                                                                   org.datanucleus.metadata.AbstractMemberMetaData mmd,
                                                                   org.datanucleus.metadata.FieldRole role,
                                                                   org.datanucleus.ClassLoaderResolver clr)
        Convenience method to return the Cassandra type that we would store the provided type as. Note that this does not support container (Collection, Map) types just single value types.
        Parameters:
        type - The java type
        serialised - Whether it should be serialised
        typeMgr - The type manager
        jdbcType - Any jdbc-type that has been specified to take into account
        mmd - The field/property that this is for
        role - The role of the field that this value represents (i.e whole field, collection element, map key, etc)
        clr - ClassLoader resolver
        Returns:
        The Cassandra type
      • getDatastoreValueForNonPersistableValue

        public static Object getDatastoreValueForNonPersistableValue​(Object value,
                                                                     String datastoreType,
                                                                     boolean serialised,
                                                                     org.datanucleus.store.types.TypeManager typeMgr,
                                                                     org.datanucleus.metadata.AbstractMemberMetaData mmd,
                                                                     org.datanucleus.metadata.FieldRole role)
        Convenience method to convert from a non-persistable value to the value to be stored in Cassandra.
        Parameters:
        value - Value for the member
        datastoreType - Cassandra column type
        serialised - Whether the value is to be stored serialised
        typeMgr - Type Manager
        mmd - The field/property that this is for
        role - The role of the field that this value represents (i.e whole field, collection element, map key, etc)
        Returns:
        The value to be stored
      • getPojoForRowForCandidate

        public static Object getPojoForRowForCandidate​(com.datastax.oss.driver.api.core.cql.Row row,
                                                       org.datanucleus.metadata.AbstractClassMetaData cmd,
                                                       org.datanucleus.ExecutionContext ec,
                                                       int[] fpMembers,
                                                       boolean ignoreCache)
        Method to take a ResultSet Row and convert it into a persistable object.
        Parameters:
        row - The results row
        cmd - Metadata for the class of which this is an instance (or subclass)
        ec - ExecutionContext managing it
        fpMembers - FetchPlan members to populate
        ignoreCache - Whether to ignore the cache when instantiating this
        Returns:
        The persistable object for this row.
      • logCqlStatement

        public static void logCqlStatement​(String stmt,
                                           Object[] values,
                                           org.datanucleus.util.NucleusLogger logger)
        Convenience method to log the provided CQL statement, substituting the provided parameters for any "?" in the statement
        Parameters:
        stmt - The CQL statement
        values - Any parameter values
        logger - The logger to log to (at DEBUG level).
      • getResultClassInfoFromColumnDefinitions

        public static ResultClassInfo getResultClassInfoFromColumnDefinitions​(Class resultClazz,
                                                                              com.datastax.oss.driver.api.core.cql.ColumnDefinitions columnDefinitions)
        Convenience method to generate a ResultClassInfo which holds members that would be used by QueryUtils.createResultObjectUsingDefaultConstructorAndSetters method
        Parameters:
        resultClazz - Class type of result class.
        columnDefinitions - Cassandra result column definitions.
        Returns:
        ResultClassPojo
      • getObjectArrayFromRow

        public static Object[] getObjectArrayFromRow​(org.datanucleus.store.types.TypeManager typeMgr,
                                                     com.datastax.oss.driver.api.core.cql.Row row,
                                                     com.datastax.oss.driver.api.core.cql.ColumnDefinitions columnDefinitions,
                                                     List<Integer> fieldsMatchingColumnIndexes,
                                                     int resultRowSize)
        Convenience method to get Object[] from Cassandra Row.
        Parameters:
        typeMgr - TypeManager
        row - Row returned from Cassandra driver
        columnDefinitions - Cassandra result column definitions.
        fieldsMatchingColumnIndexes - indices of ColumnDefinitions that match to a field of resultClass
        resultRowSize - size of Object [] that is returned
        Returns:
        Object[] of results