/** * Persist any unsaved changes that have been made to this configuration. This method has no effect if there are currently * {@link #hasChanges() no unsaved changes}. * * @return this configuration, for method chaining purposes */ public ModeShapeConfiguration save() { Graph.Batch changes = this.changes; if (changes != null && changes.isExecuteRequired()) { changes.execute(); } this.changes = null; sequencerDefinitions.clear(); mimeTypeDetectorDefinitions.clear(); repositorySourceDefinitions.clear(); return this; }
public Conjunction<Graph> into( Location at ) throws IOException, SAXException { final Name nameAttribute = this.nameAttribute; final Name typeAttribute = this.typeAttribute; GraphImporter importer = new GraphImporter(Graph.this) { @Override protected Name getNameAttribute() { return nameAttribute; } @Override protected Name getTypeAttribute() { return typeAttribute; } }; try { importer.importXml(stream, at, skipRootElement).execute(); // 'importXml' creates and uses a new batch } finally { stream.close(); } return Graph.this.nextGraph; } };
@Test public void shouldSuccessfullyApplyFunctionUsingBatch() { // Create some nodes and get the subgraph of them ... Subgraph subgraph = graph.getSubgraphOfDepth(100).at("/"); int count = countNodes(subgraph); // Determine the number of nodes using a function ... Results results = graph.batch().applyFunction(new CountNodesFunction()).to("/").execute(); assertThat(results, is(notNullValue())); assertThat(results.getRequests().size(), is(1)); FunctionRequest request = (FunctionRequest)results.getRequests().get(0); assertThat(request.output("nodeCount", PropertyType.LONG, (Long)null, context), is(new Long(count))); }
@FixFor( "MODE-966" ) @Test public void shouldStoreLargeBinaryValue() throws Exception { File file = new File("src/test/resources/testdata/test1.xmi"); assertThat(file.exists(), is(true)); BinaryFactory binaryFactory = context.getValueFactories().getBinaryFactory(); Binary binaryValue = binaryFactory.create(file); graph.batch() .create("/someFile.xmi") .with("jcr:primaryType", "nt:file") .and() .create("/someFile.xmi/jcr:content") .with("jcr:priamryType", "nt:resource") .and("jcr:data", binaryValue) .and() .execute(); // Now read the content back out ... Property data = graph.getProperty("jcr:data").on("/someFile.xmi/jcr:content"); Binary readValue = binaryFactory.create(data.getFirstValue()); // and verify the content matches ... assertThat(binaryValue.getHash(), is(readValue.getHash())); assertThat(binaryValue.getBytes(), is(readValue.getBytes())); }
/** * 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()); }
public Conjunction<Graph> into( Location at ) throws IOException, SAXException { final Name nameAttribute = this.nameAttribute; final Name typeAttribute = this.typeAttribute; GraphImporter importer = new GraphImporter(Graph.this) { @Override protected Name getNameAttribute() { return nameAttribute; } @Override protected Name getTypeAttribute() { return typeAttribute; } }; importer.importXml(uri, at, skipRootElement).execute(); // 'importXml' creates and uses a new batch return Graph.this.nextGraph; } };
@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()); }
@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()); }
@Override public void endDocument() { batch.execute(); }
@Test( expected = IllegalStateException.class ) public void shouldResultInExceptionIfFunctionResultsInErrorUsingBatch() { graph.batch().applyFunction(new SetErrorFunction()).to("/").execute(); }
@Test( expected = InvalidRequestException.class ) public void shouldNowAllowAddChildUnderRootNode() { graph.batch().create("/a").with("propB", "valueB").and("propC", "valueC").and().execute(); }
@Test( expected = IllegalStateException.class ) public void shouldResultInExceptionIfFunctionThrowsExceptionUsingBatch() { graph.batch().applyFunction(new ThrowErrorFunction()).to("/").execute(); }
public Results execute() { return Batch.this.execute(); } };
public void close() { batch.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())); } } }
@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(); }
/** * 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(); }
/** * {@inheritDoc} * * @see org.modeshape.graph.query.process.QueryProcessor#preExecute(QueryContext) */ @Override protected void preExecute( QueryContext context ) { // Submit the batch before the processing the query. No need to hold onto the batch results, // because each ProcessingComponent holds onto its AccessQueryRequest ... ((GraphQueryContext)context).getBatch().execute(); } };
/** * {@inheritDoc} * * @see org.modeshape.graph.io.Destination#submit() */ public void submit() { // Execute only if we're not ignoring submits ... if (!this.ignoreSubmit && !batch.hasExecuted()) batch.execute(); }