return domainObject;
}
public Object getFromIdentityMap(Expression selectionCriteria, Class theClass, Record translationRow, InMemoryQueryIndirectionPolicy valueHolderPolicy, boolean conforming, boolean shouldReturnInvalidatedObjects, ClassDescriptor descriptor) {
UnitOfWorkImpl unitOfWork = (conforming) ? (UnitOfWorkImpl)getSession() : null;
getSession().startOperationProfile(SessionProfiler.CACHE);
try {
Expression selectionCriteriaClone = selectionCriteria;
// Only clone if required.
if ((selectionCriteria != null) && (selectionCriteriaClone.getBuilder().getSession() == null)) {
selectionCriteriaClone = (Expression)selectionCriteria.clone();
selectionCriteriaClone.getBuilder().setSession(getSession().getRootSession(null));
selectionCriteriaClone.getBuilder().setQueryClass(theClass);
}
IdentityMap map = getIdentityMap(descriptor);
// cache the current time to avoid calculating it every time through the loop
long currentTimeInMillis = System.currentTimeMillis();
for (Enumeration cacheEnum = map.keys(); cacheEnum.hasMoreElements();) {
CacheKey key = (CacheKey)cacheEnum.nextElement();
if (!shouldReturnInvalidatedObjects && descriptor.getCacheInvalidationPolicy().isInvalidated(key, currentTimeInMillis)) {
continue;
}
Object object = key.getObject();
// Bug # 3216337 - key.getObject() should check for null; object may be GC'd (MWN)
if (object == null) {
continue;
}
// Must check for inheritance.
if ((object.getClass() == theClass) || (theClass.isInstance(object))) {
if (selectionCriteriaClone == null) {
// bug 2782991: if first found was deleted nothing returned.
if (!(conforming && unitOfWork.isObjectDeleted(object))) {
getSession().incrementProfile(SessionProfiler.CacheHits);
return object;
}
}
//CR 3677 integration of a ValueHolderPolicy
try {
if (selectionCriteriaClone.doesConform(object, getSession(), (AbstractRecord)translationRow, valueHolderPolicy)) {
// bug 2782991: if first found was deleted nothing returned.
if (!(conforming && unitOfWork.isObjectDeleted(object))) {
getSession().incrementProfile(SessionProfiler.CacheHits);
return object;
}
}
} catch (QueryException queryException) {
if (queryException.getErrorCode() == QueryException.MUST_INSTANTIATE_VALUEHOLDERS) {
if (valueHolderPolicy.shouldIgnoreIndirectionExceptionReturnConformed()) {
// bug 2782991: if first found was deleted nothing returned.
if (!(conforming && unitOfWork.isObjectDeleted(object))) {
getSession().incrementProfile(SessionProfiler.CacheHits);
return object;
}
} else if (valueHolderPolicy.shouldIgnoreIndirectionExceptionReturnNotConformed()) {
// For bug 2667870 just skip this item, but do not abort.