Search in sources :

Example 6 with TypeDescriptor

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

the class SYSSEQUENCESRowFactory method makeRow.

/**
 * Make a SYSSEQUENCES row
 *
 * @param td     a sequence descriptor
 * @param parent unused
 * @return Row suitable for inserting into SYSSEQUENCES.
 * @throws org.apache.derby.shared.common.error.StandardException
 *          thrown on failure
 */
public ExecRow makeRow(TupleDescriptor td, TupleDescriptor parent) throws StandardException {
    ExecRow row;
    String oidString = null;
    String sequenceName = null;
    String schemaIdString = null;
    TypeDescriptor typeDesc = null;
    Long currentValue = null;
    long startValue = 0;
    long minimumValue = 0;
    long maximumValue = 0;
    long increment = 0;
    boolean canCycle = false;
    if (td != null) {
        SequenceDescriptor sd = (SequenceDescriptor) td;
        UUID oid = sd.getUUID();
        oidString = oid.toString();
        sequenceName = sd.getSequenceName();
        UUID schemaId = sd.getSchemaId();
        schemaIdString = schemaId.toString();
        typeDesc = sd.getDataType().getCatalogType();
        currentValue = sd.getCurrentValue();
        startValue = sd.getStartValue();
        minimumValue = sd.getMinimumValue();
        maximumValue = sd.getMaximumValue();
        increment = sd.getIncrement();
        canCycle = sd.canCycle();
    }
    /* Build the row to insert */
    row = getExecutionFactory().getValueRow(SYSSEQUENCES_COLUMN_COUNT);
    /* 1st column is UUID */
    row.setColumn(SYSSEQUENCES_SEQUENCEID, new SQLChar(oidString));
    /* 2nd column is SEQUENCENAME */
    row.setColumn(SYSSEQUENCES_SEQUENCENAME, new SQLVarchar(sequenceName));
    /* 3nd column is SCHEMAID */
    row.setColumn(SYSSEQUENCES_SCHEMAID, new SQLChar(schemaIdString));
    /* 4th column is SEQUENCEDATATYPE */
    row.setColumn(SYSSEQUENCES_SEQUENCEDATATYPE, new UserType(typeDesc));
    /* 5th column is CURRENTVALUE */
    SQLLongint curVal;
    if (currentValue == null) {
        curVal = new SQLLongint();
    } else {
        curVal = new SQLLongint(currentValue.longValue());
    }
    row.setColumn(SYSSEQUENCES_CURRENT_VALUE, curVal);
    /* 6th column is STARTVALUE */
    row.setColumn(SYSSEQUENCES_START_VALUE, new SQLLongint(startValue));
    /* 7th column is MINIMUMVALUE */
    row.setColumn(SYSSEQUENCES_MINIMUM_VALUE, new SQLLongint(minimumValue));
    /* 8th column is MAXIMUMVALUE */
    row.setColumn(SYSSEQUENCES_MAXIMUM_VALUE, new SQLLongint(maximumValue));
    /* 9th column is INCREMENT */
    row.setColumn(SYSSEQUENCES_INCREMENT, new SQLLongint(increment));
    /* 10th column is CYCLEOPTION */
    row.setColumn(SYSSEQUENCES_CYCLE_OPTION, new SQLChar(canCycle ? "Y" : "N"));
    return row;
}
Also used : TypeDescriptor(org.apache.derby.catalog.TypeDescriptor) DataTypeDescriptor(org.apache.derby.iapi.types.DataTypeDescriptor) SQLLongint(org.apache.derby.iapi.types.SQLLongint) ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) SQLChar(org.apache.derby.iapi.types.SQLChar) SequenceDescriptor(org.apache.derby.iapi.sql.dictionary.SequenceDescriptor) UUID(org.apache.derby.catalog.UUID) SQLVarchar(org.apache.derby.iapi.types.SQLVarchar) UserType(org.apache.derby.iapi.types.UserType)

Example 7 with TypeDescriptor

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

the class PrivilegeNode method bind.

/**
 * Bind this GrantNode. Resolve all table, column, and routine references. Register
 * a dependency on the object of the privilege if it has not already been done
 *
 * @param dependencies The list of privilege objects that this statement has already seen.
 *               If the object of this privilege is not in the list then this statement is registered
 *               as dependent on the object.
 * @param grantees The list of grantees
 * @param isGrant grant if true; revoke if false
 * @return the bound node
 *
 * @exception StandardException	Standard error policy.
 */
public QueryTreeNode bind(HashMap<Provider, Provider> dependencies, List<String> grantees, boolean isGrant) throws StandardException {
    // The below code handles the case where objectName.getSchemaName()
    // returns null, in which case we'll fetch the schema descriptor for
    // the current compilation schema (see getSchemaDescriptor).
    SchemaDescriptor sd = getSchemaDescriptor(objectName.getSchemaName(), true);
    objectName.setSchemaName(sd.getSchemaName());
    // Can not grant/revoke permissions from self
    if (grantees.contains(sd.getAuthorizationId())) {
        throw StandardException.newException(SQLState.AUTH_GRANT_REVOKE_NOT_ALLOWED, objectName.getFullTableName());
    }
    switch(objectType) {
        case TABLE_PRIVILEGES:
            // can't grant/revoke privileges on system tables
            if (sd.isSystemSchema()) {
                throw StandardException.newException(SQLState.AUTH_GRANT_REVOKE_NOT_ALLOWED, objectName.getFullTableName());
            }
            TableDescriptor td = getTableDescriptor(objectName.getTableName(), sd);
            if (td == null) {
                throw StandardException.newException(SQLState.LANG_TABLE_NOT_FOUND, objectName);
            }
            // a temporary table is created later with same name.
            if (isSessionSchema(sd.getSchemaName())) {
                throw StandardException.newException(SQLState.LANG_OPERATION_NOT_ALLOWED_ON_SESSION_SCHEMA_TABLES);
            }
            if (td.getTableType() != TableDescriptor.BASE_TABLE_TYPE && td.getTableType() != TableDescriptor.VIEW_TYPE) {
                throw StandardException.newException(SQLState.AUTH_GRANT_REVOKE_NOT_ALLOWED, objectName.getFullTableName());
            }
            specificPrivileges.bind(td, isGrant);
            dependencyProvider = td;
            break;
        case ROUTINE_PRIVILEGES:
            if (!sd.isSchemaWithGrantableRoutines()) {
                throw StandardException.newException(SQLState.AUTH_GRANT_REVOKE_NOT_ALLOWED, objectName.getFullTableName());
            }
            AliasDescriptor proc = null;
            List<AliasDescriptor> list = getDataDictionary().getRoutineList(sd.getUUID().toString(), objectName.getTableName(), routineDesignator.isFunction ? AliasInfo.ALIAS_NAME_SPACE_FUNCTION_AS_CHAR : AliasInfo.ALIAS_NAME_SPACE_PROCEDURE_AS_CHAR);
            if (routineDesignator.paramTypeList == null) {
                // No signature was specified. Make sure that there is exactly one routine with that name.
                if (list.size() > 1) {
                    throw StandardException.newException((routineDesignator.isFunction ? SQLState.LANG_AMBIGUOUS_FUNCTION_NAME : SQLState.LANG_AMBIGUOUS_PROCEDURE_NAME), objectName.getFullTableName());
                }
                if (list.size() != 1) {
                    if (routineDesignator.isFunction) {
                        throw StandardException.newException(SQLState.LANG_NO_SUCH_FUNCTION, objectName.getFullTableName());
                    } else {
                        throw StandardException.newException(SQLState.LANG_NO_SUCH_PROCEDURE, objectName.getFullTableName());
                    }
                }
                proc = list.get(0);
            } else {
                // The full signature was specified
                boolean found = false;
                for (int i = list.size() - 1; (!found) && i >= 0; i--) {
                    proc = list.get(i);
                    RoutineAliasInfo routineInfo = (RoutineAliasInfo) proc.getAliasInfo();
                    int parameterCount = routineInfo.getParameterCount();
                    if (parameterCount != routineDesignator.paramTypeList.size())
                        continue;
                    TypeDescriptor[] parameterTypes = routineInfo.getParameterTypes();
                    found = true;
                    for (int parmIdx = 0; parmIdx < parameterCount; parmIdx++) {
                        if (!parameterTypes[parmIdx].equals(routineDesignator.paramTypeList.get(parmIdx))) {
                            found = false;
                            break;
                        }
                    }
                }
                if (!found) {
                    // reconstruct the signature for the error message
                    StringBuilder sb = new StringBuilder(objectName.getFullTableName());
                    sb.append("(");
                    for (int i = 0; i < routineDesignator.paramTypeList.size(); i++) {
                        if (i > 0)
                            sb.append(",");
                        sb.append(routineDesignator.paramTypeList.get(i).toString());
                    }
                    throw StandardException.newException(SQLState.LANG_NO_SUCH_METHOD_ALIAS, sb.toString());
                }
            }
            routineDesignator.setAliasDescriptor(proc);
            dependencyProvider = proc;
            break;
        case AGGREGATE_PRIVILEGES:
            dependencyProvider = getDataDictionary().getAliasDescriptor(sd.getUUID().toString(), objectName.getTableName(), AliasInfo.ALIAS_NAME_SPACE_AGGREGATE_AS_CHAR);
            if (dependencyProvider == null) {
                throw StandardException.newException(SQLState.LANG_OBJECT_NOT_FOUND, "DERBY AGGREGATE", objectName.getFullTableName());
            }
            break;
        case SEQUENCE_PRIVILEGES:
            dependencyProvider = getDataDictionary().getSequenceDescriptor(sd, objectName.getTableName());
            if (dependencyProvider == null) {
                throw StandardException.newException(SQLState.LANG_OBJECT_NOT_FOUND, "SEQUENCE", objectName.getFullTableName());
            }
            break;
        case UDT_PRIVILEGES:
            dependencyProvider = getDataDictionary().getAliasDescriptor(sd.getUUID().toString(), objectName.getTableName(), AliasInfo.ALIAS_NAME_SPACE_UDT_AS_CHAR);
            if (dependencyProvider == null) {
                throw StandardException.newException(SQLState.LANG_OBJECT_NOT_FOUND, "TYPE", objectName.getFullTableName());
            }
            break;
        default:
            throw unimplementedFeature();
    }
    if (dependencyProvider != null) {
        if (dependencies.get(dependencyProvider) == null) {
            getCompilerContext().createDependency(dependencyProvider);
            dependencies.put(dependencyProvider, dependencyProvider);
        }
    }
    return this;
}
Also used : SchemaDescriptor(org.apache.derby.iapi.sql.dictionary.SchemaDescriptor) RoutineAliasInfo(org.apache.derby.catalog.types.RoutineAliasInfo) TypeDescriptor(org.apache.derby.catalog.TypeDescriptor) AliasDescriptor(org.apache.derby.iapi.sql.dictionary.AliasDescriptor) TableDescriptor(org.apache.derby.iapi.sql.dictionary.TableDescriptor)

