Package org.apache.derby.catalog

Examples of org.apache.derby.catalog.TypeDescriptor


/*
* <A NAME="functionReturnDataType">functionReturnDataType</A>
*/
  final public TypeDescriptor functionReturnDataType() throws ParseException, StandardException {
    TypeDescriptor      typeDescriptor;
    if (jj_2_63(1)) {
      typeDescriptor = catalogType();
    } else {
      switch (jj_nt.kind) {
      case TABLE:
View Full Code Here


/*
* <A NAME="parameterTypeList">parameterTypeList</A>
*/
  final public List parameterTypeList() throws ParseException, StandardException {
    ArrayList list = new ArrayList();
    TypeDescriptor type;
    if (jj_2_73(1)) {
      type = catalogType();
            list.add(type);
      label_42:
      while (true) {
View Full Code Here

       
        AliasDescriptor ad = DataDictionaryImpl.SYSFUN_AD[f];
        if (ad == null)
        {
          // details[1] Return type
          TypeDescriptor rt =
            DataTypeDescriptor.getBuiltInDataTypeDescriptor(details[1]);

          // details[4] - zero or single argument type
          String paramType = details[4];
          TypeDescriptor[] pt;
View Full Code Here

    TransactionController   tc)
        throws StandardException
    {
        // Safe to re-use a TypeDescriptor here as they are
        // not modified during the creation of the routine
        TypeDescriptor varchar128 =
            DataTypeDescriptor.getBuiltInDataTypeDescriptor(
                    Types.VARCHAR, 128);

        UUID  sysUtilUUID = getSystemUtilSchemaDescriptor().getUUID();
        /* SYSCS_EXPORT_TABLE_LOBS_TO_EXTFILE(IN SCHEMANAME  VARCHAR(128),
View Full Code Here

    Compare if two TypeDescriptors are exactly the same
    @param object the dataTypeDescriptor to compare to.
    */
  public boolean equals(Object object)
  {
    TypeDescriptor typeDescriptor = (TypeDescriptor)object;

    if(!this.getTypeName().equals(typeDescriptor.getTypeName()) ||
       this.precision != typeDescriptor.getPrecision() ||
       this.scale != typeDescriptor.getScale() ||
       this.isNullable != typeDescriptor.isNullable() ||
       this.maximumWidth != typeDescriptor.getMaximumWidth())
       return false;
      else
      return true;
  }              
View Full Code Here

  public void checkUserType(TableDescriptor td)
    throws StandardException
  {
    ColumnDescriptor cd;
    TypeDescriptor oldType;
    DataTypeDescriptor newType = dataTypeServices;
    TypeId oldTypeId;
    TypeId newTypeId;

    if (getNodeType() != C_NodeTypes.MODIFY_COLUMN_TYPE_NODE)
      return;        // nothing to do if user not changing length

    cd = td.getColumnDescriptor(name);
    if (cd == null)
    {
      throw StandardException.newException(
        SQLState.LANG_COLUMN_NOT_FOUND_IN_TABLE, name, td.getName());
    }
   
    oldType = cd.getType();
    oldTypeId = cd.getType().getTypeId();
    newTypeId = dataTypeServices.getTypeId();
    newType.setNullability(oldType.isNullable());

    // can't change types yet.
    if (!(oldTypeId.equals(newTypeId)))
    {
      throw StandardException.newException(
           SQLState.LANG_MODIFY_COLUMN_CHANGE_TYPE, name);
    }     
   
    // can only alter the length of varchar, nvarchar, bitvarying columns
    String typeName = dataTypeServices.getTypeName();
    if (!(typeName.equals(TypeId.NATIONAL_VARCHAR_NAME)) &&
      !(typeName.equals(TypeId.VARCHAR_NAME)) &&
      !(typeName.equals(TypeId.VARBIT_NAME)))
    {
      throw StandardException.newException(
             SQLState.LANG_MODIFY_COLUMN_INVALID_TYPE);
    }
   
    // cannot decrease the length of a column
    if (newType.getMaximumWidth() < oldType.getMaximumWidth())
    {
      throw StandardException.newException(
             SQLState.LANG_MODIFY_COLUMN_INVALID_LENGTH, name);
    }
  }
View Full Code Here

    Class        inputClass = null;
    String        inputTypeName = null;
    Class        inputInterfaceClass = null;
    String        inputInterfaceName = null;
    DataTypeDescriptor   dts = null;
    TypeDescriptor     resultType = null;
    ClassFactory    cf;

    cf = getClassFactory();
    classInspector = cf.getClassInspector();

    instantiateAggDef();

    /* Add ourselves to the aggregateVector before we do anything else */
    aggregateVector.addElement(this);

    super.bindExpression(
        fromList, subqueryList,
        aggregateVector);

    if (operand != null)
    {
      /*
      ** Make sure that we don't have an aggregate
      ** IMMEDIATELY below us.  Don't search below
      ** any ResultSetNodes.
      */
      HasNodeVisitor visitor = new HasNodeVisitor(this.getClass(), ResultSetNode.class);
      operand.accept(visitor);
      if (visitor.hasNode())
      {
        throw StandardException.newException(SQLState.LANG_USER_AGGREGATE_CONTAINS_AGGREGATE,
            aggregateName);
      }

      /*
      ** Check the type of the operand.  Make sure that the user
      ** defined aggregate can handle the operand datatype.
      */
      dts = operand.getTypeServices();

      /* Convert count(nonNullableColumn) to count(*)  */
      if (uad instanceof CountAggregateDefinition &&
        !dts.isNullable())
      {
        setOperator(aggregateName);
        setMethodName(aggregateName);
      }

      /*
      ** If we have a distinct, then the value expression
      ** MUST implement Orderable because we are going
      ** to process it using it as part of a sort.
      */
      if (distinct)
      {
        /*
        ** For now, we check to see if orderable() returns
        ** true for this type.  In the future we may need
        ** to check to see if the type implements Orderable
        **
        */
        if (!operand.getTypeId().orderable(cf))
        {
          throw StandardException.newException(SQLState.LANG_COLUMN_NOT_ORDERABLE_DURING_EXECUTION,
              dts.getTypeId().getSQLTypeName());
        }

      }

      /*
      ** Don't allow an untyped null
      */
      if (operand instanceof UntypedNullConstantNode)
      {
        throw StandardException.newException(SQLState.LANG_USER_AGGREGATE_BAD_TYPE_NULL, aggregateName);
      }
    }

    /*
    ** Ask the aggregate definition whether it can handle
     ** the input datatype.  If an exception is thrown,
    ** barf.
     */
    try
    {
      aggregatorClassName = new StringBuffer();
      resultType = uad.getAggregator(dts, aggregatorClassName);
    } catch (Exception e)
    {
      //RESOLVE: would be a good idea to add some additional text to
      // this error, like during getResultDataType on aggregate x
      // maybe enhance this error everywhere (seems like execution
      // should also add some text, at the very least saying during
      // execution.  see Compiltion/Generator/UserExpressionBuilder.java
      throw StandardException.unexpectedUserException(e);
    }

    if (resultType == null)
    {
      throw StandardException.newException(SQLState.LANG_USER_AGGREGATE_BAD_TYPE,
            aggregateName,
            operand.getTypeId().getSQLTypeName());
    }

    checkAggregatorClassName(aggregatorClassName.toString());

    /*
    ** Try for a built in type matching the
    ** type name. 
    */
    TypeId compTypeId = TypeId.getBuiltInTypeId(resultType.getTypeName());
    /*
    ** If not built in, it is probably a java type.
    ** Get the sql type descriptor for that. 
    */
    if (compTypeId == null)
    {
      compTypeId = TypeId.getSQLTypeForJavaType(resultType.getTypeName());
    }

    /*
    ** Now set the type.  Get a new descriptor
    ** in case the user returned the same descriptor
    ** as was passed in.
    */
    setType(new DataTypeDescriptor(
              compTypeId,
              resultType.getPrecision(),
              resultType.getScale(),
              resultType.isNullable(),
              resultType.getMaximumWidth()
            )
        );

    return this;
  }
View Full Code Here

    if (routineInfo != null)
    {
      if (methodParms != null)
        optimizeDomainValueConversion();
     
      TypeDescriptor returnType = routineInfo.getReturnType();
      if (returnType != null)
      {
        TypeId returnTypeId = TypeId.getBuiltInTypeId(returnType.getJDBCTypeId());

        if (returnTypeId.variableLength()) {
          // Cast the return using a cast node, but have to go
          // into the SQL domain, and back to the Java domain.

          DataTypeDescriptor returnValueDtd = new DataTypeDescriptor(
                returnTypeId,
                returnType.getPrecision(),
                returnType.getScale(),
                returnType.isNullable(),
                returnType.getMaximumWidth()
              );


          ValueNode returnValueToSQL = (ValueNode) getNodeFactory().getNode(
                C_NodeTypes.JAVA_TO_SQL_VALUE_NODE,
View Full Code Here

      signature = new JSQLType[sigParameterCount];
      for (int p = 0; p < parameterCount; p++) {

        // find the declared type.

        TypeDescriptor td = parameterTypes[p];

        TypeId typeId = TypeId.getBuiltInTypeId(td.getJDBCTypeId());

        TypeId parameterTypeId = typeId;


        // if it's an OUT or INOUT parameter we need an array.
        int parameterMode = routineInfo.getParameterModes()[p];

        if (parameterMode != JDBC30Translation.PARAMETER_MODE_IN) {

          String arrayType;
          switch (typeId.getJDBCTypeId()) {
            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, false);
        }

        // 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);

        // check parameter is a ? node for INOUT and OUT parameters.

        ValueNode sqlParamNode = null;

        if (methodParms[p] instanceof SQLToJavaValueNode) {
          SQLToJavaValueNode sql2j = (SQLToJavaValueNode) methodParms[p];
          sqlParamNode = sql2j.getSQLValueNode();
        }
        else
        {
        }

        boolean isParameterMarker = true;
        if ((sqlParamNode == null) || !sqlParamNode.requiresTypeFromContext())
        {
          if (parameterMode != JDBC30Translation.PARAMETER_MODE_IN) {
          
            throw StandardException.newException(SQLState.LANG_DB2_PARAMETER_NEEDS_MARKER,
              RoutineAliasInfo.parameterMode(parameterMode),
              routineInfo.getParameterNames()[p]);
          }
          isParameterMarker = false;
        }
        else
        {
          if (applicationParameterNumbers == null)
            applicationParameterNumbers = new int[parameterCount];
            if (sqlParamNode instanceof UnaryOperatorNode) {
              ParameterNode pn = ((UnaryOperatorNode)sqlParamNode).getParameterOperand();
              applicationParameterNumbers[p] = pn.getParameterNumber();
            } else
            applicationParameterNumbers[p] = ((ParameterNode) sqlParamNode).getParameterNumber();
        }

        // this is the SQL type of the procedure parameter.
        DataTypeDescriptor paramdtd = new DataTypeDescriptor(
          parameterTypeId,
          td.getPrecision(),
          td.getScale(),
          td.isNullable(),
          td.getMaximumWidth()
        );

        boolean needCast = false;
        if (!isParameterMarker)
        {
View Full Code Here

    if (routineInfo != null)
    {
      if (methodParms != null)
        optimizeDomainValueConversion();
     
      TypeDescriptor returnType = routineInfo.getReturnType();
      if (returnType != null)
      {
        TypeId returnTypeId = TypeId.getBuiltInTypeId(returnType.getJDBCTypeId());

        if (returnTypeId.variableLength()) {
          // Cast the return using a cast node, but have to go
          // into the SQL domain, and back to the Java domain.

          DataTypeDescriptor returnValueDtd = new DataTypeDescriptor(
                returnTypeId,
                returnType.getPrecision(),
                returnType.getScale(),
                returnType.isNullable(),
                returnType.getMaximumWidth()
              );


          ValueNode returnValueToSQL = (ValueNode) getNodeFactory().getNode(
                C_NodeTypes.JAVA_TO_SQL_VALUE_NODE,
View Full Code Here

TOP

Related Classes of org.apache.derby.catalog.TypeDescriptor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.