/** * {@inheritDoc} * * @see org.modeshape.graph.sequencer.SequencerOutput#setReference(java.lang.String, java.lang.String, java.lang.String[]) */ public void setReference( String nodePath, String propertyName, String... paths ) { Path path = pathFactory.create(nodePath); path = absolute(path); if (this.paths.add(path)) { batch.create(path).and(); } batch.set(propertyName).on(nodePath).to(paths); }
/** * {@inheritDoc} * * @see org.modeshape.graph.sequencer.SequencerOutput#setProperty(org.modeshape.graph.property.Path, * org.modeshape.graph.property.Name, java.lang.Object[]) */ public void setProperty( Path nodePath, Name propertyName, Object... values ) { assert valuesAreNotIterators(values); nodePath = absolute(nodePath); if (paths.add(nodePath)) { batch.create(nodePath).and(); } batch.set(propertyName).on(nodePath).to(values); }
/** * {@inheritDoc} * * @see org.modeshape.graph.sequencer.SequencerOutput#setProperty(java.lang.String, java.lang.String, java.lang.Object[]) */ public void setProperty( String nodePath, String propertyName, Object... values ) { assert valuesAreNotIterators(values); Path path = pathFactory.create(nodePath); path = absolute(path); if (paths.add(path)) { batch.create(path).and(); } batch.set(propertyName).on(path).to(values); }
/** * 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()); }
/** * Begin the request to create a node located at the supplied path. * <p> * Like all other methods on the {@link Batch}, the request will be performed when the {@link #execute()} method is * called. * </p> * * @param atPath the path to the node that is to be created. * @param firstProperty a property for the new node * @param additionalProperties additional properties for the new node * @return the object that can be used to specify addition properties for the new node to be copied or the location of the * node where the node is to be created */ public Create<Batch> create( String atPath, Property firstProperty, Property... additionalProperties ) { return create(createPath(atPath)).with(firstProperty, additionalProperties); }
/** * Begin the request to create a node located at the supplied path. * <p> * Like all other methods on the {@link Batch}, the request will be performed when the {@link #execute()} method is * called. * </p> * * @param at the path to the node that is to be created. * @param firstProperty a property for the new node * @param additionalProperties additional properties for the new node * @return the object that can be used to specify addition properties for the new node to be copied or the location of the * node where the node is to be created */ public Create<Batch> create( Path at, Property firstProperty, Property... additionalProperties ) { return create(at).with(firstProperty, additionalProperties); }
/** * Begin the request to create a node located at the supplied path. * <p> * Like all other methods on the {@link Batch}, the request will be performed when the {@link #execute()} method is * called. * </p> * * @param at the path to the node that is to be created. * @return the object that can be used to specify addition properties for the new node to be copied or the location of the * node where the node is to be created */ public final Create<Batch> create( Path at ) { assertNotExecuted(); CheckArg.isNotNull(at, "at"); Path parent = at.getParent(); Name name = at.getLastSegment().getName(); return create(Location.create(parent), name); }
/** * Create the node at the supplied path under the current path, and return the Create operation for the last node created. * The caller <i>must</i> call {@link Graph.Create#and()} to complete the operation. * * @param path the path to the node * @param segments the segments in the remainder of the path * @return the newly-created but incomplete operation */ protected Graph.Create<Graph.Batch> createIfMissing( Path path, Name... segments ) { Path nodePath = path; Graph.Create<Graph.Batch> result = null; for (Name name : segments) { if (result != null) result.and(); nodePath = context.getValueFactories().getPathFactory().create(nodePath, name); result = batch.create(nodePath).orUpdate(); } return result; }
/** * Begin the request to create a node located at the supplied path. * <p> * Like all other methods on the {@link Batch}, the request will be performed when the {@link #execute()} method is * called. * </p> * * @param atPath the path to the node that is to be created. * @param property a property for the new node * @return the object that can be used to specify addition properties for the new node to be copied or the location of the * node where the node is to be created */ public Create<Batch> create( String atPath, Property property ) { return create(createPath(atPath)).with(property); }
/** * Begin the request to create a node located at the supplied path. * <p> * Like all other methods on the {@link Batch}, the request will be performed when the {@link #execute()} method is * called. * </p> * * @param at the path to the node that is to be created. * @param property a property for the new node * @return the object that can be used to specify addition properties for the new node to be copied or the location of the * node where the node is to be created */ public Create<Batch> create( Path at, Property property ) { return create(at).with(property); }
@Test public void shouldAddChildUnderRootNode() { graph.batch().create("/a").with("propB", "valueB").and("propC", "valueC").and().execute(); // Now look up the root node ... Node root = graph.getNodeAt("/"); assertThat(root, is(notNullValue())); assertThat(root, hasProperty(ModeShapeLexicon.UUID, getRootNodeUuid())); assertThat(root.getChildren(), hasChild(segment("a"))); // Now look up node A ... Node nodeA = graph.getNodeAt("/a"); assertThat(nodeA, is(notNullValue())); assertThat(nodeA, hasProperty("propB", "valueB")); assertThat(nodeA, hasProperty("propC", "valueC")); assertThat(nodeA.getChildren(), isEmpty()); }
/** * Begin the request to create a node located at the supplied path. * <p> * Like all other methods on the {@link Batch}, the request will be performed when the {@link #execute()} method is * called. * </p> * * @param atPath the path to the node that is to be created. * @return the object that can be used to specify addition properties for the new node to be copied or the location of the * node where the node is to be created */ public Create<Batch> create( String atPath ) { return create(createPath(atPath)); }
@Test public void shouldStoreManyPropertiesOnANode() { Graph.Create<Graph.Batch> create = graph.batch().create("/a"); for (int i = 0; i != 100; ++i) { create = create.with("property" + i, "value" + i); } create.and().execute(); // Now look up all the properties ... Node nodeA = graph.getNodeAt("/a"); assertThat(nodeA, is(notNullValue())); for (int i = 0; i != 100; ++i) { assertThat(nodeA, hasProperty("property" + i, "value" + i)); } assertThat(nodeA.getChildren(), isEmpty()); }
@Test( expected = InvalidRequestException.class ) public void shouldNowAllowAddChildUnderRootNode() { graph.batch().create("/a").with("propB", "valueB").and("propC", "valueC").and().execute(); }
@Test public void shouldCreateNodesWithBatch() { graph.batch().create(validPath, validIdProperty1).and().remove("prop").on(validPathString).execute(); graph.batch().move(validPath).and(validPath).into(validPathString).and().create(validPath).and().execute(); graph.batch().createUnder(validLocation).nodeNamed("someName").and().delete(validLocation).execute(); }
protected void createSubgraph( Batch batch, SubgraphNode initialNode, Path pathOfInitialNode ) { // Create the node with the properties ... batch.create(pathOfInitialNode).and(initialNode.getProperties()).ifAbsent().and(); // And create the children ... for (Location childLocation : initialNode.getChildren()) { Path path = childLocation.getPath(); SubgraphNode initialChild = initialNode.getNode(path.getLastSegment()); createSubgraph(batch, initialChild, path); } }
@Override protected CreateAction<Batch> createWith( Batch batch, Location parent, Name childName ) { return Batch.this.create(parent, childName); } };
/** * 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(); }
@Test( expected = InvalidRequestException.class ) public void shouldNotAllowMultipleUpdatesInBatch() { Graph.Create<Graph.Batch> create = graph.batch().create("/a"); for (int i = 0; i != 100; ++i) { create = create.with("property" + i, "value" + i); } create.and().execute(); }
/** * Create the node at the supplied path under the current path, and return the Create operation for the last node created. * The caller <i>must</i> call {@link Graph.Create#and()} to complete the operation. * * @param segment the name segment for the child * @return the newly-created but incomplete operation */ protected Graph.Create<Graph.Batch> createIfMissing( Name segment ) { Path nodePath = context.getValueFactories().getPathFactory().create(path, segment); Graph.Create<Graph.Batch> result = batch.create(nodePath).orUpdate(); return result; }