Class AbstractSessionConfiguration

java.lang.Object
org.springframework.data.cassandra.config.AbstractSessionConfiguration
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanFactoryAware
Direct Known Subclasses:
AbstractCassandraConfiguration, AbstractCqlTemplateConfiguration

@Configuration public abstract class AbstractSessionConfiguration extends Object implements org.springframework.beans.factory.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:
  • BeanFactoryAware
  • Configuration
  • Constructor Details

    • AbstractSessionConfiguration

      public AbstractSessionConfiguration()
  • Method Details

    • setBeanFactory

      public void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory) throws org.springframework.beans.BeansException
      Configures a reference to the BeanFactory.
      Specified by:
      setBeanFactory in interface org.springframework.beans.factory.BeanFactoryAware
      Parameters:
      beanFactory - reference to the BeanFactory.
      Throws:
      org.springframework.beans.BeansException - if the BeanFactory could not be initialized.
      See Also:
      • BeanFactory
    • getBeanFactory

      protected org.springframework.beans.factory.BeanFactory getBeanFactory()
      Returns the configured reference to the BeanFactory.
      Returns:
      the configured reference to the BeanFactory.
      Throws:
      IllegalStateException - if the BeanFactory reference was not configured.
      See Also:
      • BeanFactory
    • requireBeanOfType

      protected <T> T requireBeanOfType(@NonNull Class<T> beanType)
      Gets a required bean of the provided type from the BeanFactory.
      Type Parameters:
      T - parameterized class type of the bean.
      Parameters:
      beanType - type of the bean.
      Returns:
      a required bean of the given type from the BeanFactory.
      See Also:
    • getClusterName

      @Nullable @Deprecated protected String getClusterName()
      Deprecated.
      since 3.0, use getSessionName() instead.
      Returns the name of the cluster.
      Returns:
      the cluster name; may be null.
      Since:
      1.5
    • getKeyspaceName

      protected abstract String getKeyspaceName()
      Return the name of the keyspace to connect to.
      Returns:
      must not be null.
    • getLocalDataCenter

      @Nullable protected String getLocalDataCenter()
      Returns the local data center name used for LoadBalancingPolicy, defaulting to datacenter1. 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

      @Nullable protected String getSessionName()
      Returns the session name.
      Returns:
      the session name; may be null.
      Since:
      3.0
    • getCompressionType

      @Nullable protected CompressionType getCompressionType()
      Returns the CompressionType.
      Returns:
      the CompressionType, may be null.
    • getContactPoints

      protected String getContactPoints()
      Returns the Cassandra contact points. Defaults to localhost
      Returns:
      the Cassandra contact points
      See Also:
    • getPort

      protected int getPort()
      Returns the Cassandra port. Defaults to 9042.
      Returns:
      the Cassandra port
      See Also:
    • getKeyspaceCreations

      protected List<CreateKeyspaceSpecification> 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

      protected List<DropKeyspaceSpecification> 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 initialized CqlSession instance.
      Returns:
      the CqlSession.
      Throws:
      IllegalStateException - if the session factory is not initialized.
    • getRequiredSessionFactory

      protected SessionFactory getRequiredSessionFactory()
      Returns the initialized CqlSession instance.
      Returns:
      the CqlSession.
      Throws:
      IllegalStateException - if the session factory is not initialized.
    • getSessionBuilderConfigurer

      @Nullable protected SessionBuilderConfigurer getSessionBuilderConfigurer()
      Returns:
      the SessionBuilderConfigurer; may be null.
      Since:
      1.5
    • getDriverConfigLoaderBuilderConfigurer

      @Nullable protected DriverConfigLoaderBuilderConfigurer getDriverConfigLoaderBuilderConfigurer()
      Returns the DriverConfigLoaderBuilderConfigurer. The configuration gets applied after applying System Properties config overrides and before the driver config file.
      Returns:
      the DriverConfigLoaderBuilderConfigurer; may be null.
      Since:
      3.1.2
    • getDriverConfigurationResource

      @Nullable protected org.springframework.core.io.Resource getDriverConfigurationResource()
      Returns the Resource pointing to a driver configuration file. The configuration file is applied after applying System 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 protected List<String> getStartupScripts()
      Deprecated.
      since 3.0; Declare a SessionFactoryInitializer bean instead.
      Returns the list of CQL scripts to be run on startup after Keyspace 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 protected List<String> getShutdownScripts()
      Deprecated.
      since 3.0; Declare a SessionFactoryInitializer bean instead.
      Returns the list of CQL scripts to be run on shutdown after Keyspace drops and right before shutdown of the System Keyspace.
      Returns:
      the list of CQL scripts to be run on shutdown; may be empty but never null.
    • cassandraSession

      @Bean public CqlSessionFactoryBean cassandraSession()
      Creates a CqlSessionFactoryBean that provides a Cassandra CqlSession.
      Returns:
      the CqlSessionFactoryBean.
      See Also:
    • cqlTemplate

      @Bean public CqlTemplate cqlTemplate()
      Creates a CqlTemplate configured with getRequiredSessionFactory().
      Returns:
      the CqlTemplate.
      See Also: