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

The following examples show how to use com.gs.fw.common.mithra.MithraTransaction#zSetOperationEvaluationMode() . 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: DelegatingList.java    From reladomo with Apache License 2.0 6 votes vote down vote up
private void forceRefreshWithOnePk(List listToRefresh, Attribute[] pkAttributes, Operation extraOp, MithraTransaction tx, boolean oldEvaluationMode)
{
    //todo: segregate by source attribute first
    int batches = listToRefresh.size() / REFRESH_PARAMETER_THRESHOLD;
    if (listToRefresh.size() % REFRESH_PARAMETER_THRESHOLD > 0) batches++;
    for (int b = 0; b < batches; b++)
    {
        Operation op;
        try
        {
            if (tx != null) tx.zSetOperationEvaluationMode(true);
            int end = Math.min(this.size(), (b + 1) * REFRESH_PARAMETER_THRESHOLD);
            op = pkAttributes[0].in(listToRefresh.subList(b * REFRESH_PARAMETER_THRESHOLD, end), pkAttributes[0]);
            if (pkAttributes.length == 2)
            {
                op = op.and(pkAttributes[1].in(listToRefresh.subList(b * REFRESH_PARAMETER_THRESHOLD, end), pkAttributes[1]));
            }
            if (extraOp != null) op = op.and(extraOp);
        }
        finally
        {
            if (tx != null) tx.zSetOperationEvaluationMode(oldEvaluationMode);
        }
        this.getMithraObjectPortal().findAsCachedQuery(op, null, true, false, 0, false);
    }
}
 
Example 4
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 5
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 6
Source File: MithraTransactionalPortal.java    From reladomo with Apache License 2.0 4 votes vote down vote up
public List findForMassDeleteInMemory(Operation op, MithraTransaction tx)
{
    if (this.getCache().size() == 0)
    {
        return ListFactory.EMPTY_LIST;
    }
    AnalyzedOperation analyzedOperation = new AnalyzedOperation(op);
    QueryCache queryCache = this.getQueryCache(tx);
    List result = null;
    CachedQuery cachedQuery = queryCache.findByEquality(analyzedOperation.getOriginalOperation());
    if (cachedQuery == null && analyzedOperation.isAnalyzedOperationDifferent())
    {
        cachedQuery = queryCache.findByEquality(analyzedOperation.getAnalyzedOperation());
    }
    if (cachedQuery != null)
    {
        result = cachedQuery.getResult();
    }
    if (result == null)
    {
        boolean partiallyCached = this.isPartiallyCached();
        UnifiedSet dependentPortals = new UnifiedSet(3);
        op.addDependentPortalsToSet(dependentPortals);
        if (!partiallyCached)
        {
            Iterator it = dependentPortals.iterator();
            while (it.hasNext() && !partiallyCached)
            {
                MithraObjectPortal depPortal = (MithraObjectPortal) it.next();
                partiallyCached = depPortal.isPartiallyCached();
            }
        }
        try
        {
            if (tx != null)
            {
                tx.zSetOperationEvaluationMode(true);
            }
            if (!partiallyCached)
            {
                result = op.applyOperationToFullCache();
            }
            else if (dependentPortals.size() == 1 && !op.isJoinedWith(this))
            {
                // even though we're partally cached, the operation can search the cache, because there are no mapped ops
                result = op.applyOperationToFullCache();
            }
        }
        finally
        {
            if (tx != null)
            {
                tx.zSetOperationEvaluationMode(false);
            }
        }
    }
    return result;
}
 
Example 7
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 8
Source File: DelegatingList.java    From reladomo with Apache License 2.0 4 votes vote down vote up
private void forceRefreshWithMultiplePk(List listToRefresh, Attribute[] pkAttributes, Operation extraOp, MithraTransaction tx, boolean oldEvaluationMode)
{
    List<? extends List> lists;
    try
    {
        if (tx != null) tx.zSetOperationEvaluationMode(true);
        lists = segregateBySourceAttribute(listToRefresh);
    }
    finally
    {
        if (tx != null) tx.zSetOperationEvaluationMode(oldEvaluationMode);
    }
    MithraObjectPortal portal = this.getMithraObjectPortal();
    Attribute sourceAttribute = portal.getFinder().getSourceAttribute();
    for (int i = 0; i < lists.size(); i++)
    {
        TupleTempContext tempContext = new TupleTempContext(pkAttributes, true);
        tempContext.enableRetryHook();
        try
        {
            List segregatedList = lists.get(i);
            Object source;
            try
            {
                if (tx != null) tx.zSetOperationEvaluationMode(true);
                source = sourceAttribute != null ? sourceAttribute.valueOf(segregatedList.get(0)) : null;
                tempContext.insert(segregatedList, portal, REFRESH_BULK_INSERT_THRESHOLD, false);
            }
            finally
            {
                if (tx != null) tx.zSetOperationEvaluationMode(oldEvaluationMode);
            }
            Operation op = tempContext.exists(source);
            if (extraOp != null) op = op.and(extraOp);
            portal.findAsCachedQuery(op, null, true, false, 0, false);
        }
        finally
        {
            tempContext.destroy();
        }
    }
}