Class JdbcMetadataStore

java.lang.Object
org.springframework.integration.jdbc.metadata.JdbcMetadataStore
All Implemented Interfaces:
org.springframework.beans.factory.InitializingBean, org.springframework.context.Lifecycle, org.springframework.context.Phased, org.springframework.context.SmartLifecycle, org.springframework.integration.metadata.ConcurrentMetadataStore, org.springframework.integration.metadata.MetadataStore

public class JdbcMetadataStore extends Object implements org.springframework.integration.metadata.ConcurrentMetadataStore, org.springframework.beans.factory.InitializingBean, org.springframework.context.SmartLifecycle
Implementation of ConcurrentMetadataStore using a relational database via JDBC. SQL scripts to create the necessary tables are packaged as org/springframework/integration/jdbc/schema-*.sql, where * is the target database type.

The transaction management is required to use this ConcurrentMetadataStore.

This class implements SmartLifecycle and calls SELECT COUNT(METADATA_KEY) FROM %sMETADATA_STORE query according to the provided prefix on start() to check if required table is present in DB. The application context will fail to start if the table is not present. This check can be disabled via setCheckDatabaseOnStart(boolean).

Since:
5.0
  • Field Details

    • DEFAULT_TABLE_PREFIX

      public static final String DEFAULT_TABLE_PREFIX
      Default value for the table prefix property.
      See Also:
  • Constructor Details

    • JdbcMetadataStore

      public JdbcMetadataStore(DataSource dataSource)
      Instantiate a JdbcMetadataStore using provided dataSource DataSource.
      Parameters:
      dataSource - a DataSource
    • JdbcMetadataStore

      public JdbcMetadataStore(org.springframework.jdbc.core.JdbcOperations jdbcOperations)
      Instantiate a JdbcMetadataStore using provided jdbcOperations JdbcOperations.
      Parameters:
      jdbcOperations - a JdbcOperations
  • Method Details

    • setTablePrefix

      public void setTablePrefix(String tablePrefix)
      Public setter for the table prefix property. This will be prefixed to all the table names before queries are executed. Defaults to DEFAULT_TABLE_PREFIX.
      Parameters:
      tablePrefix - the tablePrefix to set
    • setRegion

      public void setRegion(String region)
      A unique grouping identifier for all messages persisted with this store. Using multiple regions allows the store to be partitioned (if necessary) for different purposes. Defaults to DEFAULT.
      Parameters:
      region - the region name to set
    • setLockHint

      public void setLockHint(String lockHint)
      Specify a row lock hint for the query in the lock-based operations. Defaults to FOR UPDATE. Can be specified as an empty string, if the target RDBMS doesn't support locking on tables from queries. The value depends on the RDBMS vendor, e.g. SQL Server requires WITH (ROWLOCK).
      Parameters:
      lockHint - the RDBMS vendor-specific lock hint.
      Since:
      5.0.7
    • afterPropertiesSet

      public void afterPropertiesSet()
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
    • setCheckDatabaseOnStart

      public void setCheckDatabaseOnStart(boolean checkDatabaseOnStart)
      The flag to perform a database check query on start or not.
      Parameters:
      checkDatabaseOnStart - false to not perform the database check.
      Since:
      6.2
    • isAutoStartup

      public boolean isAutoStartup()
      Specified by:
      isAutoStartup in interface org.springframework.context.SmartLifecycle
    • start

      public void start()
      Specified by:
      start in interface org.springframework.context.Lifecycle
    • stop

      public void stop()
      Specified by:
      stop in interface org.springframework.context.Lifecycle
    • isRunning

      public boolean isRunning()
      Specified by:
      isRunning in interface org.springframework.context.Lifecycle
    • putIfAbsent

      @Transactional public String putIfAbsent(String key, String value)
      Specified by:
      putIfAbsent in interface org.springframework.integration.metadata.ConcurrentMetadataStore
    • replace

      @Transactional public boolean replace(String key, String oldValue, String newValue)
      Specified by:
      replace in interface org.springframework.integration.metadata.ConcurrentMetadataStore
    • put

      @Transactional public void put(String key, String value)
      Specified by:
      put in interface org.springframework.integration.metadata.MetadataStore
    • get

      @Transactional public String get(String key)
      Specified by:
      get in interface org.springframework.integration.metadata.MetadataStore
    • remove

      @Transactional public String remove(String key)
      Specified by:
      remove in interface org.springframework.integration.metadata.MetadataStore