File D:\maven-qcr-plugin-testsunitaires\qcr4java\h2-1.3.170-sources\target\site\qc\lecode\api\Trigger.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.Connection;
10 import java.sql.SQLException;
11
12 /**
13 * A class that implements this interface can be used as a trigger.
14 */
15 public interface Trigger {
16
17 /**
18 * The trigger is called for INSERT statements.
19 */
20 int INSERT = 1;
21
22 /**
23 * The trigger is called for UPDATE statements.
24 */
25 int UPDATE = 2;
26
27 /**
28 * The trigger is called for DELETE statements.
29 */
30 int DELETE = 4;
31
32 /**
33 * The trigger is called for SELECT statements.
34 */
35 int SELECT = 8;
36
37 /**
38 * This method is called by the database engine once when initializing the
39 * trigger. It is called when the trigger is created, as well as when the
40 * database is opened. The type of operation is a bit field with the
41 * appropriate flags set. As an example, if the trigger is of type INSERT
42 * and UPDATE, then the parameter type is set to (INSERT | UPDATE).
43 *
44 * @param conn a connection to the database (a system connection)
45 * @param schemaName the name of the schema
46 * @param triggerName the name of the trigger used in the CREATE TRIGGER
47 * statement
48 * @param tableName the name of the table
49 * @param before whether the fire method is called before or after the
50 * operation is performed
51 * @param type the operation type: INSERT, UPDATE, DELETE, SELECT, or a
52 * combination (this parameter is a bit field)
53 */
54 void init(Connection conn, String schemaName, String triggerName, String tableName, boolean before, int type)
55 throws SQLException;
56
57 /**
58 * This method is called for each triggered action. The method is called
59 * immediately when the operation occurred (before it is committed). A
60 * transaction rollback will also rollback the operations that were done
61 * within the trigger, if the operations occurred within the same database.
62 * If the trigger changes state outside the database, a rollback trigger
63 * should be used.
64 * <p>
65 * The row arrays contain all columns of the table, in the same order
66 * as defined in the table.
67 * </p>
68 *
69 * @param conn a connection to the database
70 * @param oldRow the old row, or null if no old row is available (for
71 * INSERT)
72 * @param newRow the new row, or null if no new row is available (for
73 * DELETE)
74 * @throws SQLException if the operation must be undone
75 */
76 void fire(Connection conn, Object[] oldRow, Object[] newRow) throws SQLException;
77
78 /**
79 * This method is called when the database is closed.
80 * If the method throws an exception, it will be logged, but
81 * closing the database will continue.
82 *
83 * @throws SQLException
84 */
85 void close() throws SQLException;
86
87 /**
88 * This method is called when the trigger is dropped.
89 *
90 * @throws SQLException
91 */
92 void remove() throws SQLException;
93
94 }
95