Search in sources :

Example 1 with JSQLType

use of org.apache.derby.iapi.types.JSQLType in project derby by apache.

the class ParameterNode method setType.

/**
 * Set the DataTypeServices for this parameter
 *
 * @param descriptor	The DataTypeServices to set for this parameter
 */
@Override
void setType(DataTypeDescriptor descriptor) throws StandardException {
    /* Make sure the type is nullable. */
    /*
		 ** Generate a new descriptor with all the same properties as
		 ** the given one, except that it is nullable.
		 */
    descriptor = descriptor.getNullabilityType(true);
    if (userParameterTypes != null)
        userParameterTypes[parameterNumber] = descriptor;
    // make sure we are calling super's setType. We will get into
    // an infinite loop if this setType ends up calling the local
    // setType method
    super.setType(descriptor);
    if (getJSQLType() == null) {
        setJSQLType(new JSQLType(descriptor));
    }
}
Also used : JSQLType(org.apache.derby.iapi.types.JSQLType)

Example 2 with JSQLType

use of org.apache.derby.iapi.types.JSQLType in project derby by apache.

the class UserAggregateDefinition method getJavaClass.

/**
 * Get the Java class corresponding to a Derby datatype.
 */
private Class<?> getJavaClass(ClassFactory classFactory, DataTypeDescriptor dtd) throws StandardException, ClassNotFoundException {
    JSQLType jsqlType = new JSQLType(dtd);
    String javaClassName = MethodCallNode.getObjectTypeName(jsqlType, null);
    // 
    if (DERBY_BYTE_ARRAY_NAME.equals(javaClassName)) {
        javaClassName = byte[].class.getName();
    }
    return classFactory.loadApplicationClass(javaClassName);
}
Also used : JSQLType(org.apache.derby.iapi.types.JSQLType)

Example 3 with JSQLType

use of org.apache.derby.iapi.types.JSQLType in project derby by apache.

the class StaticMethodCallNode method resolveRoutine.

/**
 * Resolve a routine. Obtain a list of routines from the data dictionary
 * of the correct type (functions or procedures) and name.
 * Pick the best routine from the list. Currently only a single routine
 * with a given type and name is allowed, thus if changes are made to
 * support overloaded routines, careful code inspection and testing will
 * be required.
 */
private void resolveRoutine(FromList fromList, SubqueryList subqueryList, List<AggregateNode> aggregates, SchemaDescriptor sd, boolean noSchema) throws StandardException {
    if (sd.getUUID() != null) {
        List<AliasDescriptor> list = getDataDictionary().getRoutineList(sd.getUUID().toString(), methodName, forCallStatement ? AliasInfo.ALIAS_NAME_SPACE_PROCEDURE_AS_CHAR : AliasInfo.ALIAS_NAME_SPACE_FUNCTION_AS_CHAR);
        for (int i = list.size() - 1; i >= 0; i--) {
            AliasDescriptor proc = list.get(i);
            RoutineAliasInfo rai = (RoutineAliasInfo) proc.getAliasInfo();
            int parameterCount = rai.getParameterCount();
            boolean hasVarargs = rai.hasVarargs();
            if (hasVarargs) {
                // for the trailing varargs argument
                if (methodParms.length < (parameterCount - 1)) {
                    continue;
                }
            } else if (parameterCount != methodParms.length) {
                continue;
            }
            // pre-form the method signature. If it is a dynamic result set procedure
            // then we need to add in the ResultSet array
            TypeDescriptor[] parameterTypes = rai.getParameterTypes();
            int sigParameterCount = parameterCount;
            if (rai.getMaxDynamicResultSets() > 0) {
                sigParameterCount++;
            }
            signature = new JSQLType[sigParameterCount];
            for (int p = 0; p < parameterCount; p++) {
                // find the declared type.
                TypeDescriptor td = parameterTypes[p];
                TypeId typeId = TypeId.getTypeId(td);
                TypeId parameterTypeId = typeId;
                // if it's an OUT or INOUT parameter we need an array.
                int parameterMode = rai.getParameterModes()[getRoutineArgIdx(rai, p)];
                if (parameterMode != (ParameterMetaData.parameterModeIn)) {
                    String arrayType;
                    switch(typeId.getJDBCTypeId()) {
                        case java.sql.Types.BOOLEAN:
                        case java.sql.Types.SMALLINT:
                        case java.sql.Types.INTEGER:
                        case java.sql.Types.BIGINT:
                        case java.sql.Types.REAL:
                        case java.sql.Types.DOUBLE:
                            arrayType = getTypeCompiler(typeId).getCorrespondingPrimitiveTypeName().concat("[]");
                            break;
                        default:
                            arrayType = typeId.getCorrespondingJavaTypeName().concat("[]");
                            break;
                    }
                    typeId = TypeId.getUserDefinedTypeId(arrayType);
                }
                // this is the type descriptor of the require method parameter
                DataTypeDescriptor methoddtd = new DataTypeDescriptor(typeId, td.getPrecision(), td.getScale(), td.isNullable(), td.getMaximumWidth());
                signature[p] = new JSQLType(methoddtd);
                // this is the SQL type of the procedure parameter.
                DataTypeDescriptor paramdtd = new DataTypeDescriptor(parameterTypeId, td.getPrecision(), td.getScale(), td.isNullable(), td.getMaximumWidth());
                // if this is the last argument of a varargs routine...
                if (hasVarargs && (p == parameterCount - 1)) {
                    // 
                    for (int idx = p; idx < methodParms.length; idx++) {
                        coerceMethodParameter(fromList, subqueryList, aggregates, rai, methodParms.length, paramdtd, parameterTypeId, parameterMode, idx);
                    }
                } else // NOT the last argument of a varargs routine
                {
                    coerceMethodParameter(fromList, subqueryList, aggregates, rai, methodParms.length, paramdtd, parameterTypeId, parameterMode, p);
                }
            }
            if (sigParameterCount != parameterCount) {
                DataTypeDescriptor dtd = new DataTypeDescriptor(TypeId.getUserDefinedTypeId("java.sql.ResultSet[]"), 0, 0, false, -1);
                signature[parameterCount] = new JSQLType(dtd);
            }
            this.routineInfo = rai;
            ad = proc;
            // SQL, note that we are in system code.
            if (sd.isSystemSchema() && (routineInfo.getReturnType() == null) && routineInfo.getSQLAllowed() != RoutineAliasInfo.NO_SQL) {
                isSystemCode = true;
            }
            routineDefiner = sd.getAuthorizationId();
            break;
        }
    }
    if ((ad == null) && (methodParms.length == 1)) {
        ad = AggregateNode.resolveAggregate(getDataDictionary(), sd, methodName, noSchema);
    }
}
Also used : TypeId(org.apache.derby.iapi.types.TypeId) RoutineAliasInfo(org.apache.derby.catalog.types.RoutineAliasInfo) DataTypeDescriptor(org.apache.derby.iapi.types.DataTypeDescriptor) TypeDescriptor(org.apache.derby.catalog.TypeDescriptor) DataTypeDescriptor(org.apache.derby.iapi.types.DataTypeDescriptor) JSQLType(org.apache.derby.iapi.types.JSQLType) AliasDescriptor(org.apache.derby.iapi.sql.dictionary.AliasDescriptor)

