Class CassandraSupport


  • public class CassandraSupport
    extends java.lang.Object
    A class to globalize the cluster and session objects, while providing query caches on a per-instance basis. These objects are lightweight and can be
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.concurrent.Future<com.datastax.oss.driver.api.core.cql.PreparedStatement> addStatement​(java.lang.String name, java.lang.String statement)
      Add a query to the list of prepared queries maintained by this instance.
      com.datastax.oss.driver.api.core.cql.PreparedStatement getPreparedQuery​(java.lang.String qName)
      Retrieve a prepared statement added via addStatement(String, String).
      com.datastax.oss.driver.api.core.cql.PreparedStatement getPreparedQuery​(java.lang.String qName, java.lang.String q)
      Retrieve a prepared statement added via addStatement(String, String).
      com.datastax.oss.driver.api.core.CqlSession getSession()
      Returns a cassandra session wrapped to protect it from being closed.
      java.util.concurrent.Future<java.lang.Object> whenBooted​(java.util.concurrent.Callable<java.lang.Object> makeTables)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • rootRand

        public static final java.util.SplittableRandom rootRand
      • antiCollision

        public static final java.lang.ThreadLocal<java.util.SplittableRandom> antiCollision
    • Constructor Detail

      • CassandraSupport

        public CassandraSupport()
    • Method Detail

      • addStatement

        public java.util.concurrent.Future<com.datastax.oss.driver.api.core.cql.PreparedStatement> addStatement​(java.lang.String name,
                                                                                                                java.lang.String statement)
        Add a query to the list of prepared queries maintained by this instance. Queries may be added before Cassandra is booted, but will not become available until after the Cassandra boot cycle completes. Attempts to add a query with the same name more than once will be ignored. Queries are cached globally.
        Parameters:
        name - A name with which to retrieve the prepared statement instance
        statement - A string to be prepared as a CQL statement.
        Returns:
        a future that will complete after cassandra has completed its boot cycle and the statement has been prepared.
      • getSession

        public com.datastax.oss.driver.api.core.CqlSession getSession()
        Returns a cassandra session wrapped to protect it from being closed.
        Returns:
        a NonClosableSession object.
      • getPreparedQuery

        public com.datastax.oss.driver.api.core.cql.PreparedStatement getPreparedQuery​(java.lang.String qName)
        Retrieve a prepared statement added via addStatement(String, String). This method will block until cassandra has finished booting, a session has been created and the statement has been prepared. This method may return null if no statement with that name has been prepared previously.
        Parameters:
        qName - the name of the statement to retrieve
        Returns:
        the prepared statement ready for use.
      • getPreparedQuery

        public com.datastax.oss.driver.api.core.cql.PreparedStatement getPreparedQuery​(java.lang.String qName,
                                                                                       java.lang.String q)
        Retrieve a prepared statement added via addStatement(String, String). This method will block until cassandra has finished booting, a session has been created and the statement has been prepared. If the statement q was not previously prepared, this method will first prepare it and then return the prepared statement.
        Parameters:
        qName - the name of the statement to retrieve or prepare if not already prepared
        q - the query to prepare (if not already prepared).
        Returns:
        the prepared statement ready for use.
      • whenBooted

        public java.util.concurrent.Future<java.lang.Object> whenBooted​(java.util.concurrent.Callable<java.lang.Object> makeTables)