Class MongoSync4LockRepository
java.lang.Object
com.github.cloudyrock.mongock.driver.mongodb.sync.v4.repository.MongoSync4RepositoryBase<io.changock.driver.core.lock.LockEntry>
com.github.cloudyrock.mongock.driver.mongodb.sync.v4.repository.MongoSync4LockRepository
- All Implemented Interfaces:
io.changock.driver.core.common.Repository<io.changock.driver.core.lock.LockEntry,org.bson.Document>,io.changock.driver.core.lock.LockRepository<org.bson.Document>,io.changock.utils.Process
public class MongoSync4LockRepository extends MongoSync4RepositoryBase<io.changock.driver.core.lock.LockEntry> implements io.changock.driver.core.lock.LockRepository<org.bson.Document>
-
Field Summary
Fields inherited from class com.github.cloudyrock.mongock.driver.mongodb.sync.v4.repository.MongoSync4RepositoryBase
collection -
Constructor Summary
Constructors Constructor Description MongoSync4LockRepository(com.mongodb.client.MongoCollection<org.bson.Document> collection, boolean indexCreation) -
Method Summary
Modifier and Type Method Description voiddeleteAll()io.changock.driver.core.lock.LockEntryfindByKey(java.lang.String lockKey)Retrieves a lock by keyprotected org.bson.conversions.BsongetAcquireLockQuery(java.lang.String lockKey, java.lang.String owner, boolean onlyIfSameOwner)voidinsertUpdate(io.changock.driver.core.lock.LockEntry newLock)If there is a lock in the database with the same key, updates it if either is expired or both share the same owner.protected voidinsertUpdate(io.changock.driver.core.lock.LockEntry newLock, boolean onlyIfSameOwner)voidremoveByKeyAndOwner(java.lang.String lockKey, java.lang.String owner)Removes from database all the locks with the same key(only can be one) and ownervoidupdateIfSameOwner(io.changock.driver.core.lock.LockEntry newLock)If there is a lock in the database with the same key and owner, updates it.Otherwise throws a LockPersistenceExceptionMethods inherited from class com.github.cloudyrock.mongock.driver.mongodb.sync.v4.repository.MongoSync4RepositoryBase
cleanResidualUniqueKeys, createRequiredUniqueIndex, doesNeedToBeRemoved, dropIndex, getIndexDocument, initialize, isIdIndex, isIndexFine, isRequiredIndexCreated, isRightIndex, isUniqueIndex, mapFieldInstances
-
Constructor Details
-
MongoSync4LockRepository
public MongoSync4LockRepository(com.mongodb.client.MongoCollection<org.bson.Document> collection, boolean indexCreation)
-
-
Method Details
-
insertUpdate
public void insertUpdate(io.changock.driver.core.lock.LockEntry newLock)If there is a lock in the database with the same key, updates it if either is expired or both share the same owner. If there is no lock with the same key, it's inserted.- Specified by:
insertUpdatein interfaceio.changock.driver.core.lock.LockRepository<org.bson.Document>- Parameters:
newLock- lock to replace the existing one or be inserted.- Throws:
io.changock.driver.core.lock.LockPersistenceException- if there is a lock in database with same key, but is expired and belong to another owner or cannot insert/update the lock for any other reason
-
updateIfSameOwner
public void updateIfSameOwner(io.changock.driver.core.lock.LockEntry newLock)If there is a lock in the database with the same key and owner, updates it.Otherwise throws a LockPersistenceException- Specified by:
updateIfSameOwnerin interfaceio.changock.driver.core.lock.LockRepository<org.bson.Document>- Parameters:
newLock- lock to replace the existing one.- Throws:
io.changock.driver.core.lock.LockPersistenceException- if there is no lock in the database with the same key and owner or cannot update the lock for any other reason
-
findByKey
public io.changock.driver.core.lock.LockEntry findByKey(java.lang.String lockKey)Retrieves a lock by key- Specified by:
findByKeyin interfaceio.changock.driver.core.lock.LockRepository<org.bson.Document>- Parameters:
lockKey- key- Returns:
- LockEntry
-
removeByKeyAndOwner
public void removeByKeyAndOwner(java.lang.String lockKey, java.lang.String owner)Removes from database all the locks with the same key(only can be one) and owner- Specified by:
removeByKeyAndOwnerin interfaceio.changock.driver.core.lock.LockRepository<org.bson.Document>- Parameters:
lockKey- lock keyowner- lock owner
-
deleteAll
public void deleteAll()- Specified by:
deleteAllin interfaceio.changock.driver.core.lock.LockRepository<org.bson.Document>
-
insertUpdate
protected void insertUpdate(io.changock.driver.core.lock.LockEntry newLock, boolean onlyIfSameOwner) -
getAcquireLockQuery
protected org.bson.conversions.Bson getAcquireLockQuery(java.lang.String lockKey, java.lang.String owner, boolean onlyIfSameOwner)
-