01: /*
02: * Copyright 2004-2008 H2 Group. Licensed under the H2 License, Version 1.0
03: * (http://h2database.com/html/license.html).
04: * Initial Developer: H2 Group
05: */
06: package org.h2.api;
07:
08: import java.sql.Connection;
09: import java.sql.SQLException;
10:
11: /**
12: * A class that implements this interface can be used as a trigger.
13: */
14: public interface Trigger {
15:
16: /**
17: * The trigger is called for INSERT statements.
18: */
19: int INSERT = 1;
20:
21: /**
22: * The trigger is called for UPDATE statements.
23: */
24: int UPDATE = 2;
25:
26: /**
27: * The trigger is called for DELETE statements.
28: */
29: int DELETE = 4;
30:
31: /**
32: * This method is called by the database engine once when initializing the
33: * trigger.
34: *
35: * @param conn
36: * a connection to the database
37: * @param schemaName
38: * the name of the schema
39: * @param triggerName
40: * the name of the trigger used in the CREATE TRIGGER statement
41: * @param tableName
42: * the name of the table
43: * @param before
44: * whether the fire method is called before or after the
45: * operation is performed
46: * @param type
47: * the operation type: INSERT, UPDATE, or DELETE
48: */
49: void init(Connection conn, String schemaName, String triggerName,
50: String tableName, boolean before, int type)
51: throws SQLException;
52:
53: /**
54: * This method is called for each triggered action.
55: *
56: * @param conn
57: * a connection to the database
58: * @param oldRow
59: * the old row, or null if no old row is available (for INSERT)
60: * @param newRow
61: * the new row, or null if no new row is available (for DELETE)
62: * @throws SQLException
63: * if the operation must be undone
64: */
65: void fire(Connection conn, Object[] oldRow, Object[] newRow)
66: throws SQLException;
67:
68: }
|