File D:\maven-qcr-plugin-testsunitaires\qcr4java\h2-1.3.170-sources\target\site\qc\lecode\api\DatabaseEventListener.java.html

1 /*
2 * Copyright 2004-2011 H2 Group. Multiple-Licensed under the H2 License,
3 * Version 1.0, and under the Eclipse Public License, Version 1.0
4 * (http://h2database.com/html/license.html).
5 * Initial Developer: H2 Group
6 */
7 package org.h2.api;
8
9 import java.sql.SQLException;
10 import java.util.EventListener;
11
12 /**
13 * A class that implements this interface can get notified about exceptions
14 * and other events. A database event listener can be registered when
15 * connecting to a database. Example database URL:
16 * jdbc:h2:test;DATABASE_EVENT_LISTENER='com.acme.DbListener'
17 */
18 public interface DatabaseEventListener extends EventListener {
19
20 /**
21 * This state is used when scanning the database file.
22 */
23 int STATE_SCAN_FILE = 0;
24
25 /**
26 * This state is used when re-creating an index.
27 */
28 int STATE_CREATE_INDEX = 1;
29
30 /**
31 * This state is used when re-applying the transaction log or rolling back
32 * uncommitted transactions.
33 */
34 int STATE_RECOVER = 2;
35
36 /**
37 * This state is used during the BACKUP command.
38 */
39 int STATE_BACKUP_FILE = 3;
40
41 /**
42 * This state is used after re-connecting to a database (if auto-reconnect
43 * is enabled).
44 */
45 int STATE_RECONNECTED = 4;
46
47 /**
48 * This state is used when a query starts.
49 */
50 int STATE_STATEMENT_START = 5;
51
52 /**
53 * This state is used when a query ends.
54 */
55 int STATE_STATEMENT_END = 6;
56
57 /**
58 * This state is used for periodic notification during long-running queries.
59 */
60 int STATE_STATEMENT_PROGRESS = 7;
61
62 /**
63 * This method is called just after creating the object.
64 * This is done when opening the database if the listener is specified
65 * in the database URL, but may be later if the listener is set at
66 * runtime with the SET SQL statement.
67 *
68 * @param url - the database URL
69 */
70 void init(String url);
71
72 /**
73 * This method is called after the database has been opened.
74 * It is save to connect to the database and execute statements at this point.
75 */
76 void opened();
77
78 /**
79 * This method is called if an exception occurred.
80 *
81 * @param e the exception
82 * @param sql the SQL statement
83 */
84 void exceptionThrown(SQLException e, String sql);
85
86 /**
87 * This method is called for long running events, such as recovering,
88 * scanning a file or building an index.
89 * <p>
90 * More states might be added in future versions, therefore implementations
91 * should silently ignore states that they don't understand.
92 * </p>
93 *
94 * @param state the state
95 * @param name the object name
96 * @param x the current position
97 * @param max the highest possible value (might be 0)
98 */
99 void setProgress(int state, String name, int x, int max);
100
101 /**
102 * This method is called before the database is closed normally. It is save
103 * to connect to the database and execute statements at this point, however
104 * the connection must be closed before the method returns.
105 */
106 void closingDatabase();
107
108 }
109