Java Code Examples for com.gs.fw.common.mithra.MithraTransaction#zIsInOperationEvaluationMode()

The following examples show how to use com.gs.fw.common.mithra.MithraTransaction#zIsInOperationEvaluationMode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MithraTransactionalPortal.java    From reladomo with Apache License 2.0 6 votes vote down vote up
@Override
public Object getAsOneFromCache(Object srcObject, Object srcData, RelationshipHashStrategy relationshipHashStrategy, Timestamp asOfDate0, Timestamp asOfDate1)
{
    MithraTransaction tx = MithraManagerProvider.getMithraManager().getCurrentTransaction();
    if (tx == null)
    {
        return super.getAsOneFromCache(srcObject, srcData, relationshipHashStrategy, asOfDate0, asOfDate1);
    }
    else
    {
        boolean oldEvaluationMode = tx.zIsInOperationEvaluationMode();
        try
        {
            tx.zSetOperationEvaluationMode(true);
            MithraTransactionalObject result = (MithraTransactionalObject)
                    this.getCache().getAsOne(srcObject, srcData, relationshipHashStrategy, asOfDate0, asOfDate1);

            result = checkObjectForTransactionParticipation(result, tx);
            return result;
        }
        finally
        {
            tx.zSetOperationEvaluationMode(oldEvaluationMode);
        }
    }
}
 
Example 2
Source File: MithraTransactionalPortal.java    From reladomo with Apache License 2.0 6 votes vote down vote up
@Override
public Object getAsOneByIndexFromCache(Object srcObject, Object srcData, RelationshipHashStrategy relationshipHashStrategy, Timestamp asOfDate0, Timestamp asOfDate1, int indexRef)
{
    MithraTransaction tx = MithraManagerProvider.getMithraManager().getCurrentTransaction();
    if (tx == null)
    {
        return super.getAsOneByIndexFromCache(srcObject, srcData, relationshipHashStrategy, asOfDate0, asOfDate1, indexRef);
    }
    else
    {
        boolean oldEvaluationMode = tx.zIsInOperationEvaluationMode();
        try
        {
            tx.zSetOperationEvaluationMode(true);
            MithraTransactionalObject result = (MithraTransactionalObject)
                    this.getCache().getAsOneByIndex(indexRef, srcObject, srcData, relationshipHashStrategy, asOfDate0, asOfDate1);

            result = checkObjectForTransactionParticipation(result, tx);
            return result;
        }
        finally
        {
            tx.zSetOperationEvaluationMode(oldEvaluationMode);
        }
    }
}
 
Example 3
Source File: MithraTransactionalPortal.java    From reladomo with Apache License 2.0 5 votes vote down vote up
private List applyOperationAndCheck(Operation op, MithraTransaction tx)
{
    boolean oldEvaluationMode = tx.zIsInOperationEvaluationMode();
    List resultList = null;
    try
    {
        tx.zSetOperationEvaluationMode(true);
        if (this.isPureHome() || (!this.isOperationPartiallyCached(op) && !this.txParticipationRequired(tx, op)))
        {
            resultList = this.resolveOperationOnCache(op);
        }
        else
        {
            resultList = op.applyOperationToPartialCache();
            if (resultList == null && !this.isOperationPartiallyCached(op) && this.getTxParticipationMode(tx).mustParticipateInTxOnRead())
            {
                // attempt to find what we have in cache to trigger waiting for potential other transactions
                List untrustworthyResult = op.applyOperationToFullCache();
                checkTransactionParticipationAndWaitForOtherTransactions(untrustworthyResult, tx);
            }
            resultList = checkTransactionParticipationAndWaitForOtherTransactions(resultList, tx);
        }
    }
    finally
    {
        tx.zSetOperationEvaluationMode(oldEvaluationMode);
    }
    if (this.isPureHome())
    {
        checkTransactionParticipationForPureObject(resultList, tx);
    }
    return resultList;
}
 
Example 4
Source File: MithraTempContextWithSourceAttribute.java    From reladomo with Apache License 2.0 5 votes vote down vote up
protected void remove(final Object sourceAttributeValue, MithraTransaction tx)
{
    MithraObjectPortal portal = this.getMithraObjectPortal();
    this.existingContexts.remove(sourceAttributeValue);
    if (existingContexts.isEmpty())
    {
        this.getContainer().clearCurrentContext();
        portal.incrementClassUpdateCount();
        if (tx != null)
        {
            this.getContainer().clearTxContext(tx);
        }
        this.setDestroyed(true);
    }
    else
    {
        final Attribute sourceAttribute = portal.getFinder().getSourceAttribute();
        boolean operationEvalMode = false;
        if (tx != null)
        {
            operationEvalMode = tx.zIsInOperationEvaluationMode();
            tx.zSetOperationEvaluationMode(true);
        }
        try
        {
            portal.getCache().removeAll(new Filter()
            {
                public boolean matches(Object o)
                {
                    return sourceAttribute.valueOf(o).equals(sourceAttributeValue);
                }
            });
            portal.incrementClassUpdateCount();
        }
        finally
        {
            if (tx != null) tx.zSetOperationEvaluationMode(operationEvalMode);
        }
    }
}
 
Example 5
Source File: DelegatingList.java    From reladomo with Apache License 2.0 4 votes vote down vote up
protected void forceRefreshForSimpleList()
{
    if (this.size() == 0)
    {
        return;
    }
    RelatedFinder finder = this.getMithraObjectPortal().getFinder();
    Attribute[] pkAttributes = finder.getPrimaryKeyAttributes();
    Attribute sourceAttribute = finder.getSourceAttribute();
    AsOfAttribute[] asOfAttributes = finder.getAsOfAttributes();
    MithraTransaction tx = MithraManagerProvider.getMithraManager().getCurrentTransaction();
    boolean oldEvaluationMode = tx != null && tx.zIsInOperationEvaluationMode();
    if (asOfAttributes != null)
    {
        List<? extends List> segregatedByDate;
        try
        {
            if (tx != null) tx.zSetOperationEvaluationMode(true);
            segregatedByDate = segregateByAsOfAttribute(asOfAttributes);
        }
        finally
        {
            if (tx != null) tx.zSetOperationEvaluationMode(oldEvaluationMode);
        }
        for (int i = 0; i < segregatedByDate.size(); i++)
        {
            List list = segregatedByDate.get(i);
            Operation dateOp;
            try
            {
                if (tx != null) tx.zSetOperationEvaluationMode(true);
                dateOp = asOfAttributes[0].nonPrimitiveEq(asOfAttributes[0].valueOf(list.get(0)));
                if (asOfAttributes.length == 2)
                {
                    dateOp = dateOp.and(asOfAttributes[1].nonPrimitiveEq(asOfAttributes[1].valueOf(list.get(0))));
                }
            }
            finally
            {
                if (tx != null)
                {
                    tx.zSetOperationEvaluationMode(oldEvaluationMode);
                }
            }
            if (pkAttributes.length == 1 || (pkAttributes.length == 2 && sourceAttribute != null))
            {
                forceRefreshWithOnePk(list, pkAttributes, dateOp, tx, oldEvaluationMode);
            }
            else
            {
                forceRefreshWithMultiplePk(list, pkAttributes, dateOp, tx, oldEvaluationMode);
            }
        }
    }
    else
    {
        if (pkAttributes.length == 1 || (pkAttributes.length == 2 && sourceAttribute != null))
        {
            forceRefreshWithOnePk(this, pkAttributes, null, tx, oldEvaluationMode);
        }
        else
        {
            forceRefreshWithMultiplePk(this, pkAttributes, null, tx, oldEvaluationMode);
        }
    }
}
 
Example 6
Source File: PersistenceState.java    From reladomo with Apache License 2.0 4 votes vote down vote up
public static TransactionalBehavior getTransactionalBehaviorForTransactionForReadWithWaitIfNecessary(MithraTransaction threadTx,
                                                                                                     MithraTransactionalObject mto, TransactionalState transactionalState, int persistenceState)
{
    TransactionalBehavior result = null;
    if (transactionalState == null || transactionalState.hasNoTransactions()) // object is not in a transaction
    {
        if (threadTx.zIsInOperationEvaluationMode() || !mto.zGetPortal().getTxParticipationMode(threadTx).mustParticipateInTxOnRead())
        {
            result = allStates[persistenceState].getForNoTransaction();
        }
        else
        {
            TransactionalBehavior enrollBehavior = allStates[persistenceState].getForEnrollTransaction();
            result = enrollBehavior.enrollInTransactionForRead(mto, threadTx, transactionalState);
        }
    }
    else
    {
        if (transactionalState.isParticipatingInReadOrWrite(threadTx))
        {
            result = allStates[transactionalState.getPersistenceState()].getForSameTransaction();
        }
        else
        {
            if (threadTx.zIsInOperationEvaluationMode() || !mto.zGetPortal().getTxParticipationMode(threadTx).mustParticipateInTxOnRead())
            {
                result = allStates[persistenceState].getForNoTransaction();
            }
            else if (transactionalState.isEnrolledForWriteByOther(threadTx))
            {
                transactionalState.waitForTransactions(threadTx);
            }
            else
            {
                if (mto.zEnrollInTransactionForRead(transactionalState, threadTx, persistenceState))
                {
                    result = allStates[persistenceState].getForSameTransaction();
                }
            }
        }
    }
    return result;
}