📄 tabledescriptor.java
字号:
* Sets the constraint descriptor list * * @param newCDL The new constraint descriptor list for this table descriptor */ public void setConstraintDescriptorList(ConstraintDescriptorList newCDL) { constraintDescriptorList = newCDL; } /** * Empty the constraint descriptor list * * @return Nothing. * * @exception StandardException Thrown on failure */ public void emptyConstraintDescriptorList() throws StandardException { // Easier just to get a new CDL then to clean out the current one this.constraintDescriptorList = new ConstraintDescriptorList(); } /** * Gets the primary key, may return null if no primary key * * @return The priamry key or null * * @exception StandardException Thrown on failure */ public ReferencedKeyConstraintDescriptor getPrimaryKey() throws StandardException { ConstraintDescriptorList cdl = getDataDictionary().getConstraintDescriptors(this); return cdl.getPrimaryKey(); } /** * Gets the trigger descriptor list * * @return The trigger descriptor list for this table descriptor * * @exception StandardException Thrown on failure */ public GenericDescriptorList getTriggerDescriptorList() throws StandardException { return triggerDescriptorList; } /** * Sets the trigger descriptor list * * @param newCDL The new trigger descriptor list for this table descriptor */ public void setTriggerDescriptorList(GenericDescriptorList newCDL) { triggerDescriptorList = newCDL; } /** * Empty the trigger descriptor list * * @return Nothing. * * @exception StandardException Thrown on failure */ public void emptyTriggerDescriptorList() throws StandardException { // Easier just to get a new CDL then to clean out the current one this.triggerDescriptorList = new GenericDescriptorList(); } /** * Compare the tables descriptors based on the names. * Null schema names match. * * @param otherTableName the other table name * @param otherSchemaName the other schema name * * @return boolean Whether or not the 2 TableNames are equal. */ public boolean tableNameEquals(String otherTableName, String otherSchemaName) { String schemaName = getSchemaName(); if ((schemaName == null) || (otherSchemaName == null)) { return tableName.equals(otherTableName); } else { return schemaName.equals(otherSchemaName) && tableName.equals(otherTableName); } } /** * Remove this descriptor * * @param The conglomerate descriptor * * @exception StandardException on error */ public void removeConglomerateDescriptor(ConglomerateDescriptor cd) throws StandardException { conglomerateDescriptorList.dropConglomerateDescriptor(getUUID(), cd); } /** * Remove this descriptor. Warning, removes by using object * reference, not uuid. * * @param The constraint descriptor * * @exception StandardException on error */ public void removeConstraintDescriptor(ConstraintDescriptor cd) throws StandardException { constraintDescriptorList.remove(cd); } /** * Get the descriptor for a column in the table, * either by the column name or by its ordinal position (column number). * Returns NULL for columns that do not exist. * * @param columnName A String containing the name of the column * * @return A ColumnDescriptor describing the column */ public ColumnDescriptor getColumnDescriptor(String columnName) { return columnDescriptorList.getColumnDescriptor(oid, columnName); } /** * @param columnNumber The ordinal position of the column in the table * * @return A ColumnDescriptor describing the column */ public ColumnDescriptor getColumnDescriptor(int columnNumber) { return columnDescriptorList.getColumnDescriptor(oid, columnNumber); } /** * Gets a ConglomerateDescriptor[] to loop through all the conglomerate descriptors * for the table. * * @return A ConglomerateDescriptor[] for looping through the table's conglomerates * * @exception StandardException Thrown on failure */ public ConglomerateDescriptor[] getConglomerateDescriptors() { int size = conglomerateDescriptorList.size(); ConglomerateDescriptor[] cdls = new ConglomerateDescriptor[size]; conglomerateDescriptorList.toArray(cdls); return cdls; } /** * Gets a conglomerate descriptor for the given table and conglomerate number. * * @param conglomerateNumber The conglomerate number * we're interested in * * @return A ConglomerateDescriptor describing the requested * conglomerate. Returns NULL if no such conglomerate. * * @exception StandardException Thrown on failure */ public ConglomerateDescriptor getConglomerateDescriptor( long conglomerateNumber) throws StandardException { return conglomerateDescriptorList.getConglomerateDescriptor(conglomerateNumber); } /** * Gets array of conglomerate descriptors for the given table and * conglomerate number. More than one descriptors if duplicate indexes * share one conglomerate. * * @param conglomerateNumber The conglomerate number * we're interested in * * @return Array of ConglomerateDescriptors with the requested * conglomerate number. Returns size 0 array if no such conglomerate. * * @exception StandardException Thrown on failure */ public ConglomerateDescriptor[] getConglomerateDescriptors( long conglomerateNumber) throws StandardException { return conglomerateDescriptorList.getConglomerateDescriptors(conglomerateNumber); } /** * Gets a conglomerate descriptor for the given table and conglomerate UUID String. * * @param conglomerateUUID The UUID for the conglomerate * we're interested in * * @return A ConglomerateDescriptor describing the requested * conglomerate. Returns NULL if no such conglomerate. * * @exception StandardException Thrown on failure */ public ConglomerateDescriptor getConglomerateDescriptor( UUID conglomerateUUID) throws StandardException { return conglomerateDescriptorList.getConglomerateDescriptor(conglomerateUUID); } /** * Gets array of conglomerate descriptors for the given table and * conglomerate UUID. More than one descriptors if duplicate indexes * share one conglomerate. * * @param conglomerateUUID The conglomerate UUID * we're interested in * * @return Array of ConglomerateDescriptors with the requested * conglomerate UUID. Returns size 0 array if no such conglomerate. * * @exception StandardException Thrown on failure */ public ConglomerateDescriptor[] getConglomerateDescriptors( UUID conglomerateUUID) throws StandardException { return conglomerateDescriptorList.getConglomerateDescriptors(conglomerateUUID); } /** * Gets an object which lists out all the index row generators on a table together * with their conglomerate ids. * * @return An object to list out the index row generators. * * @exception StandardException Thrown on failure */ public IndexLister getIndexLister() throws StandardException { return new IndexLister( this ); } /** * Does the table have an autoincrement column or not? * * @return TRUE if the table has atleast one autoincrement column, false * otherwise */ public boolean tableHasAutoincrement() { int cdlSize = getColumnDescriptorList().size(); for (int index = 0; index < cdlSize; index++) { ColumnDescriptor cd = (ColumnDescriptor) columnDescriptorList.elementAt(index); if (cd.isAutoincrement()) return true; } return false; } /** * Gets an array of column names. * * @return An array, filled with the column names in the table. * */ public String[] getColumnNamesArray() { int size = getNumberOfColumns(); String[] s = new String[size]; for (int i = 0; i < size; i++) s[i] = getColumnDescriptor(i+1).getColumnName(); return s; } /** * gets an array of increment values for autoincrement columns in the target * table. If column is not an autoincrement column, then increment value is * 0. If table has no autoincrement columns, returns NULL. * * @return array containing the increment values of autoincrement * columns. * */ public long[] getAutoincIncrementArray() { if (!tableHasAutoincrement()) return null; int size = getNumberOfColumns(); long[] inc = new long[size]; for (int i = 0; i < size; i++) { ColumnDescriptor cd = getColumnDescriptor(i + 1); if (cd.isAutoincrement()) inc[i] = cd.getAutoincInc(); } return inc; } /** Returns a list of statistics for this table. */ private synchronized List getStatistics() throws StandardException { // if table already has the statistics descriptors initialized // no need to do anything if (statisticsDescriptorList != null) return statisticsDescriptorList; DataDictionary dd = getDataDictionary(); return statisticsDescriptorList = dd.getStatisticsDescriptors(this); } /** * Are there statistics for this particular conglomerate. * * @param cd Conglomerate/Index for which we want to check if statistics * exist. cd can be null in which case user wants to know if there are any * statistics at all on the table. */ public boolean statisticsExist(ConglomerateDescriptor cd) throws StandardException { List sdl = getStatistics(); if (cd == null) return (sdl.size() > 0); UUID cdUUID = cd.getUUID(); for (Iterator li = sdl.iterator(); li.hasNext(); ) { StatisticsDescriptor statDesc = (StatisticsDescriptor) li.next(); if (cdUUID.equals(statDesc.getReferenceID())) return true; } return false; } /** * For this conglomerate (index), return the selectivity of the first * numKeys. This basically returns the reciprocal of the number of unique * values in the leading numKey columns of the index. It is assumed that * statistics exist for the conglomerate if this function is called. * * @param cd ConglomerateDescriptor (Index) whose * cardinality we are interested in. * @param numKeys Number of leading columns of the index for which * cardinality is desired. */ public double selectivityForConglomerate(ConglomerateDescriptor cd, int numKeys) throws StandardException { if (!statisticsExist(cd)) { if (SanityManager.DEBUG) { SanityManager.THROWASSERT("no statistics exist for conglomerate" + cd); } else { double selectivity = 0.1; for (int i = 0; i < numKeys; i++) selectivity *= 0.1; return selectivity; } } UUID referenceUUID = cd.getUUID(); List sdl = getStatistics(); for (Iterator li = sdl.iterator(); li.hasNext(); ) { StatisticsDescriptor statDesc = (StatisticsDescriptor) li.next(); if (!referenceUUID.equals(statDesc.getReferenceID())) continue; if (statDesc.getColumnCount() != numKeys) continue; return statDesc.getStatistic().selectivity((Object[])null); } if (SanityManager.DEBUG) SanityManager.THROWASSERT("Internal Error-- statistics not found in selectivityForConglomerate.\n cd = " + cd + "\nnumKeys = " + numKeys); return 0.1; // shouldn't come here. } /** @see TupleDescriptor#getDescriptorName */ public String getDescriptorName() { return tableName; } /** @see TupleDescriptor#getDescriptorType */ public String getDescriptorType() { return (tableType == TableDescriptor.SYNONYM_TYPE) ? "Synonym" : "Table/View"; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -