001: /* Copyright (c) 2001-2005, The HSQL Development Group
002: * All rights reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions are met:
006: *
007: * Redistributions of source code must retain the above copyright notice, this
008: * list of conditions and the following disclaimer.
009: *
010: * Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: *
014: * Neither the name of the HSQL Development Group nor the names of its
015: * contributors may be used to endorse or promote products derived from this
016: * software without specific prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
020: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
021: * ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG,
022: * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
023: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
024: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
025: * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
026: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
027: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
028: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029: */
030:
031: package org.hsqldb;
032:
033: // fredt@users 20030727 - signature altered to support update triggers
034: /*
035:
036: Contents of row1[] and row2[] in each type of trigger.
037:
038: BEFORE INSERT
039: - row1[] contains single String object = "Statement-level".
040:
041: AFTER INSERT
042: - row1[] contains single String object = "Statement-level".
043:
044: BEFORE UPDATE
045: - row1[] contains single String object = "Statement-level".
046:
047: AFTER UPDATE
048: - row1[] contains single String object = "Statement-level".
049:
050: BEFORE DELETE
051: - row1[] contains single String object = "Statement-level".
052:
053: AFTER DELETE
054: - row1[] contains single String object = "Statement-level".
055:
056: BEFORE INSERT FOR EACH ROW
057: - row2[] contains data about to be inserted and this can
058: be modified within the trigger such that modified data gets written to the
059: database.
060:
061: AFTER INSERT FOR EACH ROW
062: - row2[] contains data just inserted into the table.
063:
064: BEFORE UPDATE FOR EACH ROW
065: - row1[] contains currently stored data and not the data that is about to be
066: updated.
067:
068: - row2[] contains the data that is about to be updated.
069:
070: AFTER UPDATE FOR EACH ROW
071: - row1[] contains old stored data.
072: - row2[] contains the new data.
073:
074: BEFORE DELETE FOR EACH ROW
075: - row1[] contains row data about to be deleted.
076:
077: AFTER DELETE FOR EACH ROW
078: - row1[] contains row data that has been deleted.
079:
080: List compiled by Andrew Knight (quozzbat@users)
081: */
082:
083: /**
084: * The interface an HSQLDB TRIGGER must implement. The user-supplied class that
085: * implements this must have a default constructor.
086: *
087: * @author Peter Hudson
088: * @version 1.7.2
089: * @since 1.7.0
090: */
091: public interface Trigger {
092:
093: // indexes into the triggers list
094: int INSERT_AFTER = 0;
095: int DELETE_AFTER = 1;
096: int UPDATE_AFTER = 2;
097: int INSERT_BEFORE = INSERT_AFTER + TriggerDef.NUM_TRIGGER_OPS;
098: int DELETE_BEFORE = DELETE_AFTER + TriggerDef.NUM_TRIGGER_OPS;
099: int UPDATE_BEFORE = UPDATE_AFTER + TriggerDef.NUM_TRIGGER_OPS;
100: int INSERT_AFTER_ROW = INSERT_AFTER + 2
101: * TriggerDef.NUM_TRIGGER_OPS;
102: int DELETE_AFTER_ROW = DELETE_AFTER + 2
103: * TriggerDef.NUM_TRIGGER_OPS;
104: int UPDATE_AFTER_ROW = UPDATE_AFTER + 2
105: * TriggerDef.NUM_TRIGGER_OPS;
106: int INSERT_BEFORE_ROW = INSERT_BEFORE + 2
107: * TriggerDef.NUM_TRIGGER_OPS;
108: int DELETE_BEFORE_ROW = DELETE_BEFORE + 2
109: * TriggerDef.NUM_TRIGGER_OPS;
110: int UPDATE_BEFORE_ROW = UPDATE_BEFORE + 2
111: * TriggerDef.NUM_TRIGGER_OPS;
112:
113: /**
114: * The method invoked upon each triggered action. <p>
115: *
116: * When UPDATE triggers are fired, oldRow contains the
117: * existing values of the table row and newRow contains the
118: * new values.<p>
119: *
120: * For INSERT triggers, oldRow is null and newRow contains the
121: * table row to be inserted.
122: *
123: * For DELETE triggers, newRow is null and oldRow contains the
124: * table row to be deleted.
125: *
126: * type contains the integer index id for trigger type, e.g.
127: * TriggerDef.INSERT_AFTER (fredt@users)
128: *
129: * @param trigName the name of the trigger
130: * @param tabName the name of the table upon which the
131: * triggered action is occuring
132: * @param oldRow the old row
133: * @param newRow the new row
134: */
135: void fire(int type, String trigName, String tabName,
136: Object[] oldRow, Object[] newRow);
137: }
|