Search in sources :

Example 81 with StandardException

use of org.apache.derby.shared.common.error.StandardException in project derby by apache.

the class GroupedAggregateResultSet method openCore.

// /////////////////////////////////////////////////////////////////////////////
// 
// ResultSet interface (leftover from NoPutResultSet)
// 
// /////////////////////////////////////////////////////////////////////////////
/**
 * Open the scan.  Load the sorter and prepare to get
 * rows from it.
 *
 * @exception StandardException thrown if cursor finished.
 */
public void openCore() throws StandardException {
    beginTime = getCurrentTimeMillis();
    // is access to open controlled and ensured valid.
    if (SanityManager.DEBUG)
        SanityManager.ASSERT(!isOpen, "GroupedAggregateResultSet already open");
    sortResultRow = (ExecIndexRow) getRowTemplate().getClone();
    sourceExecIndexRow = (ExecIndexRow) getRowTemplate().getClone();
    source.openCore();
    try {
        /* If this is an in-order group by then we do not need the sorter.
		 * (We can do the aggregation ourselves.)
		 * We save a clone of the first row so that subsequent next()s
		 * do not overwrite the saved row.
		 */
        if (!isInSortedOrder)
            scanController = loadSorter();
        ExecIndexRow currSortedRow = getNextRowFromRS();
        resultsComplete = (currSortedRow == null);
        if (usingAggregateObserver) {
            if (currSortedRow != null)
                finishedResults.add(finishAggregation(currSortedRow).getClone());
        } else if (!resultsComplete) {
            if (rollup)
                resultRows = new ExecIndexRow[numGCols() + 1];
            else
                resultRows = new ExecIndexRow[1];
            if (aggInfoList.hasDistinct()) {
                distinctValues = new ArrayList<List<Set<DataValueDescriptor>>>(resultRows.length);
            }
            for (int r = 0; r < resultRows.length; r++) {
                resultRows[r] = (ExecIndexRow) currSortedRow.getClone();
                initializeVectorAggregation(resultRows[r]);
                if (aggInfoList.hasDistinct()) {
                    distinctValues.add(new ArrayList<Set<DataValueDescriptor>>(aggregates.length));
                    initializeDistinctMaps(r, true);
                }
            }
        }
    } catch (StandardException e) {
        // DERBY-4330 Result set tree must be atomically open or
        // closed for reuse to work (after DERBY-827).
        // to make close do its thing:
        isOpen = true;
        try {
            close();
        } catch (StandardException ee) {
        }
        throw e;
    }
    isOpen = true;
    numOpens++;
    openTime += getElapsedMillis(beginTime);
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) Set(java.util.Set) HashSet(java.util.HashSet) NoPutResultSet(org.apache.derby.iapi.sql.execute.NoPutResultSet) CursorResultSet(org.apache.derby.iapi.sql.execute.CursorResultSet) ArrayList(java.util.ArrayList) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow)

Example 82 with StandardException

use of org.apache.derby.shared.common.error.StandardException in project derby by apache.

the class HashScanResultSet method openCore.

/**
 * 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 on failure to open
 */
public void openCore() throws StandardException {
    TransactionController tc;
    beginTime = getCurrentTimeMillis();
    if (SanityManager.DEBUG)
        SanityManager.ASSERT(!isOpen, "HashScanResultSet already open");
    // Get the current transaction controller
    tc = activation.getTransactionController();
    initIsolationLevel();
    if (startKeyGetter != null) {
        startPosition = (ExecIndexRow) startKeyGetter.invoke(activation);
        if (sameStartStopPosition) {
            stopPosition = startPosition;
        }
    }
    if (stopKeyGetter != null) {
        stopPosition = (ExecIndexRow) stopKeyGetter.invoke(activation);
    }
    // (and must) skip the scan, because no rows can qualify
    if (skipScan(startPosition, stopPosition)) {
        // Do nothing
        ;
    } else if (!hashtableBuilt) {
        DataValueDescriptor[] startPositionRow = startPosition == null ? null : startPosition.getRowArray();
        DataValueDescriptor[] stopPositionRow = stopPosition == null ? null : stopPosition.getRowArray();
        hashtable = tc.createBackingStoreHashtableFromScan(// conglomerate to open
        conglomId, (forUpdate ? TransactionController.OPENMODE_FORUPDATE : 0), lockMode, isolationLevel, accessedCols, startPositionRow, startSearchOperator, scanQualifiers, stopPositionRow, stopSearchOperator, // no limit on total rows.
        -1, keyColumns, // remove duplicates?
        eliminateDuplicates, // RESOLVE - is there a row estimate?
        -1, maxCapacity, // in memory Hashtable initial capacity
        initialCapacity, // in memory Hashtable load factor
        loadFactor, runTimeStatisticsOn, skipNullKeyColumns, keepAfterCommit, fetchRowLocations);
        if (runTimeStatisticsOn) {
            hashtableSize = hashtable.size();
            if (scanProperties == null) {
                scanProperties = new Properties();
            }
            try {
                if (hashtable != null) {
                    hashtable.getAllRuntimeStats(scanProperties);
                }
            } catch (StandardException se) {
            // ignore
            }
        }
        /* Remember that we created the hash table */
        hashtableBuilt = true;
        /*
			** Tell the activation about the number of qualifying rows.
			** Do this only here, not in reopen, because we don't want
			** to do this costly operation too often.
			*/
        activation.informOfRowCount(this, (long) hashtableSize);
    }
    isOpen = true;
    resetProbeVariables();
    numOpens++;
    openTime += getElapsedMillis(beginTime);
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) TransactionController(org.apache.derby.iapi.store.access.TransactionController) Properties(java.util.Properties)

