Package ru.bgcrm.util.sql

# Class ConnectionSet

java.lang.Object
ru.bgcrm.util.sql.ConnectionSet

All Implemented Interfaces:
  `AutoCloseable`

Direct Known Subclasses:
  `SingleConnectionSet`

public class ConnectionSet extends Object implements AutoCloseable
Set with DB connections, taken from a pool on demand.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final String`
  `KEY`
  `static final int`
  `TYPE_FAKE`
  `static final int`
  `TYPE_MASTER`
  `static final int`
  `TYPE_SLAVE`
  `static final int`
  `TYPE_TRASH`

- ## Constructor Summary

  Constructors
  Modifier
  Constructor
  Description
  `protected`
  `ConnectionSet(Connection master)`
  ``
  `ConnectionSet(ConnectionPool setup, boolean autoCommit)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `close()`
  Closes all the connections
  `void`
  `commit()`
  Commits all the connections
  `Connection`
  `getConnection()`
  Provides master DB connection to the main database.
  `Connection`
  `getSlaveConnection()`
  Gets slave connection to read-only DB replica.
  `Connection`
  `getTrashConnection(String tableName, int defaultType)`
  Gets connection to so-called 'trash' DB, containing non-critical data.
  `void`
  `recycle()`
  Deprecated.
  `void`
  `rollback()`
  Rolls back all the connections

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

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

- ## Field Details

  - ### KEY

    public static final String KEY
    See Also:
      - Constant Field Values

  - ### TYPE_MASTER

    public static final int TYPE_MASTER
    See Also:
      - Constant Field Values

  - ### TYPE_SLAVE

    public static final int TYPE_SLAVE
    See Also:
      - Constant Field Values

  - ### TYPE_TRASH

    public static final int TYPE_TRASH
    See Also:
      - Constant Field Values

  - ### TYPE_FAKE

    public static final int TYPE_FAKE
    See Also:
      - Constant Field Values

- ## Constructor Details

  - ### ConnectionSet

    public ConnectionSet(ConnectionPool setup, boolean autoCommit)

  - ### ConnectionSet

    protected ConnectionSet(Connection master)

- ## Method Details

  - ### getConnection

    public Connection getConnection()
    Provides master DB connection to the main database.
    Returns:

  - ### getSlaveConnection

    public Connection getSlaveConnection()
    Gets slave connection to read-only DB replica.
    Returns:

  - ### getTrashConnection

    public Connection getTrashConnection(String tableName, int defaultType)
    Gets connection to so-called 'trash' DB, containing non-critical data.
    Parameters:
      `tableName` - table name.
      `defaultType` - DB type returned if no trash DB is configured, can be:

           TYPE_SLAVE - slave DB connection;
           TYPE_FAKE -  instance of FakeConnection, does not do anything;
           TYPE_MASTER - master DB connection.

    Returns:

  - ### commit

    public void commit() throws SQLException
    Commits all the connections
    Throws:
      `SQLException`

  - ### rollback

    public void rollback()
    Rolls back all the connections

  - ### close

    public void close()
    Closes all the connections
    Specified by:
      `close` in interface `AutoCloseable`

  - ### recycle

    @Deprecated public void recycle()
    Deprecated.
    Use `close()`