001: /*
002:
003: Derby - Class org.apache.derby.iapi.db.TriggerExecutionContext
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to you under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derby.iapi.db;
023:
024: import java.sql.ResultSet;
025: import java.sql.SQLException;
026: import org.apache.derby.catalog.UUID;
027:
028: /**
029: * A trigger execution context holds information that is
030: * available from the context of a trigger invocation.
031: */
032: public interface TriggerExecutionContext {
033: /**
034: * Return value from </I>getEventType()</I> for
035: * an update trigger.
036: */
037: public static final int UPDATE_EVENT = 1;
038:
039: /**
040: * Return value from </I>getEventType()</I> for
041: * a delete trigger.
042: */
043: public static final int DELETE_EVENT = 2;
044:
045: /**
046: * Return value from </I>getEventType()</I> for
047: * an insert trigger.
048: */
049: public static final int INSERT_EVENT = 3;
050:
051: /**
052: * Get the target table name upon which the
053: * trigger event is declared.
054: *
055: * @return the target table
056: */
057: public String getTargetTableName();
058:
059: /**
060: * Get the target table UUID upon which the
061: * trigger event is declared.
062: *
063: * @return the uuid of the target table
064: */
065: public UUID getTargetTableId();
066:
067: /**
068: * Get the type for the event that caused the
069: * trigger to fire.
070: *
071: * @return the event type (e.g. UPDATE_EVENT)
072: */
073: public int getEventType();
074:
075: /**
076: * Get the text of the statement that caused the
077: * trigger to fire.
078: *
079: * @return the statement text.
080: */
081: public String getEventStatementText();
082:
083: /**
084: * Get the columns that have been modified by the statement
085: * that caused this trigger to fire. If all columns are
086: * modified, will return null (e.g. for INSERT or DELETE
087: * return null).
088: *
089: * @return an array of Strings
090: */
091: public String[] getModifiedColumns();
092:
093: /**
094: * Find out if a column was changed, by column name.
095: *
096: * @param columnName the column to check
097: *
098: * @return true if the column was modified by this statement.
099: * Note that this will always return true for INSERT
100: * and DELETE regardless of the column name passed in.
101: */
102: public boolean wasColumnModified(String columnName);
103:
104: /**
105: * Find out if a column was changed, by column number
106: *
107: * @param columnNumber the column to check
108: *
109: * @return true if the column was modified by this statement.
110: * Note that this will always return true for INSERT
111: * and DELETE regardless of the column name passed in.
112: */
113: public boolean wasColumnModified(int columnNumber);
114:
115: /**
116: * Returns a result set of the old (before) images of the changed rows.
117: * For a row trigger, this result set will have a single row. For
118: * a statement trigger, this result set has every row that has
119: * changed or will change. If a statement trigger does not affect
120: * a row, then the result set will be empty (i.e. ResultSet.next()
121: * will return false).
122: * <p>
123: * Will return null if the call is inapplicable for the trigger
124: * that is currently executing. For example, will return null if called
125: * during a the firing of an INSERT trigger.
126: *
127: * @return the ResultSet containing before images of the rows
128: * changed by the triggering event. May return null.
129: *
130: * @exception SQLException if called after the triggering event has
131: * completed
132: */
133: public ResultSet getOldRowSet() throws SQLException;
134:
135: /**
136: * Returns a result set of the new (after) images of the changed rows.
137: * For a row trigger, this result set will have a single row. For
138: * a statement trigger, this result set has every row that has
139: * changed or will change. If a statement trigger does not affect
140: * a row, then the result set will be empty (i.e. ResultSet.next()
141: * will return false).
142: * <p>
143: * Will return null if the call is inapplicable for the trigger
144: * that is currently executing. For example, will return null if
145: * called during the firing of a DELETE trigger.
146: *
147: * @return the ResultSet containing after images of the rows
148: * changed by the triggering event. May return null.
149: *
150: * @exception SQLException if called after the triggering event has
151: * completed
152: */
153: public ResultSet getNewRowSet() throws SQLException;
154:
155: /**
156: * Like getOldRowSet(), but returns a result set positioned
157: * on the first row of the before (old) result set. Used as a convenience
158: * to get a column for a row trigger. Equivalent to getOldRowSet()
159: * followed by next().
160: * <p>
161: * Will return null if the call is inapplicable for the trigger
162: * that is currently executing. For example, will return null if called
163: * during a the firing of an INSERT trigger.
164: *
165: * @return the ResultSet positioned on the old row image. May
166: * return null.
167: *
168: * @exception SQLException if called after the triggering event has
169: * completed
170: */
171: public ResultSet getOldRow() throws SQLException;
172:
173: /**
174: * Like getNewRowSet(), but returns a result set positioned
175: * on the first row of the after (new) result set. Used as a convenience
176: * to get a column for a row trigger. Equivalent to getNewRowSet()
177: * followed by next().
178: * <p>
179: * Will return null if the call is inapplicable for the trigger
180: * that is currently executing. For example, will return null if
181: * called during the firing of a DELETE trigger.
182: *
183: * @return the ResultSet positioned on the new row image. May
184: * return null.
185: *
186: * @exception SQLException if called after the triggering event has
187: * completed
188: */
189: public ResultSet getNewRow() throws SQLException;
190: }
|