Example 4 with JSQLType

use of org.apache.derby.iapi.types.JSQLType in project derby by apache.

the class SQLToJavaValueNode method getJSQLType.

/**
 *	Get the JSQLType that corresponds to this node. Could be a SQLTYPE,
 *	a Java primitive, or a Java class.
 *
 *	Overrides method in JavaValueNode.
 *
 *	@return	the corresponding JSQLType
 */
@Override
JSQLType getJSQLType() throws StandardException {
    if (jsqlType == null) {
        if (value.requiresTypeFromContext()) {
            ParameterNode pn;
            if (value instanceof UnaryOperatorNode)
                pn = ((UnaryOperatorNode) value).getParameterOperand();
            else
                pn = (ParameterNode) (value);
            jsqlType = pn.getJSQLType();
        } else {
            DataTypeDescriptor dtd = value.getTypeServices();
            if (dtd != null)
                jsqlType = new JSQLType(dtd);
        }
    }
    return jsqlType;
}
Also used : DataTypeDescriptor(org.apache.derby.iapi.types.DataTypeDescriptor) JSQLType(org.apache.derby.iapi.types.JSQLType)

Example 5 with JSQLType

use of org.apache.derby.iapi.types.JSQLType in project derby by apache.

the class MethodCallNode method getPrimitiveSignature.

String[] getPrimitiveSignature(boolean castToPrimitiveAsNecessary) throws StandardException {
    int count = signature.length;
    String[] primParmTypeNames = new String[count];
    JSQLType jsqlTyp;
    for (int i = 0; i < count; i++) {
        jsqlTyp = signature[i];
        if (jsqlTyp == null) {
            primParmTypeNames[i] = "";
        } else {
            switch(jsqlTyp.getCategory()) {
                case JSQLType.SQLTYPE:
                    if ((procedurePrimitiveArrayType != null) && (i < procedurePrimitiveArrayType.length) && (procedurePrimitiveArrayType[i] != null)) {
                        primParmTypeNames[i] = procedurePrimitiveArrayType[i];
                    } else {
                        TypeId ctid = mapToTypeID(jsqlTyp);
                        if ((ctid.isNumericTypeId() && !ctid.isDecimalTypeId()) || ctid.isBooleanTypeId()) {
                            TypeCompiler tc = getTypeCompiler(ctid);
                            primParmTypeNames[i] = tc.getCorrespondingPrimitiveTypeName();
                            if (castToPrimitiveAsNecessary) {
                                methodParms[i].castToPrimitive(true);
                            }
                        } else {
                            primParmTypeNames[i] = ctid.getCorrespondingJavaTypeName();
                        }
                    }
                    break;
                case JSQLType.JAVA_CLASS:
                    primParmTypeNames[i] = jsqlTyp.getJavaClassName();
                    break;
                case JSQLType.JAVA_PRIMITIVE:
                    primParmTypeNames[i] = JSQLType.getPrimitiveName(jsqlTyp.getPrimitiveKind());
                    if (castToPrimitiveAsNecessary) {
                        methodParms[i].castToPrimitive(true);
                    }
                    break;
                default:
                    if (SanityManager.DEBUG) {
                        SanityManager.THROWASSERT("Unknown JSQLType: " + jsqlTyp);
                    }
            }
        // end switch
        }
    // end if
    }
    return primParmTypeNames;
}
Also used : TypeId(org.apache.derby.iapi.types.TypeId) JSQLType(org.apache.derby.iapi.types.JSQLType) TypeCompiler(org.apache.derby.iapi.sql.compile.TypeCompiler)

Aggregations

JSQLType (org.apache.derby.iapi.types.JSQLType)5 DataTypeDescriptor (org.apache.derby.iapi.types.DataTypeDescriptor)2 TypeId (org.apache.derby.iapi.types.TypeId)2 TypeDescriptor (org.apache.derby.catalog.TypeDescriptor)1 RoutineAliasInfo (org.apache.derby.catalog.types.RoutineAliasInfo)1 TypeCompiler (org.apache.derby.iapi.sql.compile.TypeCompiler)1 AliasDescriptor (org.apache.derby.iapi.sql.dictionary.AliasDescriptor)1