Search in sources :

Example 1 with UserDefinedTypeIdImpl

use of org.apache.derby.catalog.types.UserDefinedTypeIdImpl in project derby by apache.

the class QueryTreeNode method bindUserType.

/**
 * Bind a UDT. This involves looking it up in the DataDictionary and filling
 * in its class name.
 *
 * @param originalDTD A datatype: might be an unbound UDT and might not be
 *
 * @return The bound UDT if originalDTD was an unbound UDT; otherwise returns originalDTD.
 */
public DataTypeDescriptor bindUserType(DataTypeDescriptor originalDTD) throws StandardException {
    // if the type is a table type, then we need to bind its user-typed columns
    if (originalDTD.getCatalogType().isRowMultiSet()) {
        return bindRowMultiSet(originalDTD);
    }
    // nothing to do if this is not a user defined type
    if (!originalDTD.getTypeId().userType()) {
        return originalDTD;
    }
    UserDefinedTypeIdImpl userTypeID = (UserDefinedTypeIdImpl) originalDTD.getTypeId().getBaseTypeId();
    // also nothing to do if the type has already been resolved
    if (userTypeID.isBound()) {
        return originalDTD;
    }
    // ok, we have an unbound UDT. lookup this type in the data dictionary
    DataDictionary dd = getDataDictionary();
    SchemaDescriptor typeSchema = getSchemaDescriptor(userTypeID.getSchemaName());
    char udtNameSpace = AliasInfo.ALIAS_NAME_SPACE_UDT_AS_CHAR;
    String unqualifiedTypeName = userTypeID.getUnqualifiedName();
    AliasDescriptor ad = dd.getAliasDescriptor(typeSchema.getUUID().toString(), unqualifiedTypeName, udtNameSpace);
    if (ad == null) {
        throw StandardException.newException(SQLState.LANG_OBJECT_NOT_FOUND, AliasDescriptor.getAliasType(udtNameSpace), unqualifiedTypeName);
    }
    createTypeDependency(ad);
    DataTypeDescriptor result = new DataTypeDescriptor(TypeId.getUserDefinedTypeId(typeSchema.getSchemaName(), unqualifiedTypeName, ad.getJavaClassName()), originalDTD.isNullable());
    return result;
}
Also used : SchemaDescriptor(org.apache.derby.iapi.sql.dictionary.SchemaDescriptor) DataTypeDescriptor(org.apache.derby.iapi.types.DataTypeDescriptor) UserDefinedTypeIdImpl(org.apache.derby.catalog.types.UserDefinedTypeIdImpl) AliasDescriptor(org.apache.derby.iapi.sql.dictionary.AliasDescriptor) DataDictionary(org.apache.derby.iapi.sql.dictionary.DataDictionary)

Example 2 with UserDefinedTypeIdImpl

use of org.apache.derby.catalog.types.UserDefinedTypeIdImpl in project derby by apache.

the class TypeId method setUserTypeIdInfo.

private void setUserTypeIdInfo() {
    UserDefinedTypeIdImpl baseUserTypeId = (UserDefinedTypeIdImpl) baseTypeId;
    typePrecedence = USER_PRECEDENCE;
    javaTypeName = baseUserTypeId.getClassName();
}
Also used : UserDefinedTypeIdImpl(org.apache.derby.catalog.types.UserDefinedTypeIdImpl)

Example 3 with UserDefinedTypeIdImpl

use of org.apache.derby.catalog.types.UserDefinedTypeIdImpl in project derby by apache.

the class BaseExpressionActivation method maxValue.

/**
 * <p>
 * Get the maximum value of 4 input values.  If less than 4 values, input
 * {@code null} for the unused parameters and place them at the end.
 * If more than 4 input values, call this multiple times to
 * accumulate results.  Also have judge's type as parameter to have a base
 * upon which the comparison is based.  An example use is for code
 * generation in bug 3858.
 * </p>
 *
 * <p>
 * If all the input values are SQL NULL, return SQL NULL. Otherwise, return
 * the maximum value of the non-NULL inputs.
 * </p>
 *
 * @param v1		1st value
 * @param v2		2nd value
 * @param v3		3rd value
 * @param v4		4th value
 * @param judgeTypeFormatId		type format id of the judge
 * @param judgeUserJDBCTypeId	JDBC type id if judge is user type;
 *								-1 if not user type
 *
 * @return	The maximum value of the 4.
 */
