/** * Create a graph sequencer output instance using {@link Graph} object. A {@link Graph.Batch} object is created as a result. * * @param graph the {@link Graph} object; may not be null */ public GraphSequencerOutput( Graph graph ) { this(graph.batch()); }
public Subgraph getConfiguration( int depth ) { Graph result = Graph.create(source, context); result.useWorkspace("configSpace"); return result.getSubgraphOfDepth(depth).at("/"); } };
/** * Request to read the node given by the supplied reference value. * * @param reference the reference property value that is to be resolved into a node * @return the node that is read from the repository * @throws ValueFormatException if the supplied reference could not be converted to an identifier property value */ public Node resolve( Reference reference ) { CheckArg.isNotNull(reference, "reference"); UUID uuid = getContext().getValueFactories().getUuidFactory().create(reference); return getNodeAt(uuid); }
/** * 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; }
public On<Conjunction<Graph>> to( Object firstValue, Object... otherValues ) { firstValue = convertReferenceValue(firstValue); for (int i = 0, len = otherValues.length; i != len; ++i) { otherValues[i] = convertReferenceValue(otherValues[i]); } return set(getContext().getPropertyFactory().create(propertyName, firstValue, otherValues)); }
/** * Begin the request to clone a node located at the supplied path into a parent node at a different location, which is * specified via the <code>into(...)</code> method on the returned {@link Clone} object. * <p> * Like all other methods on the {@link Graph}, the clone request will be performed immediately when the {@link WithUuids UUID * behavior} is specified. * </p> * <p> * The clone operation differs from the copy operation in that it must replicate nodes from one workspace to another (the copy * operations supports replicating nodes within a workspace as well as across workspaces) and that it preserves UUIDs (the * copy operation always generates new UUIDs). * </p> * * @param fromPath the path to the node that is to be copied. * @return the object that can be used to specify addition nodes to be copied or the location of the node where the node is to * be copied */ public Clone<Graph> clone( String fromPath ) { return clone(Location.create(createPath(fromPath))); }
@Test public void shouldCloneChildrenAndRemoveExistingNodesWithSameUuidIfSpecified() throws Exception { String defaultWorkspaceName = graph.getCurrentWorkspaceName(); String workspaceName = "copyChildrenSource"; graph.useWorkspace(workspaceName); String initialPath = ""; int depth = 3; Subgraph source = graph.getSubgraphOfDepth(3).at("/node1"); graph.useWorkspace(defaultWorkspaceName); graph.create("/newUuids").and(); graph.clone("/node1") .fromWorkspace(workspaceName) .as(name("node1")) graph.useWorkspace(workspaceName); graph.getNodeAt("/node1"); graph.useWorkspace(defaultWorkspaceName); graph.create("/newUuids/node1/shouldBeRemoved"); graph.clone("/node1") .fromWorkspace(workspaceName) .as(name("otherNode")) assertThat(graph.getNodeAt("/newUuids").getChildren(), hasChildren(segment("otherNode")));
String defaultWorkspaceName = graph.getCurrentWorkspaceName(); String workspaceName = "copyChildrenSource"; graph.useWorkspace(workspaceName); String initialPath = ""; int depth = 3; createSubgraph(graph, initialPath, depth, numChildrenPerNode, numPropertiesPerNode, batch, sw, System.out, null); graph.useWorkspace(defaultWorkspaceName); graph.create("/newUuids").and(); graph.clone("/node1") .fromWorkspace(workspaceName) .as(name("node1")) graph.create("/newUuids/node1/shouldBeRemoved").and(); graph.create("/refererringNode").and(); graph.set("refProp").on("/refererringNode").to(graph.getNodeAt("/newUuids/node1/shouldBeRemoved")); graph.clone("/node1") .fromWorkspace(workspaceName) .as(name("otherNode"))
@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(); } }
@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); }
@Test public void shouldNotCloneChildrenIfUuidConflictAndFailureBehavior() throws Exception { String defaultWorkspaceName = graph.getCurrentWorkspaceName(); String workspaceName = "copyChildrenSource"; graph.useWorkspace(workspaceName); String initialPath = ""; int depth = 3; createSubgraph(graph, initialPath, depth, numChildrenPerNode, numPropertiesPerNode, batch, sw, output, null); graph.useWorkspace(defaultWorkspaceName); graph.create("/newUuids").and(); graph.clone("/node1/node1/node1") .fromWorkspace(workspaceName) .as(name("node1")) graph.clone("/node1/node1/node1") .fromWorkspace(workspaceName) .as(name("shouldNotWork"))
String... extraChildren ) { FEDERATED_TIMER.start(); Node fedNode = federated.getNodeAt(pathInFederated); FEDERATED_TIMER.stop(); SOURCE_TIMER.start(); Node sourceNode = graphFor(sourceName, workspaceName).getNodeAt(pathInSource); SOURCE_TIMER.stop(); List<Location> children = federated.getChildren().of(pathInFederated); FEDERATED_TIMER.stop(); fedChildren.clear(); fedProps = federated.getPropertiesByName().on(pathInFederated); FEDERATED_TIMER.stop(); assertThat(fedProps, is(sourceProps)); Property fedProp = federated.getProperty(sourceProp.getName()).on(pathInFederated); FEDERATED_TIMER.stop(); assertThat(fedProp, is(sourceProp)); Subgraph fedSubgraph = federated.getSubgraphOfDepth(2).at(pathInFederated); FEDERATED_TIMER.stop(); SOURCE_TIMER.start(); Subgraph sourceSubgraph = graphFor(sourceName, workspaceName).getSubgraphOfDepth(2).at(pathInSource); SOURCE_TIMER.stop(); if (extraChildren.length == 0) {
@FixFor( "MODE-1182" ) @Test public void shouldBeAbleToCreateThenDestroyThenRecreateWorkspace() throws Exception { if (source.getCapabilities().supportsCreatingWorkspaces()) { String defaultWorkspaceName = graph.getCurrentWorkspaceName(); String validWorkspaceName = generateNonExistantWorkspaceName(); graph.createWorkspace().named(validWorkspaceName); graph.useWorkspace(defaultWorkspaceName); graph.destroyWorkspace().named(validWorkspaceName); graph.createWorkspace().named(validWorkspaceName); } }
public AddValue<Graph> addValue( Object value ) { return new AddValueAction<Graph>(this, this.getCurrentWorkspaceName(), value) { @Override protected Graph submit( String workspaceName, Location on, Name property, List<Object> values ) { requests.addValues(workspaceName, on, property, values); return nextGraph.and(); } }; }
/** * {@inheritDoc} * * @see org.modeshape.graph.connector.test.AbstractConnectorTest#initializeContent(org.modeshape.graph.Graph) */ @Override protected void initializeContent( Graph graph ) { if (!graph.getWorkspaces().contains("default")) { graph.createWorkspace().named("default"); } else { graph.useWorkspace("default"); } }
@Test public void shouldReadIndividualPropertiesOfNodes() { // Read each node that is a child of the root... for (Location childLocation : graph.getChildren().of("/")) { // For each node ... Node child = graph.getNodeAt(childLocation); for (Property property : child.getProperties()) { Name name = property.getName(); // Re-read the property and verify the value(s) match the value(s) in 'property' Property singleProperty = graph.getProperty(name).on(childLocation); assertThat(singleProperty, is(notNullValue())); assertThat(singleProperty, is(property)); } } }
public On<Conjunction<Graph>> to( Iterator<?> values ) { List<Object> valueList = new LinkedList<Object>(); while (values.hasNext()) { Object value = values.next(); valueList.add(value); } return set(getContext().getPropertyFactory().create(propertyName, valueList)); } };
protected void assertReference( String fromNodePath, String propertyName, String... toNodePath ) { Object[] values = graph.getProperty(propertyName).on(fromNodePath).getValuesAsArray(); assertThat(values.length, is(toNodePath.length)); for (int i = 0; i != values.length; ++i) { Object value = values[i]; assertThat(value, is(instanceOf(Reference.class))); Reference ref = (Reference)value; assertThat(graph.resolve(ref).getLocation().getPath(), is(graph.getNodeAt(toNodePath[i]).getLocation().getPath())); } }
/** * 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); }
/** * Request to read the node at the supplied path. * * @param path the path of the node that is to be read * @return the node that is read from the repository */ public Node getNodeAt( Path path ) { return getNodeAt(Location.create(path)); }