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
    void deleteAll()  
    io.changock.driver.core.lock.LockEntry findByKey​(java.lang.String lockKey)
    Retrieves a lock by key
    protected org.bson.conversions.Bson getAcquireLockQuery​(java.lang.String lockKey, java.lang.String owner, boolean onlyIfSameOwner)  
    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.
    protected void insertUpdate​(io.changock.driver.core.lock.LockEntry newLock, boolean onlyIfSameOwner)  
    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
    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

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface io.changock.utils.Process

    initialize

    Methods inherited from interface io.changock.driver.core.common.Repository

    mapFieldInstances, toEntity
  • 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:
      insertUpdate in interface io.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:
      updateIfSameOwner in interface io.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:
      findByKey in interface io.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:
      removeByKeyAndOwner in interface io.changock.driver.core.lock.LockRepository<org.bson.Document>
      Parameters:
      lockKey - lock key
      owner - lock owner
    • deleteAll

      public void deleteAll()
      Specified by:
      deleteAll in interface io.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)