Package org.eclipse.persistence.internal.sessions

Examples of org.eclipse.persistence.internal.sessions.UnitOfWorkImpl


     * @return Vector - collection of objects resulting from execution of query.
     */
    public Object executeDatabaseQuery() throws DatabaseException {
        // ensure a pessimistic locking query will go down the write connection
       if (isLockQuery() && getSession().isUnitOfWork()) {
            UnitOfWorkImpl unitOfWork = (UnitOfWorkImpl)getSession();
            // Note if a nested unit of work this will recursively start a
            // transaction early on the parent also.
            if (isLockQuery()) {
                if ((!unitOfWork.getCommitManager().isActive()) && (!unitOfWork.wasTransactionBegunPrematurely())) {
                    unitOfWork.beginTransaction();
                    unitOfWork.setWasTransactionBegunPrematurely(true);
                }
            }
        }
        if (getContainerPolicy().overridesRead()) {
            return getContainerPolicy().execute();
View Full Code Here


     * supported.
     */
    protected Object buildAndRegisterObject(AbstractRecord row) {
        Object object = null;
        if (getSession().isUnitOfWork() && (!getQuery().isReportQuery()) && (getQuery().shouldMaintainCache()) && (getQuery().isObjectLevelReadQuery())) {
            UnitOfWorkImpl unitOfWork = (UnitOfWorkImpl)getSession();
            ObjectLevelReadQuery query = (ObjectLevelReadQuery)getQuery();
            if (query.shouldConformResultsInUnitOfWork() || query.getDescriptor().shouldAlwaysConformResultsInUnitOfWork()) {
                object = query.conformIndividualResult(row, unitOfWork, getTranslationRow(), getSelectionCriteriaClone(), getInitiallyConformingIndex(), true);
                // Notifies caller to continue until conforming instance found
                if (object == null) {
View Full Code Here

     * INTERNAL:
     * Executes the prepared query on the datastore.
     */
    public Object executeDatabaseQuery() throws DatabaseException {
        if (getSession().isUnitOfWork()) {
            UnitOfWorkImpl unitOfWork = (UnitOfWorkImpl)getSession();

            // Note if a nested unit of work this will recursively start a
            // transaction early on the parent also.
            if (isLockQuery()) {
                if ((!unitOfWork.getCommitManager().isActive()) && (!unitOfWork.wasTransactionBegunPrematurely())) {
                    unitOfWork.beginTransaction();
                    unitOfWork.setWasTransactionBegunPrematurely(true);
                }
            }
            if (unitOfWork.isNestedUnitOfWork()) {
                // execute in parent UOW then register normally here.
                UnitOfWorkImpl nestedUnitOfWork = (UnitOfWorkImpl)getSession();
                setSession(nestedUnitOfWork.getParent());
                Object result = executeDatabaseQuery();
                setSession(nestedUnitOfWork);
                Object clone = registerIndividualResult(result, unitOfWork, null);

                if (shouldUseWrapperPolicy()) {
View Full Code Here

     */
    public Object executeDatabaseQuery() throws DatabaseException {

        /* Fix to allow executing non-selecting SQL in a UnitOfWork. - RB */
        if (this.session.isUnitOfWork()) {
            UnitOfWorkImpl unitOfWork = (UnitOfWorkImpl)this.session;
            /* bug:4211104 for DataModifyQueries executed during an event, while transaction was started by the uow*/
            if (!unitOfWork.getCommitManager().isActive() && !unitOfWork.isInTransaction()) {
                unitOfWork.beginEarlyTransaction();
            }
            unitOfWork.setWasNonObjectLevelModifyQueryExecuted(true);
        }
        return getQueryMechanism().executeNoSelect();
    }
View Full Code Here

     * Execute the query building the objects directly from the database result-set.
     * @exception  DatabaseException - an error has occurred on the database
     * @return object - the first object found or null if none.
     */
    protected Object executeObjectLevelReadQueryFromResultSet() throws DatabaseException {
        UnitOfWorkImpl unitOfWork = (UnitOfWorkImpl)getSession();
        DatabaseAccessor accessor = (DatabaseAccessor)unitOfWork.getAccessor();
        DatabasePlatform platform = accessor.getPlatform();
        DatabaseCall call = (DatabaseCall)getCall().clone();
        call.setQuery(this);
        AbstractRecord translationRow = getTranslationRow();
        call.translate(getTranslationRow(), null, unitOfWork);
View Full Code Here

     * This method executes within the transaction context of the caller of
     * transaction.commit(), or in the case of container-managed transactions,
     * in the context of the method for which the Container started the transaction.
     */
    public void beforeCompletion() {
        UnitOfWorkImpl uow = getUnitOfWork();
        // it's a purely sequencing listener - nothing to do in beforeCompletion.
        if(unitOfWork == null) {
            return;
        }
        try {
            Object status = getTransactionController().getTransactionStatus();
            getTransactionController().logTxStateTrace(uow, "TX_beforeCompletion", status);
            //CR# 3452053
            session.startOperationProfile(SessionProfiler.JtsBeforeCompletion);

            // In case jts transaction was internally started but completed
            // directly by TransactionManager this flag is still set to true.
            getSession().setWasJTSTransactionInternallyStarted(false);
           
            // If the uow is not active then somebody somewhere messed up
            if (!uow.isActive()) {
                throw TransactionException.inactiveUnitOfWork(uow);
            }

            // Bail out if we don't think we should actually issue the SQL
            if (!getTransactionController().canIssueSQLToDatabase_impl(status)) {
                // Must force concurrency mgrs active thread if in nested transaction
                if (getSession().isInTransaction()) {
                    getSession().getTransactionMutex().setActiveThread(Thread.currentThread());
                    if(getUnitOfWork().wasTransactionBegunPrematurely()) {
                        getUnitOfWork().setWasTransactionBegunPrematurely(false);
                    }
                    getSession().rollbackTransaction();
                }
                getSession().releaseJTSConnection();
                return;
            }

            // Must force concurrency mgrs active thread if in nested transaction
            if (getSession().isInTransaction()) {
                getSession().getTransactionMutex().setActiveThread(Thread.currentThread());
            }

            // If sequencing callback for this transaction will be required
            // in case it doesn't already exist it will be created on this very listener
            // avoiding adding more listeners while processing a listener.
            if(getTransactionController().isSequencingCallbackRequired()) {
                getTransactionController().currentlyProcessedListeners.put(getTransactionKey(), this);
            }
           
            // Send the SQL to the DB
            uow.issueSQLbeforeCompletion();

            // Fix up our merge state in the unit of work and the session
            uow.setPendingMerge();

        } catch (RuntimeException exception) {
            // Log the exception if it has not already been logged, or is a non-EclipseLink exception
            if (!(exception instanceof EclipseLinkException && ((EclipseLinkException)exception).hasBeenLogged())) {
                uow.logThrowable(SessionLog.WARNING, SessionLog.TRANSACTION, exception);
            }
           
            // Handle the exception according to transaction manager requirements
            handleException(exception);
        } finally {
View Full Code Here

        checkPrePrepare(session);

        if (!session.isUnitOfWork()) {
            return checkEarlyReturnLocal(session, translationRow);
        }
        UnitOfWorkImpl unitOfWork = (UnitOfWorkImpl)session;

        // The cache check must happen on the UnitOfWork in these cases either
        // to access transient state or for pessimistic locking, as only the
        // UOW knows which objects it has locked.
        Object result = null;
        // PERF: Avoid uow check for read-only.
        if (!this.descriptor.shouldBeReadOnly()) {
            result = checkEarlyReturnLocal(unitOfWork, translationRow);
        }
        if (result != null) {
            return result;
        }

        // PERF: If a locking query, or isolated always, then cache is ignored, so no point checking.
        // An error should be thrown on prepare is checkCacheOnly is used with these.
        if ((!unitOfWork.isNestedUnitOfWork()) && (this.descriptor.getCachePolicy().shouldIsolateObjectsInUnitOfWork()  || isLockQuery()) || unitOfWork.shouldForceReadFromDB(this, null)) {
            return null;
        }

        // follow the execution path in looking for the object.
        AbstractSession parentSession = unitOfWork.getParentIdentityMapSession(this);

        // assert parentSession != unitOfWork;
        result = checkEarlyReturn(parentSession, translationRow);

        if (result != null) {
            // Optimization: If find deleted object by exact primary key
            // treat this as cache hit but return null.  Bug 2782991.
            if (result == InvalidObject.instance) {
                return result;
            }
            Object clone = registerResultInUnitOfWork(result, unitOfWork, translationRow, false);
            if (shouldConformResultsInUnitOfWork() && unitOfWork.isObjectDeleted(clone)) {
                return InvalidObject.instance;
            }
            return clone;
        } else {
            return null;
View Full Code Here

        if (this.isResultSetOptimizedQuery) {
            return executeObjectLevelReadQueryFromResultSet();
        }
       
        if (getSession().isUnitOfWork()) {
            UnitOfWorkImpl unitOfWork = (UnitOfWorkImpl)getSession();

            // Note if a nested unit of work this will recursively start a
            // transaction early on the parent also.
            if (isLockQuery()) {
                if ((!unitOfWork.getCommitManager().isActive()) && (!unitOfWork.wasTransactionBegunPrematurely())) {
                    unitOfWork.beginTransaction();
                    unitOfWork.setWasTransactionBegunPrematurely(true);
                }
            }
            if (unitOfWork.isNestedUnitOfWork()) {
                UnitOfWorkImpl nestedUnitOfWork = (UnitOfWorkImpl)getSession();
                setSession(nestedUnitOfWork.getParent());
                Object result = executeDatabaseQuery();
                setSession(nestedUnitOfWork);
                return registerResultInUnitOfWork(result, nestedUnitOfWork, getTranslationRow(), false);
            }
        }
View Full Code Here

     * This method executes without a transaction context.
     *
     * @param status The status code of the transaction completion.
     */
    public void afterCompletion(Object status) {
        UnitOfWorkImpl uow = getUnitOfWork();
        // it's a purely sequencing listener - call sequencing callback if the transaction has committed.
        if(uow == null) {
            if(getTransactionController().isSequencingCallbackRequired()) {
                if(getTransactionController().canMergeUnitOfWork_impl(status)) {
                    callSequencingCallback();
                }
            }
        } else {
            try {
                // Log the fact that we got invoked
                getTransactionController().logTxStateTrace(uow, "TX_afterCompletion", status);
                //Cr#3452053
                session.startOperationProfile(SessionProfiler.JtsAfterCompletion);
                // The uow should still be active even in rollback case
                if (!uow.isActive()) {
                    throw TransactionException.inactiveUnitOfWork(uow);
                }
   
                // Only do merge if txn was committed
                if (getTransactionController().canMergeUnitOfWork_impl(status)) {
                    if(getTransactionController().isSequencingCallbackRequired()) {
                        callSequencingCallback();
                    }
                    if (uow.isMergePending()) {
                        // uow in PENDING_MERGE state, merge clones
                        uow.mergeClonesAfterCompletion();
                    }
                } else {
                    // call this method again because there may have been no beforeCompletion call
                    // if case transaction is to be rolled back.
                    getSession().releaseJTSConnection();
                    uow.afterExternalTransactionRollback();
                }
            } catch (RuntimeException exception) {
                // Log the exception if it has not already been logged, or is a non-EclipseLink exception
                if (!(exception instanceof EclipseLinkException && ((EclipseLinkException)exception).hasBeenLogged())) {
                    uow.logThrowable(SessionLog.WARNING, SessionLog.TRANSACTION, exception);
                }
                   
                // Rethrow it just for fun (app servers tend to ignore them at this stage)
                throw exception;
            } finally {
                session.endOperationProfile(SessionProfiler.JtsAfterCompletion);
            }
   
            // Clean up by releasing the uow and client session
            if (uow.shouldResumeUnitOfWorkOnTransactionCompletion() && getTransactionController().canMergeUnitOfWork_impl(status)){
                uow.synchronizeAndResume();
                uow.setSynchronized(false);
            }else{
                uow.release();
                // Release the session explicitly
                if (getSession().isClientSession() || (getSession().isSessionBroker() && ((SessionBroker)getSession()).isClientSessionBroker())) {
                    getSession().release();
                }
            }
View Full Code Here

        Object transaction = getTransaction();
        if (transaction == null) {
            return null;
        }
       
        UnitOfWorkImpl activeUnitOfWork = lookupActiveUnitOfWork(transaction);
        if (activeUnitOfWork == null) {
            // Txn is active but no UoW has been associated with it yet, so create one.
            activeUnitOfWork = getSession().acquireUnitOfWork();
            Object transactionKey = getTransactionKey(transaction);
            addUnitOfWork(transactionKey, activeUnitOfWork);
            activeUnitOfWork.setTransaction(transaction);
            this.activeUnitOfWorkThreadLocal.set(activeUnitOfWork);
        }
        return activeUnitOfWork;
    }
View Full Code Here

TOP

Related Classes of org.eclipse.persistence.internal.sessions.UnitOfWorkImpl

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.