Package org.apache.derby.iapi.sql.compile

Examples of org.apache.derby.iapi.sql.compile.NodeFactory


  public ValueNode putAndsOnTop()
          throws StandardException
  {
    BinaryComparisonOperatorNode    equalsNode;
    BooleanConstantNode  trueNode;
    NodeFactory    nodeFactory = getNodeFactory();
    ValueNode    andNode;

        trueNode = (BooleanConstantNode) nodeFactory.getNode(
                    C_NodeTypes.BOOLEAN_CONSTANT_NODE,
                    Boolean.TRUE,
                    getContextManager());
    equalsNode = (BinaryComparisonOperatorNode)
            nodeFactory.getNode(
                    C_NodeTypes.BINARY_EQUALS_OPERATOR_NODE,
                    this,
                    trueNode,
                    getContextManager());
    /* Set type info for the operator node */
    equalsNode.bindComparisonOperator();
    andNode = (ValueNode) nodeFactory.getNode(
                  C_NodeTypes.AND_NODE,
                  equalsNode,
                  trueNode,
                  getContextManager());
    ((AndNode) andNode).postBindFixup();
View Full Code Here


     *    leftO < rightOList.elementAt(0) or leftO > rightOList.elementAt(1)
     * NOTE - We do the conversion here since ORs will eventually be
     * optimizable and there's no benefit for the optimizer to see NOT BETWEEN
     */

    NodeFactory nodeFactory = getNodeFactory();
    ContextManager cm = getContextManager();

    /* leftO < rightOList.elementAt(0) */
    leftBCO = (BinaryComparisonOperatorNode)
          nodeFactory.getNode(
                  C_NodeTypes.BINARY_LESS_THAN_OPERATOR_NODE,
                  leftOperand,
                   rightOperandList.elementAt(0),
                  cm);
    /* Set type info for the operator node */
    leftBCO.bindComparisonOperator();

    /* leftO > rightOList.elementAt(1) */
    rightBCO = (BinaryComparisonOperatorNode)
          nodeFactory.getNode(
                C_NodeTypes.BINARY_GREATER_THAN_OPERATOR_NODE,
                leftOperand,
                rightOperandList.elementAt(1),
                cm);
    /* Set type info for the operator node */
    rightBCO.bindComparisonOperator();

    /* Create and return the OR */
    newOr = (OrNode) nodeFactory.getNode(
                        C_NodeTypes.OR_NODE,
                        leftBCO,
                        rightBCO,
                        cm);
    newOr.postBindFixup();
View Full Code Here

     *        >=    AND
     *           /   \
     *          <=    TRUE
     */

    NodeFactory nodeFactory = getNodeFactory();
    ContextManager cm = getContextManager();

        QueryTreeNode trueNode = nodeFactory.getNode(
                      C_NodeTypes.BOOLEAN_CONSTANT_NODE,
                      Boolean.TRUE,
                      cm);

    /* Create the AND <= */
    BinaryComparisonOperatorNode lessEqual =
      (BinaryComparisonOperatorNode) nodeFactory.getNode(
            C_NodeTypes.BINARY_LESS_EQUALS_OPERATOR_NODE,
            leftClone1,
            rightOperandList.elementAt(1),
            cm);

    /* Set type info for the operator node */
    lessEqual.bindComparisonOperator();

    /* Create the AND */
    AndNode newAnd = (AndNode) nodeFactory.getNode(
                        C_NodeTypes.AND_NODE,
                        lessEqual,
                        trueNode,
                        cm);
    newAnd.postBindFixup();

    /* Create the AND >= */
    BinaryComparisonOperatorNode greaterEqual =
      (BinaryComparisonOperatorNode) nodeFactory.getNode(
          C_NodeTypes.BINARY_GREATER_EQUALS_OPERATOR_NODE,
          leftOperand,
          rightOperandList.elementAt(0),
          cm);

    /* Set type info for the operator node */
    greaterEqual.bindComparisonOperator();

    /* Create the AND */
    newAnd = (AndNode) nodeFactory.getNode(
                        C_NodeTypes.AND_NODE,
                        greaterEqual,
                        newAnd,
                        cm);
    newAnd.postBindFixup();
View Full Code Here

     *    leftO between rightOList.elementAt(0) and rightOList.elementAt(1)
     * to:
     *    leftO >= rightOList.elementAt(0) and leftO <= rightOList.elementAt(1)
     */

    NodeFactory nodeFactory = getNodeFactory();
    ContextManager cm = getContextManager();

    /* leftO >= rightOList.elementAt(0) */
    leftBCO = (BinaryComparisonOperatorNode)
          nodeFactory.getNode(
              C_NodeTypes.BINARY_GREATER_EQUALS_OPERATOR_NODE,
              leftOperand,
              rightOperandList.elementAt(0),
              cm);
    /* Set type info for the operator node */
    leftBCO.bindComparisonOperator();

    /* leftO <= rightOList.elementAt(1) */
    rightBCO = (BinaryComparisonOperatorNode)
          nodeFactory.getNode(
            C_NodeTypes.BINARY_LESS_EQUALS_OPERATOR_NODE,
            leftOperand,
            rightOperandList.elementAt(1),
            cm);
    /* Set type info for the operator node */
    rightBCO.bindComparisonOperator();

    /* Create and return the AND */
    newAnd = (AndNode) nodeFactory.getNode(
                        C_NodeTypes.AND_NODE,
                        leftBCO,
                        rightBCO,
                        cm);
    newAnd.postBindFixup();
View Full Code Here

  public  ConstantNode getNullNode(TypeId typeId,
      ContextManager cm)
    throws StandardException
  {
    QueryTreeNode constantNode = null;
    NodeFactory nf = getNodeFactory();

    switch (typeId.getJDBCTypeId())
    {
      case Types.VARCHAR:
      constantNode =  nf.getNode(
                    C_NodeTypes.VARCHAR_CONSTANT_NODE,
                    typeId,
                    cm);
      break;

      case Types.CHAR:
      constantNode = nf.getNode(
                    C_NodeTypes.CHAR_CONSTANT_NODE,
                    typeId,
                    cm);
      break;

      case Types.TINYINT:
      constantNode = nf.getNode(
                    C_NodeTypes.TINYINT_CONSTANT_NODE,
                    typeId,
                    cm);
      break;

      case Types.SMALLINT:
      constantNode = nf.getNode(
                    C_NodeTypes.SMALLINT_CONSTANT_NODE,
                    typeId,
                    cm);
      break;

      case Types.INTEGER:
      constantNode = nf.getNode(
                    C_NodeTypes.INT_CONSTANT_NODE,
                    typeId,
                    cm);
      break;

      case Types.BIGINT:
      constantNode = nf.getNode(
                    C_NodeTypes.LONGINT_CONSTANT_NODE,
                    typeId,
                    cm);
      break;

      case Types.REAL:
      constantNode = nf.getNode(
                    C_NodeTypes.FLOAT_CONSTANT_NODE,
                    typeId,
                    cm);
      break;

      case Types.DOUBLE:
      constantNode = nf.getNode(
                    C_NodeTypes.DOUBLE_CONSTANT_NODE,
                    typeId,
                    cm);
      break;

      case Types.NUMERIC:
      case Types.DECIMAL:
      constantNode = nf.getNode(
                    C_NodeTypes.DECIMAL_CONSTANT_NODE,
                    typeId,
                    cm);
      break;

      case Types.DATE:
      case Types.TIME:
      case Types.TIMESTAMP:
      constantNode = nf.getNode(
                    C_NodeTypes.USERTYPE_CONSTANT_NODE,
                    typeId,
                    cm);
      break;

      case Types.BINARY:
      constantNode = nf.getNode(
                    C_NodeTypes.BIT_CONSTANT_NODE,
                    typeId,
                    cm);
      break;

      case Types.VARBINARY:
      constantNode = nf.getNode(
                    C_NodeTypes.VARBIT_CONSTANT_NODE,
                    typeId,
                    cm);
      break;

      case Types.LONGVARCHAR:
      constantNode = nf.getNode(
                    C_NodeTypes.LONGVARCHAR_CONSTANT_NODE,
                    typeId,
                    cm);
      break;

      case Types.CLOB:
      constantNode = nf.getNode(
                    C_NodeTypes.CLOB_CONSTANT_NODE,
                    typeId,
                    cm);
      break;

      case Types.LONGVARBINARY:
      constantNode = nf.getNode(
                    C_NodeTypes.LONGVARBIT_CONSTANT_NODE,
                    typeId,
                    cm);
      break;

      case Types.BLOB:
      constantNode = nf.getNode(
                    C_NodeTypes.BLOB_CONSTANT_NODE,
                    typeId,
                    cm);
      break;

      case StoredFormatIds.XML_TYPE_ID:
      constantNode = nf.getNode(
                    C_NodeTypes.XML_CONSTANT_NODE,
                    typeId,
                    cm);
      break;

      default:
      if (typeId.getSQLTypeName().equals("BOOLEAN"))
      {
        constantNode = nf.getNode(
                    C_NodeTypes.BOOLEAN_CONSTANT_NODE,
                    typeId,
                    cm);
      }
      else if (typeId.userType())
      {
        constantNode = nf.getNode(
                    C_NodeTypes.USERTYPE_CONSTANT_NODE,
                    typeId,
                    cm);
      }
      else
View Full Code Here

  public  ConstantNode getNullNode(TypeId typeId,
      ContextManager cm)
    throws StandardException
  {
    QueryTreeNode constantNode = null;
    NodeFactory nf = getNodeFactory();

    switch (typeId.getJDBCTypeId())
    {
      case Types.VARCHAR:
      constantNode =  nf.getNode(
                    C_NodeTypes.VARCHAR_CONSTANT_NODE,
                    typeId,
                    cm);
      break;

      case Types.CHAR:
      constantNode = nf.getNode(
                    C_NodeTypes.CHAR_CONSTANT_NODE,
                    typeId,
                    cm);
      break;

      case Types.TINYINT:
      constantNode = nf.getNode(
                    C_NodeTypes.TINYINT_CONSTANT_NODE,
                    typeId,
                    cm);
      break;

      case Types.SMALLINT:
      constantNode = nf.getNode(
                    C_NodeTypes.SMALLINT_CONSTANT_NODE,
                    typeId,
                    cm);
      break;

      case Types.INTEGER:
      constantNode = nf.getNode(
                    C_NodeTypes.INT_CONSTANT_NODE,
                    typeId,
                    cm);
      break;

      case Types.BIGINT:
      constantNode = nf.getNode(
                    C_NodeTypes.LONGINT_CONSTANT_NODE,
                    typeId,
                    cm);
      break;

      case Types.REAL:
      constantNode = nf.getNode(
                    C_NodeTypes.FLOAT_CONSTANT_NODE,
                    typeId,
                    cm);
      break;

      case Types.DOUBLE:
      constantNode = nf.getNode(
                    C_NodeTypes.DOUBLE_CONSTANT_NODE,
                    typeId,
                    cm);
      break;

      case Types.NUMERIC:
      case Types.DECIMAL:
      constantNode = nf.getNode(
                    C_NodeTypes.DECIMAL_CONSTANT_NODE,
                    typeId,
                    cm);
      break;

      case Types.DATE:
      case Types.TIME:
      case Types.TIMESTAMP:
      constantNode = nf.getNode(
                    C_NodeTypes.USERTYPE_CONSTANT_NODE,
                    typeId,
                    cm);
      break;

      case Types.BINARY:
      constantNode = nf.getNode(
                    C_NodeTypes.BIT_CONSTANT_NODE,
                    typeId,
                    cm);
      break;

      case Types.VARBINARY:
      constantNode = nf.getNode(
                    C_NodeTypes.VARBIT_CONSTANT_NODE,
                    typeId,
                    cm);
      break;

      case Types.LONGVARCHAR:
      constantNode = nf.getNode(
                    C_NodeTypes.LONGVARCHAR_CONSTANT_NODE,
                    typeId,
                    cm);
      break;

      case Types.CLOB:
      constantNode = nf.getNode(
                    C_NodeTypes.CLOB_CONSTANT_NODE,
                    typeId,
                    cm);
      break;

      case Types.LONGVARBINARY:
      constantNode = nf.getNode(
                    C_NodeTypes.LONGVARBIT_CONSTANT_NODE,
                    typeId,
                    cm);
      break;

      case Types.BLOB:
      constantNode = nf.getNode(
                    C_NodeTypes.BLOB_CONSTANT_NODE,
                    typeId,
                    cm);
      break;

      case StoredFormatIds.XML_TYPE_ID:
      constantNode = nf.getNode(
                    C_NodeTypes.XML_CONSTANT_NODE,
                    typeId,
                    cm);
      break;

      default:
      if (typeId.getSQLTypeName().equals("BOOLEAN"))
      {
        constantNode = nf.getNode(
                    C_NodeTypes.BOOLEAN_CONSTANT_NODE,
                    typeId,
                    cm);
      }
      else if (typeId.userType())
      {
        constantNode = nf.getNode(
                    C_NodeTypes.USERTYPE_CONSTANT_NODE,
                    typeId,
                    cm);
      }
      else
View Full Code Here

    String    columnName
  )
    throws StandardException
  {
    ContextManager  cm = getContextManager();
    NodeFactory    nodeFactory = getNodeFactory();

    ResultColumn  rc = (ResultColumn) nodeFactory.getNode
      (
        C_NodeTypes.RESULT_COLUMN,
        null,
        nodeFactory.getNode
        (
          C_NodeTypes.COLUMN_REFERENCE,
          columnName,
          tableName,
          cm
View Full Code Here

        SelectNode resultSet;

        tableName = new TableName();
        tableName.init(schemaName , targetTableName);

        NodeFactory nodeFactory = getNodeFactory();
        FromList   fromList = (FromList) nodeFactory.getNode(C_NodeTypes.FROM_LIST, getContextManager());
        fromTable = (FromTable) nodeFactory.getNode(
                                                    C_NodeTypes.FROM_BASE_TABLE,
                                                    tableName,
                                                    null,
                                                    ReuseFactory.getInteger(FromBaseTable.DELETE),
                                                    null,
                                                    getContextManager());

    //we would like to use references index & table scan instead of
    //what optimizer says for the dependent table scan.
    Properties targetProperties = new FormatableProperties();
    targetProperties.put("index", "null");
    ((FromBaseTable) fromTable).setTableProperties(targetProperties);

        fromList.addFromTable(fromTable);
        resultSet = (SelectNode) nodeFactory.getNode(
                                                     C_NodeTypes.SELECT_NODE,
                                                     null,
                                                     null,   /* AGGREGATE list */
                                                     fromList, /* FROM list */
                                                     whereClause, /* WHERE clause */
                                                     null, /* GROUP BY list */
                                                     getContextManager());

        retval =(QueryTreeNode) nodeFactory.getNode(
                                                    C_NodeTypes.DELETE_NODE,
                                                    tableName,
                                                    resultSet,
                                                    getContextManager());

View Full Code Here

        SelectNode resultSet;

        tableName = new TableName();
        tableName.init(schemaName , targetTableName);

        NodeFactory nodeFactory = getNodeFactory();
        FromList   fromList = (FromList) nodeFactory.getNode(C_NodeTypes.FROM_LIST, getContextManager());
        fromTable = (FromTable) nodeFactory.getNode(
                                                    C_NodeTypes.FROM_BASE_TABLE,
                                                    tableName,
                                                    null,
                                                    ReuseFactory.getInteger(FromBaseTable.DELETE),
                                                    null,
                                                    getContextManager());


    //we would like to use references index & table scan instead of
    //what optimizer says for the dependent table scan.
    Properties targetProperties = new FormatableProperties();
    targetProperties.put("index", "null");
    ((FromBaseTable) fromTable).setTableProperties(targetProperties);

        fromList.addFromTable(fromTable);

    resultSet = (SelectNode) nodeFactory.getNode(
                                                     C_NodeTypes.SELECT_NODE,
                                                     getSetClause(tableName, cdl),
                                                     null,   /* AGGREGATE list */
                                                     fromList, /* FROM list */
                                                     whereClause, /* WHERE clause */
                                                     null, /* GROUP BY list */
                                                     getContextManager());

        retval =(QueryTreeNode) nodeFactory.getNode(
                                                    C_NodeTypes.UPDATE_NODE,
                                                    tableName,
                                                    resultSet,
                                                    getContextManager());

View Full Code Here

    throws StandardException
  {
    ResultColumn resultColumn;
    ValueNode   valueNode;

    NodeFactory nodeFactory = getNodeFactory();
    ResultColumnList  columnList = (ResultColumnList) nodeFactory.getNode(
                        C_NodeTypes.RESULT_COLUMN_LIST,
                        getContextManager());

    valueNode =  (ValueNode) nodeFactory.getNode(C_NodeTypes.UNTYPED_NULL_CONSTANT_NODE,
                               getContextManager());
    for(int index =0 ; index < cdl.size() ; index++)
    {
      ColumnDescriptor cd = (ColumnDescriptor) cdl.elementAt(index);
      //only columns that are nullable need to be set to 'null' for ON
      //DELETE SET NULL
      if((cd.getType()).isNullable())
      {
        resultColumn = (ResultColumn) nodeFactory.getNode(
                         C_NodeTypes.RESULT_COLUMN,
                    cd,
                    valueNode,
                    getContextManager());
View Full Code Here

TOP

Related Classes of org.apache.derby.iapi.sql.compile.NodeFactory

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.