Class SessionFactoryFactoryBean
java.lang.Object
org.springframework.beans.factory.config.AbstractFactoryBean<SessionFactory>
org.springframework.data.cassandra.config.SessionFactoryFactoryBean
- All Implemented Interfaces:
Aware
,BeanClassLoaderAware
,BeanFactoryAware
,DisposableBean
,FactoryBean<SessionFactory>
,InitializingBean
Factory to create and configure a Cassandra
SessionFactory
with support for executing CQL and initializing
the database schema (a.k.a. keyspace). This factory bean invokes a SessionFactoryInitializer
to prepare a
keyspace before applying schema actions
such as creating user-defined types and tables.- Since:
- 3.0
- Author:
- Mark Paluch, Ammar Khaku
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionprotected static final boolean
protected static final boolean
protected static final boolean
Fields inherited from class org.springframework.beans.factory.config.AbstractFactoryBean
logger
Fields inherited from interface org.springframework.beans.factory.FactoryBean
OBJECT_TYPE_ATTRIBUTE
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
protected SessionFactory
protected void
createTables
(boolean drop, boolean dropUnused, boolean ifNotExists) Perform schema actions.void
destroy()
Class<?>
protected void
Perform the configuredSchemaAction
usingCassandraMappingContext
metadata.void
setConverter
(CassandraConverter converter) Set theCassandraConverter
to use.void
setKeyspaceCleaner
(KeyspacePopulator keyspaceCleaner) Set theKeyspacePopulator
to execute during the bean destruction phase, cleaning up the keyspace and leaving it in a known state for others.void
setKeyspacePopulator
(KeyspacePopulator keyspacePopulator) Set theKeyspacePopulator
to execute during the bean initialization phase.void
setSchemaAction
(SchemaAction schemaAction) Set theSchemaAction
.void
setSession
(com.datastax.oss.driver.api.core.CqlSession session) Set theCqlSession
to use.void
setSuspendLifecycleSchemaRefresh
(boolean suspendLifecycleSchemaRefresh) Set whether to suspend schema refresh settings duringafterPropertiesSet()
anddestroy()
lifecycle callbacks.Methods inherited from class org.springframework.beans.factory.config.AbstractFactoryBean
destroyInstance, getBeanFactory, getBeanTypeConverter, getEarlySingletonInterfaces, getObject, isSingleton, setBeanClassLoader, setBeanFactory, setSingleton
-
Field Details
-
DEFAULT_CREATE_IF_NOT_EXISTS
protected static final boolean DEFAULT_CREATE_IF_NOT_EXISTS- See Also:
-
DEFAULT_DROP_TABLES
protected static final boolean DEFAULT_DROP_TABLES- See Also:
-
DEFAULT_DROP_UNUSED_TABLES
protected static final boolean DEFAULT_DROP_UNUSED_TABLES- See Also:
-
-
Constructor Details
-
SessionFactoryFactoryBean
public SessionFactoryFactoryBean()
-
-
Method Details
-
setConverter
Set theCassandraConverter
to use. Schema actions will derive table and user type information from theCassandraMappingContext
insideconverter
.- Parameters:
converter
- must not be null.
-
setKeyspaceCleaner
Set theKeyspacePopulator
to execute during the bean destruction phase, cleaning up the keyspace and leaving it in a known state for others.- Parameters:
keyspaceCleaner
- theKeyspacePopulator
to use during cleanup.- See Also:
-
setKeyspacePopulator
Set theKeyspacePopulator
to execute during the bean initialization phase. TheKeyspacePopulator
is invoked before creatingthe schema
.- Parameters:
keyspacePopulator
- theKeyspacePopulator
to use during initialization.- See Also:
-
setSchemaAction
Set theSchemaAction
.- Parameters:
schemaAction
- must not be null.
-
setSuspendLifecycleSchemaRefresh
public void setSuspendLifecycleSchemaRefresh(boolean suspendLifecycleSchemaRefresh) Set whether to suspend schema refresh settings duringafterPropertiesSet()
anddestroy()
lifecycle callbacks. Disabled by default to use schema metadata settings of the session configuration. When enabled (set totrue
), then schema refresh during lifecycle methods is suspended until finishing schema actions to avoid periodic schema refreshes for each DDL statement.Suspending schema refresh can be useful to delay schema agreement until the entire schema is created. Note that disabling schema refresh may interfere with schema actions.
SchemaAction.RECREATE_DROP_UNUSED
and mapping-based schema creation rely on schema metadata.- Parameters:
suspendLifecycleSchemaRefresh
-true
to suspend the schema refresh during lifecycle callbacks;false
otherwise to retain the session schema refresh configuration.- Since:
- 2.7
-
setSession
public void setSession(com.datastax.oss.driver.api.core.CqlSession session) Set theCqlSession
to use.- Parameters:
session
- must not be null.
-
afterPropertiesSet
- Specified by:
afterPropertiesSet
in interfaceInitializingBean
- Overrides:
afterPropertiesSet
in classAbstractFactoryBean<SessionFactory>
- Throws:
Exception
-
createInstance
- Specified by:
createInstance
in classAbstractFactoryBean<SessionFactory>
-
destroy
- Specified by:
destroy
in interfaceDisposableBean
- Overrides:
destroy
in classAbstractFactoryBean<SessionFactory>
- Throws:
Exception
-
getObjectType
- Specified by:
getObjectType
in interfaceFactoryBean<SessionFactory>
- Specified by:
getObjectType
in classAbstractFactoryBean<SessionFactory>
-
performSchemaAction
protected void performSchemaAction()Perform the configuredSchemaAction
usingCassandraMappingContext
metadata. -
createTables
protected void createTables(boolean drop, boolean dropUnused, boolean ifNotExists) Perform schema actions.- Parameters:
drop
- true to drop types/tables.dropUnused
- true to drop unused types/tables (i.e. types/tables not know to be used byCassandraMappingContext
).ifNotExists
- true to perform creations fail-safe by addingIF NOT EXISTS
to each creation statement.
-