Example 83 with StandardException

use of org.apache.derby.shared.common.error.StandardException in project derby by apache.

the class HashScanResultSet method printPosition.

/**
 * Return a start or stop positioner as a String.
 */
private String printPosition(int searchOperator, GeneratedMethod positionGetter, ExecIndexRow eiRow) {
    String idt = "";
    String output = "";
    if (positionGetter == null) {
        return "\t" + MessageService.getTextMessage(SQLState.LANG_NONE) + "\n";
    }
    ExecIndexRow positioner = null;
    try {
        positioner = (ExecIndexRow) positionGetter.invoke(activation);
    } catch (StandardException e) {
        if (eiRow == null) {
            return "\t" + MessageService.getTextMessage(SQLState.LANG_POSITION_NOT_AVAIL);
        }
        return "\t" + MessageService.getTextMessage(SQLState.LANG_UNEXPECTED_EXC_GETTING_POSITIONER) + "\n";
    }
    if (positioner == null) {
        return "\t" + MessageService.getTextMessage(SQLState.LANG_NONE) + "\n";
    }
    String searchOp = null;
    switch(searchOperator) {
        case ScanController.GE:
            searchOp = ">=";
            break;
        case ScanController.GT:
            searchOp = ">";
            break;
        default:
            if (SanityManager.DEBUG) {
                SanityManager.THROWASSERT("Unknown search operator " + searchOperator);
            }
            // This is not internationalized because we should never
            // reach here.
            searchOp = "unknown value (" + searchOperator + ")";
            break;
    }
    output += "\t" + MessageService.getTextMessage(SQLState.LANG_POSITIONER, searchOp, String.valueOf(positioner.nColumns())) + "\n";
    output += "\t" + MessageService.getTextMessage(SQLState.LANG_ORDERED_NULL_SEMANTICS) + "\n";
    boolean colSeen = false;
    for (int position = 0; position < positioner.nColumns(); position++) {
        if (positioner.areNullsOrdered(position)) {
            output = output + position + " ";
            colSeen = true;
        }
        if (colSeen && position == positioner.nColumns() - 1) {
            output = output + "\n";
        }
    }
    return output;
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow)

Example 84 with StandardException

use of org.apache.derby.shared.common.error.StandardException in project derby by apache.

the class InsertResultSet method getOldStyleIdentityValue.

/**
 * Identity generation logic used in pre-10.11 databases.
 *
 * @param index   0-based index into aiCache
 */
