Class AbstractSessionConfiguration
java.lang.Object
org.springframework.data.cassandra.config.AbstractSessionConfiguration
- All Implemented Interfaces:
Aware
,BeanFactoryAware
- Direct Known Subclasses:
AbstractCassandraConfiguration
,AbstractCqlTemplateConfiguration
@Configuration
public abstract class AbstractSessionConfiguration
extends Object
implements BeanFactoryAware
Spring
Configuration
class used to configure a Cassandra client application CqlSession
connected to a
Cassandra cluster. Enables a Cassandra Keyspace to be specified along with the ability to execute arbitrary CQL on
startup as well as shutdown.- Author:
- Matthew T. Adams, John Blum, Mark Paluch
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionCreates aCqlSessionFactoryBean
that provides a CassandraCqlSession
.Creates aCqlTemplate
configured withgetRequiredSessionFactory()
.protected BeanFactory
Returns the configured reference to theBeanFactory
.protected String
Deprecated.protected CompressionType
Returns theCompressionType
.protected String
Returns the Cassandra contact points.protected DriverConfigLoaderBuilderConfigurer
Returns theDriverConfigLoaderBuilderConfigurer
.protected Resource
Returns theResource
pointing to a driver configuration file.protected List<CreateKeyspaceSpecification>
Returns the list of keyspace creations to be run right after initialization.protected List<DropKeyspaceSpecification>
Returns the list of keyspace drops to be run before shutdown.protected abstract String
Return the name of the keyspace to connect to.protected String
Returns the local data center name used forLoadBalancingPolicy
, defaulting todatacenter1
.protected int
getPort()
Returns the Cassandra port.protected com.datastax.oss.driver.api.core.CqlSession
Returns the initializedCqlSession
instance.protected SessionFactory
Returns the initializedCqlSession
instance.protected SessionBuilderConfigurer
Returns theSessionBuilderConfigurer
.protected String
Returns the session name.Deprecated.since 3.0; Declare aSessionFactoryInitializer
bean instead.Deprecated.since 3.0; Declare aSessionFactoryInitializer
bean instead.protected <T> T
requireBeanOfType
(Class<T> beanType) Gets a required bean of the providedtype
from theBeanFactory
.void
setBeanFactory
(BeanFactory beanFactory) Configures a reference to theBeanFactory
.
-
Constructor Details
-
AbstractSessionConfiguration
public AbstractSessionConfiguration()
-
-
Method Details
-
setBeanFactory
Configures a reference to theBeanFactory
.- Specified by:
setBeanFactory
in interfaceBeanFactoryAware
- Parameters:
beanFactory
- reference to theBeanFactory
.- Throws:
BeansException
- if theBeanFactory
could not be initialized.- See Also:
-
getBeanFactory
Returns the configured reference to theBeanFactory
.- Returns:
- the configured reference to the
BeanFactory
. - Throws:
IllegalStateException
- if theBeanFactory
reference was not configured.- See Also:
-
requireBeanOfType
Gets a required bean of the providedtype
from theBeanFactory
.- Type Parameters:
T
-parameterized class type
of the bean.- Parameters:
beanType
-type
of the bean.- Returns:
- a required bean of the given
type
from theBeanFactory
. - See Also:
-
getClusterName
Deprecated.since 3.0, usegetSessionName()
instead.Returns thename
of the cluster.- Returns:
- the
cluster name
; may be null. - Since:
- 1.5
-
getKeyspaceName
Return the name of the keyspace to connect to.- Returns:
- must not be null.
-
getLocalDataCenter
Returns the local data center name used forLoadBalancingPolicy
, defaulting todatacenter1
. Typically required when connecting a Cassandra cluster. Not required when using an Astra connection bundle.- Returns:
- the local data center name. Can be null when using an Astra connection bundle.
-
getSessionName
Returns the session name.- Returns:
- the session name; may be null.
- Since:
- 3.0
-
getCompressionType
Returns theCompressionType
.- Returns:
- the
CompressionType
, may be null.
-
getContactPoints
Returns the Cassandra contact points. Defaults tolocalhost
- Returns:
- the Cassandra contact points
- See Also:
-
getPort
protected int getPort()Returns the Cassandra port. Defaults to9042
.- Returns:
- the Cassandra port
- See Also:
-
getKeyspaceCreations
Returns the list of keyspace creations to be run right after initialization.- Returns:
- the list of keyspace creations, may be empty but never
null
.
-
getKeyspaceDrops
Returns the list of keyspace drops to be run before shutdown.- Returns:
- the list of keyspace drops, may be empty but never
null
.
-
getRequiredSession
protected com.datastax.oss.driver.api.core.CqlSession getRequiredSession()Returns the initializedCqlSession
instance.- Returns:
- the
CqlSession
. - Throws:
IllegalStateException
- if the session factory is not initialized.
-
getRequiredSessionFactory
Returns the initializedCqlSession
instance.- Returns:
- the
CqlSession
. - Throws:
IllegalStateException
- if the session factory is not initialized.
-
getSessionBuilderConfigurer
Returns theSessionBuilderConfigurer
.- Returns:
- the
SessionBuilderConfigurer
; may be null. - Since:
- 1.5
-
getDriverConfigLoaderBuilderConfigurer
Returns theDriverConfigLoaderBuilderConfigurer
. The configuration gets applied after applyingSystem Properties
config overrides and beforethe driver config file
.- Returns:
- the
DriverConfigLoaderBuilderConfigurer
; may be null. - Since:
- 3.1.2
-
getDriverConfigurationResource
Returns theResource
pointing to a driver configuration file. The configuration file is applied after applyingSystem Properties
and the configuration built by this configuration class.- Returns:
- the
Resource
; may be null if none provided. - Since:
- 3.1.2
- See Also:
-
getStartupScripts
Deprecated.since 3.0; Declare aSessionFactoryInitializer
bean instead.Returns the list of CQL scripts to be run on startup afterKeyspace creations
and after initialization of the System Keyspace. return super.getSessionBuilderConfigurer();- Returns:
- the list of CQL scripts to be run on startup; may be
empty
but never null.
-
getShutdownScripts
Deprecated.since 3.0; Declare aSessionFactoryInitializer
bean instead.Returns the list of CQL scripts to be run on shutdown afterKeyspace drops
and right before shutdown of theSystem
Keyspace.- Returns:
- the list of CQL scripts to be run on shutdown; may be
empty
but never null.
-
cassandraSession
Creates aCqlSessionFactoryBean
that provides a CassandraCqlSession
.- Returns:
- the
CqlSessionFactoryBean
. - See Also:
-
cqlTemplate
Creates aCqlTemplate
configured withgetRequiredSessionFactory()
.- Returns:
- the
CqlTemplate
. - See Also:
-
getSessionName()
instead.