Package overit.geocall.da
Class PoolKit
java.lang.Object
overit.geocall.da.PoolKit
- All Implemented Interfaces:
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
start(DAFunction) or start(PooledConnection, DAFunction)
methods.
PoolKit.start(pk -> {
// custom logic like
// dao.query(new CommandContext(DAO.SEARCH), pk);
});
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()voidcollectEvent(GenericEvent<?> event) Collects an event and adds it to the message queue.voidCommits all collected messages by sending them and then clearing the message queue.Create a new transaction intended as the principal onevoidRolls back the message queue by clearing all collected messages without sending them.static <R> Rstart(DAFunction<R> function) Creates a new poolkit and pass it as argument to the function parameter.static <R> Rstart(PooledConnection pc, DAFunction<R> function) Creates a new poolkit starting by aPooledConnectionand pass it as argument to the function parameter.transaction(String name) Create a new named transaction.
-
Field Details
-
usedConnections
-
completed
protected boolean completed
-
-
Method Details
-
start
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 errorDAValidateException- 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 aPooledConnectionand 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 poolkitfunction- the function that will be called once the PoolKit has been created- Returns:
- the function result
- Throws:
DAException- in case of database errorDAValidateException- in case of database validation error
-
mainTransaction
Create a new transaction intended as the principal one- Returns:
- the instance of the principal transaction
-
transaction
Create a new named transaction.- Parameters:
name- the name of the transaction- Returns:
- the instance of the transaction
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-
collectEvent
Collects an event and adds it to the message queue.- Parameters:
event- The event to be collected. This should be an instance ofGenericEvent.
-
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.
-