public static DataValueDescriptor maxValue(DataValueDescriptor v1, DataValueDescriptor v2, DataValueDescriptor v3, DataValueDescriptor v4, int judgeTypeFormatId, int judgeUserJDBCTypeId, int judgePrecision, int judgeScale, boolean judgeIsNullable, int judgeMaximumWidth, int judgeCollationType, int judgeCollationDerivation) throws StandardException {
    DataValueDescriptor judge;
    if (judgeUserJDBCTypeId == -1) {
        judge = new DataTypeDescriptor(new TypeId(judgeTypeFormatId, null), judgePrecision, judgeScale, judgeIsNullable, judgeMaximumWidth, judgeCollationType, judgeCollationDerivation).getNull();
    } else
        judge = new TypeId(judgeTypeFormatId, new UserDefinedTypeIdImpl()).getNull();
    DataValueDescriptor maxVal = v1;
    if (v2 != null && (maxVal.isNull() || judge.greaterThan(v2, maxVal).equals(true)))
        maxVal = v2;
    if (v3 != null && (maxVal.isNull() || judge.greaterThan(v3, maxVal).equals(true)))
        maxVal = v3;
    if (v4 != null && (maxVal.isNull() || judge.greaterThan(v4, maxVal).equals(true)))
        maxVal = v4;
    return maxVal;
}
Also used : TypeId(org.apache.derby.iapi.types.TypeId) DataTypeDescriptor(org.apache.derby.iapi.types.DataTypeDescriptor) UserDefinedTypeIdImpl(org.apache.derby.catalog.types.UserDefinedTypeIdImpl) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor)

Example 4 with UserDefinedTypeIdImpl

use of org.apache.derby.catalog.types.UserDefinedTypeIdImpl in project derby by apache.

the class UserDefinedTypeCompiler method convertible.

/* TypeCompiler methods */
/**
 * Right now, casting is not allowed from one user defined type
 * to another.
 *
 * @param otherType
 * @param forDataTypeFunction
 * @return true if otherType is convertible to this type, else false.
 *
 *@see TypeCompiler#convertible
 */
public boolean convertible(TypeId otherType, boolean forDataTypeFunction) {
    if (getTypeId().getBaseTypeId().isAnsiUDT()) {
        if (!otherType.getBaseTypeId().isAnsiUDT()) {
            return false;
        }
        UserDefinedTypeIdImpl thisTypeID = (UserDefinedTypeIdImpl) getTypeId().getBaseTypeId();
        UserDefinedTypeIdImpl thatTypeID = (UserDefinedTypeIdImpl) otherType.getBaseTypeId();
        return thisTypeID.getSQLTypeName().equals(thatTypeID.getSQLTypeName());
    }
    /*
		** We are a non-ANSI user defined type, we are
		** going to have to let the client find out
		** the hard way.
		*/
    return true;
}
Also used : UserDefinedTypeIdImpl(org.apache.derby.catalog.types.UserDefinedTypeIdImpl)

Example 5 with UserDefinedTypeIdImpl

use of org.apache.derby.catalog.types.UserDefinedTypeIdImpl in project derby by apache.

the class UserDefinedTypeCompiler method storable.

/**
 * ANSI UDTs can only be stored into values of exactly their own
 * type. This restriction can be lifted when we implement the
 * ANSI subclassing clauses.
 *
 * Old-style User types are storable into other user types that they
 * are assignable to. The other type must be a subclass of
 * this type, or implement this type as one of its interfaces.
 *
 * @param otherType the type of the instance to store into this type.
 * @param cf		A ClassFactory
 * @return true if otherType is storable into this type, else false.
 */
public boolean storable(TypeId otherType, ClassFactory cf) {
    if (!otherType.isUserDefinedTypeId()) {
        return false;
    }
    UserDefinedTypeIdImpl thisTypeID = (UserDefinedTypeIdImpl) getTypeId().getBaseTypeId();
    UserDefinedTypeIdImpl thatTypeID = (UserDefinedTypeIdImpl) otherType.getBaseTypeId();
    if (thisTypeID.isAnsiUDT() != thatTypeID.isAnsiUDT()) {
        return false;
    }
    if (thisTypeID.isAnsiUDT()) {
        return thisTypeID.getSQLTypeName().equals(thatTypeID.getSQLTypeName());
    }
    return cf.getClassInspector().assignableTo(otherType.getCorrespondingJavaTypeName(), getTypeId().getCorrespondingJavaTypeName());
}
Also used : UserDefinedTypeIdImpl(org.apache.derby.catalog.types.UserDefinedTypeIdImpl)

Aggregations

UserDefinedTypeIdImpl (org.apache.derby.catalog.types.UserDefinedTypeIdImpl)9 DataTypeDescriptor (org.apache.derby.iapi.types.DataTypeDescriptor)4 TypeId (org.apache.derby.iapi.types.TypeId)3 AliasDescriptor (org.apache.derby.iapi.sql.dictionary.AliasDescriptor)2 DataDictionary (org.apache.derby.iapi.sql.dictionary.DataDictionary)2 SchemaDescriptor (org.apache.derby.iapi.sql.dictionary.SchemaDescriptor)2 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)2 IOException (java.io.IOException)1 ResultSet (java.sql.ResultSet)1 TypeDescriptorImpl (org.apache.derby.catalog.types.TypeDescriptorImpl)1 ClassInspector (org.apache.derby.iapi.services.loader.ClassInspector)1 TypeCompiler (org.apache.derby.iapi.sql.compile.TypeCompiler)1 StandardException (org.apache.derby.shared.common.error.StandardException)1