Search in sources :

Example 21 with TypeDescriptor

use of org.apache.derby.catalog.TypeDescriptor in project derby by apache.

the class DataDictionaryImpl method upgradeCLOBGETSUBSTRING_10_6.

/**
 * 10.6 upgrade logic to update the return type of SYSIBM.CLOBGETSUBSTRING. The length of the
 * return type was changed in 10.5 but old versions of the metadata were not
 * upgraded at that time. See DERBY-4214.
 */
void upgradeCLOBGETSUBSTRING_10_6(TransactionController tc) throws StandardException {
    TabInfoImpl ti = getNonCoreTI(SYSALIASES_CATALOG_NUM);
    ExecIndexRow keyRow = exFactory.getIndexableRow(3);
    DataValueDescriptor aliasNameOrderable = new SQLVarchar("CLOBGETSUBSTRING");
    DataValueDescriptor nameSpaceOrderable = new SQLChar(new String(new char[] { AliasInfo.ALIAS_TYPE_FUNCTION_AS_CHAR }));
    keyRow.setColumn(1, new SQLChar(SchemaDescriptor.SYSIBM_SCHEMA_UUID));
    keyRow.setColumn(2, aliasNameOrderable);
    keyRow.setColumn(3, nameSpaceOrderable);
    AliasDescriptor oldAD = getDescriptorViaIndex(SYSALIASESRowFactory.SYSALIASES_INDEX1_ID, keyRow, (ScanQualifier[][]) null, ti, (TupleDescriptor) null, (List<TupleDescriptor>) null, AliasDescriptor.class, true, TransactionController.ISOLATION_REPEATABLE_READ, tc);
    RoutineAliasInfo oldRai = (RoutineAliasInfo) oldAD.getAliasInfo();
    TypeDescriptor newReturnType = DataTypeDescriptor.getCatalogType(Types.VARCHAR, Limits.MAX_CLOB_RETURN_LEN);
    RoutineAliasInfo newRai = new RoutineAliasInfo(oldRai.getMethodName(), oldRai.getParameterCount(), oldRai.getParameterNames(), oldRai.getParameterTypes(), oldRai.getParameterModes(), oldRai.getMaxDynamicResultSets(), oldRai.getParameterStyle(), oldRai.getSQLAllowed(), oldRai.isDeterministic(), oldRai.hasVarargs(), oldRai.hasDefinersRights(), oldRai.calledOnNullInput(), newReturnType);
    AliasDescriptor newAD = new AliasDescriptor(this, oldAD.getUUID(), oldAD.getObjectName(), oldAD.getSchemaUUID(), oldAD.getJavaClassName(), oldAD.getAliasType(), oldAD.getNameSpace(), oldAD.getSystemAlias(), newRai, oldAD.getSpecificName());
    ExecRow newRow = ti.getCatalogRowFactory().makeRow(newAD, null);
    ti.updateRow(keyRow, newRow, SYSALIASESRowFactory.SYSALIASES_INDEX1_ID, new boolean[] { false, false, false }, (int[]) null, tc);
}
Also used : RoutineAliasInfo(org.apache.derby.catalog.types.RoutineAliasInfo) TypeDescriptor(org.apache.derby.catalog.TypeDescriptor) DataTypeDescriptor(org.apache.derby.iapi.types.DataTypeDescriptor) TupleDescriptor(org.apache.derby.iapi.sql.dictionary.TupleDescriptor) SQLChar(org.apache.derby.iapi.types.SQLChar) AliasDescriptor(org.apache.derby.iapi.sql.dictionary.AliasDescriptor) ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) SQLVarchar(org.apache.derby.iapi.types.SQLVarchar) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow)

Example 22 with TypeDescriptor

use of org.apache.derby.catalog.TypeDescriptor in project derby by apache.

the class SYSCOLUMNSRowFactory method buildDescriptor.

// /////////////////////////////////////////////////////////////////////////
// 
// ABSTRACT METHODS TO BE IMPLEMENTED BY CHILDREN OF CatalogRowFactory
// 
// /////////////////////////////////////////////////////////////////////////
/**
 * Make a ColumnDescriptor out of a SYSCOLUMNS row
 *
 * @param row 					a SYSCOLUMNS row
 * @param parentTupleDescriptor	The UniqueTupleDescriptor for the object that is tied
 *								to this column
 * @param dd 					dataDictionary
 *
 * @return	a column descriptor equivalent to a SYSCOLUMNS row
 *
 * @exception   StandardException thrown on failure
 */
