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 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

      public void setConverter(CassandraConverter converter)
      Set the CassandraConverter to use. Schema actions will derive table and user type information from the CassandraMappingContext inside converter.
      Parameters:
      converter - must not be null.
    • setKeyspaceCleaner

      public void setKeyspaceCleaner(@Nullable 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.
      Parameters:
      keyspaceCleaner - the KeyspacePopulator to use during cleanup.
      See Also:
    • setKeyspacePopulator

      public void setKeyspacePopulator(@Nullable KeyspacePopulator keyspacePopulator)
      Set the KeyspacePopulator to execute during the bean initialization phase. The KeyspacePopulator is invoked before creating the schema.
      Parameters:
      keyspacePopulator - the KeyspacePopulator to use during initialization.
      See Also:
    • setSchemaAction

      public void setSchemaAction(SchemaAction schemaAction)
      Set the SchemaAction.
      Parameters:
      schemaAction - must not be null.
    • setSuspendLifecycleSchemaRefresh

      public void setSuspendLifecycleSchemaRefresh(boolean suspendLifecycleSchemaRefresh)
      Set whether to suspend schema refresh settings during 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.

      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 the CqlSession to use.
      Parameters:
      session - must not be null.
    • afterPropertiesSet

      public void afterPropertiesSet() throws Exception
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
      Overrides:
      afterPropertiesSet in class org.springframework.beans.factory.config.AbstractFactoryBean<SessionFactory>
      Throws:
      Exception
    • createInstance

      protected SessionFactory createInstance()
      Specified by:
      createInstance in class org.springframework.beans.factory.config.AbstractFactoryBean<SessionFactory>
    • destroy

      public void destroy() throws Exception
      Specified by:
      destroy in interface org.springframework.beans.factory.DisposableBean
      Overrides:
      destroy in class org.springframework.beans.factory.config.AbstractFactoryBean<SessionFactory>
      Throws:
      Exception
    • getObjectType

      @Nullable public Class<?> getObjectType()
      Specified by:
      getObjectType in interface org.springframework.beans.factory.FactoryBean<SessionFactory>
      Specified by:
      getObjectType in class org.springframework.beans.factory.config.AbstractFactoryBean<SessionFactory>
    • performSchemaAction

      protected void performSchemaAction()
      Perform the configured SchemaAction using CassandraMappingContext 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 by CassandraMappingContext).
      ifNotExists - true to perform creations fail-safe by adding IF NOT EXISTS to each creation statement.