use of org.apache.derby.iapi.types.DataValueDescriptor in project derby by apache.
the class ProjectRestrictResultSet method openCore.
//
// NoPutResultSet interface
//
/**
* open a scan on the table. scan parameters are evaluated
* at each open, so there is probably some way of altering
* their values...
*
* @exception StandardException thrown if cursor finished.
*/
public void openCore() throws StandardException {
boolean constantEval = true;
beginTime = getCurrentTimeMillis();
// - sometimes get NullPointerException in openCore().
if (SanityManager.DEBUG) {
SanityManager.ASSERT(source != null, "PRRS().openCore(), source expected to be non-null");
}
// is access to open controlled and ensured valid.
if (SanityManager.DEBUG)
SanityManager.ASSERT(!isOpen, "ProjectRestrictResultSet already open");
if (constantRestriction != null) {
DataValueDescriptor restrictBoolean;
restrictBoolean = (DataValueDescriptor) constantRestriction.invoke(activation);
// if the result is null, we make it false --
// so the row won't be returned.
constantEval = (restrictBoolean == null) || ((!restrictBoolean.isNull()) && restrictBoolean.getBoolean());
}
if (validatingCheckConstraint) {
rowLocations = DeferredConstraintsMemory.getDeferredCheckConstraintLocations(activation, validatingBaseTableUUID);
}
if (constantEval) {
source.openCore();
} else {
shortCircuitOpen = true;
}
isOpen = true;
numOpens++;
openTime += getElapsedMillis(beginTime);
}
use of org.apache.derby.iapi.types.DataValueDescriptor in project derby by apache.
the class ProjectRestrictResultSet method getNextRowCore.
/**
* Return the requested values computed
* from the next row (if any) for which
* the restriction evaluates to true.
* <p>
* restriction and projection parameters
* are evaluated for each row.
*
* @exception StandardException thrown on failure.
* @exception StandardException ResultSetNotOpen thrown if not yet open.
*
* @return the next row in the result
*/
public ExecRow getNextRowCore() throws StandardException {
if (isXplainOnlyMode())
return null;
ExecRow candidateRow = null;
ExecRow result = null;
boolean restrict = false;
DataValueDescriptor restrictBoolean;
long beginRT = 0;
/* Return null if open was short circuited by false constant expression */
if (shortCircuitOpen) {
return result;
}
beginTime = getCurrentTimeMillis();
do {
if (validatingCheckConstraint) {
candidateRow = null;
while (rowLocations.hasMoreElements() && candidateRow == null) {
DataValueDescriptor[] row = (DataValueDescriptor[]) rowLocations.nextElement();
RowLocation rl = (RowLocation) ((SQLRef) row[0]).getObject();
((ValidateCheckConstraintResultSet) source).positionScanAtRowLocation(rl);
candidateRow = source.getNextRowCore();
// if null (deleted), we move to next
}
} else {
candidateRow = source.getNextRowCore();
}
if (candidateRow != null) {
beginRT = getCurrentTimeMillis();
/* If restriction is null, then all rows qualify */
if (restriction == null) {
restrict = true;
} else {
setCurrentRow(candidateRow);
restrictBoolean = (DataValueDescriptor) restriction.invoke(activation);
restrictionTime += getElapsedMillis(beginRT);
// if the result is null, we make it false --
// so the row won't be returned.
restrict = ((!restrictBoolean.isNull()) && restrictBoolean.getBoolean());
if (!restrict) {
rowsFiltered++;
}
}
/* Update the run time statistics */
rowsSeen++;
}
} while ((candidateRow != null) && (!restrict));
if (candidateRow != null) {
beginRT = getCurrentTimeMillis();
result = doProjection(candidateRow);
projectionTime += getElapsedMillis(beginRT);
} else /* Clear the current row, if null */
{
clearCurrentRow();
}
currentRow = result;
if (runTimeStatsOn) {
if (!isTopResultSet) {
/* This is simply for RunTimeStats */
/* We first need to get the subquery tracking array via the StatementContext */
StatementContext sc = activation.getLanguageConnectionContext().getStatementContext();
subqueryTrackingArray = sc.getSubqueryTrackingArray();
}
nextTime += getElapsedMillis(beginTime);
}
return result;
}
use of org.apache.derby.iapi.types.DataValueDescriptor in project derby by apache.
the class ReferencedKeyRIChecker method rememberKey.
/**
* Remember the deletion of this key, it may cause a RESTRICT
* foreign key violation, cf. logic in @{link #postCheck}.
* @param rememberRow
* @throws StandardException
*/
private void rememberKey(ExecRow rememberRow) throws StandardException {
if (deletedKeys == null) {
// key: all columns (these are index rows, or a row containing a
// row location)
identityMap = new int[numColumns];
for (int i = 0; i < numColumns; i++) {
identityMap[i] = i;
}
deletedKeys = new BackingStoreHashtable(tc, null, identityMap, // remove duplicates: no need for more copies:
true, // one is enough to know what to look for on commit
-1, HashScanResultSet.DEFAULT_MAX_CAPACITY, HashScanResultSet.DEFAULT_INITIAL_CAPACITY, HashScanResultSet.DEFAULT_MAX_CAPACITY, false, false);
}
DataValueDescriptor[] row = rememberRow.getRowArray();
for (int i = 0; i < numColumns; i++) {
refKey[i] = row[fkInfo.colArray[i] - 1];
}
Object hashKey = KeyHasher.buildHashKey(refKey, identityMap);
DataValueDescriptor[] savedRow = (DataValueDescriptor[]) deletedKeys.remove(hashKey);
if (savedRow == null) {
savedRow = new DataValueDescriptor[numColumns + 1];
System.arraycopy(refKey, 0, savedRow, 0, numColumns);
savedRow[numColumns] = new SQLLongint(1);
} else {
savedRow[numColumns] = new SQLLongint(((SQLLongint) savedRow[numColumns]).getLong() + 1);
}
deletedKeys.putRow(false, savedRow, null);
}
use of org.apache.derby.iapi.types.DataValueDescriptor in project derby by apache.
the class ReferencedKeyRIChecker method postCheck.
/**
* Check that we have at least one more row in the referenced
* table table containing a key than the number of projected deletes of that
* key. Only used when the referenced constraint id deferred and with
* RESTRICT mode
*
* @throws StandardException Standard error policy
*/
public void postCheck() throws StandardException {
if (!fkInfo.refConstraintIsDeferrable) {
return;
}
int indexOfFirstRestrict = -1;
for (int i = 0; i < fkInfo.fkConglomNumbers.length; i++) {
if (fkInfo.raRules[i] == StatementType.RA_RESTRICT) {
indexOfFirstRestrict = i;
break;
}
}
if (indexOfFirstRestrict == -1) {
return;
}
if (deletedKeys != null) {
final Enumeration<?> e = deletedKeys.elements();
while (e.hasMoreElements()) {
final DataValueDescriptor[] row = (DataValueDescriptor[]) e.nextElement();
final DataValueDescriptor[] key = new DataValueDescriptor[row.length - 1];
System.arraycopy(row, 0, key, 0, key.length);
// The number of times this key is to be deleted,
// we need at least one more if for Fk constraint to hold.
final long requiredCount = row[row.length - 1].getLong() + 1;
if (!isDuplicated(key, requiredCount)) {
int[] oneBasedIdentityMap = new int[numColumns];
for (int i = 0; i < numColumns; i++) {
// Column numbers are numbered from 1 and
// call to RowUtil.toString below expects that
// convention.
oneBasedIdentityMap[i] = i + 1;
}
StandardException se = StandardException.newException(SQLState.LANG_FK_VIOLATION, fkInfo.fkConstraintNames[indexOfFirstRestrict], fkInfo.tableName, StatementUtil.typeName(fkInfo.stmtType), RowUtil.toString(row, oneBasedIdentityMap));
throw se;
}
}
}
}
use of org.apache.derby.iapi.types.DataValueDescriptor in project derby by apache.
the class GroupedAggregateResultSet method sameGroupingValues.
/**
* Return whether or not the new row has the same values for the
* grouping columns as the current row. (This allows us to process in-order
* group bys without a sorter.)
*
* @param currRow The current row.
* @param newRow The new row.
*
* @return The order index number which first distinguished
* these rows, or order.length if the rows match.
*
* @exception StandardException thrown on failure to get row location
*/
private int sameGroupingValues(ExecRow currRow, ExecRow newRow) throws StandardException {
for (int index = 0; index < numGCols(); index++) {
DataValueDescriptor currOrderable = currRow.getColumn(order[index].getColumnId() + 1);
DataValueDescriptor newOrderable = newRow.getColumn(order[index].getColumnId() + 1);
if (!(currOrderable.compare(DataValueDescriptor.ORDER_OP_EQUALS, newOrderable, true, true))) {
return index;
}
}
return numGCols();
}
Aggregations