Class DefaultLockRepository

java.lang.Object
org.springframework.integration.jdbc.lock.DefaultLockRepository
All Implemented Interfaces:
java.io.Closeable, java.lang.AutoCloseable, org.springframework.beans.factory.InitializingBean, LockRepository

@Repository
@Transactional
public class DefaultLockRepository
extends java.lang.Object
implements LockRepository, org.springframework.beans.factory.InitializingBean
The default implementation of the LockRepository based on the table from the script presented in the org/springframework/integration/jdbc/schema-*.sql.

This repository can't be shared between different JdbcLockRegistry instances. Otherwise it opens a possibility to break Lock contract, where JdbcLockRegistry uses non-shared ReentrantLocks for local synchronizations.

Since:
4.3
  • Field Summary

    Fields 
    Modifier and Type Field Description
    static java.lang.String DEFAULT_TABLE_PREFIX
    Default value for the table prefix property.
    static int DEFAULT_TTL
    Default value for the time-to-live property.
  • Constructor Summary

    Constructors 
    Constructor Description
    DefaultLockRepository​(javax.sql.DataSource dataSource)
    Constructor that initializes the client id that will be associated for all the locks persisted by the store instance to a random UUID.
    DefaultLockRepository​(javax.sql.DataSource dataSource, java.lang.String id)
    Constructor that allows the user to specify a client id that will be associated for all the locks persisted by the store instance.
  • Method Summary

    Modifier and Type Method Description
    boolean acquire​(java.lang.String lock)  
    void afterPropertiesSet()  
    void close()  
    void delete​(java.lang.String lock)  
    void deleteExpired()  
    boolean isAcquired​(java.lang.String lock)  
    boolean renew​(java.lang.String lock)  
    void setPrefix​(java.lang.String prefix)
    Specify the prefix for target data base table used from queries.
    void setRegion​(java.lang.String region)
    A unique grouping identifier for all locks persisted with this store.
    void setTimeToLive​(int timeToLive)
    Specify the time (in milliseconds) to expire dead locks.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • DefaultLockRepository

      @Autowired public DefaultLockRepository​(javax.sql.DataSource dataSource)
      Constructor that initializes the client id that will be associated for all the locks persisted by the store instance to a random UUID.
      Parameters:
      dataSource - the DataSource used to maintain the lock repository.
    • DefaultLockRepository

      public DefaultLockRepository​(javax.sql.DataSource dataSource, java.lang.String id)
      Constructor that allows the user to specify a client id that will be associated for all the locks persisted by the store instance.
      Parameters:
      dataSource - the DataSource used to maintain the lock repository.
      id - the client id to be associated with locks handled by the repository.
      Since:
      4.3.13
  • Method Details

    • setRegion

      public void setRegion​(java.lang.String region)
      A unique grouping identifier for all locks 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
    • setPrefix

      public void setPrefix​(java.lang.String prefix)
      Specify the prefix for target data base table used from queries.
      Parameters:
      prefix - the prefix to set (default INT_).
    • setTimeToLive

      public void setTimeToLive​(int timeToLive)
      Specify the time (in milliseconds) to expire dead locks.
      Parameters:
      timeToLive - the time to expire dead locks.
    • afterPropertiesSet

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

      public void close()
      Specified by:
      close in interface java.lang.AutoCloseable
      Specified by:
      close in interface java.io.Closeable
      Specified by:
      close in interface LockRepository
    • delete

      public void delete​(java.lang.String lock)
      Specified by:
      delete in interface LockRepository
    • acquire

      @Transactional(isolation=SERIALIZABLE) public boolean acquire​(java.lang.String lock)
      Specified by:
      acquire in interface LockRepository
    • isAcquired

      public boolean isAcquired​(java.lang.String lock)
      Specified by:
      isAcquired in interface LockRepository
    • deleteExpired

      public void deleteExpired()
      Specified by:
      deleteExpired in interface LockRepository
    • renew

      public boolean renew​(java.lang.String lock)
      Specified by:
      renew in interface LockRepository