/** * Add a request to create a node with the given properties under the supplied location. * * @param parentLocation the location of the existing parent node, under which the new child should be created * @param workspaceName the name of the workspace containing the parent * @param childName the name of the new child to create under the existing parent * @param properties the properties of the new node, which should include any {@link Location#getIdProperties() identification * properties} for the new node * @return this builder for method chaining; never null * @throws IllegalArgumentException if the location, workspace name, or child name is null */ public BatchRequestBuilder createNode( Location parentLocation, String workspaceName, Name childName, Iterator<Property> properties ) { return add(new CreateNodeRequest(parentLocation, workspaceName, childName, CreateNodeRequest.DEFAULT_CONFLICT_BEHAVIOR, properties)); }
/** * {@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)) { CreateNodeRequest that = (CreateNodeRequest)obj; if (!this.under().isSame(that.under())) return false; if (!this.conflictBehavior().equals(that.conflictBehavior())) return false; if (!this.inWorkspace().equals(that.conflictBehavior())) return false; if (!this.properties().equals(that.properties())) return false; return true; } return false; }
/** * {@inheritDoc} * <p> * This method does not clone the results. * </p> * * @see org.modeshape.graph.request.ChangeRequest#clone() */ @Override public CreateNodeRequest clone() { CreateNodeRequest request = new CreateNodeRequest(under, workspaceName, childName, conflictBehavior, properties); request.setActualLocationOfNode(actualLocation); return request; }
/** * {@inheritDoc} * * @see org.modeshape.graph.request.processor.RequestProcessor#process(org.modeshape.graph.request.CreateNodeRequest) */ @Override public void process( CreateNodeRequest request ) { CreateNodeRequest source = (CreateNodeRequest)federatedRequest.getFirstProjectedRequest().getRequest(); if (checkErrorOrCancel(request, source)) return; request.setActualLocationOfNode(source.getActualLocationOfNode()); }
WorkspaceType workspace = getWorkspace(request, request.inWorkspace()); if (workspace == null) return; NodeType parentNode = txn.getNode(workspace, request.under()); List<Property> propsToStore = new ArrayList<Property>(request.properties().size()); for (Property property : request.properties()) { if (property.getName().equals(ModeShapeLexicon.UUID) || property.getName().equals(JcrLexicon.UUID)) { uuid = getExecutionContext().getValueFactories().getUuidFactory().create(property.getValues().next()); switch (request.conflictBehavior()) { case APPEND: node = txn.addChild(workspace, parentNode, request.named(), -1, uuid, propsToStore); break; case DO_NOT_REPLACE: node = txn.getFirstChild(workspace, parentNode, request.named()); if (node == null) { node = txn.addChild(workspace, parentNode, request.named(), -1, uuid, propsToStore); node = txn.getFirstChild(workspace, parentNode, request.named()); if (node != null) { List<NodeType> children = txn.getChildren(workspace, node); node = txn.addChild(workspace, parentNode, request.named(), -1, uuid, propsToStore); node = txn.getFirstChild(workspace, parentNode, request.named()); if (node == null) { node = txn.addChild(workspace, parentNode, request.named(), -1, uuid, propsToStore); } else {
protected void assertNextRequestIsCreate( Location parent, String child, Property... properties ) { Name name = context.getValueFactories().getNameFactory().create(child); Request request = executedRequests.poll(); assertThat(request, is(instanceOf(CreateNodeRequest.class))); CreateNodeRequest create = (CreateNodeRequest)request; assertThat(create.under(), is(parent)); assertThat(create.named(), is(name)); assertThat(create.properties(), hasItems(properties)); }
path = "'/" + childName + "'"; } else { path = printable(under(), childName); sb.append(properties()); switch (conflictBehavior()) { case APPEND: sb.append(" by appending");
@Override public void process( CreateNodeRequest request ) { // Just update the actual location ... Location parent = actualLocationOf(request.under()); // just make sure it has a path ... Name name = request.named(); Path childPath = context.getValueFactories().getPathFactory().create(parent.getPath(), name); request.setActualLocationOfNode(Location.create(childPath)); }
CreateNodeRequest create = new CreateNodeRequest(parent, workspaceName, childName, nodePoperties); create.setActualLocationOfNode(location); // set this so we don't have to figure it out process(create); if (create.isCancelled() || create.hasError()) return;
/** * {@inheritDoc} * * @see org.modeshape.graph.request.processor.RequestProcessor#process(org.modeshape.graph.request.CreateNodeRequest) */ @Override public void process( CreateNodeRequest request ) { ProjectedRequest projected = federatedRequest.getFirstProjectedRequest(); // Check the projection first ... if (checkErrorOrCancel(request, federatedRequest)) return; Request projectedRequest = projected.getRequest(); // Check the error on the projected request ... if (checkErrorOrCancel(request, projectedRequest)) return; // No error, so project the results back to the federated repository ... Location sourceLocation = null; if (RequestType.CREATE_NODE == projectedRequest.getType()) { CreateNodeRequest source = (CreateNodeRequest)projectedRequest; sourceLocation = source.getActualLocationOfNode(); } else if (RequestType.READ_NODE == projectedRequest.getType()) { // In this case, the original request was to create the node only if it was missing, // but we knew it already exists because the parent was a placeholder and the child // mapped to an existing proxy node. Therefore, record the location... ReadNodeRequest source = (ReadNodeRequest)projectedRequest; sourceLocation = source.getActualLocationOfNode(); } request.setActualLocationOfNode(projectToFederated(request.under(), projected.getProjection(), sourceLocation, request)); }
public Location getLocation() { Location parentLoc = Location.create(parent); CreateNodeRequest request = requests.createNode(parentLoc, workspaceName, childName, this.properties.iterator()); return request.getActualLocationOfNode(); }
/** * Sets the actual and complete location of the node being created. This method must be called when processing the request, * and the actual location must have a {@link Location#getPath() path}. * * @param actual the actual location of the node being created, or null if the {@link #under() current location} should be * used * @throws IllegalArgumentException the actual location is null or does not have a path * @throws IllegalStateException if the request is frozen */ public void setActualLocationOfNode( Location actual ) { checkNotFrozen(); CheckArg.isNotNull(actual, "actual"); if (!actual.hasPath()) { throw new IllegalArgumentException(GraphI18n.actualLocationMustHavePath.text(actual)); } assert actual.hasPath(); this.actualLocation = actual; }
PathWorkspace workspace = getWorkspace(request, request.inWorkspace()); if (workspace == null) return; Path parent = request.under().getPath(); CheckArg.isNotNull(parent, "request.under().getPath()"); PathNode node = null; if (parentNode == null) { Path lowestExisting = workspace.getLowestExistingPath(parent); request.setError(new PathNotFoundException(request.under(), lowestExisting, GraphI18n.nodeDoesNotExist.text(parent))); return; request.setError(new InvalidRequestException(msg.text(repository.getSourceName(), workspace.getName()))); return; Map<Name, Property> propsToStore = new HashMap<Name, Property>(request.properties().size()); for (Property property : request.properties()) { if (property.size() > 0) propsToStore.put(property.getName(), property); NodeConflictBehavior conflictBehavior = request.conflictBehavior(); switch (conflictBehavior) { case APPEND: node = newWorkspace.createNode(getExecutionContext(), parentNode, request.named(), propsToStore, conflictBehavior); break; case DO_NOT_REPLACE: for (Segment childSegment : parentNode.getChildSegments()) { if (request.named().equals(childSegment.getName())) { Path childPath = pathFactory.create(parent, childSegment); node = newWorkspace.getNode(childPath);
CreateNodeRequest createNode = (CreateNodeRequest)nextCommand; Path expectedPath = context.getValueFactories().getPathFactory().create(path); Path parentPath = createNode.under().getPath(); assertThat(parentPath, is(expectedPath.getParent())); assertThat(createNode.named(), is(expectedPath.getLastSegment().getName())); for (Property prop : createNode.properties()) { propertiesByName.put(prop.getName(), prop);
public Node getNode() { Location parentLoc = Location.create(parent); CreateNodeRequest request = requests.createNode(parentLoc, workspaceName, childName, this.properties.iterator()); return getNodeAt(request.getActualLocationOfNode()); }
MapWorkspace workspace = getWorkspace(request, request.inWorkspace()); if (workspace == null) return; Path parent = request.under().getPath(); CheckArg.isNotNull(parent, "request.under().getPath()"); MapNode node = null; if (parentNode == null) { Path lowestExisting = workspace.getLowestExistingPath(parent); request.setError(new PathNotFoundException(request.under(), lowestExisting, GraphI18n.nodeDoesNotExist.text(parent))); return; List<Property> propsToStore = new ArrayList<Property>(request.properties().size()); for (Property property : request.properties()) { if (property.getName().equals(ModeShapeLexicon.UUID) || property.getName().equals(JcrLexicon.UUID)) { uuid = getExecutionContext().getValueFactories().getUuidFactory().create(property.getValues().next()); switch (request.conflictBehavior()) { case APPEND: node = workspace.createNode(getExecutionContext(), parentNode, request.named(), uuid, propsToStore); break; case DO_NOT_REPLACE: for (MapNode child : parentNode.getChildren()) { if (request.named().equals(child.getName().getName())) { node = child; break; node = workspace.createNode(getExecutionContext(), parentNode, request.named(), uuid, propsToStore); node = getTargetNode(workspace, null, Location.create(pathFactory.create(parent, request.named()), uuid));
Path parentPath = request.under().getPath(); assertThat(parentPath, is(expectedPath.getParent())); assertThat(request.named(), is(expectedPath.getLastSegment().getName())); for (Property actual : request.properties()) { Property expected = expectedProperties.remove(actual.getName()); assertThat("unexpected property: " + actual, expected, is(notNullValue())); msg.append(expected.getName()); msg.append(" on node ").append(request.under());
/** * Add a request to create a node with the given properties under the supplied location. * * @param parentLocation the location of the existing parent node, under which the new child should be created * @param workspaceName the name of the workspace containing the parent * @param childName the name of the new child to create under the existing parent * @param properties the properties of the new node, which should include any {@link Location#getIdProperties() identification * properties} for the new node * @return the request; never null * @throws IllegalArgumentException if the location, workspace name, or child name is null */ public CreateNodeRequest createNode( Location parentLocation, String workspaceName, Name childName, Property[] properties ) { return process(new CreateNodeRequest(parentLocation, workspaceName, childName, CreateNodeRequest.DEFAULT_CONFLICT_BEHAVIOR, properties)); }
Location locationAfter = createRequest.getActualLocationOfNode();
ProjectedNode projectedNode = project(request.under(), request.inWorkspace(), request, true); CreateNodeRequest pushDownRequest = new CreateNodeRequest(proxy.location(), proxy.workspaceName(), request.named(), request.conflictBehavior(), request.properties()); federatedRequest.add(pushDownRequest, proxy.isSameLocationAsOriginal(), false, proxy.projection()); switch (request.conflictBehavior()) { case UPDATE: case DO_NOT_REPLACE: Location parent = request.under(); if (parent.hasPath()) { PathFactory pathFactory = getExecutionContext().getValueFactories().getPathFactory(); Path childPath = pathFactory.create(parent.getPath(), request.named()); Location childLocation = Location.create(childPath); projectedNode = project(childLocation, request.inWorkspace(), request, true); if (projectedNode != null) { if (projectedNode.isProxy()) { request.setActualLocationOfNode(projectedNode.location()); return; String msg = GraphI18n.unableToCreateNodeUnderPlaceholder.text(readable(request.named()), readable(request.under()), request.inWorkspace(), getSourceName()); request.setError(new UnsupportedRequestException(msg));