Package tigase.db.util.locker

## Class ConnectionLock

- java.lang.Object
- - tigase.db.util.locker.ConnectionLock

-     public abstract class ConnectionLock
      extends java.lang.Object

- - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `protected boolean` | `isLocked` |
    `protected java.lang.String` | `jdbcConnection` |
    `protected int` | `lockAttemptDelay` |
    `protected int` | `lockAttemptsLimit` |

  - ### Constructor Summary

    Constructors
    Modifier | Constructor | Description
    --- | --- | ---
    `protected` | `ConnectionLock​(java.lang.String db_conn)` |

  - ### Method Summary

    All Methods Static Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `cleanup()` |
    `protected boolean` | `executeQuery​(java.sql.Connection connection, java.lang.String query)` |
    `static java.util.Optional<ConnectionLock>` | `getConnectionLocker​(java.lang.String db_conn)` |
    `boolean` | `isLocked()` |
    `boolean` | `lock()` |
    `protected abstract boolean` | `lockDatabase​(java.sql.Connection connection)` |
    `protected void` | `release​(java.sql.Statement statement, java.sql.ResultSet resultSet)` |
    `boolean` | `unlock()` |
    `protected abstract boolean` | `unlockDatabase​(java.sql.Connection connection)` |

    - ### Methods inherited from class java.lang.Object

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

- - ### Field Detail

    - #### isLocked

          protected boolean isLocked

    - #### jdbcConnection

          protected java.lang.String jdbcConnection

    - #### lockAttemptDelay

          protected int lockAttemptDelay

    - #### lockAttemptsLimit

          protected int lockAttemptsLimit

  - ### Constructor Detail

    - #### ConnectionLock

          protected ConnectionLock​(java.lang.String db_conn)

  - ### Method Detail

    - #### getConnectionLocker

          public static java.util.Optional<ConnectionLock> getConnectionLocker​(java.lang.String db_conn)
                                                                        throws java.lang.IllegalArgumentException

      Throws:
        `java.lang.IllegalArgumentException`

    - #### lock

          public boolean lock()

    - #### unlock

          public boolean unlock()

    - #### cleanup

          public void cleanup()

    - #### isLocked

          public boolean isLocked()

    - #### lockDatabase

          protected abstract boolean lockDatabase​(java.sql.Connection connection)

      Parameters:
        `connection` - `Connection` which should hold the lock
      Returns:
        `true` if the locking was successful or `false` if it wasn't

    - #### release

          protected void release​(java.sql.Statement statement,
                                 java.sql.ResultSet resultSet)

    - #### unlockDatabase

          protected abstract boolean unlockDatabase​(java.sql.Connection connection)

      Parameters:
        `connection` - `Connection` which holds the lock and which should be unlocked
      Returns:
        `true` if the unlocking was successful or `false` if it wasn't and the lock is still hold

    - #### executeQuery

          protected boolean executeQuery​(java.sql.Connection connection,
                                         java.lang.String query)