Package org.jesterj.ingest.persistence
Class CassandraSupport
- java.lang.Object
-
- org.jesterj.ingest.persistence.CassandraSupport
-
public class CassandraSupport extends java.lang.ObjectA class to globalize the cluster and session objects, while providing query caches on a per-instance basis. These objects are lightweight and can be
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classCassandraSupport.NonClosableSession
-
Field Summary
Fields Modifier and Type Field Description static java.lang.ThreadLocal<java.util.SplittableRandom>antiCollisionstatic CassandraSupport.NonClosableSessionNON_CLOSABLE_SESSIONstatic java.util.SplittableRandomrootRand
-
Constructor Summary
Constructors Constructor Description CassandraSupport()
-
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.PreparedStatementgetPreparedQuery(java.lang.String qName)Retrieve a prepared statement added viaaddStatement(String, String).com.datastax.oss.driver.api.core.cql.PreparedStatementgetPreparedQuery(java.lang.String qName, java.lang.String q)Retrieve a prepared statement added viaaddStatement(String, String).com.datastax.oss.driver.api.core.CqlSessiongetSession()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)
-
-
-
Field Detail
-
rootRand
public static final java.util.SplittableRandom rootRand
-
antiCollision
public static final java.lang.ThreadLocal<java.util.SplittableRandom> antiCollision
-
NON_CLOSABLE_SESSION
public static CassandraSupport.NonClosableSession NON_CLOSABLE_SESSION
-
-
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 instancestatement- 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
NonClosableSessionobject.
-
getPreparedQuery
public com.datastax.oss.driver.api.core.cql.PreparedStatement getPreparedQuery(java.lang.String qName)
Retrieve a prepared statement added viaaddStatement(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 viaaddStatement(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 preparedq- 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)
-
-