batch.readProperty(ModeShapeLexicon.DERIVED_FROM).on(child).and();
fedProps = federated.getPropertiesByName().on(pathInFederated); FEDERATED_TIMER.stop(); assertThat(fedProps, is(sourceProps));
batch.set(uriPropertyName).to(newUri).on(pathToNamespaceNode).and();
.set("propA") .to("valueA") .on("/") .and() .create("/a")
assertSameProperties(result, graph.getProperties().on(location));
cache.nodeOperations.preSetProperty(this, property.getName(), info); properties.put(name, info); cache.operations.set(property).on(location); markAsChanged(); cache.nodeOperations.postSetProperty(this, property.getName(), previous);
/** * {@inheritDoc} * * @see org.modeshape.graph.GraphMerger.PropertyMerger#mergeProperty(Batch, Path, Property, Property) */ public void mergeProperty( Batch batch, Path path, Property actual, Property desired ) { // the actual property already exists ... Iterator<?> actualValues = actual.getValues(); Iterator<?> desiredValues = desired.getValues(); boolean performSet = false; while (actualValues.hasNext() && desiredValues.hasNext()) { Object actualValue = actualValues.next(); Object desiredValue = desiredValues.next(); if (ValueComparators.OBJECT_COMPARATOR.compare(actualValue, desiredValue) != 0) { performSet = true; break; } } if (!performSet && (actualValues.hasNext() || desiredValues.hasNext())) { performSet = true; } if (performSet) { batch.set(desired).on(path); } } }
@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())); }
@Test public void shouldAddValuesToExistingProperty() { String initialPath = ""; int depth = 1; int numChildrenPerNode = 1; int numPropertiesPerNode = 1; Stopwatch sw = new Stopwatch(); boolean batch = true; createSubgraph(graph, initialPath, depth, numChildrenPerNode, numPropertiesPerNode, batch, sw, output, null); assertThat(graph.getChildren().of("/"), hasChildren(segment("node1"))); Subgraph subgraph = graph.getSubgraphOfDepth(2).at("/"); assertThat(subgraph, is(notNullValue())); assertThat(subgraph.getNode("node1"), hasProperty("property1", "The quick brown fox jumped over the moon. What? ")); graph.addValue("foo").andValue("bar").to("property1").on("node1"); assertThat(graph.getChildren().of("/"), hasChildren(segment("node1"))); subgraph = graph.getSubgraphOfDepth(2).at("/"); assertThat(subgraph, is(notNullValue())); assertThat(subgraph.getNode("node1"), hasProperty("property1", "The quick brown fox jumped over the moon. What? ", "foo", "bar")); }
@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(); } }
protected GraphReturnable( ReturnType returnObject, Graph.Batch batch, Path path, Name... names ) { super(returnObject); assert batch != null; assert path != null; assert names.length > 0; this.context = batch.getGraph().getContext(); this.batch = batch; // Make sure there are nodes down to the supplied path ... createIfMissing(path, names).and(); this.path = context.getValueFactories().getPathFactory().create(path, names); try { properties = batch.getGraph().getPropertiesByName().on(this.path); } catch (PathNotFoundException e) { // The node doesn't exist yet (wasn't yet saved) properties = new HashMap<Name, Property>(); } }
protected void matchProperties( Batch batch, Node actualNode, Node desiredNode ) { Location actualLocation = actualNode.getLocation(); assert actualLocation != null; Collection<Property> desiredProperties = desiredNode.getProperties(); if (desiredProperties.isEmpty()) return; for (Property desiredProperty : desiredProperties) { Name propertyName = desiredProperty.getName(); Property actual = actualNode.getProperty(propertyName); if (actual == null) { batch.set(desiredProperty).on(actualLocation); } else { PropertyMerger merger = MERGERS.get(propertyName); if (merger == null) merger = DEFAULT_MERGER; merger.mergeProperty(batch, actualLocation.getPath(), actual, desiredProperty); } } }
/** * Remove a property from this node. * * @param name the name of the property to be removed; may not be null * @return the previous information for the property, or null if there was no previous property */ public PropertyInfo<PropertyPayload> removeProperty( Name name ) { assert !isStale(); cache.authorizer.checkPermissions(getPath(), Action.REMOVE); load(); if (!properties.containsKey(name)) return null; cache.nodeOperations.preRemoveProperty(this, name); PropertyInfo<PropertyPayload> results = properties.remove(name); markAsChanged(); cache.operations.remove(name).on(location); cache.nodeOperations.postRemoveProperty(this, name, results); return results; }
@Test public void shouldGetPropertiesByNameOnNode() { setPropertiesToReadOn(Location.create(validPath), validIdProperty1, validIdProperty2); Map<Name, Property> propsByName = graph.getPropertiesByName().on(validPath); assertThat(numberOfExecutions, is(1)); assertNextRequestReadProperties(Location.create(validPath), validIdProperty1, validIdProperty2); assertNoMoreRequests(); assertThat(propsByName.get(validIdProperty1.getName()), is(validIdProperty1)); assertThat(propsByName.get(validIdProperty2.getName()), is(validIdProperty2)); setPropertiesToReadOn(Location.create(validPath)); propsByName = graph.getPropertiesByName().on(validPath); assertThat(numberOfExecutions, is(1)); assertNextRequestReadProperties(Location.create(validPath)); assertNoMoreRequests(); assertThat(propsByName.isEmpty(), is(true)); }
@Test public void shouldAddValuesToNonExistantProperty() { String initialPath = ""; int depth = 1; int numChildrenPerNode = 1; int numPropertiesPerNode = 1; Stopwatch sw = new Stopwatch(); boolean batch = true; createSubgraph(graph, initialPath, depth, numChildrenPerNode, numPropertiesPerNode, batch, sw, output, null); assertThat(graph.getChildren().of("/"), hasChildren(segment("node1"))); graph.addValue("foo").andValue("bar").to("newProperty").on("node1"); assertThat(graph.getChildren().of("/"), hasChildren(segment("node1"))); Subgraph subgraph = graph.getSubgraphOfDepth(2).at("/"); assertThat(subgraph, is(notNullValue())); assertThat(subgraph.getNode("node1"), hasProperty("property1", "The quick brown fox jumped over the moon. What? ")); assertThat(subgraph.getNode("node1"), hasProperty("newProperty", "foo", "bar")); }
@Test public void shouldGetPropertiesOnNode() { setPropertiesToReadOn(Location.create(validPath), validIdProperty1, validIdProperty2); Collection<Property> props = graph.getProperties().on(validPath); assertThat(numberOfExecutions, is(1)); assertNextRequestReadProperties(Location.create(validPath), validIdProperty1, validIdProperty2); assertNoMoreRequests(); assertThat(props, hasItems(validIdProperty1, validIdProperty2)); setPropertiesToReadOn(Location.create(validPath)); props = graph.getProperties().on(validPath); assertThat(numberOfExecutions, is(1)); assertNextRequestReadProperties(Location.create(validPath)); assertNoMoreRequests(); assertThat(props.size(), is(0)); }
@Test public void shouldNotRemoveValuesFromNonExistantProperty() { String initialPath = ""; int depth = 1; int numChildrenPerNode = 1; int numPropertiesPerNode = 1; Stopwatch sw = new Stopwatch(); boolean batch = true; createSubgraph(graph, initialPath, depth, numChildrenPerNode, numPropertiesPerNode, batch, sw, output, null); assertThat(graph.getChildren().of("/"), hasChildren(segment("node1"))); graph.removeValue("The quick brown fox jumped over the moon. What? ").from("noSuchProperty").on("node1"); assertThat(graph.getChildren().of("/"), hasChildren(segment("node1"))); Subgraph subgraph = graph.getSubgraphOfDepth(2).at("/"); assertThat(subgraph, is(notNullValue())); assertThat(subgraph.getNode("node1"), hasProperty("property1", "The quick brown fox jumped over the moon. What? ")); }
@Test public void shouldRemoveValuesFromExistingProperty() { String initialPath = ""; int depth = 1; int numChildrenPerNode = 1; int numPropertiesPerNode = 1; Stopwatch sw = new Stopwatch(); boolean batch = true; createSubgraph(graph, initialPath, depth, numChildrenPerNode, numPropertiesPerNode, batch, sw, output, null); assertThat(graph.getChildren().of("/"), hasChildren(segment("node1"))); graph.removeValue("The quick brown fox jumped over the moon. What? ").andValue("bar").from("property1").on("node1"); assertThat(graph.getChildren().of("/"), hasChildren(segment("node1"))); Subgraph subgraph = graph.getSubgraphOfDepth(2).at("/"); assertThat(subgraph, is(notNullValue())); assertThat(subgraph.getNode("node1"), hasProperty("property1")); }