Package org.apache.derby.iapi.sql

Examples of org.apache.derby.iapi.sql.ResultSet


                    outerNode.appendChild( arrayNode );

                    int arrayLength = Array.getLength( fieldContents );
                    for ( int i = 0; i < arrayLength; i++ )
                    {
                        ResultSet   cellRS = (ResultSet) Array.get( fieldContents, i );

                        if ( cellRS != null )
                        {
                            Element cellNode = cellRS.toXML( arrayNode, "cell" );
                            cellNode.setAttribute( "cellNumber", Integer.toString( i ) );
                        }
                    }
                }
                else
                {
                    ResultSet   innerRS = (ResultSet) fieldContents;

                    innerRS.toXML( outerNode, field.getName() );
                }
            }   // end if fieldContents is not null
        }   // end loop through fields

        return outerNode;


                    continue;
                }

                 if (cursorName.equals(executingCursorName)) {

                    ResultSet rs = a.getResultSet();
                    if (rs == null)
                        continue;

                     // if the result set is closed, the the cursor doesn't exist
                     if (rs.isClosed()) {                  
                        continue;
                     }

                    return (CursorActivation)a;
                 }

            if (!a.getResultSetHoldability())
            {
                continue;
            }

            ResultSet rs = ((CursorActivation) a).getResultSet();

            /* is there an open result set? */
            if ((rs != null) && !rs.isClosed() && rs.returnsRows())
            {
                seenOpenResultSets = true;
                break;
            }
        }

        if (!seenOpenResultSets)
            return(true);

        // There may be open ResultSet's that are yet to be garbage collected
        // let's try and force these out rather than throw an error
        System.gc();
        System.runFinalization();


        /* For every activation */
        for (int i = acts.size() - 1; i >= 0; i--) {
               
            Activation a = acts.get(i);

            if (SanityManager.DEBUG)
            {
                SanityManager.ASSERT(a instanceof CursorActivation, "a is not a CursorActivation");
            }

            if (!a.isInUse())
            {
                continue;
            }

            if (!a.getResultSetHoldability())
            {
                continue;
            }

            ResultSet rs = ((CursorActivation) a).getResultSet();

            /* is there an open held result set? */
            if ((rs != null) && !rs.isClosed() && rs.returnsRows())
            {
                return(false);
            }
        }
        return(true);

                continue;
            }
           
            /* for this prepared statement */
            if (pStmt == a.getPreparedStatement()) {
                ResultSet rs = a.getResultSet();

                /* is there an open result set? */
                if (rs != null && ! rs.isClosed())
                {
                    if (!rs.returnsRows())
                        continue;
                    seenOpenResultSets = true;
                    break;
                }
               
            }
        }

        if (!seenOpenResultSets)
            return false;

        // There may be open ResultSet's that are yet to be garbage collected
        // let's try and force these out rather than throw an error
        System.gc();
        System.runFinalization();


        /* For every activation */
        // synchronize on acts as other threads may be closing activations
        // in this list, thus invalidating the Enumeration
        for (int i = acts.size() - 1; i >= 0; i--) {
               
            Activation a = acts.get(i);

            if (!a.isInUse())
            {
                continue;
            }

            /* for this prepared statement */
            if (pStmt == a.getPreparedStatement()) {
                ResultSet rs = a.getResultSet();

                /* is there an open result set? */
                if (rs != null && ! rs.isClosed())
                {
                    if ((provider != null) && rs.returnsRows()) {
                    DependencyManager dmgr = getDataDictionary().getDependencyManager();

                    throw StandardException.newException(SQLState.LANG_CANT_INVALIDATE_OPEN_RESULT_SET,
                                    dmgr.getActionString(action),
                                    provider.getObjectName());

            //Determine if the activation has a resultset and if that resultset
            //returns rows. For such an activation, we need to take special
            //actions during commit and rollback as explained in the comments
            //below.
            ResultSet activationResultSet = a.getResultSet();
            boolean resultsetReturnsRows =
                    activationResultSet != null &&
                    activationResultSet.returnsRows();

            if (forRollback) {
                if (resultsetReturnsRows)
                    //Since we are dealing with rollback, we need to reset
                    //the activation no matter what the holdability might
                    //be provided that resultset returns rows. An example
                    //where we do not want to close a resultset that does
                    //not return rows would be a java procedure which has
                    //user invoked rollback inside of it. That rollback
                    //should not reset the activation associated with
                    //the call to java procedure because that activation
                    //is still being used.
                    a.reset();
                // Only invalidate statements if we performed DDL.
                if (dataDictionaryInWriteMode()) {
                    ExecPreparedStatement ps = a.getPreparedStatement();
                    if (ps != null) {
                        ps.makeInvalid(DependencyManager.ROLLBACK, this);
                    }
                }
            } else {
                //We are dealing with commit here.
                if (resultsetReturnsRows){
                    if (a.getResultSetHoldability() == false)
                        //Close result sets that return rows and are not held
                        //across commit. This is to implement closing JDBC
                        //result sets that are CLOSE_CURSOR_ON_COMMIT at commit
                        //time.
                        activationResultSet.close();
                    else
                        //Clear the current row of the result sets that return
                        //rows and are held across commit. This is to implement
                        //keeping JDBC result sets open that are
                        //HOLD_CURSORS_OVER_COMMIT at commit time and marking
                        //the resultset to be not on a valid row position. The
                        //user will need to reposition within the resultset
                        //before doing any row operations.
                        activationResultSet.clearCurrentRow();                         
                }
                a.clearHeapConglomerateController();
            }
        }
    }

    checkStmt.append(td.getQualifiedName());
    checkStmt.append(" WHERE NOT(");
    checkStmt.append(constraintText);
    checkStmt.append(")");
 
    ResultSet rs = null;
    try
    {
      PreparedStatement ps = lcc.prepareInternalStatement(checkStmt.toString());

            // This is a substatement; for now, we do not set any timeout
            // for it. We might change this behaviour later, by linking
            // timeout to its parent statement's timeout settings.
      rs = ps.executeSubStatement(lcc, false, 0L);
      ExecRow row = rs.getNextRow();
      if (SanityManager.DEBUG)
      {
        if (row == null)
        {
          SanityManager.THROWASSERT("did not get any rows back from query: "+checkStmt.toString());
        }
      }

      Number value = ((Number)((NumberDataValue)row.getRowArray()[0]).getObject());
      /*
      ** Value may be null if there are no rows in the
      ** table.
      */
      if ((value != null) && (value.longValue() != 0))
      { 
                // The query yielded a valid value > 0, so we must conclude the
                // check constraint is violated.
                if (isCheckConstraint) {
                    if (isInitiallyDeferred) {
                        // Remember the violation
                        List<UUID> violatingConstraints = new ArrayList<UUID>();
                        violatingConstraints.add(constraintId);

                        // FIXME: We don't know the row locations of the
                        // violating rows, so for now, just pretend we know one,
                        // then invalidate the row location information forcing
                        // full table check at validation time
                        CheckInfo newCi[] = new CheckInfo[1];
                        DeferredConstraintsMemory.rememberCheckViolations(
                                lcc,
                                td.getObjectID(),
                                td.getSchemaName(),
                                td.getName(),
                                null,
                                violatingConstraints,
                                new HeapRowLocation() /* dummy */,
                                newCi);
                        newCi[0].setInvalidatedRowLocations();

                    } else {
                        throw StandardException.newException(
                                SQLState.LANG_ADD_CHECK_CONSTRAINT_FAILED,
                                constraintName,
                                td.getQualifiedName(),
                                value.toString());
                    }
                }
        /*
         * for not null constraint violations exception will be thrown in caller
         * check constraint will not get here since exception is thrown
         * above
         */
        return false;
      }
    }
    finally
    {
      if (rs != null)
      {
        rs.close();
      }
    }
    return true;
  }

    PreparedStatement ps = lcc.prepareInternalStatement(updateStmt);

        // This is a substatement; for now, we do not set any timeout
        // for it. We might change this behaviour later, by linking
        // timeout to its parent statement's timeout settings.
    ResultSet rs = ps.executeSubStatement(lcc, true, 0L);
    rs.close();
  }

    PreparedStatement ps = lcc.prepareInternalStatement(maxStmt);

        // This is a substatement, for now we do not set any timeout for it
        // We might change this later by linking timeout to parent statement
    ResultSet rs = ps.executeSubStatement(lcc, false, 0L);
    DataValueDescriptor[] rowArray = rs.getNextRow().getRowArray();
    rs.close();
    rs.finish();

    return rowArray[0].getLong();
  }         

      try
      {
                // This is a substatement; for now, we do not set any timeout
                // for it. We might change this behaviour later, by linking
                // timeout to its parent statement's timeout settings.
        ResultSet rs = ps.executeSubStatement
          (activation, spsActivation, false, 0L);

                if (isWhen)
                {
                    // This is a WHEN clause. Expect a single BOOLEAN value
                    // to be returned.
                    ExecRow row = rs.getNextRow();
                    if (SanityManager.DEBUG && row.nColumns() != 1) {
                        SanityManager.THROWASSERT(
                            "Expected WHEN clause to have exactly "
                            + "one column, found: " + row.nColumns());
                    }

                    DataValueDescriptor value = row.getColumn(1);
                    if (SanityManager.DEBUG) {
                        SanityManager.ASSERT(value instanceof SQLBoolean);
                    }

                    whenClauseWasTrue =
                            !value.isNull() && value.getBoolean();

                    if (SanityManager.DEBUG) {
                        SanityManager.ASSERT(rs.getNextRow() == null,
                                "WHEN clause returned more than one row");
                    }
                }
                else if (rs.returnsRows())
                {
                    // Fetch all the data to ensure that functions in the select list or values statement will
                    // be evaluated and side effects will happen. Why else would the trigger action return
                    // rows, but for side effects?
                    // The result set was opened in ps.execute()
                    while( rs.getNextRow() != null)
                    {
                    }
                }
                rs.close();
      }
      catch (StandardException e)
      {
        /*
        ** When a trigger SPS action is executed and results in

      return;
    }

    if (activation != null) {

      ResultSet rs = activation.getResultSet();
      if (rs instanceof BasicNoPutResultSetImpl) {
        ((BasicNoPutResultSetImpl) rs).addWarning(w);
      }

    }

TOP

Related Classes of org.apache.derby.iapi.sql.ResultSet

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.