/** * INTERNAL */ public void addNonFetchJoinAttributes(ObjectLevelReadQuery theQuery, GenerationContext generationContext) { ParseTreeContext context = generationContext.getParseTreeContext(); for (Iterator i = unusedVariables.iterator(); i.hasNext();) { String variable = (String)i.next(); Expression expr = null; if (!context.isRangeVariable(variable)) { Node path = context.pathForVariable(variable); expr = path.generateExpression(generationContext); theQuery.addNonFetchJoinedAttribute(expr); } else { // Ignore, assume 'Select 1 from Employee e' or sorts // unused range variable => not supported yet //throw JPQLException.notYetImplemented(context.getQueryInfo(), // "Variable [" + variable + "] is defined in a range variable declaration, but not used in the rest of the query."); } } }
/** * INTERNAL */ public void addNonFetchJoinAttributes(ObjectLevelReadQuery theQuery, GenerationContext generationContext) { ParseTreeContext context = generationContext.getParseTreeContext(); for (Iterator i = unusedVariables.iterator(); i.hasNext();) { String variable = (String)i.next(); Expression expr = null; if (!context.isRangeVariable(variable)) { Node path = context.pathForVariable(variable); expr = path.generateExpression(generationContext); theQuery.addNonFetchJoinedAttribute(expr); } else { // Ignore, assume 'Select 1 from Employee e' or sorts // unused range variable => not supported yet //throw JPQLException.notYetImplemented(context.getQueryInfo(), // "Variable [" + variable + "] is defined in a range variable declaration, but not used in the rest of the query."); } } }
/** * PUBLIC: * Specify the one-to-one mapped attribute to be optimized in this query. * The query will join the object(s) being read with the one-to-one * attribute. The difference between this and a joined attribute is that * it allows data to be retrieved based on a join, but will not populate * the joined attribute. It also allows all of the data required for the * object(s) to be read in a single query instead of (n) queries. This * should be used when the application knows that it requires the part for * all of the objects being read. This can be used only for one-to-one * mappings where the target is not the same class as the source, either * directly or through inheritance. Also two joins cannot be done to the * same class. * * <p>Note: This cannot be used for objects where it is possible not to have * a part, as these objects will be omitted from the result set, unless an * outer join is used through passing and expression using "getAllowingNull". * * <p>Example: query.addNonFetchJoinedAttribute("address") * * @see #addNonFetchJoinedAttribute(Expression) */ public void addNonFetchJoinedAttribute(String attributeName) { addNonFetchJoinedAttribute(getExpressionBuilder().get(attributeName)); }
/** * INTERNAL */ public void addNonFetchJoinAttributes(ObjectLevelReadQuery theQuery, GenerationContext generationContext) { ParseTreeContext context = generationContext.getParseTreeContext(); for (Iterator i = unusedVariables.iterator(); i.hasNext();) { String variable = (String)i.next(); Expression expr = null; if (!context.isRangeVariable(variable)) { Node path = context.pathForVariable(variable); expr = path.generateExpression(generationContext); theQuery.addNonFetchJoinedAttribute(expr); } else { // unused range variable => not supported yet throw JPQLException.notYetImplemented(context.getQueryInfo(), "Variable [" + variable + "] is defined in a range variable declaration, but not used in the rest of the query."); } } }
private Expression addNonFetchJoinedAttribute(org.eclipse.persistence.jpa.jpql.parser.Expression expression, IdentificationVariable identificationVariable) { String variableName = identificationVariable.getVariableName(); // Always add the expression, as it may not be defined elsewhere, // unless it has already been defined as the builder. Expression queryExpression = queryContext.getQueryExpression(variableName); if (queryExpression == null) { queryExpression = queryContext.buildExpression(expression); queryContext.addQueryExpression(variableName, queryExpression); } ObjectLevelReadQuery query = (ObjectLevelReadQuery) queryContext.getDatabaseQuery(); if (query.getExpressionBuilder() != queryExpression) { query.addNonFetchJoinedAttribute(queryExpression); } return queryExpression; }
private Expression addNonFetchJoinedAttribute(org.eclipse.persistence.jpa.jpql.parser.Expression expression, IdentificationVariable identificationVariable) { String variableName = identificationVariable.getVariableName(); // Always add the expression, as it may not be defined elsewhere, // unless it has already been defined as the builder. Expression queryExpression = queryContext.getQueryExpression(variableName); if (queryExpression == null) { queryExpression = queryContext.buildExpression(expression); queryContext.addQueryExpression(variableName, queryExpression); } ObjectLevelReadQuery query = (ObjectLevelReadQuery) queryContext.getDatabaseQuery(); if (query.getExpressionBuilder() != queryExpression) { query.addNonFetchJoinedAttribute(queryExpression); } return queryExpression; }
query.addNonFetchJoinedAttribute(((InternalSelection) join).getCurrentNode());