Package org.javalite.async
Class DBCommandListener
java.lang.Object
org.javalite.async.CommandListener
org.javalite.async.DBCommandListener
- All Implemented Interfaces:
javax.jms.MessageListener
Standard command listener to process commands that require a database access.
ActiveJDBC class
Base
will be used to open a connection.
This class will open a new connection, start a new transaction and will execute the command.
After that, the transaction will be committed. In case execution of a command fails,
the transaction will be rolled back and command and exception wil be passed to onException(Command, Exception)
method, where a subclass can process them further. The connection will be closed regardless of outcome.
- Author:
- Igor Polevoy on 2/14/16.
-
Constructor Summary
ConstructorDescriptionUse this constructor to open a connection using a set of properties from "database.properties" file according to current ACTIVE_ENV environment (development, production, etc.).DBCommandListener(String jndiConnection)
JNDI string to open a connection from a pool. -
Method Summary
Modifier and TypeMethodDescription<T extends Command>
voidonCommand(T command)
protected void
onException(Command command, Exception exception)
Override in subclasses to handle exceptions.Methods inherited from class org.javalite.async.CommandListener
onMessage, parseCommand
-
Constructor Details
-
DBCommandListener
JNDI string to open a connection from a pool. Example: "java:comp/env/jdbc/yourdb".- Parameters:
jndiConnection
- JDBC connection string.
-
DBCommandListener
public DBCommandListener()Use this constructor to open a connection using a set of properties from "database.properties" file according to current ACTIVE_ENV environment (development, production, etc.).
-
-
Method Details
-
onCommand
- Overrides:
onCommand
in classCommandListener
- Parameters:
command
- command to execute.
-
onException
Override in subclasses to handle exceptions. This implementation does nothing.- Parameters:
command
- command that was unsuccessfully executedexception
- exception caught during command execution
-