public class CqlSessionFactoryBean extends Object implements FactoryBean<com.datastax.oss.driver.api.core.CqlSession>, InitializingBean, DisposableBean, PersistenceExceptionTranslator
CqlSession
, which is a thread-safe singleton. As such, it is
sufficient to have one CqlSession
per application and keyspace.Modifier and Type | Field and Description |
---|---|
static String |
CASSANDRA_SYSTEM_SESSION |
static String |
DEFAULT_CONTACT_POINTS |
static int |
DEFAULT_PORT |
protected org.slf4j.Logger |
logger |
OBJECT_TYPE_ATTRIBUTE
Constructor and Description |
---|
CqlSessionFactoryBean() |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet() |
protected com.datastax.oss.driver.api.core.CqlSessionBuilder |
buildBuilder() |
protected com.datastax.oss.driver.api.core.CqlSession |
buildSession(com.datastax.oss.driver.api.core.CqlSessionBuilder sessionBuilder)
Build a
Session to the user-defined Keyspace or the default Keyspace if
the user did not specify a Keyspace by name . |
protected com.datastax.oss.driver.api.core.CqlSession |
buildSystemSession(com.datastax.oss.driver.api.core.CqlSessionBuilder sessionBuilder)
Build the Cassandra
System Session . |
protected void |
closeSession()
Close the regular session object.
|
protected void |
closeSystemSession()
Close the system session object.
|
protected void |
createTables(boolean drop,
boolean dropUnused,
boolean ifNotExists)
Perform schema actions.
|
void |
destroy() |
CassandraConverter |
getConverter() |
List<KeyspaceActions> |
getKeyspaceActions() |
protected String |
getKeyspaceName()
Gets the name of the Cassandra Keyspace to connect to.
|
Set<KeyspaceActionSpecification> |
getKeyspaceSpecifications() |
protected CassandraMappingContext |
getMappingContext() |
com.datastax.oss.driver.api.core.CqlSession |
getObject() |
Class<? extends com.datastax.oss.driver.api.core.CqlSession> |
getObjectType() |
SchemaAction |
getSchemaAction() |
protected com.datastax.oss.driver.api.core.CqlSession |
getSession()
Returns a reference to the connected Cassandra
CqlSession . |
List<String> |
getShutdownScripts()
Deprecated.
Use
SessionFactoryInitializer or
SessionFactoryFactoryBean with
KeyspacePopulator instead. |
List<String> |
getStartupScripts()
Deprecated.
Use
SessionFactoryInitializer or
SessionFactoryFactoryBean with
KeyspacePopulator instead. |
boolean |
isConnected()
Null-safe operation to determine whether the Cassandra
CqlSession is connected or not. |
protected void |
performSchemaAction()
Perform the configure
SchemaAction using CassandraMappingContext metadata. |
void |
setContactPoints(Collection<InetSocketAddress> contactPoints)
Set a collection of the contact points (hosts) to connect to.
|
void |
setContactPoints(String contactPoints)
Set a comma-delimited string of the contact points (hosts) to connect to.
|
void |
setConverter(CassandraConverter converter)
Deprecated.
|
void |
setKeyspaceActions(List<KeyspaceActions> keyspaceActions)
Set a
List of KeyspaceActions to be executed on initialization. |
void |
setKeyspaceAlterations(List<AlterKeyspaceSpecification> specifications)
|
void |
setKeyspaceCreations(List<CreateKeyspaceSpecification> specifications)
|
void |
setKeyspaceDrops(List<DropKeyspaceSpecification> specifications)
|
void |
setKeyspaceName(String keyspaceName)
Sets the name of the Cassandra Keyspace to connect to.
|
void |
setKeyspaceShutdownScripts(List<String> scripts)
Set a
List of raw CQL statements that are executed in the scope of the system keyspace when
this factory is destroyed . |
void |
setKeyspaceSpecifications(List<? extends KeyspaceActionSpecification> keyspaceSpecifications) |
void |
setKeyspaceStartupScripts(List<String> scripts)
Set a
List of raw CQL statements that are executed in the scope of the system keyspace when
this factory is initialized . |
void |
setLocalDatacenter(String localDatacenter)
Sets the name of the local datacenter.
|
void |
setPassword(String password)
Set the password to use.
|
void |
setPort(int port)
Set the port for the contact points.
|
void |
setSchemaAction(SchemaAction schemaAction)
Deprecated.
Use
CassandraSessionFactoryBean with
setSchemaAction(SchemaAction) instead. |
void |
setSessionBuilderConfigurer(SessionBuilderConfigurer sessionBuilderConfigurer)
Sets the
SessionBuilderConfigurer to configure the
SessionBuilder . |
void |
setShutdownScripts(List<String> scripts)
Deprecated.
Use
SessionFactoryInitializer or
SessionFactoryFactoryBean with
KeyspacePopulator instead. |
void |
setStartupScripts(List<String> scripts)
Deprecated.
Use
SessionFactoryInitializer or
SessionFactoryFactoryBean with
KeyspacePopulator instead. |
void |
setUsername(String username)
Set the username to use.
|
DataAccessException |
translateExceptionIfPossible(RuntimeException e) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
isSingleton
public static final String CASSANDRA_SYSTEM_SESSION
public static final String DEFAULT_CONTACT_POINTS
public static final int DEFAULT_PORT
protected final org.slf4j.Logger logger
public boolean isConnected()
CqlSession
is connected or not.CqlSession
is connected.AsyncAutoCloseable.isClosed()
,
getObject()
public void setContactPoints(String contactPoints)
localhost
; see
DEFAULT_CONTACT_POINTS
. Contact points may use the form host:port
, or a simple host
to use
the configured port
.contactPoints
- the contact points used by the new cluster, must not be null.public void setContactPoints(Collection<InetSocketAddress> contactPoints)
localhost
; see
DEFAULT_CONTACT_POINTS
.contactPoints
- the contact points used by the new cluster, must not be null. Use
unresolved addresses
to delegate hostname
resolution to the driver.public void setLocalDatacenter(@Nullable String localDatacenter)
localDatacenter
- a String indicating the name of the local datacenter.public void setPort(int port)
9042
, see DEFAULT_PORT
.port
- the port used by the new cluster.public void setUsername(String username)
username
- The username to set.public void setPassword(String password)
password
- The password to set.@Deprecated public void setConverter(CassandraConverter converter)
SessionFactoryFactoryBean
with
SessionFactoryFactoryBean.setConverter(CassandraConverter)
instead.CassandraConverter
to use. Schema actions will derive table and user type information from the
CassandraMappingContext
inside converter
.converter
- must not be null.@Nullable public CassandraConverter getConverter()
CassandraConverter
.public void setKeyspaceActions(List<KeyspaceActions> keyspaceActions)
List
of KeyspaceActions
to be executed on initialization. Keyspace actions may contain create
and drop specifications.keyspaceActions
- the List
of KeyspaceActions
.public List<KeyspaceActions> getKeyspaceActions()
List
of KeyspaceActions
.public void setKeyspaceAlterations(List<AlterKeyspaceSpecification> specifications)
List
of alter keyspace specifications
that are executed when this
factory is initialized
. Alter keyspace
specifications
are executed on a system session with no keyspace set, before executing
setStartupScripts(List)
.specifications
- the List
of create keyspace specifications
.public void setKeyspaceCreations(List<CreateKeyspaceSpecification> specifications)
List
of create keyspace specifications
that are executed when
this factory is initialized
. Create keyspace
specifications
are executed on a system session with no keyspace set, before executing
setStartupScripts(List)
.specifications
- the List
of create keyspace specifications
.public void setKeyspaceDrops(List<DropKeyspaceSpecification> specifications)
List
of drop keyspace specifications
that are executed when this
factory is destroyed
. Drop keyspace specifications
are
executed on a system session with no keyspace set, before executing setShutdownScripts(List)
.specifications
- the List
of drop keyspace specifications
.public void setKeyspaceName(@Nullable String keyspaceName)
keyspaceName
- a String indicating the name of the Keyspace in which to connect.getKeyspaceName()
@Nullable protected String getKeyspaceName()
setKeyspaceName(String)
public void setKeyspaceSpecifications(List<? extends KeyspaceActionSpecification> keyspaceSpecifications)
keyspaceSpecifications
- The KeyspaceActionSpecification
to set.public Set<KeyspaceActionSpecification> getKeyspaceSpecifications()
KeyspaceActionSpecification
associated with this factory.public void setKeyspaceStartupScripts(List<String> scripts)
List
of raw CQL statements
that are executed in the scope of the system keyspace when
this factory is initialized
. Scripts are executed on a system session with no
keyspace set, after executing setKeyspaceCreations(List)
.scripts
- the scripts to execute on startuppublic void setKeyspaceShutdownScripts(List<String> scripts)
List
of raw CQL statements
that are executed in the scope of the system keyspace when
this factory is destroyed
. Drop keyspace specifications
are
executed on a system session with no keyspace set, after executing setKeyspaceDrops(List)
.scripts
- the scripts to execute on shutdownprotected CassandraMappingContext getMappingContext()
CassandraMappingContext
.@Deprecated public void setSchemaAction(SchemaAction schemaAction)
CassandraSessionFactoryBean
with
setSchemaAction(SchemaAction)
instead.SchemaAction
.schemaAction
- must not be null.public SchemaAction getSchemaAction()
SchemaAction
.protected com.datastax.oss.driver.api.core.CqlSession getSession()
CqlSession
.CqlSession
.IllegalStateException
- if the Cassandra CqlSession
was not properly initialized.CqlSession
public void setSessionBuilderConfigurer(@Nullable SessionBuilderConfigurer sessionBuilderConfigurer)
SessionBuilderConfigurer
to configure the
SessionBuilder
.sessionBuilderConfigurer
- @Deprecated public void setStartupScripts(@Nullable List<String> scripts)
SessionFactoryInitializer
or
SessionFactoryFactoryBean
with
KeyspacePopulator
instead.@Deprecated public List<String> getStartupScripts()
SessionFactoryInitializer
or
SessionFactoryFactoryBean
with
KeyspacePopulator
instead.@Deprecated public void setShutdownScripts(@Nullable List<String> scripts)
SessionFactoryInitializer
or
SessionFactoryFactoryBean
with
KeyspacePopulator
instead.@Deprecated public List<String> getShutdownScripts()
SessionFactoryInitializer
or
SessionFactoryFactoryBean
with
KeyspacePopulator
instead.public void afterPropertiesSet()
afterPropertiesSet
in interface InitializingBean
protected com.datastax.oss.driver.api.core.CqlSessionBuilder buildBuilder()
protected com.datastax.oss.driver.api.core.CqlSession buildSystemSession(com.datastax.oss.driver.api.core.CqlSessionBuilder sessionBuilder)
System Session
.sessionBuilder
- CqlSessionBuilder
used to a build a Cassandra CqlSession
.System Session
.CqlSessionBuilder
,
CqlSession
protected com.datastax.oss.driver.api.core.CqlSession buildSession(com.datastax.oss.driver.api.core.CqlSessionBuilder sessionBuilder)
Session
to the user-defined Keyspace or the default Keyspace if
the user did not specify a Keyspace by name
.sessionBuilder
- CqlSessionBuilder
used to a build a Cassandra CqlSession
.CqlSession
to the user-defined Keyspace.CqlSessionBuilder
,
CqlSession
protected void performSchemaAction()
SchemaAction
using CassandraMappingContext
metadata.protected void createTables(boolean drop, boolean dropUnused, boolean ifNotExists)
drop
- true to drop types/tables.dropUnused
- true to drop unused types/tables (i.e. types/tables not known to be used by the
CassandraMappingContext
).ifNotExists
- true to perform fail-safe creations by adding IF NOT EXISTS
to each creation
statement.public com.datastax.oss.driver.api.core.CqlSession getObject()
getObject
in interface FactoryBean<com.datastax.oss.driver.api.core.CqlSession>
public Class<? extends com.datastax.oss.driver.api.core.CqlSession> getObjectType()
getObjectType
in interface FactoryBean<com.datastax.oss.driver.api.core.CqlSession>
@Nullable public DataAccessException translateExceptionIfPossible(RuntimeException e)
translateExceptionIfPossible
in interface PersistenceExceptionTranslator
public void destroy()
destroy
in interface DisposableBean
protected void closeSession()
protected void closeSystemSession()
Copyright © 2011–2022 Pivotal Software, Inc.. All rights reserved.