/** * INTERNAL: * Return the fields required in the select clause, for fetch group reading. * Top level (not nested) passes null instead of nestedMapping. */ protected List<DatabaseField> getFetchGroupSelectionFields(DatabaseMapping nestedMapping) { Set<DatabaseField> fetchedFields = getFetchGroupNonNestedFieldsSet(nestedMapping); // Build field list in the same order as descriptor's fields so that the fields printed in the usual order in SELECT clause. List<DatabaseField> fields = new ArrayList(fetchedFields.size()); for (Iterator iterator = getDescriptor().getFields().iterator(); iterator.hasNext();) { DatabaseField field = (DatabaseField)iterator.next(); if (fetchedFields.contains(field)) { fields.add(field); } } return fields; }
/** * INTERNAL: * Return the fields required in the select clause, for fetch group reading. * Top level (not nested) passes null instead of nestedMapping. */ protected List<DatabaseField> getFetchGroupSelectionFields(DatabaseMapping nestedMapping) { Set<DatabaseField> fetchedFields = getFetchGroupNonNestedFieldsSet(nestedMapping); // Build field list in the same order as descriptor's fields so that the fields printed in the usual order in SELECT clause. List<DatabaseField> fields = new ArrayList(fetchedFields.size()); for (Iterator iterator = getDescriptor().getFields().iterator(); iterator.hasNext();) { DatabaseField field = (DatabaseField)iterator.next(); if (fetchedFields.contains(field)) { fields.add(field); } } return fields; }
/** * INTERNAL: * Return join manager responsible for managing all aspects of joining for the query. * Queries without joining should not have a joinedAttributeManager. */ public JoinedAttributeManager getJoinedAttributeManager() { if (this.joinedAttributeManager == null) { this.joinedAttributeManager = new JoinedAttributeManager(getDescriptor(), getExpressionBuilder(), this); } return this.joinedAttributeManager; }
/** * INTERNAL: * Return join manager responsible for managing all aspects of joining for the query. * Queries without joining should not have a joinedAttributeManager. */ public JoinedAttributeManager getJoinedAttributeManager() { if (this.joinedAttributeManager == null) { this.joinedAttributeManager = new JoinedAttributeManager(getDescriptor(), getExpressionBuilder(), this); } return this.joinedAttributeManager; }
/** * INTERNAL: * Return join manager responsible for managing all aspects of joining for the query. * Queries without joining should not have a joinedAttributeManager. */ public JoinedAttributeManager getJoinedAttributeManager() { if (this.joinedAttributeManager == null) { this.joinedAttributeManager = new JoinedAttributeManager(getDescriptor(), getExpressionBuilder(), this); } return this.joinedAttributeManager; }
if(!shouldExtendPessimisticLockScope || getDescriptor() == null) { return; int size = getDescriptor().getMappings().size(); boolean isExtended = false; boolean isFurtherExtensionRequired = false; for(int i=0; i < size; i++) { DatabaseMapping mapping = getDescriptor().getMappings().get(i); if(mapping.isForeignReferenceMapping()) { ForeignReferenceMapping frMapping = (ForeignReferenceMapping)mapping;
if(!shouldExtendPessimisticLockScope || getDescriptor() == null) { return; int size = getDescriptor().getMappings().size(); boolean isExtended = false; boolean isFurtherExtensionRequired = false; for(int i=0; i < size; i++) { DatabaseMapping mapping = getDescriptor().getMappings().get(i); if(mapping.isForeignReferenceMapping()) { ForeignReferenceMapping frMapping = (ForeignReferenceMapping)mapping;
/** * INTERNAL: * Initialize fetch group */ public void initializeFetchGroup() { if (this.fetchGroup != null) { //fetch group already set. return; } //not explicitly set dynamically fetch group if (this.fetchGroupName != null) {//set pre-defined named group this.fetchGroup = getDescriptor().getFetchGroupManager().getFetchGroup(this.fetchGroupName); if (this.fetchGroup == null) { //named fetch group is not defined in the descriptor throw QueryException.fetchGroupNotDefinedInDescriptor(this.fetchGroupName); } } else {//not set fetch group at all //use the default fetch group if not explicitly turned off if (shouldUseDefaultFetchGroup()) { this.fetchGroup = getDescriptor().getDefaultFetchGroup(); } } }
/** * INTERNAL: * Return the fields selected by the query. * This includes the partial or joined fields. * This is only used for custom SQL executions. */ public Vector getSelectionFields() { if (hasPartialAttributeExpressions()) { return getPartialAttributeSelectionFields(true); } else if (hasFetchGroup()) { return getFetchGroupSelectionFields(true); } else if (hasJoining()) { JoinedAttributeManager joinManager = getJoinedAttributeManager(); Vector fields = NonSynchronizedVector.newInstance(getDescriptor().getAllFields().size() + joinManager.getJoinedAttributeExpressions().size() + joinManager.getJoinedMappingExpressions().size()); Helper.addAllToVector(fields, getDescriptor().getAllFields()); addSelectionFieldsForJoinedExpressions(fields, joinManager.getJoinedAttributeExpressions()); addSelectionFieldsForJoinedExpressions(fields, joinManager.getJoinedMappingExpressions()); return fields; } return getDescriptor().getAllFields(); }
/** * INTERNAL: * Return the fields selected by the query. * This includes the partial or joined fields. * This is only used for custom SQL executions. */ public Vector getSelectionFields() { if (hasPartialAttributeExpressions()) { return getPartialAttributeSelectionFields(true); } Vector fields = NonSynchronizedVector.newInstance(); if (getExecutionFetchGroup() != null) { fields.addAll(getFetchGroupSelectionFields()); } else { fields.addAll(getDescriptor().getAllSelectionFields(this)); } // Add joined fields. if (hasJoining()) { addJoinSelectionFields(fields, true); } if (hasAdditionalFields()) { // Add additional fields, use for batch reading m-m. fields.addAll(getAdditionalFields()); } return fields; }
/** * INTERNAL: * Return the fields selected by the query. * This includes the partial or joined fields. * This is only used for custom SQL executions. */ public Vector getSelectionFields() { if (hasPartialAttributeExpressions()) { return getPartialAttributeSelectionFields(true); } Vector fields = NonSynchronizedVector.newInstance(); if (getExecutionFetchGroup() != null) { fields.addAll(getFetchGroupSelectionFields()); } else { fields.addAll(getDescriptor().getAllSelectionFields(this)); } // Add joined fields. if (hasJoining()) { addJoinSelectionFields(fields, true); } if (hasAdditionalFields()) { // Add additional fields, use for batch reading m-m. fields.addAll(getAdditionalFields()); } return fields; }
/** * INTERNAL: * Return the descriptor for the base expression. This is used in ReportItem when building the * return value (a class), as none of the expressions will have a session. */ public ClassDescriptor getContainingDescriptor(ObjectLevelReadQuery query) { AbstractSession session; Class queryClass = null; if (getBaseExpression().isExpressionBuilder()){ queryClass = ((ExpressionBuilder)getBaseExpression()).getQueryClass(); return query.getSession().getDescriptor(queryClass); } else { //it must be a QueryKeyExpression return query.getLeafDescriptorFor(getBaseExpression(), query.getDescriptor()); } }
/** * INTERNAL: * Return the descriptor for the base expression. This is used in ReportItem when building the * return value (a class), as none of the expressions will have a session. */ public ClassDescriptor getContainingDescriptor(ObjectLevelReadQuery query) { Class queryClass = null; if (getBaseExpression().isExpressionBuilder()){ queryClass = ((ExpressionBuilder)getBaseExpression()).getQueryClass(); return query.getSession().getDescriptor(queryClass); } else { // It must be a QueryKeyExpression. return getBaseExpression().getLeafDescriptor(query, query.getDescriptor(), query.getSession()); } }
/** * INTERNAL: * Return the descriptor for the base expression. This is used in ReportItem when building the * return value (a class), as none of the expressions will have a session. */ public ClassDescriptor getContainingDescriptor(ObjectLevelReadQuery query) { Class queryClass = null; if (getBaseExpression().isExpressionBuilder()){ queryClass = ((ExpressionBuilder)getBaseExpression()).getQueryClass(); return query.getSession().getDescriptor(queryClass); } else { // It must be a QueryKeyExpression. return getBaseExpression().getLeafDescriptor(query, query.getDescriptor(), query.getSession()); } }
/** * INTERNAL: * In the case of EJBQL or query by example, an expression needs to be * generated. Build the required expression. */ public void buildSelectionCriteria(AbstractSession session) { if (isParsed() || (getExampleObject() == null)) { return; } ObjectLevelReadQuery query = (ObjectLevelReadQuery)getQuery(); query.checkDescriptor(session); QueryByExamplePolicy policy = getQueryByExamplePolicy(); if (policy == null) { policy = new QueryByExamplePolicy(); } if (query.getReferenceClass().isInstance(getExampleObject())) { Expression exampleExpression = query.getDescriptor().getObjectBuilder().buildExpressionFromExample(getExampleObject(), policy, query.getExpressionBuilder(), new IdentityHashMap(), session); if (getSelectionCriteria() != null) { setSelectionCriteria(getSelectionCriteria().and(exampleExpression)); } else { setSelectionCriteria(exampleExpression); } } else { throw QueryException.exampleAndReferenceObjectClassMismatch(getExampleObject().getClass(), query.getReferenceClass(), query); } setIsParsed(true); }
/** * INTERNAL: * In the case of EJBQL or query by example, an expression needs to be * generated. Build the required expression. */ public void buildSelectionCriteria(AbstractSession session) { if (isParsed() || (getExampleObject() == null)) { return; } ObjectLevelReadQuery query = (ObjectLevelReadQuery)getQuery(); query.checkDescriptor(session); QueryByExamplePolicy policy = getQueryByExamplePolicy(); if (policy == null) { policy = new QueryByExamplePolicy(); } if (query.getReferenceClass().isInstance(getExampleObject())) { Expression exampleExpression = query.getDescriptor().getObjectBuilder().buildExpressionFromExample(getExampleObject(), policy, query.getExpressionBuilder(), new IdentityHashMap(), session); if (getSelectionCriteria() != null) { setSelectionCriteria(getSelectionCriteria().and(exampleExpression)); } else { setSelectionCriteria(exampleExpression); } } else { throw QueryException.exampleAndReferenceObjectClassMismatch(getExampleObject().getClass(), query.getReferenceClass(), query); } setIsParsed(true); }
/** * INTERNAL: * Add mandatory attributes to fetch group, create entityFetchGroup. */ public void prepareFetchGroup() throws QueryException { FetchGroupManager fetchGroupManager = this.descriptor.getFetchGroupManager(); if (fetchGroupManager != null) { if (this.fetchGroup == null) { if (this.fetchGroupName != null) { this.fetchGroup = fetchGroupManager.getFetchGroup(this.fetchGroupName); } else if (this.shouldUseDefaultFetchGroup) { this.fetchGroup = this.descriptor.getFetchGroupManager().getDefaultFetchGroup(); } } if (this.fetchGroup != null) { if (hasPartialAttributeExpressions()) { //fetch group does not work with partial attribute reading throw QueryException.fetchGroupNotSupportOnPartialAttributeReading(); } // currently SOP is incompatible with fetch groups setShouldUseSerializedObjectPolicy(false); this.descriptor.getFetchGroupManager().prepareAndVerify(this.fetchGroup); } } else { // FetchGroupManager is null if (this.fetchGroup != null || this.fetchGroupName != null) { throw QueryException.fetchGroupValidOnlyIfFetchGroupManagerInDescriptor(getDescriptor().getJavaClassName(), getName()); } } }
/** * INTERNAL: * builds and registers an object from a row for cursors. * Behavior is different from the query version in that refreshing is not * supported. */ protected Object buildAndRegisterObject(AbstractRecord row) { ReadQuery query = this.query; if (query.isObjectLevelReadQuery()) { ObjectLevelReadQuery objectQuery = (ObjectLevelReadQuery)query; if (objectQuery.hasBatchReadAttributes() && objectQuery.getBatchFetchPolicy().isIN()) { objectQuery.getBatchFetchPolicy().addDataResults(row); } if (this.session.isUnitOfWork() && (!query.isReportQuery()) && query.shouldMaintainCache() && (objectQuery.shouldConformResultsInUnitOfWork() || objectQuery.getDescriptor().shouldAlwaysConformResultsInUnitOfWork())) { Object object = objectQuery.conformIndividualResult( objectQuery.buildObject(row), (UnitOfWorkImpl)this.session, this.translationRow, this.selectionCriteriaClone, this.initiallyConformingIndex); // Notifies caller to continue until conforming instance found if (object == null) { return InvalidObject.instance; } return object; } } return query.buildObject(row); }
/** * INTERNAL: * builds and registers an object from a row for cursors. * Behavior is different from the query version in that refreshing is not * supported. */ protected Object buildAndRegisterObject(AbstractRecord row) { ReadQuery query = this.query; if (query.isObjectLevelReadQuery()) { ObjectLevelReadQuery objectQuery = (ObjectLevelReadQuery)query; if (objectQuery.hasBatchReadAttributes() && objectQuery.getBatchFetchPolicy().isIN()) { objectQuery.getBatchFetchPolicy().addDataResults(row); } if (this.session.isUnitOfWork() && (!query.isReportQuery()) && query.shouldMaintainCache() && (objectQuery.shouldConformResultsInUnitOfWork() || objectQuery.getDescriptor().shouldAlwaysConformResultsInUnitOfWork())) { Object object = objectQuery.conformIndividualResult( objectQuery.buildObject(row), (UnitOfWorkImpl)this.session, this.translationRow, this.selectionCriteriaClone, this.initiallyConformingIndex); // Notifies caller to continue until conforming instance found if (object == null) { return InvalidObject.instance; } return object; } } return query.buildObject(row); }
/** * INTERNAL: * builds and registers an object from a row for cursors. * Behavior is different from the query version in that refreshing is not * supported. */ protected Object buildAndRegisterObject(AbstractRecord row) { Object object = null; if (getSession().isUnitOfWork() && (!getQuery().isReportQuery()) && (getQuery().shouldMaintainCache()) && (getQuery().isObjectLevelReadQuery())) { UnitOfWorkImpl unitOfWork = (UnitOfWorkImpl)getSession(); ObjectLevelReadQuery query = (ObjectLevelReadQuery)getQuery(); if (query.shouldConformResultsInUnitOfWork() || query.getDescriptor().shouldAlwaysConformResultsInUnitOfWork()) { object = query.conformIndividualResult(row, unitOfWork, getTranslationRow(), getSelectionCriteriaClone(), getInitiallyConformingIndex(), true); // Notifies caller to continue until conforming instance found if (object == null) { return InvalidObject.instance; } } else { // This will now automatically clone the result. object = query.buildObject(row); } } else { object = getQuery().buildObject(row); } return object; }