batch.create(pathToNamespaceNode).orReplace().with(namespaceProperties).and(uriPropertyName, newUri).and(); if (existingPrefixForNewUri == null) { batch.delete(pathToOldNamespaceNode).and(); batch.set(uriPropertyName).to(newUri).on(pathToNamespaceNode).and(); batch.execute(); return previousUrisByNewPrefixes;
protected GraphReturnable( ReturnType returnObject, Graph.Batch batch, Path path, Name... names ) { super(returnObject); assert batch != null; assert path != null; assert names.length > 0; this.context = batch.getGraph().getContext(); this.batch = batch; // Make sure there are nodes down to the supplied path ... createIfMissing(path, names).and(); this.path = context.getValueFactories().getPathFactory().create(path, names); try { properties = batch.getGraph().getPropertiesByName().on(this.path); } catch (PathNotFoundException e) { // The node doesn't exist yet (wasn't yet saved) properties = new HashMap<Name, Property>(); } }
Graph.Batch batch = store.batch(); for (Node<Payload, PropertyPayload> nodeToBeRefreshed : refreshState.getNodesToBeRefreshed()) { batch.read(nodeToBeRefreshed.getLocation()); readResults = batch.execute(); } catch (org.modeshape.graph.property.PathNotFoundException e) { throw new InvalidStateException(e.getLocalizedMessage(), e); if (operations.isExecuteRequired()) {
batch.read(firstPath); batch.readSubgraphOfDepth(loadDepth).at(nextPath); } else { batch.read(nextPath); nextPath = pathFactory.create(nextPath, iter.next()); if (!iter.hasNext() && loadDepth > 1) { batch.readSubgraphOfDepth(loadDepth).at(nextPath); } else { batch.read(nextPath); Results batchResults = batch.execute();
batch.readProperty(ModeShapeLexicon.DERIVED_FROM).on(child).and(); Results derivedResults = batch.execute(); if (!derivedResults.getRequests().isEmpty()) { Graph.Batch deleteExistingBatch = graph.batch(); deleteExistingBatch.delete(childLocation).and(); break; // nothing more to do for this child deleteExistingBatch.execute();
assertThat(cache.changeDependencies.size(), is(1)); assertThat(cache.changeDependencies.get(sports.getNodeId()).getMovedFrom(), is(cars.getNodeId())); assertThat(cache.operations.isExecuteRequired(), is(true));
if (!operations.isExecuteRequired()) { operations.execute(); } catch (org.modeshape.graph.property.PathNotFoundException e) { throw new InvalidStateException(e.getLocalizedMessage(), e);
assertThat(cache.changeDependencies.size(), is(1)); assertThat(cache.changeDependencies.get(sports.getNodeId()).getMovedFrom(), is(cars.getNodeId())); assertThat(cache.operations.isExecuteRequired(), is(true));
assertThat(cache.changeDependencies.size(), is(1)); assertThat(cache.changeDependencies.get(sports.getNodeId()).getMovedFrom(), is(cars.getNodeId())); assertThat(cache.operations.isExecuteRequired(), is(true));
Results results = store.batch().copy(source).fromWorkspace(sourceWorkspace).to(destination).execute();
cache.operations.copy(child.getLocation()).to(copyLocation);
@Test public void shouldMoveNodeInBatches() { graph.batch().move(validPath).into(validIdProperty1, validIdProperty2).execute(); assertThat(numberOfExecutions, is(1)); assertNextRequestIsMove(Location.create(validPath), Location.create(validIdProperty1, validIdProperty2)); assertNoMoreRequests(); graph.batch().move(validPathString).into(validIdProperty1, validIdProperty2).execute(); assertThat(numberOfExecutions, is(1)); assertNextRequestIsMove(Location.create(validPath), Location.create(validIdProperty1, validIdProperty2)); assertNoMoreRequests(); graph.batch().move(validUuid).into(validPath).execute(); assertThat(numberOfExecutions, is(1)); assertNextRequestIsMove(Location.create(validUuid), Location.create(validPath)); .move(validPath) .into(validIdProperty1, validIdProperty2) .and() .move(validPathString) .into(validIdProperty1, validIdProperty2) .and() .move(validUuid) .into(validPath) .execute();
@Test public void shouldCopyNodeInBatches() { graph.batch().copy(validPath).into(validIdProperty1, validIdProperty2).execute(); assertThat(numberOfExecutions, is(1)); assertNextRequestIsCopy(Location.create(validPath), Location.create(validIdProperty1, validIdProperty2)); assertNoMoreRequests(); graph.batch().copy(validPathString).into(validIdProperty1, validIdProperty2).execute(); assertThat(numberOfExecutions, is(1)); assertNextRequestIsCopy(Location.create(validPath), Location.create(validIdProperty1, validIdProperty2)); assertNoMoreRequests(); graph.batch().copy(validUuid).into(validPath).execute(); assertThat(numberOfExecutions, is(1)); assertNextRequestIsCopy(Location.create(validUuid), Location.create(validPath)); .copy(validPath) .into(validIdProperty1, validIdProperty2) .and() .copy(validPathString) .into(validIdProperty1, validIdProperty2) .and() .copy(validUuid) .into(validPath) .execute();
Results results = store.batch().move(nodeToMove).as(newName).into(newParentPath).execute(); MoveBranchRequest moveRequest = (MoveBranchRequest)results.getRequests().get(0); Location locationAfter = moveRequest.getActualLocationAfter();
protected boolean doUnregister( String uri ) { // Read the store ... ValueFactory<String> stringFactory = store.getContext().getValueFactories().getStringFactory(); boolean result = false; try { Subgraph nsGraph = store.getSubgraphOfDepth(2).at(parentOfNamespaceNodes); // Iterate over the existing mappings, looking for one that uses the prefix and uri ... Set<Location> locationsToRemove = new HashSet<Location>(); for (Location nsLocation : nsGraph.getRoot().getChildren()) { Node ns = nsGraph.getNode(nsLocation); String actualUri = stringFactory.create(ns.getProperty(uriPropertyName).getFirstValue()); if (actualUri.equals(uri)) { locationsToRemove.add(ns.getLocation()); result = true; } } // Remove any other nodes that have the same URI ... Graph.Batch batch = store.batch(); for (Location namespaceToRemove : locationsToRemove) { batch.delete(namespaceToRemove).and(); } // Execute all these changes ... batch.execute(); } catch (PathNotFoundException e) { // Nothing stored yet, so do nothing ... } return result; }
@Test public void shouldRenameNodeByRemovingAndAddingAtEndOfChildrenEvenWithSameNameSiblings() { Node<Object, Object> sports = cache.findNodeWith(path("/Cars/Sports")); assertConnectionsUsed(1); // "Utility" was found because it is child of "Cars" loaded when "Sports" was loaded sports.rename(name("Utility")); // "Sports" was already loaded, as was "Cars" assertNoMoreConnectionsUsed(); Node<Object, Object> cars = cache.findNodeWith(path("/Cars")); assertChildren(cars, "Hybrid", "Luxury", "Utility", "Utility[2]"); assertThat(sports.getParent(), is(cars)); // Ensure that the changes were recorded appropriately ... assertThat(cars.isChanged(false), is(true)); // 'sports' renamed as child assertThat(sports.isChanged(false), is(true)); // path has changed assertThat(cache.hasPendingChanges(), is(true)); assertThat(cache.operations.isExecuteRequired(), is(true)); // Save "/Cars" but keep the changes ... assertConnectionsUsed(0); cache.save(cars); assertConnectionsUsed(2); // 1 to load children required by validation, 1 to perform save // Now the state should reflect our changes, but we need to refind the nodes ... Node<Object, Object> utility2 = cache.findNodeWith(path("/Cars/Utility[2]")); assertConnectionsUsed(1); assertNoMoreConnectionsUsed(); assertChildren(cars, "Hybrid", "Luxury", "Utility", "Utility[2]"); assertThat(utility2.getParent(), is(cars)); // Now there should be no changes ... assertNoChanges(); // System.out.println(cache.root.getSnapshot(false)); }
@Test public void shouldRenameNodeByRemovingAndAddingAtEndOfChildren() { Node<Object, Object> sports = cache.findNodeWith(path("/Cars/Sports")); assertConnectionsUsed(1); // "Utility" was found because it is child of "Cars" loaded when "Sports" was loaded sports.rename(name("non-sports")); // "Sports" was already loaded, as was "Cars" assertNoMoreConnectionsUsed(); Node<Object, Object> cars = cache.findNodeWith(path("/Cars")); assertChildren(cars, "Hybrid", "Luxury", "Utility", "non-sports"); assertThat(sports.getParent(), is(cars)); // Ensure that the changes were recorded appropriately ... assertThat(cars.isChanged(false), is(true)); // 'sports' renamed as child assertThat(sports.isChanged(false), is(true)); // path has changed assertThat(cache.hasPendingChanges(), is(true)); assertThat(cache.operations.isExecuteRequired(), is(true)); // Save "/Cars" but keep the changes ... assertConnectionsUsed(0); cache.save(cars); assertConnectionsUsed(2); // 1 to load children required by validation, 1 to perform save // Now the state should reflect our changes, but we need to refind the nodes ... Node<Object, Object> nonSports = cache.findNodeWith(path("/Cars/non-sports")); assertConnectionsUsed(1); assertNoMoreConnectionsUsed(); assertChildren(cars, "Hybrid", "Luxury", "Utility", "non-sports"); assertThat(nonSports.getParent(), is(cars)); // Now there should be no changes ... assertNoChanges(); // System.out.println(cache.root.getSnapshot(false)); }