📄 systriggersrowfactory.java
字号:
/* Derby - Class org.apache.derby.impl.sql.catalog.SYSTRIGGERSRowFactory 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.impl.sql.catalog;import org.apache.derby.iapi.types.DataTypeDescriptor;import org.apache.derby.iapi.types.DataValueDescriptor;import org.apache.derby.iapi.types.TypeId;import org.apache.derby.iapi.types.TypeId;import org.apache.derby.iapi.types.DataValueFactory;import org.apache.derby.iapi.types.RowLocation;import org.apache.derby.iapi.sql.dictionary.CatalogRowFactory;import org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator;import org.apache.derby.iapi.sql.dictionary.DataDictionary;import org.apache.derby.iapi.sql.dictionary.SystemColumn;import org.apache.derby.iapi.sql.dictionary.TriggerDescriptor;import org.apache.derby.iapi.sql.dictionary.TupleDescriptor;import org.apache.derby.iapi.sql.execute.ExecIndexRow;import org.apache.derby.iapi.sql.execute.ExecRow;import org.apache.derby.iapi.sql.execute.ExecutionFactory;import org.apache.derby.iapi.error.StandardException;import org.apache.derby.iapi.services.monitor.Monitor;import org.apache.derby.catalog.ReferencedColumns;import org.apache.derby.catalog.types.ReferencedColumnsDescriptorImpl;import org.apache.derby.catalog.UUID;import org.apache.derby.iapi.services.uuid.UUIDFactory;import org.apache.derby.iapi.services.sanity.SanityManager;import org.apache.derby.iapi.types.SQLTimestamp;import java.sql.Timestamp;/** * Factory for creating a SYSTRIGGERS row. * * * @version 0.1 * @author Jamie */public class SYSTRIGGERSRowFactory extends CatalogRowFactory{ static final String TABLENAME_STRING = "SYSTRIGGERS"; /* Column #s for sysinfo (1 based) */ public static final int SYSTRIGGERS_TRIGGERID = 1; public static final int SYSTRIGGERS_TRIGGERNAME = 2; public static final int SYSTRIGGERS_SCHEMAID = 3; public static final int SYSTRIGGERS_CREATIONTIMESTAMP = 4; public static final int SYSTRIGGERS_EVENT = 5; public static final int SYSTRIGGERS_FIRINGTIME = 6; public static final int SYSTRIGGERS_TYPE = 7; public static final int SYSTRIGGERS_STATE = TriggerDescriptor.SYSTRIGGERS_STATE_FIELD; public static final int SYSTRIGGERS_TABLEID = 9; public static final int SYSTRIGGERS_WHENSTMTID = 10; public static final int SYSTRIGGERS_ACTIONSTMTID = 11; public static final int SYSTRIGGERS_REFERENCEDCOLUMNS = 12; public static final int SYSTRIGGERS_TRIGGERDEFINITION = 13; public static final int SYSTRIGGERS_REFERENCINGOLD = 14; public static final int SYSTRIGGERS_REFERENCINGNEW = 15; public static final int SYSTRIGGERS_OLDREFERENCINGNAME = 16; public static final int SYSTRIGGERS_NEWREFERENCINGNAME = 17; public static final int SYSTRIGGERS_COLUMN_COUNT = SYSTRIGGERS_NEWREFERENCINGNAME; public static final int SYSTRIGGERS_INDEX1_ID = 0; public static final int SYSTRIGGERS_INDEX2_ID = 1; public static final int SYSTRIGGERS_INDEX3_ID = 2; private static final int[][] indexColumnPositions = { {SYSTRIGGERS_TRIGGERID}, {SYSTRIGGERS_TRIGGERNAME, SYSTRIGGERS_SCHEMAID}, {SYSTRIGGERS_TABLEID, SYSTRIGGERS_CREATIONTIMESTAMP} }; private static final String[][] indexColumnNames = { {"TRIGGERID"}, {"TRIGGERNAME", "SCHEMAID"}, {"CREATIONTIMESTAMP"} }; private static final boolean[] uniqueness = { true, true, false, }; private static final String[] uuids = { "c013800d-00d7-c025-4809-000a0a411200" // catalog UUID ,"c013800d-00d7-c025-480a-000a0a411200" // heap UUID ,"c013800d-00d7-c025-480b-000a0a411200" // SYSTRIGGERS_INDEX1 ,"c013800d-00d7-c025-480c-000a0a411200" // SYSTRIGGERS_INDEX2 ,"c013800d-00d7-c025-480d-000a0a411200" // SYSTRIGGERS_INDEX3 }; ///////////////////////////////////////////////////////////////////////////// // // CONSTRUCTORS // ///////////////////////////////////////////////////////////////////////////// public SYSTRIGGERSRowFactory(UUIDFactory uuidf, ExecutionFactory ef, DataValueFactory dvf, boolean convertIdToLower) { super(uuidf,ef,dvf,convertIdToLower); initInfo(SYSTRIGGERS_COLUMN_COUNT, TABLENAME_STRING, indexColumnPositions, indexColumnNames, uniqueness, uuids); } ///////////////////////////////////////////////////////////////////////////// // // METHODS // ///////////////////////////////////////////////////////////////////////////// /** * Make a SYSTRIGGERS row. * * @param emptyRow Make an empty row if this parameter is true * @param triggerDescriptor In-memory tuple to be converted to a disk row. * * @return Row suitable for inserting into SYSTRIGGERS. * * @exception StandardException thrown on failure */ public ExecRow makeRow(TupleDescriptor td, TupleDescriptor parent) throws StandardException { DataTypeDescriptor dtd; ExecRow row; DataValueDescriptor col; String name = null; UUID uuid = null; UUID suuid = null; // schema UUID tuuid = null; // referenced table UUID actionSPSID = null; // action sps uuid string UUID whenSPSID = null; // when clause sps uuid string Timestamp createTime = null; String event = null; String time = null; String type = null; String enabled = null; String triggerDefinition = null; String oldReferencingName = null; String newReferencingName = null; ReferencedColumns rcd = null; boolean referencingOld = false; boolean referencingNew = false; if (td != null) { TriggerDescriptor triggerDescriptor = (TriggerDescriptor)td; name = triggerDescriptor.getName(); uuid = triggerDescriptor.getUUID(); suuid = triggerDescriptor.getSchemaDescriptor().getUUID(); createTime = triggerDescriptor.getCreationTimestamp(); // for now we are assuming that a trigger can only listen to a single event event = triggerDescriptor.listensForEvent(TriggerDescriptor.TRIGGER_EVENT_UPDATE) ? "U" : triggerDescriptor.listensForEvent(TriggerDescriptor.TRIGGER_EVENT_DELETE) ? "D" : "I"; time = triggerDescriptor.isBeforeTrigger() ? "B" : "A"; type = triggerDescriptor.isRowTrigger() ? "R" : "S"; enabled = triggerDescriptor.isEnabled() ? "E" : "D"; tuuid = triggerDescriptor.getTableDescriptor().getUUID(); int[] refCols = triggerDescriptor.getReferencedCols(); rcd = (refCols != null) ? new ReferencedColumnsDescriptorImpl(refCols) : null; actionSPSID = triggerDescriptor.getActionId(); whenSPSID = triggerDescriptor.getWhenClauseId(); triggerDefinition = triggerDescriptor.getTriggerDefinition(); referencingOld = triggerDescriptor.getReferencingOld(); referencingNew = triggerDescriptor.getReferencingNew(); oldReferencingName = triggerDescriptor.getOldReferencingName(); newReferencingName = triggerDescriptor.getNewReferencingName(); } /* Build the row to insert */ row = getExecutionFactory().getValueRow(SYSTRIGGERS_COLUMN_COUNT); /* 1st column is TRIGGERID */ row.setColumn(1, dvf.getCharDataValue((uuid == null) ? null : uuid.toString())); /* 2nd column is TRIGGERNAME */ row.setColumn(2, dvf.getVarcharDataValue(name)); /* 3rd column is SCHEMAID */ row.setColumn(3, dvf.getCharDataValue((suuid == null) ? null : suuid.toString())); /* 4th column is CREATIONTIMESTAMP */ row.setColumn(4, dvf.getDataValue(createTime)); /* 5th column is EVENT */ row.setColumn(5, dvf.getCharDataValue(event)); /* 6th column is FIRINGTIME */ row.setColumn(6, dvf.getCharDataValue(time)); /* 7th column is TYPE */ row.setColumn(7, dvf.getCharDataValue(type)); /* 8th column is STATE */ row.setColumn(8, dvf.getCharDataValue(enabled)); /* 9th column is TABLEID */ row.setColumn(9, dvf.getCharDataValue((tuuid == null) ? null : tuuid.toString())); /* 10th column is WHENSTMTID */ row.setColumn(10, dvf.getCharDataValue((whenSPSID == null) ? null : whenSPSID.toString())); /* 11th column is ACTIONSTMTID */ row.setColumn(11, dvf.getCharDataValue((actionSPSID == null) ? null : actionSPSID.toString())); /* 12th column is REFERENCEDCOLUMNS * (user type org.apache.derby.catalog.ReferencedColumns) */ row.setColumn(12, dvf.getDataValue(rcd)); /* 13th column is TRIGGERDEFINITION */ row.setColumn(13, dvf.getLongvarcharDataValue(triggerDefinition)); /* 14th column is REFERENCINGOLD */ row.setColumn(14, dvf.getDataValue(referencingOld)); /* 15th column is REFERENCINGNEW */ row.setColumn(15, dvf.getDataValue(referencingNew)); /* 16th column is OLDREFERENCINGNAME */ row.setColumn(16, dvf.getVarcharDataValue(oldReferencingName)); /* 17th column is NEWREFERENCINGNAME */ row.setColumn(17, dvf.getVarcharDataValue(newReferencingName)); return row; } /** * Builds an empty index row. * * @param indexNumber Index to build empty row for. * @param rowLocation Row location for last column of index row * * @return corresponding empty index row * @exception StandardException thrown on failure */ public ExecIndexRow buildEmptyIndexRow( int indexNumber, RowLocation rowLocation) throws StandardException { int ncols = getIndexColumnCount(indexNumber); ExecIndexRow row = getExecutionFactory().getIndexableRow(ncols + 1); row.setColumn(ncols + 1, rowLocation); switch( indexNumber ) { case SYSTRIGGERS_INDEX1_ID: /* 1st column is TRIGGERID (UUID - char(36)) */ row.setColumn(1, getDataValueFactory().getCharDataValue((String) null)); break; case SYSTRIGGERS_INDEX2_ID: /* 1st column is TRIGGERNAME (varchar(128)) */ row.setColumn(1, getDataValueFactory().getVarcharDataValue((String) null)); /* 2nd column is SCHEMAID (char(32)) */ row.setColumn(2, getDataValueFactory().getCharDataValue((String) null)); break; case SYSTRIGGERS_INDEX3_ID: /* 1nd column is TABLEID (char(32)) */ row.setColumn(2, getDataValueFactory().getCharDataValue((String) null)); /* 2nd column is COMPILATIONTIMESTAMP (timestamp) */ row.setColumn(2, new SQLTimestamp()); break; } // end switch return row; } /////////////////////////////////////////////////////////////////////////// // // ABSTRACT METHODS TO BE IMPLEMENTED BY CHILDREN OF CatalogRowFactory // /////////////////////////////////////////////////////////////////////////// /** * Make an Tuple Descriptor out of a SYSTRIGGERS row * * @param row a SYSTRIGGERS row * @param parentTupleDescriptor unused * @param dd dataDictionary * * @return a descriptor equivalent to a SYSTRIGGERS row * * @exception StandardException thrown on failure */ public TupleDescriptor buildDescriptor ( ExecRow row, TupleDescriptor parentTupleDescriptor, DataDictionary dd ) throws StandardException { DataValueDescriptor col; String name; char theChar; String uuidStr; String triggerDefinition; String oldReferencingName; String newReferencingName; UUID uuid; UUID suuid; // schema UUID tuuid; // referenced table UUID actionSPSID = null; // action sps uuid string UUID whenSPSID = null; // when clause sps uuid string Timestamp createTime; int eventMask = 0; boolean isBefore; boolean isRow; boolean isEnabled; boolean referencingOld; boolean referencingNew; ReferencedColumns rcd; TriggerDescriptor descriptor; DataDescriptorGenerator ddg = dd.getDataDescriptorGenerator(); if (SanityManager.DEBUG) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -