Class DefaultLockRepository
java.lang.Object
org.springframework.integration.jdbc.lock.DefaultLockRepository
- All Implemented Interfaces:
- Closeable,- AutoCloseable,- Aware,- InitializingBean,- SmartInitializingSingleton,- ApplicationContextAware,- Lifecycle,- Phased,- SmartLifecycle,- LockRepository
public class DefaultLockRepository
extends Object
implements LockRepository, InitializingBean, ApplicationContextAware, SmartInitializingSingleton, SmartLifecycle
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.
 
 This class implements SmartLifecycle and calls
 SELECT COUNT(REGION) FROM %sLOCK 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:
- 4.3
- Author:
- Dave Syer, Artem Bilan, Glenn Renfro, Gary Russell, Alexandre Strubel, Ruslan Stelmachenko
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final StringDefault value for the table prefix property.static final DurationDefault value for the time-to-live property.Fields inherited from interface org.springframework.context.SmartLifecycleDEFAULT_PHASE
- 
Constructor SummaryConstructorsConstructorDescriptionDefaultLockRepository(DataSource dataSource) Constructor that initializes the client id that will be associated for all the locks persisted by the store instance to a randomUUID.DefaultLockRepository(DataSource dataSource, 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 SummaryModifier and TypeMethodDescriptionbooleanAcquire a lock for a key.voidvoidvoidclose()voidRemove a lock from this repository.voidRemove all the expired locks.Return the current insert query.Return the current renew query.Return the current update query.booleanisAcquired(String lock) Check if a lock is held by this repository.booleanbooleanbooleanRenew the lease for a lock.voidsetApplicationContext(ApplicationContext applicationContext) voidsetCheckDatabaseOnStart(boolean checkDatabaseOnStart) The flag to perform a database check query on start or not.voidsetInsertQuery(String insertQuery) Set a customINSERTquery for a lock record.voidSpecify the prefix for target database table used from queries.voidA unique grouping identifier for all locks persisted with this store.voidsetRenewQuery(String renewQuery) Set a customINSERTquery for a lock record.voidsetTimeToLive(int timeToLive) Specify the time (in milliseconds) to expire deadlocks.voidsetTransactionManager(PlatformTransactionManager transactionManager) Set aPlatformTransactionManagerfor operations.voidsetUpdateQuery(String updateQuery) Set a customUPDATEquery for a lock record.voidstart()voidstop()Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.context.SmartLifecyclegetPhase, stop
- 
Field Details- 
DEFAULT_TABLE_PREFIXDefault value for the table prefix property.- See Also:
 
- 
DEFAULT_TTLDefault value for the time-to-live property.
 
- 
- 
Constructor Details- 
DefaultLockRepositoryConstructor that initializes the client id that will be associated for all the locks persisted by the store instance to a randomUUID.- Parameters:
- dataSource- the- DataSourceused to maintain the lock repository.
 
- 
DefaultLockRepositoryConstructor 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- DataSourceused to maintain the lock repository.
- id- the client id to be associated with locks handled by the repository.
- Since:
- 4.3.13
 
 
- 
- 
Method Details- 
setRegionA 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 toDEFAULT.- Parameters:
- region- the region name to set
 
- 
setPrefixSpecify the prefix for target database table used from queries.- Parameters:
- prefix- the prefix to set (default- INT_).
 
- 
setTimeToLivepublic void setTimeToLive(int timeToLive) Specify the time (in milliseconds) to expire deadlocks.- Parameters:
- timeToLive- the time to expire deadlocks.
 
- 
setTransactionManagerSet aPlatformTransactionManagerfor operations. Otherwise, a primaryPlatformTransactionManagerbean is obtained from the application context.- Parameters:
- transactionManager- the- PlatformTransactionManagerto use.
- Since:
- 6.0
 
- 
setApplicationContext- Specified by:
- setApplicationContextin interface- ApplicationContextAware
- Throws:
- BeansException
 
- 
setUpdateQuerySet a customUPDATEquery for a lock record. ThegetUpdateQuery()can be used as a template for customization. The default query is:UPDATE %sLOCK SET CLIENT_ID=?, CREATED_DATE=? WHERE REGION=? AND LOCK_KEY=? AND (CLIENT_ID=? OR CREATED_DATE<?)- Parameters:
- updateQuery- the query to update a lock record.
- Since:
- 6.1
- See Also:
 
- 
getUpdateQueryReturn the current update query. Can be used in a setter as a concatenation of the default query and some extra hint.- Returns:
- the current update query.
- Since:
- 6.1
- See Also:
 
- 
setInsertQuerySet a customINSERTquery for a lock record. ThegetInsertQuery()can be used as a template for customization. The default query isINSERT INTO %sLOCK (REGION, LOCK_KEY, CLIENT_ID, CREATED_DATE) VALUES (?, ?, ?, ?). For example a PostgreSQLON CONFLICT DO NOTHINGhint can be provided like this:lockRepository.setInsertQuery(lockRepository.getInsertQuery() + " ON CONFLICT DO NOTHING");- Parameters:
- insertQuery- the insert query for a lock record.
- Since:
- 6.1
- See Also:
 
- 
getInsertQueryReturn the current insert query. Can be used in a setter as a concatenation of the default query and some extra hint.- Returns:
- the current insert query.
- Since:
- 6.1
- See Also:
 
- 
setRenewQuerySet a customINSERTquery for a lock record. ThegetRenewQuery()can be used as a template for customization. The default query is:UPDATE %sLOCK SET CREATED_DATE=? WHERE REGION=? AND LOCK_KEY=? AND CLIENT_ID=?- Parameters:
- renewQuery- the update query to renew a lock record.
- Since:
- 6.1
- See Also:
 
- 
getRenewQueryReturn the current renew query. Can be used in a setter as a concatenation of a default query and some extra hint.- Returns:
- the current renew query.
- Since:
- 6.1
- See Also:
 
- 
setCheckDatabaseOnStartpublic 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
 
- 
afterPropertiesSetpublic void afterPropertiesSet()- Specified by:
- afterPropertiesSetin interface- InitializingBean
 
- 
afterSingletonsInstantiatedpublic void afterSingletonsInstantiated()- Specified by:
- afterSingletonsInstantiatedin interface- SmartInitializingSingleton
 
- 
isAutoStartuppublic boolean isAutoStartup()- Specified by:
- isAutoStartupin interface- SmartLifecycle
 
- 
start
- 
stop
- 
isRunning
- 
closepublic void close()- Specified by:
- closein interface- AutoCloseable
- Specified by:
- closein interface- Closeable
- Specified by:
- closein interface- LockRepository
 
- 
deleteDescription copied from interface:LockRepositoryRemove a lock from this repository.- Specified by:
- deletein interface- LockRepository
- Parameters:
- lock- the lock to remove.
 
- 
acquireDescription copied from interface:LockRepositoryAcquire a lock for a key.- Specified by:
- acquirein interface- LockRepository
- Parameters:
- lock- the key for lock to acquire.
- Returns:
- acquired or not.
 
- 
isAcquiredDescription copied from interface:LockRepositoryCheck if a lock is held by this repository.- Specified by:
- isAcquiredin interface- LockRepository
- Parameters:
- lock- the lock to check.
- Returns:
- acquired or not.
 
- 
deleteExpiredpublic void deleteExpired()Description copied from interface:LockRepositoryRemove all the expired locks.- Specified by:
- deleteExpiredin interface- LockRepository
 
- 
renewDescription copied from interface:LockRepositoryRenew the lease for a lock.- Specified by:
- renewin interface- LockRepository
- Parameters:
- lock- the lock to renew.
- Returns:
- renewed or not.
 
 
-