/** * PUBLIC: * Specify the foreign-reference mapped attribute to be optimized in this query. * The query will execute normally, however when any of the batched parts is accessed, * the parts will all be read in a single query, * this allows all of the data required for the parts 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 for one-to-one, one-to-many, many-to-many and direct collection mappings. * * The use of the expression allows for nested batch reading to be expressed. * <p>Example: query.addBatchReadAttribute(query.getExpressionBuilder().get("policies").get("claims")) * * @see ObjectLevelReadQuery#addJoinedAttribute(String) */ public void addBatchReadAttribute(Expression attributeExpression) { getBatchReadAttributeExpressions().add(attributeExpression); }
/** * INTERNAL: * Used to optimize joining by pre-computing the nested join queries for the mappings. */ public void computeBatchReadMappingQueries() { // Cannot prepare the batch queries if using inheritance, as child descriptors can have different mappings. if (hasBatchReadAttributes() && (!getDescriptor().hasInheritance())) { this.batchReadAttributes = new ArrayList(getBatchReadAttributeExpressions().size()); setBatchReadMappingQueries(new HashMap(getBatchReadAttributeExpressions().size())); computeNestedQueriesForBatchReadExpressions(getBatchReadAttributeExpressions()); } }
/** * INTERNAL: * Return if the attribute is specified for batch reading. */ public boolean isAttributeBatchRead(String attributeName) { if (!hasBatchReadAttributes()) { return false; } Vector batchReadAttributeExpressions = getBatchReadAttributeExpressions(); int size = batchReadAttributeExpressions.size(); for (int index = 0; index < size; index++) { QueryKeyExpression expression = (QueryKeyExpression)batchReadAttributeExpressions.get(index); while (!expression.getBaseExpression().isExpressionBuilder()) { expression = (QueryKeyExpression)expression.getBaseExpression(); } if (expression.getName().equals(attributeName)) { return true; } } return false; }
/** * PUBLIC: * Specify the foreign-reference mapped attribute to be optimized in this query. * The query will execute normally, however when any of the batched parts is accessed, * the parts will all be read in a single query, * this allows all of the data required for the parts 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 for one-to-one, one-to-many, many-to-many and direct collection mappings. * * The use of the expression allows for nested batch reading to be expressed. * <p>Example: query.addBatchReadAttribute("phoneNumbers") * * @see #addBatchReadAttribute(Expression) * @see ObjectLevelReadQuery#addJoinedAttribute(String) */ public void addBatchReadAttribute(String attributeName) { if (! getQueryMechanism().isExpressionQueryMechanism()){ throw QueryException.batchReadingNotSupported(this); } getBatchReadAttributeExpressions().add(getExpressionBuilder().get(attributeName)); }
List batchExpressions = ((ReadAllQuery)query).getBatchReadAttributeExpressions(); int size = batchExpressions.size(); for (int index = 0; index < size; index++) {
List batchExpressions = ((ReadAllQuery)query).getBatchReadAttributeExpressions(); int size = batchExpressions.size(); for (int index = 0; index < size; index++) {
for (Enumeration enumtr = ((ReadAllQuery)mappingQuery).getBatchReadAttributeExpressions().elements(); enumtr.hasMoreElements();) { Expression expression = ((Expression)enumtr.nextElement()).rebuildOn(batchQuery.getExpressionBuilder()); batchQuery.addBatchReadAttribute(expression); Vector nestedExpressions = extractNestedExpressions(query.getBatchReadAttributeExpressions(), batchQuery.getExpressionBuilder(), false); Helper.addAllToVector(batchQuery.getBatchReadAttributeExpressions(), nestedExpressions);
for (Expression batchReadExp : readAllQuery.getBatchReadAttributeExpressions()) { builderString = buildBuilderString(builderString, method, iteration, queryIdentifier); buildExpressionString(builderString, method, queryIdentifier, batchReadExp, ".addBatchReadAttribute(");
for (Enumeration batchReadEnum = readAllQuery.getBatchReadAttributeExpressions().elements(); batchReadEnum.hasMoreElements();) { Expression batchReadExp = (Expression)batchReadEnum.nextElement(); builderString = buildBuilderString(builderString, method, iteration, queryIdentifier);
for (Expression batchReadExp : readAllQuery.getBatchReadAttributeExpressions()) { builderString = buildBuilderString(builderString, method, iteration, queryIdentifier); buildExpressionString(builderString, method, queryIdentifier, batchReadExp, ".addBatchReadAttribute(");
((ReadAllQuery)nestedQuery).setBatchReadAttributeExpressions(extractNestedExpressions(((ReadAllQuery)sourceQuery).getBatchReadAttributeExpressions(), ((ReadAllQuery)nestedQuery).getExpressionBuilder(), false));
List batchExpressions = ((ReadAllQuery)query).getBatchReadAttributeExpressions(); int size = batchExpressions.size(); for (int index = 0; index < size; index++) {
for (Expression expression : ((ReadAllQuery)mappingQuery).getBatchReadAttributeExpressions()) { batchQuery.addBatchReadAttribute(expression); batchQuery.getBatchReadAttributeExpressions().addAll(nestedExpressions);
for (Expression expression : ((ReadAllQuery)mappingQuery).getBatchReadAttributeExpressions()) { batchQuery.addBatchReadAttribute(expression); batchQuery.getBatchReadAttributeExpressions().addAll(nestedExpressions);