Class PoolKit

java.lang.Object
overit.geocall.da.PoolKit
All Implemented Interfaces:
AutoCloseable

public class PoolKit extends Object implements AutoCloseable
This class is used as a reference to get new connections from the pool. This class allows you to:
  • the connection will be extracted on demand
  • allows you to obtain connections from different pools
  • allows you to perform one or more operations in the transaction (which was previously a prerogative of the tasks)
  • commit or rollback messages automatically and manually
To get a Poolkit reference you can use the start(DAFunction) or start(PooledConnection, DAFunction) methods.

  PoolKit.start(pk -> {
   // custom logic like
   // dao.query(new CommandContext(DAO.SEARCH), pk);
  });
 
  • Field Details

  • Method Details

    • start

      public static <R> R start(DAFunction<R> function) throws DAValidateException, DAException
      Creates a new poolkit and pass it as argument to the function parameter. After the function has been called, the PoolKit will be closed and all the connection used will be released.
      Type Parameters:
      R - the function return type
      Parameters:
      function - the function that will be called once the PoolKit has been created
      Returns:
      the function result
      Throws:
      DAException - in case of database error
      DAValidateException - in case of database validation error
    • start

      public static <R> R start(PooledConnection pc, DAFunction<R> function) throws DAValidateException, DAException
      Creates a new poolkit starting by a PooledConnection and pass it as argument to the function parameter. After the function has been called, the PoolKit will be closed and all the connection used will be released.
      Type Parameters:
      R - the function return type
      Parameters:
      pc - the connection that is automatically added to the poolkit
      function - the function that will be called once the PoolKit has been created
      Returns:
      the function result
      Throws:
      DAException - in case of database error
      DAValidateException - in case of database validation error
    • mainTransaction

      public PoolKit.Transaction mainTransaction()
      Create a new transaction intended as the principal one
      Returns:
      the instance of the principal transaction
    • transaction

      public PoolKit.Transaction transaction(String name)
      Create a new named transaction.
      Parameters:
      name - the name of the transaction
      Returns:
      the instance of the transaction
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
    • collectEvent

      public void collectEvent(GenericEvent<?> event)
      Collects an event and adds it to the message queue.
      Parameters:
      event - The event to be collected. This should be an instance of GenericEvent.
    • commitMessages

      public void commitMessages()
      Commits all collected messages by sending them and then clearing the message queue.
    • rollbackMessages

      public void rollbackMessages()
      Rolls back the message queue by clearing all collected messages without sending them.