KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hsqldb > Trigger


1 /* Copyright (c) 2001-2005, The HSQL Development Group
2  * All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * Redistributions of source code must retain the above copyright notice, this
8  * list of conditions and the following disclaimer.
9  *
10  * Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  *
14  * Neither the name of the HSQL Development Group nor the names of its
15  * contributors may be used to endorse or promote products derived from this
16  * software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG,
22  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */

30
31
32 package org.hsqldb;
33
34 // fredt@users 20030727 - signature altered to support update triggers
35
/*
36
37 Contents of row1[] and row2[] in each type of trigger.
38
39 BEFORE INSERT
40  - row1[] contains single String object = "Statement-level".
41
42 AFTER INSERT
43  - row1[] contains single String object = "Statement-level".
44
45 BEFORE UPDATE
46  - row1[] contains single String object = "Statement-level".
47
48 AFTER UPDATE
49  - row1[] contains single String object = "Statement-level".
50
51 BEFORE DELETE
52  - row1[] contains single String object = "Statement-level".
53
54 AFTER DELETE
55  - row1[] contains single String object = "Statement-level".
56
57 BEFORE INSERT FOR EACH ROW
58  - row2[] contains data about to be inserted and this can
59 be modified within the trigger such that modified data gets written to the
60 database.
61
62 AFTER INSERT FOR EACH ROW
63  - row2[] contains data just inserted into the table.
64
65 BEFORE UPDATE FOR EACH ROW
66  - row1[] contains currently stored data and not the data that is about to be
67 updated.
68
69  - row2[] contains the data that is about to be updated.
70
71 AFTER UPDATE FOR EACH ROW
72  - row1[] contains old stored data.
73  - row2[] contains the new data.
74
75 BEFORE DELETE FOR EACH ROW
76  - row1[] contains row data about to be deleted.
77
78 AFTER DELETE FOR EACH ROW
79  - row1[] contains row data that has been deleted.
80
81 List compiled by Andrew Knight (quozzbat@users)
82 */

83
84 /**
85  * The interface an HSQLDB TRIGGER must implement. The user-supplied class that
86  * implements this must have a default constructor.
87  *
88  * @author Peter Hudson
89  * @version 1.7.2
90  * @since 1.7.0
91  */

92 public interface Trigger {
93
94     // indexes into the triggers list
95
int INSERT_AFTER = 0;
96     int DELETE_AFTER = 1;
97     int UPDATE_AFTER = 2;
98     int INSERT_BEFORE = INSERT_AFTER + TriggerDef.NUM_TRIGGER_OPS;
99     int DELETE_BEFORE = DELETE_AFTER + TriggerDef.NUM_TRIGGER_OPS;
100     int UPDATE_BEFORE = UPDATE_AFTER + TriggerDef.NUM_TRIGGER_OPS;
101     int INSERT_AFTER_ROW = INSERT_AFTER + 2 * TriggerDef.NUM_TRIGGER_OPS;
102     int DELETE_AFTER_ROW = DELETE_AFTER + 2 * TriggerDef.NUM_TRIGGER_OPS;
103     int UPDATE_AFTER_ROW = UPDATE_AFTER + 2 * TriggerDef.NUM_TRIGGER_OPS;
104     int INSERT_BEFORE_ROW = INSERT_BEFORE + 2 * TriggerDef.NUM_TRIGGER_OPS;
105     int DELETE_BEFORE_ROW = DELETE_BEFORE + 2 * TriggerDef.NUM_TRIGGER_OPS;
106     int UPDATE_BEFORE_ROW = UPDATE_BEFORE + 2 * TriggerDef.NUM_TRIGGER_OPS;
107
108     /**
109      * The method invoked upon each triggered action. <p>
110      *
111      * When UPDATE triggers are fired, oldRow contains the
112      * existing values of the table row and newRow contains the
113      * new values.<p>
114      *
115      * For INSERT triggers, oldRow is null and newRow contains the
116      * table row to be inserted.
117      *
118      * For DELETE triggers, newRow is null and oldRow contains the
119      * table row to be deleted.
120      *
121      * type contains the integer index id for trigger type, e.g.
122      * TriggerDef.INSERT_AFTER (fredt@users)
123      *
124      * @param trigName the name of the trigger
125      * @param tabName the name of the table upon which the
126      * triggered action is occuring
127      * @param oldRow the old row
128      * @param newRow the new row
129      */

130     void fire(int type, String JavaDoc trigName, String JavaDoc tabName, Object JavaDoc[] oldRow,
131               Object JavaDoc[] newRow);
132 }
133
Popular Tags