Search in sources :

Example 6 with CursorResultSet

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

the class DeleteResultSet method deleteDeferredRows.

// delete the rows that in case deferred case and
// during cascade delete (All deletes are deferred during cascade action)
void deleteDeferredRows() throws StandardException {
    DataValueDescriptor rlColumn;
    RowLocation baseRowLocation;
    ExecRow defRLRow;
    deferredBaseCC = tc.openCompiledConglomerate(false, (TransactionController.OPENMODE_FORUPDATE | TransactionController.OPENMODE_SECONDARY_LOCKED), lockMode, TransactionController.ISOLATION_SERIALIZABLE, constants.heapSCOCI, heapDCOCI);
    CursorResultSet rs = rowHolder.getResultSet();
    try {
        /*
			** We need to do a fetch doing a partial row
			** read.  We need to shift our 1-based bit
			** set to a zero based bit set like the store
			** expects.
			*/
        FormatableBitSet readBitSet = RowUtil.shift(baseRowReadList, 1);
        rs.open();
        while ((defRLRow = rs.getNextRow()) != null) {
            rlColumn = defRLRow.getColumn(rlColumnNumber);
            baseRowLocation = (RowLocation) (rlColumn).getObject();
            /* Get the base row at the given RowLocation */
            boolean row_exists = deferredBaseCC.fetch(baseRowLocation, deferredSparseRow.getRowArray(), readBitSet);
            // the rows before the dependent result get a chance to delete
            if (cascadeDelete && !row_exists)
                continue;
            if (SanityManager.DEBUG) {
                if (!row_exists) {
                    SanityManager.THROWASSERT("could not find row " + baseRowLocation);
                }
            }
            rc.deleteRow(deferredBaseRow, baseRowLocation);
            source.markRowAsDeleted();
        }
    } finally {
        rs.close();
    }
}
Also used : CursorResultSet(org.apache.derby.iapi.sql.execute.CursorResultSet) ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) FormatableBitSet(org.apache.derby.iapi.services.io.FormatableBitSet) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) RowLocation(org.apache.derby.iapi.types.RowLocation)

Example 7 with CursorResultSet

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

the class DeleteVTIResultSet method openCore.

/**
 *		@exception StandardException Standard Derby error policy
 */
