public class SessionFactoryFactoryBean extends AbstractFactoryBean<SessionFactory>
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.SessionFactoryInitializer| Modifier and Type | Field and Description |
|---|---|
protected static boolean |
DEFAULT_CREATE_IF_NOT_EXISTS |
protected static boolean |
DEFAULT_DROP_TABLES |
protected static boolean |
DEFAULT_DROP_UNUSED_TABLES |
loggerOBJECT_TYPE_ATTRIBUTE| Constructor and Description |
|---|
SessionFactoryFactoryBean() |
| Modifier and Type | Method and Description |
|---|---|
void |
afterPropertiesSet() |
protected SessionFactory |
createInstance() |
protected void |
createTables(boolean drop,
boolean dropUnused,
boolean ifNotExists)
Perform schema actions.
|
void |
destroy() |
Class<?> |
getObjectType() |
protected void |
performSchemaAction()
Perform the configured
SchemaAction using CassandraMappingContext metadata. |
void |
setConverter(CassandraConverter converter)
Set the
CassandraConverter to use. |
void |
setKeyspaceCleaner(KeyspacePopulator keyspaceCleaner)
Set the
KeyspacePopulator 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 the
KeyspacePopulator to execute during the bean initialization phase. |
void |
setSchemaAction(SchemaAction schemaAction)
Set the
SchemaAction. |
void |
setSession(com.datastax.oss.driver.api.core.CqlSession session)
Set the
CqlSession to use. |
void |
setSuspendLifecycleSchemaRefresh(boolean suspendLifecycleSchemaRefresh)
Set whether to suspend schema refresh settings during
afterPropertiesSet() and destroy()
lifecycle callbacks. |
destroyInstance, getBeanFactory, getBeanTypeConverter, getEarlySingletonInterfaces, getObject, isSingleton, setBeanClassLoader, setBeanFactory, setSingletonprotected static final boolean DEFAULT_CREATE_IF_NOT_EXISTS
protected static final boolean DEFAULT_DROP_TABLES
protected static final boolean DEFAULT_DROP_UNUSED_TABLES
public void setConverter(CassandraConverter converter)
CassandraConverter to use. Schema actions will derive table and user type information from the
CassandraMappingContext inside converter.converter - must not be null.public void setKeyspaceCleaner(@Nullable KeyspacePopulator keyspaceCleaner)
KeyspacePopulator to execute during the bean destruction phase, cleaning up the keyspace and
leaving it in a known state for others.keyspaceCleaner - the KeyspacePopulator to use during cleanup.setKeyspacePopulator(org.springframework.data.cassandra.core.cql.session.init.KeyspacePopulator)public void setKeyspacePopulator(@Nullable KeyspacePopulator keyspacePopulator)
KeyspacePopulator to execute during the bean initialization phase. The
KeyspacePopulator is invoked before creating
the schema.keyspacePopulator - the KeyspacePopulator to use during initialization.setKeyspaceCleaner(org.springframework.data.cassandra.core.cql.session.init.KeyspacePopulator)public void setSchemaAction(SchemaAction schemaAction)
SchemaAction.schemaAction - must not be null.public void setSuspendLifecycleSchemaRefresh(boolean suspendLifecycleSchemaRefresh)
afterPropertiesSet() and destroy()
lifecycle callbacks. Disabled by default to use schema metadata settings of the session configuration. When enabled
(set to true), 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.
suspendLifecycleSchemaRefresh - true to suspend the schema refresh during lifecycle callbacks;
false otherwise to retain the session schema refresh configuration.public void setSession(com.datastax.oss.driver.api.core.CqlSession session)
CqlSession to use.session - must not be null.public void afterPropertiesSet()
throws Exception
afterPropertiesSet in interface InitializingBeanafterPropertiesSet in class AbstractFactoryBean<SessionFactory>Exceptionprotected SessionFactory createInstance()
createInstance in class AbstractFactoryBean<SessionFactory>public void destroy()
throws Exception
destroy in interface DisposableBeandestroy in class AbstractFactoryBean<SessionFactory>Exception@Nullable public Class<?> getObjectType()
getObjectType in interface FactoryBean<SessionFactory>getObjectType in class AbstractFactoryBean<SessionFactory>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.Copyright © 2011–2023 Pivotal Software, Inc.. All rights reserved.