public TupleDescriptor buildDescriptor(ExecRow row, TupleDescriptor parentTupleDescriptor, DataDictionary dd) throws StandardException {
    if (SanityManager.DEBUG) {
        int expectedCols = dd.checkVersion(DataDictionary.DD_VERSION_DERBY_10_14, null) ? SYSCOLUMNS_COLUMN_COUNT : (SYSCOLUMNS_COLUMN_COUNT - 1);
        SanityManager.ASSERT(row.nColumns() == expectedCols, "Wrong number of columns for a SYSCOLUMNS row");
    }
    int columnNumber;
    String columnName;
    String defaultID;
    DefaultInfoImpl defaultInfo = null;
    ColumnDescriptor colDesc;
    DataValueDescriptor defaultValue = null;
    UUID defaultUUID = null;
    UUID uuid = null;
    UUIDFactory uuidFactory = getUUIDFactory();
    long autoincStart, autoincInc, autoincValue;
    boolean autoincCycle = false;
    DataDescriptorGenerator ddg = dd.getDataDescriptorGenerator();
    /*
		** We're going to be getting the UUID for this sucka
		** so make sure it is a UniqueTupleDescriptor.
		*/
    if (parentTupleDescriptor != null) {
        if (SanityManager.DEBUG) {
            if (!(parentTupleDescriptor instanceof UniqueTupleDescriptor)) {
                SanityManager.THROWASSERT(parentTupleDescriptor.getClass().getName() + " not instanceof UniqueTupleDescriptor");
            }
        }
        uuid = ((UniqueTupleDescriptor) parentTupleDescriptor).getUUID();
    } else {
        /* 1st column is REFERENCEID (char(36)) */
        uuid = uuidFactory.recreateUUID(row.getColumn(SYSCOLUMNS_REFERENCEID).getString());
    }
    /* NOTE: We get columns 5 and 6 next in order to work around 
		 * a 1.3.0 HotSpot bug.  (#4361550)
		 */
    // 5th column is COLUMNDEFAULT (serialiazable)
    Object object = row.getColumn(SYSCOLUMNS_COLUMNDEFAULT).getObject();
    if (object instanceof DataValueDescriptor) {
        defaultValue = (DataValueDescriptor) object;
    } else if (object instanceof DefaultInfoImpl) {
        defaultInfo = (DefaultInfoImpl) object;
        defaultValue = defaultInfo.getDefaultValue();
    }
    /* 6th column is DEFAULTID (char(36)) */
    defaultID = row.getColumn(SYSCOLUMNS_COLUMNDEFAULTID).getString();
    if (defaultID != null) {
        defaultUUID = uuidFactory.recreateUUID(defaultID);
    }
    /* 2nd column is COLUMNNAME (varchar(128)) */
    columnName = row.getColumn(SYSCOLUMNS_COLUMNNAME).getString();
    /* 3rd column is COLUMNNUMBER (int) */
    columnNumber = row.getColumn(SYSCOLUMNS_COLUMNNUMBER).getInt();
    /* 4th column is COLUMNDATATYPE */
    /*
		** What is stored in the column is a TypeDescriptorImpl, which
		** points to a BaseTypeIdImpl.  These are simple types that are
		** intended to be movable to the client, so they don't have
		** the entire implementation.  We need to wrap them in DataTypeServices
		** and TypeId objects that contain the full implementations for
		** language processing.
		*/
    TypeDescriptor catalogType = (TypeDescriptor) row.getColumn(SYSCOLUMNS_COLUMNDATATYPE).getObject();
    DataTypeDescriptor dataTypeServices = DataTypeDescriptor.getType(catalogType);
    /* 7th column is AUTOINCREMENTVALUE (long) */
    autoincValue = row.getColumn(SYSCOLUMNS_AUTOINCREMENTVALUE).getLong();
    /* 8th column is AUTOINCREMENTSTART (long) */
    autoincStart = row.getColumn(SYSCOLUMNS_AUTOINCREMENTSTART).getLong();
    /* 9th column is AUTOINCREMENTINC (long) */
    autoincInc = row.getColumn(SYSCOLUMNS_AUTOINCREMENTINC).getLong();
    if (row.nColumns() >= 10) {
        DataValueDescriptor col = row.getColumn(SYSCOLUMNS_AUTOINCREMENTINCCYCLE);
        autoincCycle = col.getBoolean();
    }
    DataValueDescriptor col = row.getColumn(SYSCOLUMNS_AUTOINCREMENTSTART);
    autoincStart = col.getLong();
    col = row.getColumn(SYSCOLUMNS_AUTOINCREMENTINC);
    autoincInc = col.getLong();
    // Hard upgraded tables <=10.13 come with a false autoincCyle before they are first
    // explicitly set with cycle or no cycle command.
    colDesc = new ColumnDescriptor(columnName, columnNumber, dataTypeServices, defaultValue, defaultInfo, uuid, defaultUUID, autoincStart, autoincInc, autoincValue, autoincCycle);
    return colDesc;
}
Also used : UUIDFactory(org.apache.derby.iapi.services.uuid.UUIDFactory) ColumnDescriptor(org.apache.derby.iapi.sql.dictionary.ColumnDescriptor) DefaultInfoImpl(org.apache.derby.catalog.types.DefaultInfoImpl) DataDescriptorGenerator(org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator) TypeDescriptor(org.apache.derby.catalog.TypeDescriptor) UUID(org.apache.derby.catalog.UUID) UniqueTupleDescriptor(org.apache.derby.iapi.sql.dictionary.UniqueTupleDescriptor)

Aggregations

TypeDescriptor (org.apache.derby.catalog.TypeDescriptor)22 DataTypeDescriptor (org.apache.derby.iapi.types.DataTypeDescriptor)14 UUID (org.apache.derby.catalog.UUID)6 RoutineAliasInfo (org.apache.derby.catalog.types.RoutineAliasInfo)6 AliasDescriptor (org.apache.derby.iapi.sql.dictionary.AliasDescriptor)5 ResultSet (java.sql.ResultSet)3 ArrayList (java.util.ArrayList)3 ColumnDescriptor (org.apache.derby.iapi.sql.dictionary.ColumnDescriptor)3 ExecRow (org.apache.derby.iapi.sql.execute.ExecRow)3 IOException (java.io.IOException)2 PreparedStatement (java.sql.PreparedStatement)2 SQLException (java.sql.SQLException)2 DataDescriptorGenerator (org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator)2 SchemaDescriptor (org.apache.derby.iapi.sql.dictionary.SchemaDescriptor)2 SequenceDescriptor (org.apache.derby.iapi.sql.dictionary.SequenceDescriptor)2 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)2 SQLChar (org.apache.derby.iapi.types.SQLChar)2 SQLLongint (org.apache.derby.iapi.types.SQLLongint)2 SQLVarchar (org.apache.derby.iapi.types.SQLVarchar)2 TypeId (org.apache.derby.iapi.types.TypeId)2