Package org.apache.derby.iapi.sql.conn

Examples of org.apache.derby.iapi.sql.conn.LanguageConnectionContext


    synchronized (getConnectionSynchronization()) {

          setupContextStack();
        try {
        LanguageConnectionContext lcc = getEmbedConnection().getLanguageConnection();
        final ExecRow newRow;
        try {

        /* Push and pop a StatementContext around a next call
         * so that the ResultSet will get correctly closed down
         * on an error.
         * (Cache the LanguageConnectionContext)
         */
                StatementContext statementContext =
                    lcc.pushStatementContext(isAtomic,
               concurrencyOfThisResultSet==java.sql.ResultSet.CONCUR_READ_ONLY,
               getSQLText(),
               getParameterValueSet(),
                                             false, timeoutMillis);

        switch (position)
        {
          case BEFOREFIRST:
            newRow = theResults.setBeforeFirstRow();
            break;

          case FIRST:
            newRow = theResults.getFirstRow();
            break;

          case NEXT:
            newRow = theResults.getNextRow();
            break;

          case LAST:
            newRow = theResults.getLastRow();
            break;

          case AFTERLAST:
            newRow = theResults.setAfterLastRow();
            break;

          case PREVIOUS:
            newRow = theResults.getPreviousRow();
            break;

          case ABSOLUTE:
            newRow = theResults.getAbsoluteRow(row);
            break;

          case RELATIVE:
            newRow = theResults.getRelativeRow(row);
            break;

          default:
            newRow = null;
            if (SanityManager.DEBUG)
            {
              SanityManager.THROWASSERT(
                "Unexpected value for position - " + position);
            }
        }

        lcc.popStatementContext(statementContext, null);
                InterruptStatus.restoreIntrFlagIfSeen(lcc);
        } catch (Throwable t) {
        /*
         * Need to close the result set here because the error might
         * cause us to lose the current connection if this is an XA
         * connection and we won't be able to do the close later
         */
        throw closeOnTransactionError(t);
      }
        
      SQLWarning w = theResults.getWarnings();
      if (w != null) {
        if (topWarning == null)
          topWarning = w;
        else
          topWarning.setNextWarning(w);
      }
     
            boolean onRow = (currentRow = newRow) != null;     

      //if (onRow && !(currentRow instanceof org.apache.derby.impl.sql.execute.ValueRow))
      //  System.out.println(currentRow.getClass());

        // The ResultSet may implicitly close when when the ResultSet type
        // is TYPE_FORWARD_ONLY and the next method of ResultSet returns
        // false. This will cause a commit if autocommit = true.
        if (!onRow && (position == NEXT)) {

         // In case of resultset for MetaData, we will only commit
         // if we are the only statement currently opened for this
         // connection; otherwise we don't want to affect other
         // resultSet's by committing the MetaData one.
         // There is no internal xact (xact isolation) for MetaData type
         // of resultSet; therefore committing (to release locks) would end
         // up committing all the other resultSet for this connection.
         //
         // We do synchronize on the connection, therefore Activation count
         // should be valid and protected.
         //
      //LanguageConnectionContext lcc = getEmbedConnection().getLanguageConnection();
         if (forMetaData && (lcc.getActivationCount() > 1)) {
           // we do not want to commit here as there seems to be other
           // statements/resultSets currently opened for this connection.
         } else if (owningStmt != null &&
            owningStmt.getResultSetType() == TYPE_FORWARD_ONLY) {
         // allow the satement to commit if required.
View Full Code Here


        // just give up and return
        return;
      }
           
      try  {
                LanguageConnectionContext lcc =
                    getEmbedConnection().getLanguageConnection();

        try  {
          theResults.close();
           
            if (this.singleUseActivation != null)
            {
              this.singleUseActivation.close();
              this.singleUseActivation = null;
            }

                    InterruptStatus.restoreIntrFlagIfSeen(lcc);
        } catch (Throwable t) {
          throw handleException(t);
        }

          // In case of resultset for MetaData, we will only commit
            // if we are the only statement currently opened for this
            // connection; otherwise we don't want to affect other
            // resultSet's by committing the MetaData one.
            // There is no internal xact (xact isolation) for MetaData type
            // of resultSet; therefore committing (to release locks) would end
            // up committing all the other resultSet for this connection.
            //
            // We do synchronize on the connection, therefore Activation count
            // should be valid and protected.
            //
            if (forMetaData) {

              if (lcc.getActivationCount() > 1) {
               // we do not want to commit here as there seems to be other
            // statements/resultSets currently opened for this connection.
          } else if (owningStmt != null)
            // allow the satement to commit if required.
               owningStmt.resultSetClosing(this);
View Full Code Here

    boolean purgeRows,
    boolean defragmentRows,
    boolean truncateEnd)
        throws SQLException
  {
    LanguageConnectionContext lcc       = ConnectionUtil.getCurrentLCC();
    TransactionController     tc        = lcc.getTransactionExecute();

    try
        {
            DataDictionary data_dictionary = lcc.getDataDictionary();

            // Each of the following may give up locks allowing ddl on the
            // table, so each phase needs to do the data dictionary lookup.
            // The order is important as it makes sense to first purge
            // deleted rows, then defragment existing non-deleted rows, and
View Full Code Here

   */
  public void insertRow() throws SQLException {
        synchronized (getConnectionSynchronization()) {
            checksBeforeInsert();
            setupContextStack();
            LanguageConnectionContext lcc = getEmbedConnection().getLanguageConnection();
            StatementContext statementContext = null;
            try {
                /*
                 * construct the insert statement
                 *
                 * If no values have been supplied for a column, it will be set
                 * to the column's default value, if any.
                 * If no default value had been defined, the default value of a
                 * nullable column is set to NULL.
                 */

                boolean foundOneColumnAlready = false;
                StringBuffer insertSQL = new StringBuffer("INSERT INTO ");
                StringBuffer valuesSQL = new StringBuffer("VALUES (");
                CursorActivation activation = lcc.lookupCursorActivation(getCursorName());

                ExecCursorTableReference targetTable =
                        activation.getPreparedStatement().getTargetTable();
                // got the underlying (schema.)table name
                insertSQL.append(getFullBaseTableName(targetTable));
                ResultDescription rd = theResults.getResultDescription();

                insertSQL.append(" (");
                // in this for loop we are constructing list of column-names
                // and values (?) ,... part of the insert sql
                for (int i=1; i<=rd.getColumnCount(); i++) {
                    if (foundOneColumnAlready) {
                        insertSQL.append(",");
                        valuesSQL.append(",");
                    }
                    // using quotes around the column name
                    // to preserve case sensitivity
                    insertSQL.append(IdUtil.normalToDelimited(
                            rd.getColumnDescriptor(i).getName()));
                    if (columnGotUpdated[i-1]) {
                        valuesSQL.append("?");
                    } else {
                        valuesSQL.append("DEFAULT");
                    }
                    foundOneColumnAlready = true;
                }
                insertSQL.append(") ");
                valuesSQL.append(") ");
                insertSQL.append(valuesSQL);

                StatementContext currSC = lcc.getStatementContext();
                Activation parentAct = null;

                if (currSC != null) {
                    parentAct = currSC.getActivation();
                }

                // Context used for preparing, don't set any timeout (use 0)
                statementContext = lcc.pushStatementContext(
                        isAtomic,
                        false,
                        insertSQL.toString(),
                        null,
                        false,
                        0L);

                // A priori, the new statement context inherits the activation
                // of the existing statementContext, so that that activation
                // ends up as parent of the new activation 'act' created below,
                // which will be the activation of the pushed statement
                // context.
                statementContext.setActivation(parentAct);

                org.apache.derby.iapi.sql.PreparedStatement ps =
                        lcc.prepareInternalStatement(insertSQL.toString());
                Activation act = ps.getActivation(lcc, false);

                statementContext.setActivation(act);

                // in this for loop we are assigning values for parameters
                //in sql constructed earlier VALUES (?, ..)
                for (int i=1, paramPosition=0; i<=rd.getColumnCount(); i++) {
                    // if the column got updated, do following
                    if (columnGotUpdated[i-1]) { 
                        act.getParameterValueSet().
                                getParameterForSet(paramPosition++).
                                setValue(updateRow.getColumn(i));
                    }
                }
                // Don't see any timeout when inserting rows (use 0)
                //execute the insert
                org.apache.derby.iapi.sql.ResultSet rs =
          ps.executeSubStatement(activation, act, true, 0L);
                act.close();

                lcc.popStatementContext(statementContext, null);
                InterruptStatus.restoreIntrFlagIfSeen(lcc);
            } catch (Throwable t) {
                throw closeOnTransactionError(t);
            } finally {
                if (statementContext != null)
                    lcc.popStatementContext(statementContext, null);
                restoreContextStack();
            }
        }
  }
View Full Code Here

        int[][]                  index_col_map       =  null;
        ScanController[]         index_scan          =  null;
        ConglomerateController[] index_cc            =  null;
        DataValueDescriptor[][]  index_row           =  null;

    LanguageConnectionContext lcc       = ConnectionUtil.getCurrentLCC();
    TransactionController     nested_tc = null;

    try {

            SchemaDescriptor sd =
                data_dictionary.getSchemaDescriptor(
                    schemaName, nested_tc, true);
            TableDescriptor td =
                data_dictionary.getTableDescriptor(tableName, sd);
            nested_tc =
                tc.startNestedUserTransaction(false);

            if (td == null)
            {
                throw StandardException.newException(
                    SQLState.LANG_TABLE_NOT_FOUND,
                    schemaName + "." + tableName);
            }

            switch (td.getTableType())
            {
            /* Skip views and vti tables */
            case TableDescriptor.VIEW_TYPE:
            case TableDescriptor.VTI_TYPE:
              return;
            // other types give various errors here
            // DERBY-719,DERBY-720
            default:
              break;
            }


      ConglomerateDescriptor heapCD =
                td.getConglomerateDescriptor(td.getHeapConglomerateId());

      /* Get a row template for the base table */
      ExecRow baseRow =
                lcc.getLanguageConnectionFactory().getExecutionFactory().getValueRow(
                    td.getNumberOfColumns());


      /* Fill the row with nulls of the correct type */
      ColumnDescriptorList cdl = td.getColumnDescriptorList();
View Full Code Here

       
        // Check that the cursor is not positioned on insertRow
        checkNotOnInsertRow();
       
        setupContextStack();
        LanguageConnectionContext lcc = getEmbedConnection().getLanguageConnection();
        StatementContext statementContext = null;
        try {
            if (currentRowHasBeenUpdated == false) //nothing got updated on this row
                return; //nothing to do since no updates were made to this row

            //now construct the update where current of sql
            boolean foundOneColumnAlready = false;
            StringBuffer updateWhereCurrentOfSQL = new StringBuffer("UPDATE ");
            CursorActivation activation = lcc.lookupCursorActivation(getCursorName());


            ExecCursorTableReference targetTable = activation.getPreparedStatement().getTargetTable();
            updateWhereCurrentOfSQL.append(getFullBaseTableName(targetTable));//got the underlying (schema.)table name
            updateWhereCurrentOfSQL.append(" SET ");
            ResultDescription rd = theResults.getResultDescription();

            for (int i=1; i<=rd.getColumnCount(); i++) { //in this for loop we are constructing columnname=?,... part of the update sql
                if (columnGotUpdated[i-1]) { //if the column got updated, do following
                    if (foundOneColumnAlready)
                        updateWhereCurrentOfSQL.append(",");
                    //using quotes around the column name to preserve case sensitivity
                    updateWhereCurrentOfSQL.append(IdUtil.normalToDelimited(
                            rd.getColumnDescriptor(i).getName()) + "=?");
                    foundOneColumnAlready = true;
                }
            }
            //using quotes around the cursor name to preserve case sensitivity
            updateWhereCurrentOfSQL.append(" WHERE CURRENT OF " +
                    IdUtil.normalToDelimited(getCursorName()));

            StatementContext currSC = lcc.getStatementContext();
            Activation parentAct = null;

            if (currSC != null) {
                parentAct = currSC.getActivation();
            }

            // Context used for preparing, don't set any timeout (use 0)
            statementContext = lcc.pushStatementContext(isAtomic, false, updateWhereCurrentOfSQL.toString(), null, false, 0L);

            // A priori, the new statement context inherits the activation of
            // the existing statementContext, so that that activation ends up
            // as parent of the new activation 'act' created below, which will
            // be the activation of the pushed statement context.
            statementContext.setActivation(parentAct);

            org.apache.derby.iapi.sql.PreparedStatement ps = lcc.prepareInternalStatement(updateWhereCurrentOfSQL.toString());
            Activation act = ps.getActivation(lcc, false);

            statementContext.setActivation(act);

            //in this for loop we are assigning values for parameters in sql constructed earlier with columnname=?,...
            for (int i=1, paramPosition=0; i<=rd.getColumnCount(); i++) {
                if (columnGotUpdated[i-1])  //if the column got updated, do following
                    act.getParameterValueSet().getParameterForSet(paramPosition++).setValue(updateRow.getColumn(i));
            }
            // Don't set any timeout when updating rows (use 0)
            // Execute the update where current of sql.
            org.apache.derby.iapi.sql.ResultSet rs =
        ps.executeSubStatement(activation, act, true, 0L);
            SQLWarning w = act.getWarnings();
            if (w != null) {
                addWarning(w);
            }
            act.close();
            //For forward only resultsets, after a update, the ResultSet will be positioned right before the next row.
            if (getType() == TYPE_FORWARD_ONLY) {
                currentRow = null;
            } else {
                movePosition(RELATIVE, 0, "relative");
            }
            lcc.popStatementContext(statementContext, null);
            InterruptStatus.restoreIntrFlagIfSeen(lcc);
        } catch (Throwable t) {
            throw closeOnTransactionError(t);
        } finally {
            if (statementContext != null)
                lcc.popStatementContext(statementContext, null);
            restoreContextStack();
            initializeUpdateRowModifiers();
        }
      }
    }
View Full Code Here

            // Check that the cursor is not positioned on insertRow
            checkNotOnInsertRow();

            setupContextStack();
           
            LanguageConnectionContext lcc = getEmbedConnection().getLanguageConnection();
            StatementContext statementContext = null;
           
            //now construct the delete where current of sql
            try {
                StringBuffer deleteWhereCurrentOfSQL = new StringBuffer("DELETE FROM ");
                CursorActivation activation = lcc.lookupCursorActivation(getCursorName());
                deleteWhereCurrentOfSQL.append(getFullBaseTableName(activation.getPreparedStatement().getTargetTable()));//get the underlying (schema.)table name
                //using quotes around the cursor name to preserve case sensitivity
                deleteWhereCurrentOfSQL.append(" WHERE CURRENT OF " +
                        IdUtil.normalToDelimited(getCursorName()));

                StatementContext currSC = lcc.getStatementContext();
                Activation parentAct = null;

                if (currSC != null) {
                    parentAct = currSC.getActivation();
                }

                // Context used for preparing, don't set any timeout (use 0)
                statementContext = lcc.pushStatementContext(isAtomic, false, deleteWhereCurrentOfSQL.toString(), null, false, 0L);

                // A priori, the new statement context inherits the activation
                // of the existing statementContext, so that that activation
                // ends up as parent of the new activation 'act' created below,
                // which will be the activation of the pushed statement
                // context.
                statementContext.setActivation(parentAct);

                org.apache.derby.iapi.sql.PreparedStatement ps = lcc.prepareInternalStatement(deleteWhereCurrentOfSQL.toString());
                // Get activation, so that we can get the warning from it
                Activation act = ps.getActivation(lcc, false);

                statementContext.setActivation(act);

                // Don't set any timeout when deleting rows (use 0)
                //execute delete where current of sql
                org.apache.derby.iapi.sql.ResultSet rs =
          ps.executeSubStatement(activation, act, true, 0L);
                SQLWarning w = act.getWarnings();
                if (w != null) {
                    addWarning(w);
                }
                act.close();
                //After a delete, the ResultSet will be positioned right before
                //the next row.
                currentRow = null;
                lcc.popStatementContext(statementContext, null);
                InterruptStatus.restoreIntrFlagIfSeen(lcc);
            } catch (Throwable t) {
                    throw closeOnTransactionError(t);
            } finally {
                if (statementContext != null)
                    lcc.popStatementContext(statementContext, null);
                restoreContextStack();
                initializeUpdateRowModifiers();
            }
        }
    }
View Full Code Here

      boolean pushStack = false;
            EmbedConnection ec = getEmbedConnection();
      try {

        StringDataValue dvd = (StringDataValue)getColumn(columnIndex);
                LanguageConnectionContext lcc = ec.getLanguageConnection();

                if (wasNull = dvd.isNull()) {
                    InterruptStatus.restoreIntrFlagIfSeen();
          return null;
                }
View Full Code Here

    checkScrollCursor(positionText);

    synchronized (getConnectionSynchronization()) {
      setupContextStack();

            LanguageConnectionContext lcc =
                getEmbedConnection().getLanguageConnection();

            try {
        try {

          /*
           * Push and pop a StatementContext around a next call so
           * that the ResultSet will get correctly closed down on an
           * error. (Cache the LanguageConnectionContext)
           */
                    // No timeout for this operation (use 0)
          StatementContext statementContext =
                        lcc.pushStatementContext(isAtomic,
             concurrencyOfThisResultSet==java.sql.ResultSet.CONCUR_READ_ONLY,
             getSQLText(),
                                                 getParameterValueSet(),
                                                 false, 0L);

          boolean result = theResults.checkRowPosition(position);

          lcc.popStatementContext(statementContext, null);
                    InterruptStatus.restoreIntrFlagIfSeen(lcc);
          return result;

        } catch (Throwable t) {
          /*
 
View Full Code Here

                     String  spsText,
                     boolean net)
    throws StandardException, SQLException
  {

    LanguageConnectionContext lcc = getLanguageConnectionContext();

    /* We now need to do this in sub transaction because we could possibly recompile SPS
     * later, and the recompile is in a sub transaction, and will update the SYSSTATEMENTS
     * entry.  Don't want to block.
     */
    lcc.beginNestedTransaction(true);

    DataDictionary dd = getLanguageConnectionContext().getDataDictionary();
    SPSDescriptor spsd = dd.getSPSDescriptor(
                    spsName,
                    net ? dd.getSysIBMSchemaDescriptor() :
                    dd.getSystemSchemaDescriptor());
    lcc.commitNestedTransaction();

    if (spsd == null)
    {
      throw Util.notImplemented(spsName);
    }
View Full Code Here

TOP

Related Classes of org.apache.derby.iapi.sql.conn.LanguageConnectionContext

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.