Package org.apache.derby.iapi.sql

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


        //reset the activation to clear warnings
        //and clear existing result sets in case this has been cached
        a.reset();
        a.setMaxRows(maxRows);
                ResultSet resultsToWrap = ps.execute(a, timeoutMillis);
                addWarning(ps.getCompileTimeWarnings());
        addWarning(a.getWarnings());


        if (resultsToWrap.returnsRows()) {

                    // The statement returns rows, so calling it with
                    // executeUpdate() is not allowed.
                    if (executeUpdate) {
                        throw StandardException.newException(
                                SQLState.LANG_INVALID_CALL_TO_EXECUTE_UPDATE);
                    }

          EmbedResultSet lresults = factory.newEmbedResultSet(getEmbedConnection(), resultsToWrap, forMetaData, this, ps.isAtomic());
          results = lresults;


          // Set up the finalization of the ResultSet to
          // mark the activation as unused. It will be
          // closed sometime later by the connection
          // outside of finalization.
          if (a.isSingleExecution())
            lresults.singleUseActivation = a;

          updateCount = -1L;
          retval = true;
        }
        else {

          // Only applipable for an insert statement, which does not return rows.
          //the auto-generated keys resultset will be null if used for non-insert statement
          if (a.getAutoGeneratedKeysResultsetMode() && (resultsToWrap.getAutoGeneratedKeysResultset() != null))
          {
            resultsToWrap.getAutoGeneratedKeysResultset().open();
            autoGeneratedKeysResultSet = factory.newEmbedResultSet(getEmbedConnection(),
              resultsToWrap.getAutoGeneratedKeysResultset(), false, this, ps.isAtomic());
          }

          updateCount = resultsToWrap.modifiedRowCount();
          results = null; // note that we have none.

                    int dynamicResultCount = 0;
          if (a.getDynamicResults() != null) {
                        dynamicResultCount =
                            processDynamicResults(a.getDynamicResults(),
                                                  a.getMaxDynamicResults());
          }
                   
                    resultsToWrap.close(); // Don't need the result set any more

                    // executeQuery() is not allowed if the statement
                    // doesn't return exactly one ResultSet.
                    if (executeQuery && dynamicResultCount != 1) {
                        throw StandardException.newException(


      if (executionConstants != null)
      {
        lccToUse.validateStmtExecution(executionConstants);
      }

      ResultSet resultSet = null;
      try {
 
        resultSet = activation.execute();

        resultSet.open();
      } catch (StandardException se) {
        /* Cann't handle recompiling SPS action recompile here */
        if (!se.getMessageId().equals(SQLState.LANG_STATEMENT_NEEDS_RECOMPILE)
             || spsAction)
          throw se;
        statementContext.cleanupOnError(se);
        continue recompileOutOfDatePlan;

      }


      if (needToClearSavePoint)
      {
        /* We're done with our updates */
        statementContext.clearSavePoint();
      }

      lccToUse.popStatementContext(statementContext, null);         

      if (activation.isSingleExecution() && resultSet.isClosed())
      {
        // if the result set is 'done', i.e. not openable,
        // then we can also release the activation.
        // Note that a result set with output parameters
        // or rows to return is explicitly finished

        String executingCursorName = a.getCursorName();

         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 = (Activation) acts.elementAt(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 = (Activation) acts.elementAt(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());

    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.execute(lcc, true, 0L);
    rs.close();
    rs.finish();
  }

    LanguageConnectionContext lcc = activation.getLanguageConnectionContext();
    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.execute(lcc, false, 0L);
    DataValueDescriptor[] rowArray = rs.getNextRow().getRowArray();
    rs.close();
    rs.finish();

    return rowArray[0].getLong();
  }         

    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.execute(lcc, true, 0L);
    rs.close();
    rs.finish();
  }

    LanguageConnectionContext lcc = activation.getLanguageConnectionContext();
    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.execute(lcc, false, 0L);
    DataValueDescriptor[] rowArray = rs.getNextRow().getRowArray();
    rs.close();
    rs.finish();

    return rowArray[0].getLong();
  }         

        //reset the activation to clear warnings
        //and clear existing result sets in case this has been cached
        a.reset();
        a.setMaxRows(maxRows);
                ResultSet resultsToWrap = ps.execute(a,
                                                     false,
                                                     timeoutMillis);
        addWarning(a.getWarnings());


        if (resultsToWrap.returnsRows()) {

                    // The statement returns rows, so calling it with
                    // executeUpdate() is not allowed.
                    if (executeUpdate) {
                        throw StandardException.newException(
                                SQLState.LANG_INVALID_CALL_TO_EXECUTE_UPDATE);
                    }

          EmbedResultSet lresults = factory.newEmbedResultSet(getEmbedConnection(), resultsToWrap, forMetaData, this, ps.isAtomic());
          results = lresults;


          // Set up the finalization of the ResultSet to
          // mark the activation as unused. It will be
          // closed sometime later by the connection
          // outside of finalization.
          if (a.isSingleExecution())
            lresults.singleUseActivation = a;

          updateCount = -1;
          retval = true;
        }
        else {

          // Only applipable for an insert statement, which does not return rows.
          //the auto-generated keys resultset will be null if used for non-insert statement
          if (a.getAutoGeneratedKeysResultsetMode() && (resultsToWrap.getAutoGeneratedKeysResultset() != null))
          {
            resultsToWrap.getAutoGeneratedKeysResultset().open();
            autoGeneratedKeysResultSet = factory.newEmbedResultSet(getEmbedConnection(),
              resultsToWrap.getAutoGeneratedKeysResultset(), false, this, ps.isAtomic());
          }

          updateCount = resultsToWrap.modifiedRowCount();

          resultsToWrap.finish()// Don't need the result set any more
          results = null; // note that we have none.

                    int dynamicResultCount = 0;
          if (a.getDynamicResults() != null) {
                        dynamicResultCount =

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.