Package org.h2.api
Interface DatabaseEventListener
- All Superinterfaces:
EventListener
A class that implements this interface can get notified about exceptions
and other events. A database event listener can be registered when
connecting to a database. Example database URL:
jdbc:h2:./test;DATABASE_EVENT_LISTENER='com.acme.DbListener'
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
This state is used during the BACKUP command.static final int
This state is used when re-creating an index.static final int
This state is used after re-connecting to a database (if auto-reconnect is enabled).static final int
This state is used when re-applying the transaction log or rolling back uncommitted transactions.static final int
This state is used when scanning the database file.static final int
This state is used when a query ends.static final int
This state is used for periodic notification during long-running queries.static final int
This state is used when a query starts. -
Method Summary
Modifier and TypeMethodDescriptiondefault void
This method is called before the database is closed normally.default void
exceptionThrown
(SQLException e, String sql) This method is called if an exception occurred.default void
This method is called just after creating the object.default void
opened()
This method is called after the database has been opened.default void
setProgress
(int state, String name, long x, long max) This method is called for long running events, such as recovering, scanning a file or building an index.
-
Field Details
-
STATE_SCAN_FILE
static final int STATE_SCAN_FILEThis state is used when scanning the database file.- See Also:
-
STATE_CREATE_INDEX
static final int STATE_CREATE_INDEXThis state is used when re-creating an index.- See Also:
-
STATE_RECOVER
static final int STATE_RECOVERThis state is used when re-applying the transaction log or rolling back uncommitted transactions.- See Also:
-
STATE_BACKUP_FILE
static final int STATE_BACKUP_FILEThis state is used during the BACKUP command.- See Also:
-
STATE_RECONNECTED
static final int STATE_RECONNECTEDThis state is used after re-connecting to a database (if auto-reconnect is enabled).- See Also:
-
STATE_STATEMENT_START
static final int STATE_STATEMENT_STARTThis state is used when a query starts.- See Also:
-
STATE_STATEMENT_END
static final int STATE_STATEMENT_ENDThis state is used when a query ends.- See Also:
-
STATE_STATEMENT_PROGRESS
static final int STATE_STATEMENT_PROGRESSThis state is used for periodic notification during long-running queries.- See Also:
-
-
Method Details
-
init
This method is called just after creating the object. This is done when opening the database if the listener is specified in the database URL, but may be later if the listener is set at runtime with the SET SQL statement.- Parameters:
url
- - the database URL
-
opened
default void opened()This method is called after the database has been opened. It is safe to connect to the database and execute statements at this point. -
exceptionThrown
This method is called if an exception occurred.- Parameters:
e
- the exceptionsql
- the SQL statement
-
setProgress
This method is called for long running events, such as recovering, scanning a file or building an index.More states might be added in future versions, therefore implementations should silently ignore states that they don't understand.
- Parameters:
state
- the statename
- the object namex
- the current positionmax
- the highest possible value or 0 if unknown
-
closingDatabase
default void closingDatabase()This method is called before the database is closed normally. It is safe to connect to the database and execute statements at this point, however the connection must be closed before the method returns.
-