/** * INTERNAL: * Iterate through a list of joined expressions and add the fields they represent to a list * of fields. */ protected void addSelectionFieldsForJoinedExpressions(List fields, List joinedExpressions) { for (int index = 0; index < joinedExpressions.size(); index++) { ObjectExpression objectExpression = (ObjectExpression)joinedExpressions.get(index); // Expression may not have been initialized. objectExpression.getBuilder().setSession(getSession().getRootSession(null)); objectExpression.getBuilder().setQueryClass(getReferenceClass()); ClassDescriptor descriptor = objectExpression.getMapping().getReferenceDescriptor(); fields.addAll(descriptor.getFields()); } }
/** * INTERNAL: * Used for joining in conjunction with pessimistic locking * Iterate through a list of joined expressions and ensure expression is set on the locking * clause for each expression that represents a pessimisically locked descriptor. */ private void setupLockingClauseForJoinedExpressions(List joinedExpressions, AbstractSession session) { // Must iterate over all of the joined attributes, just check // if any of them have pessimistic locking defined on the descriptor. for (Iterator e = joinedExpressions.iterator(); e.hasNext();) { Expression expression = (Expression)e.next(); // Expression has not yet been validated. if (expression.isObjectExpression()) { ObjectExpression joinedAttribute = (ObjectExpression)expression; // Expression may not have been initialized. joinedAttribute.getBuilder().setSession(session.getRootSession(null)); if (joinedAttribute.getBuilder().getQueryClass() == null){ joinedAttribute.getBuilder().setQueryClass(descriptor.getJavaClass()); } ClassDescriptor nestedDescriptor = null;// joinedAttribute.getDescriptor(); // expression may not be valid, no descriptor, validation occurs later. if (nestedDescriptor == null) { return; } } } return; }
/** * Return the row with primary keys and their values from the given expression. */ public AbstractRecord extractPrimaryKeyRowFromExpression(Expression expression, AbstractRecord translationRow, AbstractSession session) { AbstractRecord primaryKeyRow = createRecord(getPrimaryKeyMappings().size()); //put the curent session onthe expression builder for use later store current session incase //it is required at a later stage AbstractSession oldSession = expression.getBuilder().getSession(); expression.getBuilder().setSession(session.getRootSession(null)); // Get all the field & values from expression boolean isValid = expression.extractPrimaryKeyValues(true, getDescriptor(), primaryKeyRow, translationRow); expression.getBuilder().setSession(session.getRootSession(null)); if (!isValid) { return null; } // Check that the sizes match up if (primaryKeyRow.size() != getDescriptor().getPrimaryKeyFields().size()) { return null; } return primaryKeyRow; }
selectionCriteriaClone.getBuilder().setSession(unitOfWork.getRootSession(null)); selectionCriteriaClone.getBuilder().setQueryClass(getReferenceClass());
/** * Return the row with primary keys and their values from the given expression. */ public Vector extractPrimaryKeyFromExpression(boolean requiresExactMatch, Expression expression, AbstractRecord translationRow, AbstractSession session) { AbstractRecord primaryKeyRow = createRecord(getPrimaryKeyMappings().size()); //put the curent session onthe expression builder for use later store current session incase //it is required at a later stage AbstractSession oldSession = expression.getBuilder().getSession(); expression.getBuilder().setSession(session.getRootSession(null)); // Get all the field & values from expression. boolean isValid = expression.extractPrimaryKeyValues(requiresExactMatch, getDescriptor(), primaryKeyRow, translationRow); if (requiresExactMatch && (!isValid)) { return null; } // Check that the sizes match. if (primaryKeyRow.size() != getDescriptor().getPrimaryKeyFields().size()) { return null; } return extractPrimaryKeyFromRow(primaryKeyRow, session); }
DataExpression fieldExpressionClone = (DataExpression)fieldExpression.clone(); fieldExpressionClone.getBuilder().setQueryClass(getQuery().getReferenceClass()); fieldExpressionClone.getBuilder().setSession(getSession().getRootSession(null)); field = fieldExpressionClone.getField(); if(field == null) { valueClone.getBuilder().setSession(getSession()); valueClone.getBuilder().setQueryClass(getQuery().getReferenceClass()); expRequiresSelectIterator.iterateOn(valueClone);
/** * INTERNAL: * Return the fields selected by the query. * This includes the partial or joined fields. * This is used for custom SQL executions. */ public Vector getSelectionFields() { if ((!hasPartialAttributeExpressions()) && (!getJoinedAttributeManager().hasJoinedAttributes()) && (!hasFetchGroupAttributeExpressions())) { return getDescriptor().getAllFields(); } Vector fields; if (hasFetchGroupAttributeExpressions()) {//fetch group support List fetchGroupAttrExps = getFetchGroup().getFetchGroupAttributeExpressions(); fields = new Vector(fetchGroupAttrExps.size()); for (int index = 0; index < fetchGroupAttrExps.size(); index++) { Expression expression = (Expression)fetchGroupAttrExps.get(index); // Expression may not have been initialized. expression.getBuilder().setSession(getSession().getRootSession(null)); expression.getBuilder().setQueryClass(getReferenceClass()); Helper.addAllToVector(fields, expression.getFields()); } } else { fields = new Vector(getDescriptor().getAllFields().size() + getJoinedAttributeManager().getJoinedAttributeExpressions().size() + getJoinedAttributeManager().getJoinedMappingExpressions().size()); Helper.addAllToVector(fields, getDescriptor().getAllFields()); addSelectionFieldsForJoinedExpressions(fields, getJoinedAttributeManager().getJoinedAttributeExpressions()); addSelectionFieldsForJoinedExpressions(fields, getJoinedAttributeManager().getJoinedMappingExpressions()); } return fields; }
objectExpression.getBuilder().setSession(session.getRootSession(null)); if (objectExpression.getBuilder().getQueryClass() == null){ objectExpression.getBuilder().setQueryClass(descriptor.getJavaClass());
selectionCriteriaClone.getBuilder().setSession(getSession().getRootSession(null)); selectionCriteriaClone.getBuilder().setQueryClass(theClass);
builder.setSession(normalizer.getSession().getRootSession(null)); builder.setSession(normalizer.getSession().getRootSession(null));
builder.setSession(session.getRootSession(null));
selectionCriteriaClone.getBuilder().setSession(getSession().getRootSession(null)); selectionCriteriaClone.getBuilder().setQueryClass(theClass);
Expression criteria = null; setSession(normalizer.getSession().getRootSession(null));
/** * Validate and prepare the join expression. */ protected void prepareJoinExpression(Expression expression, AbstractSession session) { // Must be query key expression. if (!expression.isQueryKeyExpression()) { throw QueryException.mappingForExpressionDoesNotSupportJoining(expression); } QueryKeyExpression objectExpression = (QueryKeyExpression)expression; // Expression may not have been initialized. objectExpression.getBuilder().setSession(session.getRootSession(null)); if (objectExpression.getBuilder().getQueryClass() == null){ objectExpression.getBuilder().setQueryClass(descriptor.getJavaClass()); } // Can only join relationships. if ((objectExpression.getMapping() == null) || (!objectExpression.getMapping().isJoiningSupported())) { throw QueryException.mappingForExpressionDoesNotSupportJoining(objectExpression); } // Search if any of the expression traverse a 1-m. ObjectExpression baseExpression = objectExpression; while (!baseExpression.isExpressionBuilder()) { if (((QueryKeyExpression)baseExpression).shouldQueryToManyRelationship()) { setIsToManyJoinQuery(true); } if (((QueryKeyExpression)baseExpression).shouldUseOuterJoin()) { setIsOuterJoinedAttributeQuery(true); } baseExpression = (ObjectExpression)((QueryKeyExpression)baseExpression).getBaseExpression(); } }
if ((getSelectionCriteria() != null) && (getSelectionKey() == null) && (getSelectionObject() == null)) { selectionCriteriaClone = (Expression)getSelectionCriteria().clone(); selectionCriteriaClone.getBuilder().setSession(unitOfWork.getRootSession(null)); selectionCriteriaClone.getBuilder().setQueryClass(getReferenceClass());
selectionCriteria.getBuilder().setSession(session.getRootSession(query)); selectionCriteria.getBuilder().setQueryClass(getDescriptor().getJavaClass()); if (!selectionCriteria.doesConform(cachedObject, session, translationRow, policyToUse)) { selectionCriteria.getBuilder().setSession(session.getRootSession(query)); selectionCriteria.getBuilder().setQueryClass(getDescriptor().getJavaClass()); selectionCriteria.getBuilder().setSession(session.getRootSession(query)); selectionCriteria.getBuilder().setQueryClass(getDescriptor().getJavaClass());