📄 tabledescriptor.java
字号:
/* Derby - Class org.apache.derby.iapi.sql.dictionary.TableDescriptor Copyright 1997, 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.context.ContextManager;import org.apache.derby.iapi.error.StandardException;import org.apache.derby.iapi.sql.dictionary.GenericDescriptorList;import org.apache.derby.iapi.sql.depend.Provider;import org.apache.derby.iapi.sql.execute.ExecRow;import org.apache.derby.catalog.UUID;import org.apache.derby.catalog.DependableFinder;import org.apache.derby.iapi.services.io.FormatableBitSet;import org.apache.derby.iapi.sql.StatementType;import org.apache.derby.iapi.services.io.StoredFormatIds;import org.apache.derby.iapi.types.DataValueDescriptor;import org.apache.derby.iapi.sql.depend.Provider;import org.apache.derby.iapi.sql.execute.ExecRow;import org.apache.derby.iapi.sql.execute.ExecutionContext;import org.apache.derby.iapi.reference.SQLState;import org.apache.derby.catalog.Dependable;import org.apache.derby.iapi.services.sanity.SanityManager;import java.util.Vector;import java.util.Enumeration;import java.util.List;import java.util.Iterator;/** * This class represents a table descriptor. The external interface to this * class is: <p> <ol> <li>external interface </li> <li>public String getSchemaName();</li> <li>public String getQualifiedName();</li> <li>public int getTableType();</li> <li>public long getHeapConglomerateId() throws StandardException;</li> <li>public int getNumberOfColumns(); </li> <li>public FormatableBitSet getReferencedColumnMap();</li> <li>public void setReferencedColumnMap(FormatableBitSet referencedColumnMap);</li> <li>public int getMaxColumnID() throws StandardException;</li> <li>public void setUUID(UUID uuid);</li> <li>public char getLockGranularity();</li> <li>public void setTableName(String newTableName);</li> <li>public void setLockGranularity(char lockGranularity);</li> <li>public ExecRow getEmptyExecRow( ContextManager cm) throws StandardException;</li> <li>public boolean tableNameEquals(String otherSchemaName, String otherTableName);</li> <li>public ReferencedKeyConstraintDescriptor getPrimaryKey() throws StandardException;</li> <li>public void removeConglomerateDescriptor(ConglomerateDescriptor cd) throws StandardException;</li> <li>public void removeConstraintDescriptor(ConstraintDescriptor cd) throws StandardException;</li> <li>public void getAffectedIndexes(...) throws StandardException;</li> <li>public void getAllRelevantTriggers(...) throws StandardException;</li> <li>public void getAllRelevantConstraints(...) throws StandardException</li> <li>public ColumnDescriptorList getColumnDescriptorList();</li> <li> public String[] getColumnNamesArray();</li> <li>public long[] getAutoincIncrementArray();</li> <li>public ColumnDescriptor getColumnDescriptor(String columnName);</li> <li>public ColumnDescriptor getColumnDescriptor(int columnNumber);</li> <li>public ConglomerateDescriptor[] getConglomerateDescriptors() throws StandardException;</li> <li>public ConglomerateDescriptor getConglomerateDescriptor(long conglomerateNumber) throws StandardException;</li> <li>public ConglomerateDescriptor getConglomerateDescriptor(UUID conglomerateUUID) throws StandardException;</li> <li>public IndexLister getIndexLister() throws StandardException;</li> <li>public ViewDescriptor getViewDescriptor();</li> <li>public boolean tableHasAutoincrement();</li> <li>public boolean statisticsExist(ConglomerateDescriptor cd) throws StandardException;</li> <li>public double selectivityForConglomerate(...)throws StandardException;</li> </ol> <p> * * @author Jeff Lichtman */public class TableDescriptor extends TupleDescriptor implements UniqueSQLObjectDescriptor, Provider{ public static final int BASE_TABLE_TYPE = 0; public static final int SYSTEM_TABLE_TYPE = 1; public static final int VIEW_TYPE = 2; public static final int GLOBAL_TEMPORARY_TABLE_TYPE = 3; public static final int SYNONYM_TYPE = 4; public static final char ROW_LOCK_GRANULARITY = 'R'; public static final char TABLE_LOCK_GRANULARITY = 'T'; public static final char DEFAULT_LOCK_GRANULARITY = ROW_LOCK_GRANULARITY; /** */ // implementation private char lockGranularity; private boolean onCommitDeleteRows; //true means on commit delete rows, false means on commit preserve rows of temporary table. private boolean onRollbackDeleteRows; //true means on rollback delete rows. This is the only value supported. SchemaDescriptor schema; String tableName; UUID oid; int tableType; long heapConglomNumber = -1; ColumnDescriptorList columnDescriptorList; ConglomerateDescriptorList conglomerateDescriptorList; ConstraintDescriptorList constraintDescriptorList; private GenericDescriptorList triggerDescriptorList; ViewDescriptor viewDescriptor; FormatableBitSet referencedColumnMap; /** A list of statistics pertaining to this table-- */ private List statisticsDescriptorList; /** * Constructor for a TableDescriptor (this is for a temporary table). * * @param dataDictionary The data dictionary that this descriptor lives in * @param tableName The name of the temporary table * @param schema The schema descriptor for this table. * @param tableType An integer identifier for the type of the table : declared global temporary table * @param onCommitDeleteRows If true, on commit delete rows else on commit preserve rows of temporary table. * @param onRollbackDeleteRows If true, on rollback, delete rows from temp tables which were logically modified. true is the only supported value */ public TableDescriptor ( DataDictionary dataDictionary, String tableName, SchemaDescriptor schema, int tableType, boolean onCommitDeleteRows, boolean onRollbackDeleteRows ) { this(dataDictionary, tableName, schema, tableType, '\0'); this.onCommitDeleteRows = onCommitDeleteRows; this.onRollbackDeleteRows = onRollbackDeleteRows; } /** * Constructor for a TableDescriptor. * * @param dataDictionary The data dictionary that this descriptor lives in * @param tableName The name of the table * @param schema The schema descriptor for this table. * @param tableType An integer identifier for the type of the table * (base table, view, etc.) * @param lockGranularity The lock granularity. */ public TableDescriptor ( DataDictionary dataDictionary, String tableName, SchemaDescriptor schema, int tableType, char lockGranularity ) { super( dataDictionary ); this.schema = schema; this.tableName = tableName; this.tableType = tableType; this.lockGranularity = lockGranularity; this.conglomerateDescriptorList = new ConglomerateDescriptorList(); this.columnDescriptorList = new ColumnDescriptorList(); this.constraintDescriptorList = new ConstraintDescriptorList(); this.triggerDescriptorList = new GenericDescriptorList(); } // // TableDescriptor interface // /** * Gets the name of the schema the table lives in. * * @return A String containing the name of the schema the table * lives in. */ public String getSchemaName() { return schema.getSchemaName(); } /** * Gets the SchemaDescriptor for this TableDescriptor. * * @return SchemaDescriptor The SchemaDescriptor. */ public SchemaDescriptor getSchemaDescriptor() { return schema; } /** * Gets the name of the table. * * @return A String containing the name of the table. */ public String getName() { return tableName; } /** * Sets the the table name in case of rename table. * * This is used only by rename table * @param newTableName The new table name. */ public void setTableName(String newTableName) { this.tableName = newTableName; } /** * Gets the full, qualified name of the table. * * @return A String containing the name of the table. */ public String getQualifiedName() { //quoteStringIfNecessary is for bug 3476. If the schemaName and/or tableName has //double quotes in it, this method will put them in quotes and replace every //double quote with 2 double quotes. return quoteStringIfNecessary(getSchemaName()) + "." + quoteStringIfNecessary(getName()); } /** * If the name has double quotes in it, put two double quotes for every single * double quote. * For eg, if table name is m"n, return it as "m""n". For now, this is used * by DMLModStatementNode.parseCheckConstraint(). * * @param name The String with or without double quotes * * @return The quoted String */ private String quoteStringIfNecessary(String name) { String quotedString = name; int quotePos = name.indexOf("\""); if (quotePos == -1) return name; //string does have quotes in it. while(quotePos != -1) { quotedString = quotedString.substring(0,quotePos) + "\"" + quotedString.substring(quotePos); quotePos = quotedString.indexOf("\"",quotePos+2); } return "\"" + quotedString + "\""; } /** * Gets the UUID of the table. * * @return The UUID of the table. */ public UUID getUUID() { return oid; } /** * Gets an identifier telling what type of table this is * (base table, declared global temporary table, view, etc.) * * @return An identifier telling what type of table this is. */ public int getTableType() { return tableType; } /** * Gets the id for the heap conglomerate of the table. * There may also be keyed conglomerates, these are * stored separately in the conglomerates table. * * @return the id of the heap conglomerate for the table. * * @exception StandardException Thrown on error */ public long getHeapConglomerateId() throws StandardException { DataDictionary dd = getDataDictionary(); ConglomerateDescriptor cd = null; /* If we've already cached the heap conglomerate number, then * simply return it. */ if (heapConglomNumber != -1) { return heapConglomNumber; } ConglomerateDescriptor[] cds = getConglomerateDescriptors(); for (int index = 0; index < cds.length; index++) { cd = cds[index]; if ( ! cd.isIndex()) break; } if (SanityManager.DEBUG) { if (cd == null) { SanityManager.THROWASSERT( "cd is expected to be non-null for " + tableName); } if (cd.isIndex()) { SanityManager.THROWASSERT( "Did not find heap conglomerate for " + tableName); } } heapConglomNumber = cd.getConglomerateNumber(); return heapConglomNumber; } /** * Gets the number of columns in the table. * * @return the number of columns in the table. * */ public int getNumberOfColumns() { return getColumnDescriptorList().size(); } /** * Get the referenced column map of the table. * * @return the referencedColumnMap of the table. * */ public FormatableBitSet getReferencedColumnMap() { return referencedColumnMap; } /** * Set the referenced column map of the table. * * @param referencedColumnMap FormatableBitSet of referenced columns. * * @return void. * */ public void setReferencedColumnMap(FormatableBitSet referencedColumnMap) { this.referencedColumnMap = referencedColumnMap; } /** * Gets the highest column id in the table. For now this is the same as * the number of columns. However, in the future, after we implement * ALTER TABLE DROP COLUMN, this correspondence won't hold any longer. * * @return the highest column ID in the table * * @exception StandardException Thrown on error */ public int getMaxColumnID() throws StandardException { int maxColumnID = 1; int cdlSize = getColumnDescriptorList().size(); for (int index = 0; index < cdlSize; index++) { ColumnDescriptor cd = (ColumnDescriptor) columnDescriptorList.elementAt(index); maxColumnID = Math.max( maxColumnID, cd.getPosition() ); } return maxColumnID; } /** * Sets the UUID of the table * * @param oid The UUID of the table to be set in the descriptor * * @return Nothing */ public void setUUID(UUID oid) { this.oid = oid; } /** * Gets the lock granularity for the table. * * @return A char representing the lock granularity for the table.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -