Search in sources :

Example 11 with CursorResultSet

use of org.apache.derby.iapi.sql.execute.CursorResultSet in project derby by apache.

the class UpdateResultSet method foundRow.

public static boolean foundRow(ExecRow checkRow, int[] colsToCheck, TemporaryRowHolderImpl rowHolder) throws StandardException {
    ExecRow scanRow;
    boolean foundMatch = false;
    Object[] checkRowArray = checkRow.getRowArray();
    DataValueDescriptor checkCol;
    DataValueDescriptor scanCol;
    CursorResultSet rs = rowHolder.getResultSet();
    try {
        /*
			** For each inserted row
			*/
        rs.open();
        while ((scanRow = rs.getNextRow()) != null) {
            Object[] scanRowArray = scanRow.getRowArray();
            int i;
            for (i = 0; i < colsToCheck.length; i++) {
                checkCol = (DataValueDescriptor) checkRowArray[colsToCheck[i] - 1];
                scanCol = (DataValueDescriptor) scanRowArray[colsToCheck[i] - 1];
                BooleanDataValue result = checkCol.equals(scanCol, // result
                checkCol);
                if (!result.getBoolean()) {
                    break;
                }
            }
            if (i == colsToCheck.length) {
                foundMatch = true;
                break;
            }
        }
    } finally {
        rs.close();
    }
    return foundMatch;
}
Also used : BooleanDataValue(org.apache.derby.iapi.types.BooleanDataValue) CursorResultSet(org.apache.derby.iapi.sql.execute.CursorResultSet) ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor)

Example 12 with CursorResultSet

use of org.apache.derby.iapi.sql.execute.CursorResultSet in project derby by apache.

the class UpdateVTIResultSet method openCore.

/**
 *		@exception StandardException Standard Derby error policy
 */
protected void openCore() throws StandardException {
    int rowLocationColumn = -1;
    boolean firstRow = true;
    rs = activation.getTargetVTI();
    ExecRow row = getNextRowCore(sourceResultSet);
    if (null != row)
        rowLocationColumn = row.nColumns();
    /* The source does not know whether or not we are doing a
		 * deferred mode insert.  If we are, then we must clear the
		 * index scan info from the activation so that the row changer
		 * does not re-use that information (which won't be valid for
		 * a deferred mode insert).
		 */
    if (constants.deferred) {
        activation.clearIndexScanInfo();
    }
    if (null == rowHolder && constants.deferred) {
        Properties properties = new Properties();
        /*
			** If deferred we save a copy of the entire row.
			*/
        rowHolder = new TemporaryRowHolderImpl(activation, properties, resultDescription);
    }
    try {
        while (row != null) {
            if (constants.deferred) {
                // Add the row number to the row.
                if (firstRow) {
                    row.getColumn(rowLocationColumn).setValue(rs.getRow());
                    firstRow = false;
                } else {
                    DataValueDescriptor rowLocation = row.cloneColumn(rowLocationColumn);
                    rowLocation.setValue(rs.getRow());
                    row.setColumn(rowLocationColumn, rowLocation);
                }
                rowHolder.insert(row);
            } else
                updateVTI(rs, row);
            rowCount++;
            // No need to do a next on a single row source
            if (constants.singleRowSource) {
                row = null;
            } else {
                row = getNextRowCore(sourceResultSet);
            }
        }
    } catch (StandardException se) {
        throw se;
    } catch (Throwable t) {
        throw StandardException.unexpectedUserException(t);
    }
    /*
		** If it's a deferred update, scan the temporary conglomerate and
		** insert the rows into the VTI using rowChanger.
		*/
    if (constants.deferred) {
        CursorResultSet tempRS = rowHolder.getResultSet();
        try {
            tempRS.open();
            while ((row = tempRS.getNextRow()) != null) {
                int rowNumber = row.getColumn(rowLocationColumn).getInt();
                rs.absolute(rowNumber);
                updateVTI(rs, row);
            }
        } catch (Throwable t) {
            throw StandardException.unexpectedUserException(t);
        } finally {
            sourceResultSet.clearCurrentRow();
            tempRS.close();
        }
    }
    if (rowHolder != null) {
        rowHolder.close();
    // rowHolder kept across opens
    }
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) CursorResultSet(org.apache.derby.iapi.sql.execute.CursorResultSet) ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) Properties(java.util.Properties)

Example 13 with CursorResultSet

use of org.apache.derby.iapi.sql.execute.CursorResultSet in project derby by apache.

the class MatchingClauseConstantAction method executeConstantAction.

public void executeConstantAction(Activation activation, TemporaryRowHolderImpl thenRows) throws StandardException {
    // nothing to do if no rows qualified
    if (thenRows == null) {
        return;
    }
    CursorResultSet sourceRS = thenRows.getResultSet();
    GeneratedMethod actionGM = ((BaseActivation) activation).getMethod(_actionMethodName);
    // 
    try {
        activation.pushConstantAction(_thenAction);
        try {
            // 
            // Poke the temporary table into the variable which will be pushed as
            // an argument to the INSERT/UPDATE/DELETE action.
            // 
            Field resultSetField = activation.getClass().getField(_resultSetFieldName);
            resultSetField.set(activation, sourceRS);
            Activation cursorActivation = sourceRS.getActivation();
            // 
            // Now execute the generated method which creates an InsertResultSet,
            // UpdateResultSet, or DeleteResultSet.
            // 
            Method actionMethod = activation.getClass().getMethod(_actionMethodName);
            _actionRS = (ResultSet) actionMethod.invoke(activation, null);
        } catch (Exception e) {
            throw StandardException.plainWrapException(e);
        }
        // this is where the INSERT/UPDATE/DELETE is processed
        _actionRS.open();
    } finally {
        activation.popConstantAction();
    }
}
Also used : Field(java.lang.reflect.Field) CursorResultSet(org.apache.derby.iapi.sql.execute.CursorResultSet) Activation(org.apache.derby.iapi.sql.Activation) GeneratedMethod(org.apache.derby.iapi.services.loader.GeneratedMethod) Method(java.lang.reflect.Method) GeneratedMethod(org.apache.derby.iapi.services.loader.GeneratedMethod) StandardException(org.apache.derby.shared.common.error.StandardException) IOException(java.io.IOException)

Aggregations

CursorResultSet (org.apache.derby.iapi.sql.execute.CursorResultSet)13 ExecRow (org.apache.derby.iapi.sql.execute.ExecRow)10 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)5 StandardException (org.apache.derby.shared.common.error.StandardException)5 Properties (java.util.Properties)4 RowLocation (org.apache.derby.iapi.types.RowLocation)3 ResultSet (java.sql.ResultSet)2 FormatableBitSet (org.apache.derby.iapi.services.io.FormatableBitSet)2 CheckInfo (org.apache.derby.impl.sql.execute.DeferredConstraintsMemory.CheckInfo)2 IOException (java.io.IOException)1 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 StreamStorable (org.apache.derby.iapi.services.io.StreamStorable)1 GeneratedMethod (org.apache.derby.iapi.services.loader.GeneratedMethod)1 Activation (org.apache.derby.iapi.sql.Activation)1 LanguageProperties (org.apache.derby.iapi.sql.LanguageProperties)1 ResultColumnDescriptor (org.apache.derby.iapi.sql.ResultColumnDescriptor)1 ColumnDescriptor (org.apache.derby.iapi.sql.dictionary.ColumnDescriptor)1 TemporaryRowHolder (org.apache.derby.iapi.sql.execute.TemporaryRowHolder)1 BooleanDataValue (org.apache.derby.iapi.types.BooleanDataValue)1