Example 8 with TypeDescriptor

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

the class QueryTreeNode method bindRowMultiSet.

/**
 * Bind the UDTs in a table type.
 *
 * @param originalDTD A datatype: might be an unbound UDT and might not be
 *
 * @return The bound table type if originalDTD was an unbound table type; otherwise returns originalDTD.
 */
public DataTypeDescriptor bindRowMultiSet(DataTypeDescriptor originalDTD) throws StandardException {
    if (!originalDTD.getCatalogType().isRowMultiSet()) {
        return originalDTD;
    }
    RowMultiSetImpl originalMultiSet = (RowMultiSetImpl) originalDTD.getTypeId().getBaseTypeId();
    TypeDescriptor[] columnTypes = originalMultiSet.getTypes();
    int columnCount = columnTypes.length;
    for (int i = 0; i < columnCount; i++) {
        columnTypes[i] = bindUserCatalogType(columnTypes[i]);
    }
    originalMultiSet.setTypes(columnTypes);
    return originalDTD;
}
Also used : DataTypeDescriptor(org.apache.derby.iapi.types.DataTypeDescriptor) TypeDescriptor(org.apache.derby.catalog.TypeDescriptor) RowMultiSetImpl(org.apache.derby.catalog.types.RowMultiSetImpl)

Example 9 with TypeDescriptor

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

the class JavaToSQLValueNode method bindExpression.

/**
 * Bind this expression.  This means binding the sub-expressions,
 * as well as figuring out what the return type is for this expression.
 *
 * @param fromList		The FROM list for the query this
 *				expression is in, for binding columns.
 * @param subqueryList		The subquery list being built as we find
 *							SubqueryNodes
 * @param aggregates    The aggregate list being built as we find
 *                      AggregateNodes
 *
 * @return	The new top of the expression tree.
 *
 * @exception StandardException		Thrown on error
 */
