public class CassandraAccessor extends Object implements InitializingBean
CassandraAccessor
provides access to a Cassandra SessionFactory
and the
CassandraExceptionTranslator
.
Classes providing a higher abstraction level usually extend CassandraAccessor
to provide a richer set of
functionality on top of a SessionFactory
using Session
.
InitializingBean
,
Session
Modifier and Type | Field and Description |
---|---|
protected CqlExceptionTranslator |
exceptionTranslator |
protected org.slf4j.Logger |
logger
Logger available to subclasses
|
Constructor and Description |
---|
CassandraAccessor() |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet()
Ensures the Cassandra
Session and exception translator has been propertly set. |
protected <T extends com.datastax.driver.core.PreparedStatement> |
applyStatementSettings(T statement)
Prepare the given CQL Statement (or
PreparedStatement ), applying statement
settings such as retry policy and consistency level. |
protected <T extends com.datastax.driver.core.Statement> |
applyStatementSettings(T statement)
Prepare the given CQL Statement (or
PreparedStatement ), applying statement
settings such as fetch size, retry policy, and consistency level. |
com.datastax.driver.core.ConsistencyLevel |
getConsistencyLevel() |
CqlExceptionTranslator |
getExceptionTranslator()
Return the exception translator used by this template to translate Cassandra specific Exceptions into Spring DAO's
Exception Hierarchy.
|
int |
getFetchSize() |
com.datastax.driver.core.policies.RetryPolicy |
getRetryPolicy() |
com.datastax.driver.core.Session |
getSession()
Deprecated.
since 2.0. This class uses a
SessionFactory to dispatch CQL calls amongst different
Session s during its lifecycle. |
SessionFactory |
getSessionFactory()
Returns the Cassandra
SessionFactory used by this template to perform Cassandra data access operations. |
void |
setConsistencyLevel(com.datastax.driver.core.ConsistencyLevel consistencyLevel)
Set the consistency level for this template.
|
void |
setExceptionTranslator(CqlExceptionTranslator exceptionTranslator)
Sets the exception translator used by this template to translate Cassandra specific Exceptions into Spring DAO's
Exception Hierarchy.
|
void |
setFetchSize(int fetchSize)
Set the fetch size for this template.
|
void |
setRetryPolicy(com.datastax.driver.core.policies.RetryPolicy retryPolicy)
Set the retry policy for this template.
|
void |
setSession(com.datastax.driver.core.Session session)
Sets the Cassandra
Session used by this template to perform Cassandra data access operations. |
void |
setSessionFactory(SessionFactory sessionFactory)
Sets the Cassandra
SessionFactory used by this template to perform Cassandra data access operations. |
protected DataAccessException |
translate(String task,
String cql,
com.datastax.driver.core.exceptions.DriverException ex)
Translate the given
DriverException into a generic DataAccessException . |
protected DataAccessException |
translateExceptionIfPossible(com.datastax.driver.core.exceptions.DriverException ex)
Translate the given
DriverException into a generic DataAccessException . |
protected final org.slf4j.Logger logger
protected CqlExceptionTranslator exceptionTranslator
public void afterPropertiesSet()
Session
and exception translator has been propertly set.afterPropertiesSet
in interface InitializingBean
public void setConsistencyLevel(com.datastax.driver.core.ConsistencyLevel consistencyLevel)
Statement.setConsistencyLevel(ConsistencyLevel)
,
RetryPolicy
public com.datastax.driver.core.ConsistencyLevel getConsistencyLevel()
ConsistencyLevel
specified for this template.public void setExceptionTranslator(CqlExceptionTranslator exceptionTranslator)
exceptionTranslator
- exception translator to set; must not be null.CqlExceptionTranslator
public CqlExceptionTranslator getExceptionTranslator()
CqlExceptionTranslator
public void setFetchSize(int fetchSize)
Statement.setFetchSize(int)
public int getFetchSize()
public void setRetryPolicy(com.datastax.driver.core.policies.RetryPolicy retryPolicy)
Statement.setRetryPolicy(RetryPolicy)
,
RetryPolicy
public com.datastax.driver.core.policies.RetryPolicy getRetryPolicy()
RetryPolicy
specified for this template.public void setSession(com.datastax.driver.core.Session session)
Session
used by this template to perform Cassandra data access operations. The
session
will replace the current getSessionFactory()
with DefaultSessionFactory
.session
- Cassandra Session
used by this template, must not benull.Session
,
DefaultSessionFactory
@Deprecated public com.datastax.driver.core.Session getSession()
SessionFactory
to dispatch CQL calls amongst different
Session
s during its lifecycle.Session
from SessionFactory
used by this template to perform Cassandra data
access operations.Session
used by this template.Session
public void setSessionFactory(SessionFactory sessionFactory)
SessionFactory
used by this template to perform Cassandra data access operations.sessionFactory
- Cassandra Session
used by this template. Must not benull.Session
public SessionFactory getSessionFactory()
SessionFactory
used by this template to perform Cassandra data access operations.SessionFactory
used by this template.SessionFactory
protected <T extends com.datastax.driver.core.PreparedStatement> T applyStatementSettings(T statement)
PreparedStatement
), applying statement
settings such as retry policy and consistency level.statement
- the CQL Statement to preparesetRetryPolicy(RetryPolicy)
,
setConsistencyLevel(ConsistencyLevel)
protected <T extends com.datastax.driver.core.Statement> T applyStatementSettings(T statement)
PreparedStatement
), applying statement
settings such as fetch size, retry policy, and consistency level.statement
- the CQL Statement to preparesetFetchSize(int)
,
setRetryPolicy(RetryPolicy)
,
setConsistencyLevel(ConsistencyLevel)
protected DataAccessException translateExceptionIfPossible(com.datastax.driver.core.exceptions.DriverException ex)
DriverException
into a generic DataAccessException
.
The returned DataAccessException
is supposed to contain the original DriverException
as root cause.
However, client code may not generally rely on this due to DataAccessException
s possibly being caused by
other resource APIs as well. That said, a getRootCause() instanceof DataAccessException
check (and
subsequent cast) is considered reliable when expecting Cassandra-based access to have happened.
ex
- the offending DriverException
DriverException
DataAccessException
protected DataAccessException translate(String task, String cql, com.datastax.driver.core.exceptions.DriverException ex)
DriverException
into a generic DataAccessException
.
The returned DataAccessException
is supposed to contain the original DriverException
as root cause.
However, client code may not generally rely on this due to DataAccessException
s possibly being caused by
other resource APIs as well. That said, a getRootCause() instanceof DataAccessException
check (and
subsequent cast) is considered reliable when expecting Cassandra-based access to have happened.
task
- readable text describing the task being attemptedcql
- CQL query or update that caused the problem (may be null
)ex
- the offending DriverException
DriverException
NestedRuntimeException.getRootCause()
,
Consistent
exception hierarchyCopyright © 2011–2017 Pivotal Software, Inc.. All rights reserved.