📄 triggerdescriptor.java
字号:
/* Derby - Class org.apache.derby.iapi.sql.dictionary.TriggerDescriptor Copyright 1999, 2004 The Apache Software Foundation or its licensors, as applicable. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */package org.apache.derby.iapi.sql.dictionary;import org.apache.derby.iapi.services.io.Formatable;import org.apache.derby.iapi.sql.depend.Dependent;import org.apache.derby.iapi.sql.depend.Provider;import org.apache.derby.iapi.error.StandardException;import org.apache.derby.catalog.ReferencedColumns;import org.apache.derby.catalog.UUID;import java.sql.Timestamp;import org.apache.derby.iapi.reference.SQLState;import org.apache.derby.iapi.services.sanity.SanityManager;import org.apache.derby.iapi.sql.StatementType;import org.apache.derby.catalog.DependableFinder;import org.apache.derby.catalog.Dependable;import org.apache.derby.iapi.services.io.StoredFormatIds;import org.apache.derby.iapi.error.StandardException;import org.apache.derby.iapi.sql.depend.DependencyManager;import org.apache.derby.iapi.sql.depend.Dependent;import org.apache.derby.iapi.sql.depend.Dependency;import org.apache.derby.iapi.sql.depend.Provider;import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;import org.apache.derby.iapi.services.context.ContextManager;import org.apache.derby.iapi.services.context.ContextService;import java.io.ObjectOutput;import java.io.ObjectInput;import java.io.IOException;/** * A trigger. * <p> * We are dependent on TableDescriptors, SPSDescriptors (for our * WHEN clause and our action). Note that we don't strictly * need to be dependent on out SPSes because we could just disallow * anyone from dropping an sps of type 'T', but to keep dependencies * uniform, we'll do be dependent. * <p> * We are a provider for DML (PreparedStatements or SPSes) * * The public methods for this class are: * * <ol> * <li>getUUID * <li>getName * <li>getSchemaDescriptor * <li> public boolean listensForEvent(int event); * <li> public int getTriggerEventMask(); * <li> public Timestamp getCreationTimestamp(); * <li> public boolean isBeforeTrigger(); * <li> public boolean isRowTrigger(); * <li> public UUID getActionId(); * <li> public SPSDescriptor getActionSPS(); * <li> public UUID getWhenClauseId(); * <li> public SPSDescriptor getWhenClauseSPS() * <li> public TableDescriptor getTableDescriptor() * <li> public ReferencedColumns getReferencedColumnsDescriptor() * <li> public int[] getReferencedCols(); * <li> public boolean isEnabled(); * <li> public void setEnabled(); * <li> public void setDisabled(); * <li> public boolean needsToFire(int stmtType, int[] modifiedCols) * <li> public String getTriggerDefinition(); * <li> public boolean getReferencingOld(); * <li> public boolean getReferencingNew(); * <li> public String getOldReferencingName(); * <li> public String getNewReferencingName(); * </ol> * @author Jamie */public class TriggerDescriptor extends TupleDescriptor implements UniqueSQLObjectDescriptor, Provider, Dependent, Formatable { // field that we want users to be able to know about public static final int SYSTRIGGERS_STATE_FIELD = 8; public static final int TRIGGER_EVENT_UPDATE = 1; public static final int TRIGGER_EVENT_DELETE = 2; public static final int TRIGGER_EVENT_INSERT = 4; private UUID id; private String name; private String oldReferencingName; private String newReferencingName; private String triggerDefinition; private SchemaDescriptor sd; private int eventMask; private boolean isBefore; private boolean isRow; private boolean referencingOld; private boolean referencingNew; private TableDescriptor td; private UUID actionSPSId; private SPSDescriptor actionSPS; private UUID whenSPSId; private SPSDescriptor whenSPS; private boolean isEnabled; private int[] referencedCols; private Timestamp creationTimestamp; private UUID triggerSchemaId; private UUID triggerTableId; /** * Niladic constructor, for formatable */ public TriggerDescriptor() {} /** * Constructor. Used when creating a trigger from SYS.SYSTRIGGERS * * @param dataDictionary the data dictionary * @param sd the schema descriptor for this trigger * @param id the trigger id * @param name the trigger name * @param eventMask TriggerDescriptor.TRIGGER_EVENT_XXXX * @param isBefore is this a before (as opposed to after) trigger * @param isRow is this a row trigger or statement trigger * @param isEnabled is this trigger enabled or disabled * @param td the table upon which this trigger is defined * @param whenSPSId the sps id for the when clause (may be null) * @param actionSPSId the spsid for the trigger action (may be null) * @param creationTimestamp when was this trigger created? * @param referencedCols what columns does this trigger reference (may be null) * @param triggerDefinition The original user text of the trigger action * @param referencingOld whether or not OLD appears in REFERENCING clause * @param referencingNew whether or not NEW appears in REFERENCING clause * @param oldReferencingName old referencing table name, if any, that appears in REFERCING clause * @param newReferencingName new referencing table name, if any, that appears in REFERCING clause */ public TriggerDescriptor ( DataDictionary dataDictionary, SchemaDescriptor sd, UUID id, String name, int eventMask, boolean isBefore, boolean isRow, boolean isEnabled, TableDescriptor td, UUID whenSPSId, UUID actionSPSId, Timestamp creationTimestamp, int[] referencedCols, String triggerDefinition, boolean referencingOld, boolean referencingNew, String oldReferencingName, String newReferencingName ) { super(dataDictionary); this.id = id; this.sd = sd; this.name = name; this.eventMask = eventMask; this.isBefore = isBefore; this.isRow = isRow; this.td = td; this.actionSPSId = actionSPSId; this.whenSPSId = whenSPSId; this.isEnabled = isEnabled; this.referencedCols = referencedCols; this.creationTimestamp = creationTimestamp; this.triggerDefinition = triggerDefinition; this.referencingOld = referencingOld; this.referencingNew = referencingNew; this.oldReferencingName = oldReferencingName; this.newReferencingName = newReferencingName; triggerSchemaId = sd.getUUID(); triggerTableId = td.getUUID(); } /** * Get the trigger UUID * * @return the id */ public UUID getUUID() { return id; } /** * Get the trigger name * * @return the name */ public String getName() { return name; } public UUID getTableId() { return triggerTableId; } /** * Get the triggers schema descriptor * * @return the schema descriptor * * @exception StandardException on error */ public SchemaDescriptor getSchemaDescriptor() throws StandardException { if (sd == null) { sd = getDataDictionary().getSchemaDescriptor(triggerSchemaId, null); } return sd; } /** * Indicate whether this trigger listens for this * type of event. * * @param event TRIGGER_EVENT_XXXX * * @return true if it listens to the specified event. */ public boolean listensForEvent(int event) { return (event & eventMask) == event; } /** * Get the trigger event mask. Currently, a trigger * may only listen for a single event, though it may * OR multiple events in the future. * * @return the trigger event mask */ public int getTriggerEventMask() { return eventMask; } /** * Get the time that this trigger was created. * * @return the time the trigger was created */ public Timestamp getCreationTimestamp() { return creationTimestamp; } /** * Is this a before trigger * * @return true if it is a before trigger */ public boolean isBeforeTrigger() { return isBefore; } /** * Is this a row trigger * * @return true if it is a before trigger */ public boolean isRowTrigger() { return isRow; } /** * Get the trigger action sps UUID * * @return the uuid of the sps action */ public UUID getActionId() { return actionSPSId; } /** * Get the trigger action sps * * @return the trigger action sps * * @exception StandardException on error */ public SPSDescriptor getActionSPS(LanguageConnectionContext lcc) throws StandardException { if (actionSPS == null) { //bug 4821 - do the sysstatement look up in a nested readonly //transaction rather than in the user transaction. Because of //this, the nested compile transaction which is attempting to //compile the trigger will not run into any locking issues with //the user transaction for sysstatements. lcc.beginNestedTransaction(true); actionSPS = getDataDictionary().getSPSDescriptor(actionSPSId); lcc.commitNestedTransaction(); } return actionSPS; } /** * Get the trigger when clause sps UUID * * @return the uuid of the sps action */ public UUID getWhenClauseId() { return whenSPSId; } /** * Get the trigger when clause sps * * @return the sps of the when clause * * @exception StandardException on error */ public SPSDescriptor getWhenClauseSPS() throws StandardException { if (whenSPS == null) { whenSPS = getDataDictionary().getSPSDescriptor(whenSPSId); } return whenSPS; } /** * Get the trigger table descriptor * * @return the table descripor upon which this trigger * is declared * * @exception StandardException on error */ public TableDescriptor getTableDescriptor() throws StandardException { if (td == null) { td = getDataDictionary().getTableDescriptor(triggerTableId); } return td; } /** * Get the referenced table descriptor for this trigger. * * @return the referenced table descriptor * * @exception StandardException on error */ // caller converts referencedCols to referencedColsDescriptor...// public ReferencedColumns getReferencedColumnsDescriptor()// throws StandardException// {// return (referencedCols == null) ? // (ReferencedColumns)null :// new ReferencedColumnsDescriptorImpl(referencedCols);// } /** * Get the referenced column array for this trigger, used in "alter table * drop column", we get the handle and change it * * @return the referenced column array */ public int[] getReferencedCols() { return referencedCols; } /** * Is this trigger enabled * * @return true if it is enabled */ public boolean isEnabled() { return isEnabled; } /** * Mark this trigger as enabled *
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -