com.gs.fw.common.mithra.portal.MithraTransactionalPortal Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of reladomo Show documentation
Show all versions of reladomo Show documentation
Reladomo is an object-relational mapping framework.
/*
Copyright 2016 Goldman Sachs.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
package com.gs.fw.common.mithra.portal;
import com.gs.fw.common.mithra.*;
import com.gs.fw.common.mithra.extractor.RelationshipHashStrategy;
import com.gs.fw.common.mithra.tempobject.MithraTuplePersister;
import com.gs.fw.common.mithra.behavior.txparticipation.FullTransactionalParticipationMode;
import com.gs.fw.common.mithra.behavior.txparticipation.ReadCacheWithOptimisticLockingTxParticipationMode;
import com.gs.fw.common.mithra.behavior.txparticipation.TxParticipationMode;
import com.gs.fw.common.mithra.behavior.state.PersistenceState;
import com.gs.fw.common.mithra.behavior.TemporalContainer;
import com.gs.fw.common.mithra.cache.Cache;
import com.gs.fw.common.mithra.finder.AnalyzedOperation;
import com.gs.fw.common.mithra.finder.Operation;
import com.gs.fw.common.mithra.finder.RelatedFinder;
import com.gs.fw.common.mithra.finder.UpdateCountHolderImpl;
import com.gs.fw.common.mithra.finder.orderby.OrderBy;
import com.gs.fw.common.mithra.querycache.CachedQuery;
import com.gs.fw.common.mithra.querycache.QueryCache;
import com.gs.fw.common.mithra.transaction.InTransactionDatedTransactionalObject;
import com.gs.fw.common.mithra.transaction.MithraObjectPersister;
import com.gs.fw.common.mithra.transaction.TransactionLocal;
import com.gs.collections.impl.set.mutable.UnifiedSet;
import com.gs.fw.common.mithra.util.ListFactory;
import java.sql.Timestamp;
import java.util.Iterator;
import java.util.List;
public class MithraTransactionalPortal extends MithraAbstractObjectPortal
{
private static TransactionLocal transactionalQueryCache = new TransactionLocal();
private TransactionLocal txPatricipationMode = new TransactionLocal();
private TxParticipationMode defaultTxParticipationMode = FullTransactionalParticipationMode.getInstance();
public MithraTransactionalPortal(MithraObjectDeserializer databaseObject, Cache cache,
RelatedFinder finder, int relationshipCacheSize, int minQueriesToKeep,
RelatedFinder[] superClassFinders, RelatedFinder[] subClassFinders, String uniqueAlias, int hierarchyDepth,
MithraObjectPersister mithraObjectPersister)
{
super(databaseObject, cache, finder, relationshipCacheSize, minQueriesToKeep, hierarchyDepth, new UpdateCountHolderImpl(),
mithraObjectPersister, (MithraTuplePersister) mithraObjectPersister, true);
this.setSuperClassFinders(superClassFinders);
this.setSubClassFinders(subClassFinders);
this.setUniqueAlias(uniqueAlias);
}
public static void initializeTransactionalQueryCache(MithraTransaction tx)
{
transactionalQueryCache.set(tx, new QueryCache(1000, 50));
}
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;
}
public void prepareForMassDelete(Operation op, boolean forceImplicitJoin)
{
MithraTransaction tx = MithraManagerProvider.getMithraManager().getCurrentTransaction();
tx.executeBufferedOperationsForPortal(this);
List result = this.findForMassDeleteInMemory(op, tx);
if (result == null)
{
tx.executeBufferedOperations();
result = this.getMithraObjectPersister().findForMassDelete(op, forceImplicitJoin);
}
for(int i=0;i 1)
{
Iterator it = dependentPortals.iterator();
while (it.hasNext() && !participate)
{
MithraObjectPortal depPortal = (MithraObjectPortal) it.next();
participate = depPortal.getTxParticipationMode(tx).mustParticipateInTxOnRead();
}
}
}
return participate;
}
private void checkTransactionParticipationForPureObject(List list, MithraTransaction tx)
{
if (list == null) return;
if (this.getTxParticipationMode(tx).mustParticipateInTxOnRead())
{
for(int i=0;i