/** * Returns full prefetch path, that is a dot separated String of node names * starting from root and up to and including this node. Note that root * "name" is considered to be an empty string. */ public String getPath() { return getPath(null); }
/** * Returns full prefetch path, that is a dot separated String of node names starting * from root and up to and including this node. Note that root "name" is considered to * be an empty string. */ public String getPath() { return getPath(null); }
@Override public boolean startDisjointPrefetch(PrefetchTreeNode node) { out.append("/pd:").append(node.getPath()); return true; }
@Override public boolean startUnknownPrefetch(PrefetchTreeNode node) { out.append("/pu:").append(node.getPath()); return true; }
@Override public boolean startDisjointByIdPrefetch(PrefetchTreeNode node) { out.append("/pi:").append(node.getPath()); return true; }
@Override public boolean startJointPrefetch(PrefetchTreeNode node) { out.append("/pj:").append(node.getPath()); return true; }
/** * Returns a collection of String paths indicating relationships to objects that are * prefetched together with this query. * * @deprecated since 1.2 use 'getPrefetchTree' to explore prefetches. */ public Collection getPrefetches() { if (getPrefetchTree() != null) { Collection nodes = getPrefetchTree().nonPhantomNodes(); Collection paths = new ArrayList(nodes.size()); Iterator it = nodes.iterator(); while (it.hasNext()) { paths.add(((PrefetchTreeNode) it.next()).getPath()); } return paths; } return Collections.EMPTY_LIST; }
public boolean startDisjointPrefetch(PrefetchTreeNode node) { encoder.print("<prefetch type=\"disjoint\">"); encoder.print(node.getPath()); encoder.println("</prefetch>"); return true; }
public boolean startDisjointPrefetch(PrefetchTreeNode node) { encoder.print("<prefetch type=\"disjoint\">"); encoder.print(node.getPath()); encoder.println("</prefetch>"); return true; }
public boolean startDisjointByIdPrefetch(PrefetchTreeNode node) { encoder.print("<prefetch type=\"disjointById\">"); encoder.print(node.getPath()); encoder.println("</prefetch>"); return true; }
public boolean startJointPrefetch(PrefetchTreeNode node) { encoder.print("<prefetch type=\"joint\">"); encoder.print(node.getPath()); encoder.println("</prefetch>"); return true; }
public boolean startUnknownPrefetch(PrefetchTreeNode node) { encoder.print("<prefetch>"); encoder.print(node.getPath()); encoder.println("</prefetch>"); return true; }
public boolean startJointPrefetch(PrefetchTreeNode node) { encoder.print("<prefetch type=\"joint\">"); encoder.print(node.getPath()); encoder.println("</prefetch>"); return true; }
public boolean startUnknownPrefetch(PrefetchTreeNode node) { encoder.print("<prefetch>"); encoder.print(node.getPath()); encoder.println("</prefetch>"); return true; }
public void validateObject(ProjectPath treeNodePath, Validator validator) { SelectQuery query = (SelectQuery) treeNodePath.getObject(); validateName(query, treeNodePath, validator); // Resolve root to Entity for further validation Entity root = validateRoot(query, treeNodePath, validator); // validate path-based parts if (root != null) { validateQualifier(root, query.getQualifier(), treeNodePath, validator); Iterator orderings = query.getOrderings().iterator(); while (orderings.hasNext()) { validateOrdering( root, (Ordering) orderings.next(), treeNodePath, validator); } if (query.getPrefetchTree() != null) { Iterator prefetches = query .getPrefetchTree() .nonPhantomNodes() .iterator(); while (prefetches.hasNext()) { validatePrefetch(root, ((PrefetchTreeNode) prefetches.next()) .getPath(), treeNodePath, validator); } } } }
while (prefetchesIt.hasNext()) { PrefetchTreeNode prefetch = (PrefetchTreeNode) prefetchesIt.next(); String path = prefetch.getPath(); if (path.indexOf('.') >= 0) { throw new CayenneRuntimeException("Only one-step relationships are "
protected PrefetchProcessorNode toResultsTree(ClassDescriptor descriptor, PrefetchTreeNode prefetchTree, List<Object[]> rows, int position) { List<DataRow> rowsColumn = new ArrayList<>(rows.size()); for (Object[] row : rows) { rowsColumn.add((DataRow) row[position]); } if (prefetchTree != null) { PrefetchTreeNode prefetchTreeNode = null; for (PrefetchTreeNode prefetch : prefetchTree.getChildren()) { if (descriptor.getEntity().getName().equals(prefetch.getEntityName())) { if (prefetchTreeNode == null) { prefetchTreeNode = new PrefetchTreeNode(); } PrefetchTreeNode addPath = prefetchTreeNode.addPath(prefetch.getPath()); addPath.setSemantics(prefetch.getSemantics()); addPath.setPhantom(false); } } prefetchTree = prefetchTreeNode; } if (prefetchTree == null) { return new ObjectResolver(context, descriptor, metadata.isRefreshingObjects()) .synchronizedRootResultNodeFromDataRows(rowsColumn); } else { HierarchicalObjectResolver resolver = new HierarchicalObjectResolver(context, metadata, descriptor, true); return resolver.synchronizedRootResultNodeFromDataRows(prefetchTree, rowsColumn, prefetchResultsByPath); } }
private void addPrefetchedColumnsIfAny(final String visitedIdentifier) { PrefetchTreeNode prefetchTree = context.getCompiledExpression().getPrefetchTree(); if (prefetchTree != null) { for (PrefetchTreeNode prefetch : prefetchTree.adjacentJointNodes()) { ClassDescriptor descriptor = context.getEntityDescriptor(prefetch.getEjbqlPathEntityId()); if (visitedIdentifier.equals(prefetch.getEjbqlPathEntityId())) { DbEntity table = descriptor.getRootDbEntities().iterator().next(); ObjEntity objectEntity = descriptor.getEntity(); prefetch.setEntityName(objectEntity.getName()); Expression prefetchExp = ExpressionFactory.exp(prefetch.getPath()); Expression dbPrefetch = objectEntity.translateToDbPath(prefetchExp); DbRelationship r = null; for (PathComponent<DbAttribute, DbRelationship> component : table.resolvePath(dbPrefetch, context .getMetadata().getPathSplitAliases())) { r = component.getRelationship(); } if (r == null) { throw new CayenneRuntimeException("Invalid joint prefetch '%s' for entity: %s" , prefetch, objectEntity.getName()); } for (DbAttribute attribute : r.getTargetEntity().getAttributes()) { appendColumn(prefetch.getEjbqlPathEntityId() + "." + prefetch.getPath(), attribute, "", prefetch.getPath() + "." + attribute.getName(), null); } } } } }
@Test public void testBuildQuery_Prefetches() { SelectQuery<E2> query = new SelectQuery<E2>(E2.class); ResourceEntity<E2> resultFilter = getResourceEntity(E2.class); AgRelationship incoming = resultFilter.getAgEntity().getRelationship(E2.E3S.getName()); @SuppressWarnings("unchecked") AgPersistentEntity<E3> target = Mockito.mock(AgPersistentEntity.class); resultFilter.getChildren().put(E2.E3S.getName(), new ResourceEntity<E3>(target, incoming)); SelectContext<E2> context = new SelectContext<E2>(E2.class); context.setEntity(resultFilter); context.setSelect(query); SelectQuery<E2> amended = makeQueryStage.buildQuery(context); assertSame(query, amended); PrefetchTreeNode rootPrefetch = amended.getPrefetchTree(); assertNotNull(rootPrefetch); assertEquals(1, rootPrefetch.getChildren().size()); PrefetchTreeNode child1 = rootPrefetch.getChildren().iterator().next(); assertEquals(E2.E3S.getName(), child1.getPath()); }
String prefetchPath = node.getPath();