@Test public void shouldSetMultiplePropertiesAtOnce() { Property p1 = createProperty("propName1", new Float(3.0f)); Property p2 = createProperty("propName2", new Double(1.0)); Property p3 = createProperty("propName3", "String value"); graph.batch().set(p1, p2, p3).on(validPath).execute(); assertNextRequestUpdateProperties(Location.create(validPath), p1, p2, p3); }
.with("propB", "valueB") .and("propC", "valueC") .and() .create("/b") .with("propD", "valueD")
graph.batch().set("description").on("/testnodeC/testnodeD").to("This is the value").and().execute();
Results results = store.batch().copy(source).fromWorkspace(sourceWorkspace).to(destination).execute();
batch.set(actual.getName()).on(path).to(unionedValues).and();
Results results = store.batch().move(nodeToMove).as(newName).into(newParentPath).execute(); MoveBranchRequest moveRequest = (MoveBranchRequest)results.getRequests().get(0); Location locationAfter = moveRequest.getActualLocationAfter();
@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)
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 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)
@Override public void startElement( String uri, String localName, String qName, Attributes attributes ) { Path nodePath; if (parents.isEmpty()) { nodePath = pathFactory.createRootPath(); } else { nodePath = path(parents.peek(), qName); batch.create(nodePath).and(); } parents.push(nodePath); for (int i = 0; i < attributes.getLength(); i++) { String rawValue = attributes.getValue(i); String[] values = rawValue.split(","); Property prop = propFactory.create(name(attributes.getQName(i)), (Object[])values); batch.set(prop).on(nodePath).and(); } }
/** * This method attempts to create a very small subgraph and then delete all of the nodes in that subgraph, all within the same * batch operation. */ @FixFor( "MODE-788" ) @Test public void shouldCreateAndDeleteTwoNodeSubgraphInSameOperation() { // Look for the root before we do anyting ... Node root = graph.getNodeAt("/"); assertThat(root, is(notNullValue())); assertThat(root, hasProperty(ModeShapeLexicon.UUID, getRootNodeUuid())); assertThat(root.getChildren(), isEmpty()); graph.batch().create("/a").and().create("/a/b").and().delete("/a").and().execute(); // Now look up the root node ... root = graph.getNodeAt("/"); assertThat(root, is(notNullValue())); assertThat(root, hasProperty(ModeShapeLexicon.UUID, getRootNodeUuid())); assertThat(root.getChildren(), isEmpty()); }
@Override protected Batch submit( String workspaceName, Location on, Name property, List<Object> values ) { requestQueue.removeValues(workspaceName, on, property, values); return nextRequests.and(); } };
/** * This method attempts to create a small subgraph and then delete all of the nodes in that subgraph, all within the same * batch operation. */ @FixFor( "MODE-788" ) @Test public void shouldCreateAndDeleteNodeInSameOperation() { graph.batch().create("/a").with("propB", "valueB").and("propC", "valueC").and().delete("/a").and().execute(); }
protected void assertReadUsingBatch( String... pathsInFederated ) { Graph.Batch batch = federated.batch(); for (String pathInFederated : pathsInFederated) { batch.read(pathInFederated).and(); } Results results = batch.execute(); for (String pathInFederated : pathsInFederated) { assertThat(results.getNode(pathInFederated), is(notNullValue())); } } }
public ThisType setProperty( Name propertyName, Object[] values ) { // Set the property via the batch ... batch.set(propertyName).on(path).to(values).and(); // Record that we changed this property ... properties.put(propertyName, context.getPropertyFactory().create(propertyName, values)); return thisType(); }
@Test public void shouldNotCombineNonAdjacentSetPropertyCalls() { Property p1 = createProperty("propName1", new Float(3.0f)); Property p2 = createProperty("propName2", new Double(1.0)); Property p3 = createProperty("propName3", "String value"); graph.batch().set(p1).on(validPath).and().set(p2).on(validPath).and().set(p3).on(validUuid).execute(); extractRequestsFromComposite(); assertNextRequestUpdateProperties(Location.create(validPath), p1, p2); assertNextRequestSetProperty(Location.create(validUuid), p3); }
@Override protected Batch submit( String workspaceName, Location on, Name property, List<Object> values ) { requestQueue.addValues(workspaceName, on, property, values); return nextRequests.and(); } };