protected void openCore() throws StandardException {
    ExecRow row = getNextRowCore(sourceResultSet);
    if (row != null) {
        rs = activation.getTargetVTI();
        if (SanityManager.DEBUG) {
            SanityManager.ASSERT(rs != null, "rs expected to be non-null");
        }
    }
    /* The source does not know whether or not we are doing a
		 * deferred mode delete.  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 delete).
		 */
    if (constants.deferred) {
        activation.clearIndexScanInfo();
        if (null == rowHolder)
            rowHolder = new TemporaryRowHolderImpl(activation, new Properties(), (ResultDescription) null);
    }
    try {
        while (row != null) {
            if (!constants.deferred)
                rs.deleteRow();
            else {
                ExecRow rowId = new ValueRow(1);
                rowId.setColumn(1, new SQLInteger(rs.getRow()));
                rowHolder.insert(rowId);
            }
            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 (constants.deferred) {
        CursorResultSet tempRS = rowHolder.getResultSet();
        try {
            ExecRow deferredRowBuffer = null;
            tempRS.open();
            while ((deferredRowBuffer = tempRS.getNextRow()) != null) {
                int rowNumber = deferredRowBuffer.getColumn(1).getInt();
                rs.absolute(rowNumber);
                rs.deleteRow();
            }
        } 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) Properties(java.util.Properties) SQLInteger(org.apache.derby.iapi.types.SQLInteger)

Example 8 with CursorResultSet

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

the class DeleteCascadeResultSet method mergeResultSets.

@SuppressWarnings("UseOfObsoleteCollectionType")
private void mergeResultSets() throws StandardException {
    Vector<TemporaryRowHolder> sVector = activation.getParentResultSet(resultSetId);
    int size = sVector.size();
    // temporary result set.
    if (size > 1) {
        ExecRow row;
        int rowHolderId = 0;
        // copy all the vallues in the result set to the current resultset row holder
        while (rowHolderId < size) {
            if (rowHolderId == tempRowHolderId) {
                // skipping the row holder that  we are copying the rows into.
                rowHolderId++;
                continue;
            }
            TemporaryRowHolder currentRowHolder = sVector.elementAt(rowHolderId);
            CursorResultSet rs = currentRowHolder.getResultSet();
            rs.open();
            while ((row = rs.getNextRow()) != null) {
                rowHolder.insert(row);
            }
            rs.close();
            rowHolderId++;
        }
    }
}
Also used : CursorResultSet(org.apache.derby.iapi.sql.execute.CursorResultSet) TemporaryRowHolder(org.apache.derby.iapi.sql.execute.TemporaryRowHolder) ExecRow(org.apache.derby.iapi.sql.execute.ExecRow)

Example 9 with CursorResultSet

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

the class DeleteResultSet method runFkChecker.

/**
 * Make sure foreign key constraints are not violated
 */
void runFkChecker(boolean restrictCheckOnly) throws StandardException {
    if (fkChecker != null) {
        /*
			** Second scan to make sure all the foreign key
			** constraints are ok.  We have to do this after
			** we have completed the deletes in case of self referencing
			** constraints.
			*/
        CursorResultSet rs = rowHolder.getResultSet();
        try {
            rs.open();
            ExecRow defRLRow;
            while ((defRLRow = rs.getNextRow()) != null) {
                // Argument "1" below: If a PK referenced by an FK is
                // deferred, require at least one to be present in the
                // primary table since we have deleted the row unless
                // postCheck == true, in which the call to postChecks does
                // the actual checking, and we need at least one to fulfill
                // the constraint.
                fkChecker.doPKCheck(activation, defRLRow, restrictCheckOnly, 1);
            }
            if (restrictCheckOnly) {
                fkChecker.postCheck();
            }
        } finally {
            rs.close();
        }
    }
}
Also used : CursorResultSet(org.apache.derby.iapi.sql.execute.CursorResultSet) ExecRow(org.apache.derby.iapi.sql.execute.ExecRow)

Example 10 with CursorResultSet

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

the class InsertVTIResultSet method openCore.

/**
 *		@exception StandardException Standard Derby error policy
 */
protected void openCore() throws StandardException {
    /* We must instantiate the VTI on each execution if any of the
		 * parameters contain a ?.
		 */
    if (ps == null) {
        ps = (PreparedStatement) vtiRS.getVTIConstructor().invoke(activation);
    }
    if (ps instanceof DeferModification) {
        try {
            ((DeferModification) ps).modificationNotify(DeferModification.INSERT_STATEMENT, constants.deferred);
        } catch (Throwable t) {
            throw StandardException.unexpectedUserException(t);
        }
    }
    ExecRow row = getNextRowCore(sourceResultSet);
    try {
        rs = ps.executeQuery();
    } catch (Throwable t) {
        throw StandardException.unexpectedUserException(t);
    }
    /* 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 (firstExecute && constants.deferred) {
        Properties properties = new Properties();
        /*
			** If deferred we save a copy of the entire row.
			*/
        rowHolder = new TemporaryRowHolderImpl(activation, properties, resultDescription);
    }
    while (row != null) {
        /*
			** If we're doing a deferred insert, insert into the temporary
			** conglomerate.  Otherwise, insert directly into the permanent
			** conglomerates using the rowChanger.
			*/
        if (constants.deferred) {
            rowHolder.insert(row);
        } else {
            insertIntoVTI(rs, row);
        }
        rowCount++;
        // No need to do a next on a single row source
        if (constants.singleRowSource) {
            row = null;
        } else {
            row = getNextRowCore(sourceResultSet);
        }
    }
    /*
		** If it's a deferred insert, scan the temporary conglomerate and
		** insert the rows into the permanent conglomerates using rowChanger.
		*/
    if (constants.deferred) {
        CursorResultSet tempRS = rowHolder.getResultSet();
        try {
            tempRS.open();
            while ((row = tempRS.getNextRow()) != null) {
                insertIntoVTI(rs, row);
            }
        } finally {
            sourceResultSet.clearCurrentRow();
            tempRS.close();
        }
    }
    if (rowHolder != null) {
        rowHolder.close();
    // rowHolder kept across opens
    }
}
Also used : DeferModification(org.apache.derby.vti.DeferModification) CursorResultSet(org.apache.derby.iapi.sql.execute.CursorResultSet) ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) Properties(java.util.Properties)

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