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
  • Constructor Details

    • ConnectionSet

      public ConnectionSet(ConnectionPool setup, boolean autoCommit)
    • ConnectionSet

      protected ConnectionSet(Connection master)
  • Method Details

    • context

      public static ConnectionSet context(Map<String,Object> context)
      Gets a connection set object from a context by KEY
      Parameters:
      context - the context
      Returns:
      the connection set
    • getConnection

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

      public Connection getSlaveConnection()
      Gets slave connection to read-only DB replica
      Returns:
      the slave connection
    • 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:
      the connection
    • commit

      public void commit() throws SQLException
      Commits all the connections
      Throws:
      SQLException - if a commit fails
    • rollback

      public void rollback()
      Rolls back all the connections
    • close

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

      public void toContext(Map<String,Object> context)
      Puts the connection set to a context by KEY
      Parameters:
      context - the context
    • recycle

      @Deprecated public void recycle()
      Deprecated.