/** * Obtain a graph to the source for which this engine exists. * * @param context the context in which the graph operations should be performed; never null * @return the graph; never null * @throws RepositorySourceException if a connection to the source cannot be established */ protected Graph graph( ExecutionContext context ) { assert context != null; return Graph.create(sourceName, connectionFactory, context); }
/** * Obtain a graph to this configuration repository. This method will always return the same graph instance. * * @return the graph; never null */ public Graph graph() { if (graph == null) { graph = Graph.create(source, context); if (workspace != null) graph.useWorkspace(workspace); } return graph; }
/** * Create a graph instance that uses a transient, in-memory source and the supplied {@link ExecutionContext context}. * * @param context the context in which all executions should be performed * @return the new graph * @throws IllegalArgumentException if the context parameter is null */ public static Graph create( ExecutionContext context ) { InMemoryRepositorySource source = new InMemoryRepositorySource(); source.setName("Transient source"); return create(source, context); }
private void createNamespaceParentIfNeeded() { // Create the node if it does not already exist ... this.store.create(this.parentOfNamespaceNodes).ifAbsent().and(JcrLexicon.PRIMARY_TYPE, ModeShapeLexicon.NAMESPACES).and(); }
protected Graph getConfigurationGraph() { Graph graph = Graph.create(configuration.getRepositorySource(), context); if (configuration.getWorkspace() != null) { graph.useWorkspace(configuration.getWorkspace()); } return graph; }
/** * {@inheritDoc} * * @see org.modeshape.graph.connector.test.AbstractConnectorTest#initializeContent(org.modeshape.graph.Graph) */ @Override protected void initializeContent( Graph graph ) { graph.create("/testNode").and(); source.setAllowsUpdates(false); }
@Ignore @Test public void shouldAddAndReadNodeRepeatedly() throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); System.setOut(new PrintStream(baos)); graph.create("/cacheTest").with("jcr:primaryType").and(); for (int i = 0; i < 3; i++) { graph.getNodeAt("/cacheTest"); } System.err.println(baos.toByteArray().length); }
public Subgraph getConfiguration( int depth ) { Graph result = Graph.create(source, context); result.useWorkspace("configSpace"); return result.getSubgraphOfDepth(depth).at("/"); } };
@SuppressWarnings( "synthetic-access" ) public Subgraph getConfiguration( int depth ) { Graph result = Graph.create(configRepositorySource, context); result.useWorkspace("configSpace"); return result.getSubgraphOfDepth(depth).at("/a/b/Test Repository"); } };
@Test public void shouldProvidePathToInput() throws Exception { this.sequencedProperty = mock(Property.class); graph.create("/a").and().create("/a/b").and().create("/a/b/c").and(); Node input = graph.getNodeAt("/a/b/c"); StreamSequencerContext sequencerContext = sequencer.createStreamSequencerContext(input, sequencedProperty, seqContext, problems); assertThat(sequencerContext.getInputPath(), is(context.getValueFactories().getPathFactory().create("/a/b/c"))); }
protected void assertThatSourceIsNotSearchable( RepositorySource source ) { try { Graph graph = Graph.create(wrapped, context); graph.search("term", 100, 0); fail("Wrapped repository source should not support searching"); } catch (InvalidRequestException e) { // expected ... } assertThat(source.getCapabilities().supportsSearches(), is(false)); }
@Before public void beforeEaach() { context = new ExecutionContext(); graphSource = new InMemoryRepositorySource(); graphSource.setName("Graph source"); initialContentSource = new XmlFileRepositorySource(); initialContentSource.setName("Initial content source"); initialContentSource.setContentLocation(resourceUrl("aircraft.xml")); graph = Graph.create(graphSource, context); initialContent = Graph.create(initialContentSource, context); }
public Subgraph getConfiguration( int depth ) { Subgraph result = null; if (configSource != null) { Graph config = Graph.create(configSource, getExecutionContext()); config.useWorkspace(null); // default workspace result = config.getSubgraphOfDepth(depth).at(source.getName()); } return result; } });
@Test public void shouldSendSearchRequestToSearchEngine() throws Exception { assertThatSourceIsNotSearchable(wrapped); loadContentInto(wrapped, "aircraft.xml"); searchable = newSynchronousSearchable(); assertThat(searchable.getCapabilities().supportsSearches(), is(true)); QueryResults results = Graph.create(searchable, context).search("Boeing", 100, 1); assertThat(results, is(notNullValue())); }
@Test public void shouldSendQueryRequestToSearchEngine() throws Exception { assertThatSourceIsNotSearchable(wrapped); loadContentInto(wrapped, "aircraft.xml"); searchable = newSynchronousSearchable(); assertThat(searchable.getCapabilities().supportsQueries(), is(true)); QueryResults results = Graph.create(searchable, context) .query(sql.parseQuery("SELECT * FROM t1", typeSystem), schemata) .execute(); assertThat(results, is(notNullValue())); }
@Before public void beforeEaach() throws SAXException, IOException { context = new ExecutionContext(); graphSource = new InMemoryRepositorySource(); graphSource.setName("Graph source"); graph = Graph.create(graphSource, context); graph.importXmlFrom(resourceUrl("aircraft.xml")).into("/"); }
@Test public void shouldInitializeSourceWithOnlySomeNodes() { assertNoChildren(graph, "/"); graph.create("/Aircraft").and(); graph.merge(initialContent); // print = true; printSubgraph(graph, "/"); assertNodeExists(initialContent, "Aircraft"); assertNodeDoesNotExist(initialContent, "Aircraft[2]"); }
@Test public void shouldCreateNodeAndReturnGraph() { graph.create(validPath).and().getNodeAt(validPath); assertThat(numberOfExecutions, is(2)); assertNextRequestIsCreate(Location.create(validPath.getParent()), "c"); assertNextRequestReadNode(Location.create(validPath)); assertNoMoreRequests(); }
@Test public void shouldSendAllRequestsToAsynchronousWrappedSourceWhenRequestsAreNotSearchOrQueryRequests() throws Exception { assertThatSourceIsNotSearchable(wrapped); loadContentInto(wrapped, "aircraft.xml"); searchable = newAsynchronousSearchable(); Graph graph = Graph.create(searchable, context); Node boeing777 = graph.getNodeAt("/Aircraft/Commercial/Boeing 777"); assertThat(boeing777, is(notNullValue())); // Now do a batch ... graph.batch().read("/Aircraft/Commercial/Boeing 777").and().read("/Aircraft/Commercial/Boeing 787").execute(); } }
@Test public void shouldSendAllRequestsToSynchronousWrappedSourceWhenRequestsAreNotSearchOrQueryRequests() throws Exception { assertThatSourceIsNotSearchable(wrapped); loadContentInto(wrapped, "aircraft.xml"); searchable = newSynchronousSearchable(); Graph graph = Graph.create(searchable, context); Node boeing777 = graph.getNodeAt("/Aircraft/Commercial/Boeing 777"); assertThat(boeing777, is(notNullValue())); // Now do a batch ... graph.batch().read("/Aircraft/Commercial/Boeing 777").and().read("/Aircraft/Commercial/Boeing 787").execute(); }