private NumberDataValue getOldStyleIdentityValue(int index) throws StandardException {
    NumberDataValue newValue;
    TransactionController nestedTC = null;
    TransactionController tcToUse;
    try {
        // DERBY-5780, defaulting log syncing to false, which improves
        // performance of identity value generation.  If system
        // crashes may reuse an identity value because commit did not
        // sync, but only if no subsequent user transaction has
        // committed or aborted and thus no row can exist that used
        // the previous value.  Without this identity values pay
        // a synchronous I/O to the log file for each new value no
        // matter how many are inserted in a single transaction.
        nestedTC = tc.startNestedUserTransaction(false, false);
        tcToUse = nestedTC;
    } catch (StandardException se) {
        // If I cannot start a Nested User Transaction use the parent
        // transaction to do all the work.
        tcToUse = tc;
    }
    try {
        /* If tcToUse == tc, then we are using parent xaction-- this
                can happen if for some reason we couldn't start a nested
                transaction
             */
        newValue = dd.getSetAutoincrementValue(constants.autoincRowLocation[index], tcToUse, true, (NumberDataValue) aiCache[index], (tcToUse == tc));
    } catch (StandardException se) {
        if (tcToUse == tc) {
            /* we've using the parent xaction and we've timed out; just
                    throw an error and exit.
                 */
            throw se;
        }
        if (se.getMessageId().equals(SQLState.LOCK_TIMEOUT) || se.isSelfDeadlock()) {
            // if we couldn't do this with a nested xaction, retry with
            // parent-- we need to wait this time!
            newValue = dd.getSetAutoincrementValue(constants.autoincRowLocation[index], tc, true, (NumberDataValue) aiCache[index], true);
        } else if (se.getMessageId().equals(SQLState.LANG_OUTSIDE_RANGE_FOR_DATATYPE)) {
            // error message
            throw StandardException.newException(SQLState.LANG_AI_OVERFLOW, se, constants.getTableName(), constants.getColumnName(index));
        } else
            throw se;
    } finally {
        if (nestedTC != null) {
            // DERBY-5493 - prior to fix all nested user update
            // transactions did a nosync commit when commit() was
            // called, this default has been changed to do synced
            // commit.  Changed this commit to be commitNoSync to
            // not introduce performce degredation for autoincrement
            // keys.  As before, if server crashes the changes
            // made in the nested transaction may be lost.  If any
            // subsequent user transaction is commited, including any
            // inserts that would depend on the autoincrement value
            // change then the nested tranaction is guaranteed on
            // system crash.
            nestedTC.commitNoSync(TransactionController.RELEASE_LOCKS);
            nestedTC.destroy();
        }
    }
    return newValue;
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) TransactionController(org.apache.derby.iapi.store.access.TransactionController) NumberDataValue(org.apache.derby.iapi.types.NumberDataValue)

Example 85 with StandardException

use of org.apache.derby.shared.common.error.StandardException in project derby by apache.

the class FKInfo method readExternal.

/**
 * Read this object from a stream of stored objects.
 *
 * @param in read this.
 *
 * @exception IOException					thrown on error
 * @exception ClassNotFoundException		thrown on error
 */
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    try {
        /*
			** Create a new RowLocation from the format id.
			*/
        int formatid = FormatIdUtil.readFormatIdInteger(in);
        rowLocation = (RowLocation) Monitor.newInstanceFromIdentifier(formatid);
        if (SanityManager.DEBUG) {
            SanityManager.ASSERT(rowLocation != null, "row location is null in readExternal");
        }
        schemaName = (String) in.readObject();
        tableName = (String) in.readObject();
        type = in.readInt();
        stmtType = in.readInt();
        refUUID = (UUID) in.readObject();
        refConglomNumber = in.readLong();
        refConstraintID = (UUID) in.readObject();
        refConstraintIsDeferrable = in.readBoolean();
        fkConstraintNames = new String[ArrayUtil.readArrayLength(in)];
        ArrayUtil.readArrayItems(in, fkConstraintNames);
        fkUUIDs = new UUID[ArrayUtil.readArrayLength(in)];
        ArrayUtil.readArrayItems(in, fkUUIDs);
        fkConglomNumbers = ArrayUtil.readLongArray(in);
        fkIsSelfReferencing = ArrayUtil.readBooleanArray(in);
        colArray = ArrayUtil.readIntArray(in);
        raRules = ArrayUtil.readIntArray(in);
        deferrable = ArrayUtil.readBooleanArray(in);
        fkIds = new UUID[ArrayUtil.readArrayLength(in)];
        ArrayUtil.readArrayItems(in, fkIds);
    } catch (StandardException exception) {
        throw new StreamCorruptedException(exception.toString());
    }
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) StreamCorruptedException(java.io.StreamCorruptedException)

Aggregations

StandardException (org.apache.derby.shared.common.error.StandardException)276 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)43 LanguageConnectionContext (org.apache.derby.iapi.sql.conn.LanguageConnectionContext)37 IOException (java.io.IOException)32 Properties (java.util.Properties)29 RawTransaction (org.apache.derby.iapi.store.raw.xact.RawTransaction)27 TransactionController (org.apache.derby.iapi.store.access.TransactionController)26 ContextManager (org.apache.derby.iapi.services.context.ContextManager)22 RawContainerHandle (org.apache.derby.iapi.store.raw.data.RawContainerHandle)20 SQLException (java.sql.SQLException)17 FormatableBitSet (org.apache.derby.iapi.services.io.FormatableBitSet)17 DataDictionary (org.apache.derby.iapi.sql.dictionary.DataDictionary)16 ConglomerateController (org.apache.derby.iapi.store.access.ConglomerateController)12 RowLocation (org.apache.derby.iapi.types.RowLocation)11 SQLLongint (org.apache.derby.iapi.types.SQLLongint)11 StorageFile (org.apache.derby.io.StorageFile)10 TableDescriptor (org.apache.derby.iapi.sql.dictionary.TableDescriptor)9 ScanController (org.apache.derby.iapi.store.access.ScanController)9 File (java.io.File)8 LogInstant (org.apache.derby.iapi.store.raw.log.LogInstant)8