Search in sources :

Example 91 with DataValueDescriptor

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);
}
Also used : DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor)

Example 92 with DataValueDescriptor

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;
}
Also used : ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) RowLocation(org.apache.derby.iapi.types.RowLocation) StatementContext(org.apache.derby.iapi.sql.conn.StatementContext)

Example 93 with DataValueDescriptor

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);
}
Also used : SQLLongint(org.apache.derby.iapi.types.SQLLongint) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) SQLLongint(org.apache.derby.iapi.types.SQLLongint) BackingStoreHashtable(org.apache.derby.iapi.store.access.BackingStoreHashtable)

Example 94 with DataValueDescriptor

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;
            }
        }
    }
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) SQLLongint(org.apache.derby.iapi.types.SQLLongint)

Example 95 with DataValueDescriptor

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();
}
Also used : DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor)

Aggregations

DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)328 ExecIndexRow (org.apache.derby.iapi.sql.execute.ExecIndexRow)72 ExecRow (org.apache.derby.iapi.sql.execute.ExecRow)62 RowLocation (org.apache.derby.iapi.types.RowLocation)54 SQLLongint (org.apache.derby.iapi.types.SQLLongint)51 StandardException (org.apache.derby.shared.common.error.StandardException)43 SQLChar (org.apache.derby.iapi.types.SQLChar)42 FormatableBitSet (org.apache.derby.iapi.services.io.FormatableBitSet)36 SQLVarchar (org.apache.derby.iapi.types.SQLVarchar)36 ScanController (org.apache.derby.iapi.store.access.ScanController)35 ConglomerateController (org.apache.derby.iapi.store.access.ConglomerateController)32 UUID (org.apache.derby.catalog.UUID)31 TupleDescriptor (org.apache.derby.iapi.sql.dictionary.TupleDescriptor)24 RawTransaction (org.apache.derby.iapi.store.raw.xact.RawTransaction)16 DataDescriptorGenerator (org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator)15 RawContainerHandle (org.apache.derby.iapi.store.raw.data.RawContainerHandle)15 DataTypeDescriptor (org.apache.derby.iapi.types.DataTypeDescriptor)15 Properties (java.util.Properties)14 UserType (org.apache.derby.iapi.types.UserType)13 Page (org.apache.derby.iapi.store.raw.Page)11