Class SessionFactoryFactoryBean
java.lang.Object
org.springframework.beans.factory.config.AbstractFactoryBean<SessionFactory>
org.springframework.data.cassandra.config.SessionFactoryFactoryBean
- All Implemented Interfaces:
org.springframework.beans.factory.Aware,org.springframework.beans.factory.BeanClassLoaderAware,org.springframework.beans.factory.BeanFactoryAware,org.springframework.beans.factory.DisposableBean,org.springframework.beans.factory.FactoryBean<SessionFactory>,org.springframework.beans.factory.InitializingBean
public class SessionFactoryFactoryBean
extends org.springframework.beans.factory.config.AbstractFactoryBean<SessionFactory>
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
FieldsModifier and TypeFieldDescriptionprotected static final booleanprotected static final booleanprotected static final booleanFields inherited from class org.springframework.beans.factory.config.AbstractFactoryBean
loggerFields inherited from interface org.springframework.beans.factory.FactoryBean
OBJECT_TYPE_ATTRIBUTE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidprotected SessionFactoryprotected voidcreateTables(boolean drop, boolean dropUnused, boolean ifNotExists) Perform schema actions.voiddestroy()Class<?>protected voidPerform the configuredSchemaActionusingCassandraMappingContextmetadata.voidsetConverter(CassandraConverter converter) Set theCassandraConverterto use.voidsetKeyspaceCleaner(KeyspacePopulator keyspaceCleaner) Set theKeyspacePopulatorto execute during the bean destruction phase, cleaning up the keyspace and leaving it in a known state for others.voidsetKeyspacePopulator(KeyspacePopulator keyspacePopulator) Set theKeyspacePopulatorto execute during the bean initialization phase.voidsetSchemaAction(SchemaAction schemaAction) Set theSchemaAction.voidsetSession(com.datastax.oss.driver.api.core.CqlSession session) Set theCqlSessionto use.voidsetSuspendLifecycleSchemaRefresh(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 theCassandraConverterto use. Schema actions will derive table and user type information from theCassandraMappingContextinsideconverter.- Parameters:
converter- must not be null.
-
setKeyspaceCleaner
Set theKeyspacePopulatorto execute during the bean destruction phase, cleaning up the keyspace and leaving it in a known state for others.- Parameters:
keyspaceCleaner- theKeyspacePopulatorto use during cleanup.- See Also:
-
setKeyspacePopulator
Set theKeyspacePopulatorto execute during the bean initialization phase. TheKeyspacePopulatoris invoked before creatingthe schema.- Parameters:
keyspacePopulator- theKeyspacePopulatorto 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_UNUSEDand mapping-based schema creation rely on schema metadata.- Parameters:
suspendLifecycleSchemaRefresh-trueto suspend the schema refresh during lifecycle callbacks;falseotherwise to retain the session schema refresh configuration.- Since:
- 2.7
-
setSession
public void setSession(com.datastax.oss.driver.api.core.CqlSession session) Set theCqlSessionto use.- Parameters:
session- must not be null.
-
afterPropertiesSet
- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean- Overrides:
afterPropertiesSetin classorg.springframework.beans.factory.config.AbstractFactoryBean<SessionFactory>- Throws:
Exception
-
createInstance
- Specified by:
createInstancein classorg.springframework.beans.factory.config.AbstractFactoryBean<SessionFactory>
-
destroy
- Specified by:
destroyin interfaceorg.springframework.beans.factory.DisposableBean- Overrides:
destroyin classorg.springframework.beans.factory.config.AbstractFactoryBean<SessionFactory>- Throws:
Exception
-
getObjectType
- Specified by:
getObjectTypein interfaceorg.springframework.beans.factory.FactoryBean<SessionFactory>- Specified by:
getObjectTypein classorg.springframework.beans.factory.config.AbstractFactoryBean<SessionFactory>
-
performSchemaAction
protected void performSchemaAction()Perform the configuredSchemaActionusingCassandraMappingContextmetadata. -
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 EXISTSto each creation statement.
-