@Override
ValueNode bindExpression(FromList fromList, SubqueryList subqueryList, List<AggregateNode> aggregates) throws StandardException {
    // method invocations are not allowed in ADD TABLE clauses.
    // And neither are field references.
    javaNode.checkReliability(this);
    /* Bind the expression under us */
    javaNode = javaNode.bindExpression(fromList, subqueryList, aggregates);
    if (javaNode instanceof StaticMethodCallNode) {
        AggregateNode agg = ((StaticMethodCallNode) javaNode).getResolvedAggregate();
        if (agg != null) {
            return agg.bindExpression(fromList, subqueryList, aggregates);
        }
    }
    DataTypeDescriptor dts = javaNode.getDataType();
    if (dts == null) {
        throw StandardException.newException(SQLState.LANG_NO_CORRESPONDING_S_Q_L_TYPE, javaNode.getJavaTypeName());
    }
    TypeDescriptor catalogType = dts.getCatalogType();
    if (catalogType.isRowMultiSet() || (catalogType.getTypeName().equals("java.sql.ResultSet"))) {
        throw StandardException.newException(SQLState.LANG_TABLE_FUNCTION_NOT_ALLOWED);
    }
    setType(dts);
    // RoutineAliasInfo to javaNode.
    if (dts.getTypeId().isStringTypeId()) {
        this.setCollationInfo(javaNode.getCollationType(), StringDataValue.COLLATION_DERIVATION_IMPLICIT);
    }
    return this;
}
Also used : TypeDescriptor(org.apache.derby.catalog.TypeDescriptor) DataTypeDescriptor(org.apache.derby.iapi.types.DataTypeDescriptor) DataTypeDescriptor(org.apache.derby.iapi.types.DataTypeDescriptor)

Example 10 with TypeDescriptor

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

the class NewInvocationNode method bindExpression.

/**
 * Bind this expression.  This means binding the sub-expressions,
 * as well as figuring out what the return type is for this expression.
 *
 * @param fromList		The FROM list for the query this
 *                      expression is in, for binding columns.
 * @param subqueryList  The subquery list being built as we find SubqueryNodes
 * @param aggregates    The aggregate list being built as we find AggregateNodes
 *
 * @return	Nothing
 *
 * @exception StandardException		Thrown on error
 */
JavaValueNode bindExpression(FromList fromList, SubqueryList subqueryList, List<AggregateNode> aggregates) throws StandardException {
    bindParameters(fromList, subqueryList, aggregates);
    verifyClassExist(javaClassName);
    /*
		** Get the parameter type names out of the parameters and put them
		** in an array.
		*/
    String[] parmTypeNames = getObjectSignature();
    boolean[] isParam = getIsParam();
    ClassInspector classInspector = getClassFactory().getClassInspector();
    /*
		** Find the matching constructor.
		*/
    try {
        /* First try with built-in types and mappings */
        method = classInspector.findPublicConstructor(javaClassName, parmTypeNames, null, isParam);
        /* If no match, then retry to match any possible combinations of
			 * object and primitive types.
			 */
        if (method == null) {
            String[] primParmTypeNames = getPrimitiveSignature(false);
            method = classInspector.findPublicConstructor(javaClassName, parmTypeNames, primParmTypeNames, isParam);
        }
    } catch (ClassNotFoundException e) {
        /*
			** If one of the classes couldn't be found, just act like the
			** method couldn't be found.  The error lists all the class names,
			** which should give the user enough info to diagnose the problem.
			*/
        method = null;
    }
    if (method == null) {
        /* Put the parameter type names into a single string */
        String parmTypes = "";
        for (int i = 0; i < parmTypeNames.length; i++) {
            if (i != 0)
                parmTypes += ", ";
            parmTypes += (parmTypeNames[i].length() != 0 ? parmTypeNames[i] : MessageService.getTextMessage(SQLState.LANG_UNTYPED));
        }
        throw StandardException.newException(SQLState.LANG_NO_CONSTRUCTOR_FOUND, javaClassName, parmTypes);
    }
    methodParameterTypes = classInspector.getParameterTypes(method);
    for (int i = 0; i < methodParameterTypes.length; i++) {
        if (ClassInspector.primitiveType(methodParameterTypes[i]))
            methodParms[i].castToPrimitive(true);
    }
    /* Set type info for any null parameters */
    if (someParametersAreNull()) {
        setNullParameterInfo(methodParameterTypes);
    }
    /* Constructor always returns an object of type javaClassName */
    if (SanityManager.DEBUG) {
        SanityManager.ASSERT(javaClassName.equals(classInspector.getType(method)), "Constructor is wrong type, expected " + javaClassName + " actual is " + classInspector.getType(method));
    }
    setJavaTypeName(javaClassName);
    if (routineInfo != null) {
        TypeDescriptor returnType = routineInfo.getReturnType();
        if (returnType != null) {
            setCollationType(returnType.getCollationType());
        }
    }
    return this;
}
Also used : TypeDescriptor(org.apache.derby.catalog.TypeDescriptor) ClassInspector(org.apache.derby.iapi.services.loader.ClassInspector)

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