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 |
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 the keyspace session.
|
protected com.datastax.oss.driver.api.core.CqlSession |
buildSystemSession(com.datastax.oss.driver.api.core.CqlSessionBuilder sessionBuilder)
Build the 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. |
boolean |
isSingleton() |
protected void |
performSchemaAction()
Perform the configure
SchemaAction using CassandraMappingContext metadata. |
void |
setContactPoints(String contactPoints)
Set a comma-delimited string of the contact points (hosts) to connect to.
|
void |
setConverter(CassandraConverter converter)
Deprecated.
Use
CassandraSessionFactoryBean with
setConverter(CassandraConverter) instead. |
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 |
setSessionSessionBuilderConfigurer(SessionBuilderConfigurer sessionSessionBuilderConfigurer)
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) |
public static final int DEFAULT_PORT
public static final String DEFAULT_CONTACT_POINTS
protected final org.slf4j.Logger logger
public boolean isConnected()
CqlSession
is connected or not.CqlSession
is connected.Session#isClosed()
,
getObject()
public void setContactPoints(String contactPoints)
localhost
; see
DEFAULT_CONTACT_POINTS
.contactPoints
- the contact points used by the new cluster.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.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 List<KeyspaceActions> getKeyspaceActions()
List
of KeyspaceActions
.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 void setKeyspaceSpecifications(List<? extends KeyspaceActionSpecification> keyspaceSpecifications)
keyspaceSpecifications
- The KeyspaceActionSpecification
to set.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 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 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 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 shutdownpublic Set<KeyspaceActionSpecification> getKeyspaceSpecifications()
KeyspaceActionSpecification
associated with this factory.public void setLocalDatacenter(@Nullable String localDatacenter)
localDatacenter
- a String indicating the name of the local datacenter.protected com.datastax.oss.driver.api.core.CqlSession getSession()
CqlSession
.CqlSession
.IllegalStateException
- if the Cassandra CqlSession
was not properly initialized.Session
public void setSessionSessionBuilderConfigurer(@Nullable SessionBuilderConfigurer sessionSessionBuilderConfigurer)
SessionBuilderConfigurer
to configure the
SessionBuilder
.sessionSessionBuilderConfigurer
- @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.@Deprecated public void setConverter(CassandraConverter converter)
CassandraSessionFactoryBean
with
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
.protected CassandraMappingContext getMappingContext()
CassandraMappingContext
.@Deprecated public void setSchemaAction(SchemaAction schemaAction)
CassandraSessionFactoryBean
with
setSchemaAction(SchemaAction)
instead.SchemaAction
.schemaAction
- must not be null.public SchemaAction getSchemaAction()
SchemaAction
.public void afterPropertiesSet()
afterPropertiesSet
in interface InitializingBean
protected com.datastax.oss.driver.api.core.CqlSession buildSystemSession(com.datastax.oss.driver.api.core.CqlSessionBuilder sessionBuilder)
sessionBuilder
- protected com.datastax.oss.driver.api.core.CqlSession buildSession(com.datastax.oss.driver.api.core.CqlSessionBuilder sessionBuilder)
sessionBuilder
- public void destroy()
destroy
in interface DisposableBean
protected void closeSession()
protected void closeSystemSession()
protected com.datastax.oss.driver.api.core.CqlSessionBuilder buildBuilder()
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 know to be used by
CassandraMappingContext
).ifNotExists
- true to perform creations fail-safe 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>
public boolean isSingleton()
isSingleton
in interface FactoryBean<com.datastax.oss.driver.api.core.CqlSession>
@Nullable public DataAccessException translateExceptionIfPossible(RuntimeException e)
translateExceptionIfPossible
in interface PersistenceExceptionTranslator
Copyright © 2011–2020 Pivotal Software, Inc.. All rights reserved.