/** * Add a request to read the children of a node at the supplied location in the designated workspace. * * @param of the location of the node whose children are to be read * @param workspaceName the name of the workspace * @return this builder for method chaining; never null * @throws IllegalArgumentException if the location or workspace name is null */ public BatchRequestBuilder readAllChildren( Location of, String workspaceName ) { return add(new ReadAllChildrenRequest(of, workspaceName)); }
/** * {@inheritDoc} * * @see org.modeshape.graph.request.processor.RequestProcessor#process(org.modeshape.graph.request.ReadAllChildrenRequest) */ @Override public void process( ReadAllChildrenRequest request ) { ReadAllChildrenRequest source = (ReadAllChildrenRequest)federatedRequest.getFirstProjectedRequest().getRequest(); if (checkErrorOrCancel(request, source)) return; request.setActualLocationOfNode(source.getActualLocationOfNode()); for (Location childInSource : source.getChildren()) { request.addChild(childInSource); } request.setCachePolicy(getDefaultCachePolicy()); setCacheableInfo(request, source.getCachePolicy()); }
@Override public void process( ReadAllChildrenRequest request ) { PathWorkspace workspace = getWorkspace(request, request.inWorkspace()); if (workspace == null) return; PathNode node = getTargetNode(workspace, request, request.of()); if (node == null) { request.setError(new PathNotFoundException(request.of(), workspace.getLowestExistingPath(request.of().getPath()))); return; } List<Path.Segment> childSegments = node.getChildSegments(); for (Path.Segment childSegment : childSegments) { request.addChild(Location.create(pathFactory.create(node.getPath(), childSegment))); } request.setActualLocationOfNode(Location.create(node.getPath(), node.getUuid())); setCacheableInfo(request); }
/** * {@inheritDoc} * * @see java.lang.Object#equals(java.lang.Object) */ @Override public boolean equals( Object obj ) { if (obj == this) return true; if (this.getClass().isInstance(obj)) { ReadAllChildrenRequest that = (ReadAllChildrenRequest)obj; if (!this.of().isSame(that.of())) return false; if (!this.inWorkspace().equals(that.inWorkspace())) return false; return true; } return false; }
/** * {@inheritDoc} * * @see org.modeshape.graph.request.processor.RequestProcessor#process(org.modeshape.graph.request.ReadAllChildrenRequest) */ @Override public void process( ReadAllChildrenRequest request ) { MapWorkspace workspace = getWorkspace(request, request.inWorkspace()); MapNode node = getTargetNode(workspace, request, request.of()); if (node == null) { assert request.hasError(); return; } Location actualLocation = getActualLocation(request.of(), node); assert actualLocation != null; Path path = actualLocation.getPath(); // Get the names of the children ... List<MapNode> children = node.getChildren(); for (MapNode child : children) { Segment childName = child.getName(); Path childPath = pathFactory.create(path, childName); request.addChild(childPath, propertyFactory.create(ModeShapeLexicon.UUID, child.getUuid())); } request.setActualLocationOfNode(actualLocation); setCacheableInfo(request); }
Path federatedPath = request.of().getPath(); Map<Name, Integer> childSnsIndexes = new HashMap<Name, Integer>(); ProjectedRequest projectedRequest = federatedRequest.getFirstProjectedRequest(); request.setCachePolicy(getDefaultCachePolicy()); Location actualLocation = request.of(); int numMerged = 0; while (projectedRequest != null) { request.cancel(); return; childSnsIndexes, projection); request.addChild(childInRepos); if (federatedPath == null) federatedPath = childInRepos.getPath().getParent(); } else { ReadAllChildrenRequest readFromSource = (ReadAllChildrenRequest)sourceRequest; Location sourceLocation = readFromSource.getActualLocationOfNode(); if (sourceLocation.hasIdProperties()) { actualLocation = determineActualLocation(actualLocation, readFromSource.getActualLocationOfNode(), projection); if (federatedPath == null) federatedPath = actualLocation.getPath(); for (Location childInSource : readFromSource.getChildren()) { request.addChild(getChildLocationWithCorrectSnsIndex(childInSource, federatedPath, childSnsIndexes, projection));
if (request == null) return; ReadAllChildrenRequest readAll = new ReadAllChildrenRequest(request.of(), request.inWorkspace()); process(readAll); if (readAll.hasError()) { request.setError(readAll.getError()); return; List<Location> allChildren = readAll.getChildren(); request.setActualLocationOfNode(readAll.getActualLocationOfNode()); setCacheableInfo(request);
@Test public void shouldCreateValidRequestWithValidLocation() { request = new ReadAllChildrenRequest(validPathLocation1, workspace1); assertThat(request.of(), is(sameInstance(validPathLocation1))); assertThat(request.inWorkspace(), is(sameInstance(workspace1))); assertThat(request.hasError(), is(false)); assertThat(request.getError(), is(nullValue())); }
public void process( ReadAllChildrenRequest request ) { ProjectedNode projectedNode = project(request.of(), request.inWorkspace(), request, false); if (!children.isEmpty()) { ReadAllChildrenRequest placeholderRequest = new ReadAllChildrenRequest(placeholder.location(), request.inWorkspace()); placeholderRequest.addChildren(children); if (firstRequest) { firstRequest = false; placeholderRequest.setActualLocationOfNode(placeholder.location()); federatedRequest.add(placeholderRequest, true, true, null); children = new LinkedList<Location>(); ReadAllChildrenRequest placeholderRequest = new ReadAllChildrenRequest(placeholder.location(), request.inWorkspace()); placeholderRequest.addChildren(children); if (firstRequest) { firstRequest = false; placeholderRequest.setActualLocationOfNode(placeholder.location()); federatedRequest.add(placeholderRequest, true, true, null); ReadAllChildrenRequest pushDownRequest = new ReadAllChildrenRequest(proxy.location(), proxy.workspaceName()); federatedRequest.add(pushDownRequest, proxy.isSameLocationAsOriginal(), false, proxy.projection());
if (request.isCancelled()) return; ReadAllChildrenRequest readChildren = new ReadAllChildrenRequest(request.at(), request.inWorkspace()); process(readChildren); if (readChildren.hasError()) { request.setError(readChildren.getError()); return; if (readChildren.isCancelled()) return; request.setActualLocationOfNode(readChildren.getActualLocationOfNode());
@Override public void process( ReadAllChildrenRequest request ) { // Read the children from the map ... if (children.containsKey(request.of())) { for (Location child : children.get(request.of())) { request.addChild(child); } } // Set the actual location request.setActualLocationOfNode(actualLocationOf(request.of())); }
@Test public void shouldAllowAddingChildren() { request = new ReadAllChildrenRequest(validPathLocation1, workspace1); request.addChild(validPathLocation1); request.addChild(validPathLocation2); assertThat(request.getChildren().size(), is(2)); assertThat(request.getChildren(), hasItems(validPathLocation1, validPathLocation2)); } }
ReadAllChildrenRequest readChildren = new ReadAllChildrenRequest(request.at(), request.inWorkspace()); process(readChildren); if (readChildren.hasError()) { request.setError(readChildren.getError()); return;
protected void assertNextRequestReadChildren( Location at, Location... children ) { Request request = executedRequests.poll(); assertThat(request, is(instanceOf(ReadAllChildrenRequest.class))); ReadAllChildrenRequest readAll = (ReadAllChildrenRequest)request; assertThat(readAll.of(), is(at)); assertThat(readAll.getChildren(), hasItems(children)); }
@Test public void shouldConsiderNotEqualTwoRequestsWithDifferentLocations() { request = new ReadAllChildrenRequest(validPathLocation1, workspace1); ReadAllChildrenRequest request2 = new ReadAllChildrenRequest(validPathLocation2, workspace1); assertThat(request.equals(request2), is(false)); }
ReadAllChildrenRequest readAllChildren = (ReadAllChildrenRequest)request; expires = computeExpirationTime(readAllChildren); getOrCreateNode(readAllChildren.getActualLocationOfNode(), expires).setChildren(readAllChildren.getChildren()); break; case READ_BRANCH:
public List<Location> of( Location at ) { return requests.readAllChildren(at, getCurrentWorkspaceName()).getChildren(); }
WorkspaceType workspace = getWorkspace(request, request.inWorkspace()); NodeType node = getTargetNode(workspace, request, request.of()); if (node == null) { assert request.hasError(); return; Location actualLocation = getActualLocation(workspace, request.of(), node); assert actualLocation != null; Path path = actualLocation.getPath(); childLocation = Location.create(childPath); request.addChild(childLocation); request.setActualLocationOfNode(actualLocation); setCacheableInfo(request);
ReadAllChildrenRequest readAll = new ReadAllChildrenRequest(Location.create(parentPath), request.inWorkspace()); process(readAll); if (readAll.hasError()) { request.setError(readAll.getError()); return; List<Location> allChildren = readAll.getChildren();