if (getSelectionCriteria() != null) { ExpressionBuilder builder = getSelectionCriteria().getBuilder(); builder.setSession(unitOfWork.getRootSession(null)); builder.setQueryClass(getReferenceClass()); Map indexedInterimResult = unitOfWork.scanForConformingInstances(getSelectionCriteria(), getReferenceClass(), arguments, this); cursor.setSelectionCriteriaClone(getSelectionCriteria()); cursor.setTranslationRow(arguments); Object clone = conformIndividualResult(object, unitOfWork, arguments, getSelectionCriteria(), indexedInterimResult, buildDirectlyFromRows); if (clone != null) { fromDatabase.addElement(clone); for (Object iter = cp.iteratorFor(result); cp.hasNext(iter);) { Object object = cp.next(iter, sessionToUse); Object clone = conformIndividualResult(object, unitOfWork, arguments, getSelectionCriteria(), indexedInterimResult, buildDirectlyFromRows); if (clone != null) { fromDatabase.addElement(clone);
if (getSelectionCriteria() != null) { ExpressionBuilder builder = getSelectionCriteria().getBuilder(); builder.setSession(unitOfWork.getRootSession(null)); builder.setQueryClass(getReferenceClass()); Map<Object, Object> indexedInterimResult = unitOfWork.scanForConformingInstances(getSelectionCriteria(), getReferenceClass(), arguments, this); cursor.setSelectionCriteriaClone(getSelectionCriteria()); cursor.setTranslationRow(arguments); Object clone = conformIndividualResult(buildObject(row), unitOfWork, arguments, getSelectionCriteria(), indexedInterimResult); if (clone != null) { fromDatabase.add(clone); for (Object iter = cp.iteratorFor(result); cp.hasNext(iter);) { Object object = cp.next(iter, sessionToUse); Object clone = conformIndividualResult(registerIndividualResult(object, null, unitOfWork, null, null), unitOfWork, arguments, getSelectionCriteria(), indexedInterimResult); if (clone != null) { fromDatabase.add(clone);
/** * INTERNAL: * Check and return custom query flag. Custom query flag value is initialized when stored value is {@code null}. * Called from {@link #checkForCustomQuery(AbstractSession, AbstractRecord)} to retrieve custom query flag. * @param session Current session (not used). * @param translationRow Database record (not used). * @return Current custom query flag. Value will never be {@code null}. */ @Override protected Boolean checkCustomQueryFlag(final AbstractSession session, final AbstractRecord translationRow) { // #436871 - Use local copy to avoid NPE from concurrent modification. final Boolean useCustomQuery = isCustomQueryUsed; if (useCustomQuery != null) { return useCustomQuery; // Initialize custom query flag. } else { final boolean useCustomQueryValue = !isUserDefined() && isExpressionQuery() && getSelectionCriteria() == null && isDefaultPropertiesQuery() && (!hasOrderByExpressions()) && descriptor.getQueryManager().hasReadAllQuery(); setIsCustomQueryUsed(useCustomQueryValue); return Boolean.valueOf(useCustomQueryValue); } }
Expression selectionCriteria = getSelectionCriteria(); if (selectionCriteria != null) { ExpressionBuilder builder = getSelectionCriteria().getBuilder(); builder.setSession(unitOfWork.getRootSession(null)); builder.setQueryClass(getReferenceClass()); cursor.setSelectionCriteriaClone(getSelectionCriteria()); cursor.setTranslationRow(arguments); Object clone = conformIndividualResult(buildObject(row), unitOfWork, arguments, getSelectionCriteria(), indexedInterimResult); if (clone != null) { fromDatabase.add(clone); for (Object iter = cp.iteratorFor(result); cp.hasNext(iter);) { Object object = cp.next(iter, sessionToUse); Object clone = conformIndividualResult(registerIndividualResult(object, null, unitOfWork, null, null), unitOfWork, arguments, getSelectionCriteria(), indexedInterimResult); if (clone != null) { fromDatabase.add(clone);
/** * INTERNAL: * Check to see if a custom query should be used for this query. * This is done before the query is copied and prepared/executed. * null means there is none. */ protected DatabaseQuery checkForCustomQuery(AbstractSession session, AbstractRecord translationRow) { checkDescriptor(session); // Check if user defined a custom query. if (isCustomQueryUsed() == null) { setIsCustomQueryUsed((!isUserDefined()) && isExpressionQuery() && (getSelectionCriteria() == null) && (!hasOrderByExpressions()) && (this.descriptor.getQueryManager().hasReadAllQuery())); } if (isCustomQueryUsed().booleanValue()) { return this.descriptor.getQueryManager().getReadAllQuery(); } else { return null; } }
/** * INTERNAL: * Check to see if a custom query should be used for this query. * This is done before the query is copied and prepared/executed. * null means there is none. */ @Override protected DatabaseQuery checkForCustomQuery(AbstractSession session, AbstractRecord translationRow) { Boolean useCustomQuery = isCustomQueryUsed; checkDescriptor(session); // Check if user defined a custom query. if (useCustomQuery == null) { setIsCustomQueryUsed((!isUserDefined()) && isExpressionQuery() && (getSelectionCriteria() == null) && isDefaultPropertiesQuery() && (!hasOrderByExpressions()) && (this.descriptor.getQueryManager().hasReadAllQuery())); // Value of isCustomQueryUsed is updated by setIsCustomQueryUsed method. useCustomQuery = isCustomQueryUsed; } if (useCustomQuery != null && useCustomQuery.booleanValue()) { ReadAllQuery customQuery = this.descriptor.getQueryManager().getReadAllQuery(); if (this.accessors != null) { customQuery = (ReadAllQuery) customQuery.clone(); customQuery.setIsExecutionClone(true); customQuery.setAccessors(this.accessors); } isCustomQueryUsed = useCustomQuery; return customQuery; } isCustomQueryUsed = useCustomQuery; return null; }
rootSession = ((UnitOfWorkImpl)rootSession).getParent(); Vector allCachedVector = rootSession.getIdentityMapAccessor().getAllFromIdentityMap(getSelectionCriteria(), getReferenceClass(), translationRow, getInMemoryQueryIndirectionPolicyState(), false);
/** * INTERNAL: * The cache check is done before the prepare as a hit will not require the work to be done. */ protected Object checkEarlyReturnImpl(AbstractSession session, AbstractRecord translationRow) { // Check for in-memory only query. if (shouldCheckCacheOnly()) { // assert !isReportQuery(); if (shouldUseWrapperPolicy()) { getContainerPolicy().setElementDescriptor(this.descriptor); } // PERF: Fixed to not query each unit of work cache (is not conforming), // avoid hashtable and primary key indexing. // At some point we may need to support some kind of in-memory with conforming option, // but we do not currently allow this. AbstractSession rootSession = session; while (rootSession.isUnitOfWork()) { rootSession = ((UnitOfWorkImpl)rootSession).getParent(); } Vector allCachedVector = rootSession.getIdentityMapAccessor().getAllFromIdentityMap(getSelectionCriteria(), getReferenceClass(), translationRow, getInMemoryQueryIndirectionPolicyState(), false); // Must ensure that all of the objects returned are correctly registered in the unit of work. if (session.isUnitOfWork()) { allCachedVector = ((UnitOfWorkImpl)session).registerAllObjects(allCachedVector); } return getContainerPolicy().buildContainerFromVector(allCachedVector, session); } else { return null; } }
rootSession = ((UnitOfWorkImpl)rootSession).getParent(); Vector allCachedVector = rootSession.getIdentityMapAccessor().getAllFromIdentityMap(getSelectionCriteria(), getReferenceClass(), translationRow, getInMemoryQueryIndirectionPolicyState(), false);
if (query.getSelectionCriteria() == null) { builder = new ExpressionBuilder(); originalSelectionCriteria = query.getSelectionCriteria().copiedVersionFrom(clonedExpressions); builder = originalSelectionCriteria.getBuilder();
Expression backRef = builder.getManualQueryKey(getAttributeName() + "-back-ref", descriptorToUse); Expression twisted = backRef.twist(getSelectionCriteria(), builder); if (query.getSelectionCriteria() != null) { twisted = twisted.and(query.getSelectionCriteria().cloneUsing(backRef));