/** * Sets or updates a property value. The property key will be set to a constant. This is a convenience method * which allows treating the multi-valued nature of properties as only containing a single value. Care must be * taken when using this method because properties are not only uniquely identified by just key and name but also * visibility so adding properties with the same name and different visibility strings is still permitted. * * @param name The name of the property. * @param value The value of the property. * @param visibility The visibility to give this property. */ default void setProperty(String name, Object value, Visibility visibility, Authorizations authorizations) { prepareMutation().setProperty(name, value, visibility).save(authorizations); }
Metadata newMetadata = Metadata.create(); newMetadata.add("meta1", "value3", VISIBILITY_A); m.setProperty("propBmeta", "propBmeta", newMetadata, VISIBILITY_A); m.save(AUTHORIZATIONS_ALL); graph.flush();
/** * Sets or updates a property value. The property key will be set to a constant. This is a convenience method * which allows treating the multi-valued nature of properties as only containing a single value. Care must be * taken when using this method because properties are not only uniquely identified by just key and name but also * visibility so adding properties with the same name and different visibility strings is still permitted. * * @param name The name of the property. * @param value The value of the property. * @param visibility The visibility to give this property. */ default void setProperty(String name, Object value, Visibility visibility, Authorizations authorizations) { prepareMutation().setProperty(name, value, visibility).save(authorizations); }
Metadata newMetadata = Metadata.create(); newMetadata.add("meta1", "value3", VISIBILITY_A); m.setProperty("propBmeta", "propBmeta", newMetadata, VISIBILITY_A); m.save(AUTHORIZATIONS_ALL); graph.flush();
/** * Sets or updates a property value. The property key will be set to a constant. This is a convenience method * which allows treating the multi-valued nature of properties as only containing a single value. Care must be * taken when using this method because properties are not only uniquely identified by just key and name but also * visibility so adding properties with the same name and different visibility strings is still permitted. * * @param name The name of the property. * @param value The value of the property. * @param metadata The metadata to assign to this property. * @param visibility The visibility to give this property. */ default void setProperty(String name, Object value, Metadata metadata, Visibility visibility, Authorizations authorizations) { prepareMutation().setProperty(name, value, metadata, visibility).save(authorizations); }
/** * Sets or updates a property value. The property key will be set to a constant. This is a convenience method * which allows treating the multi-valued nature of properties as only containing a single value. Care must be * taken when using this method because properties are not only uniquely identified by just key and name but also * visibility so adding properties with the same name and different visibility strings is still permitted. * * @param name The name of the property. * @param value The value of the property. * @param metadata The metadata to assign to this property. * @param visibility The visibility to give this property. */ default void setProperty(String name, Object value, Metadata metadata, Visibility visibility, Authorizations authorizations) { prepareMutation().setProperty(name, value, metadata, visibility).save(authorizations); }
@Test public void historicalPropertyValueAddProp() { graph.prepareVertex("v1", VISIBILITY_A) .setProperty("prop1_A", "value1", VISIBILITY_A) .setProperty("prop2_B", "value2", VISIBILITY_B) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); // Add property Vertex v1 = graph.getVertex("v1", AUTHORIZATIONS_A_AND_B); v1.prepareMutation() .setProperty("prop3_A", "value3", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); v1 = graph.getVertex("v1", AUTHORIZATIONS_A_AND_B); List<HistoricalPropertyValue> values = toList(v1.getHistoricalPropertyValues(AUTHORIZATIONS_A_AND_B)); Collections.reverse(values); assertEquals(3, values.size()); assertEquals("prop1_A", values.get(0).getPropertyName()); assertEquals("prop2_B", values.get(1).getPropertyName()); assertEquals("prop3_A", values.get(2).getPropertyName()); }
.setProperty("prop3_A", "value4", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); .setProperty("prop3_A", "value3", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.flush();
@Test public void historicalPropertyValueAddProp() { graph.prepareVertex("v1", VISIBILITY_A) .setProperty("prop1_A", "value1", VISIBILITY_A) .setProperty("prop2_B", "value2", VISIBILITY_B) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); // Add property Vertex v1 = graph.getVertex("v1", AUTHORIZATIONS_A_AND_B); v1.prepareMutation() .setProperty("prop3_A", "value3", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); v1 = graph.getVertex("v1", AUTHORIZATIONS_A_AND_B); List<HistoricalPropertyValue> values = toList(v1.getHistoricalPropertyValues(AUTHORIZATIONS_A_AND_B)); Collections.reverse(values); assertEquals(3, values.size()); assertEquals("prop1_A", values.get(0).getPropertyName()); assertEquals("prop2_B", values.get(1).getPropertyName()); assertEquals("prop3_A", values.get(2).getPropertyName()); }
.setProperty("prop3_A", "value4", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); .setProperty("prop3_A", "value3", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.flush();
.setProperty("prop1", "value1", prop1Metadata, VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.flush();
@Test public void testAlterVertexWithoutIndexing() { assumeTrue("alter vertex without indexing not supported", !isDefaultSearchIndex()); graph.prepareVertex("v1", VISIBILITY_A) .setIndexHint(IndexHint.DO_NOT_INDEX) .save(AUTHORIZATIONS_A); graph.flush(); Vertex v1 = graph.getVertex("v1", AUTHORIZATIONS_A); v1.prepareMutation() .setProperty("prop1", "value1", VISIBILITY_A) .setIndexHint(IndexHint.DO_NOT_INDEX) .save(AUTHORIZATIONS_A); graph.flush(); Iterable<Vertex> vertices = graph.query(AUTHORIZATIONS_A) .has("prop1", "value1") .vertices(); assertVertexIds(vertices); }
@Test public void testElementMutationDoesntChangeObjectUntilSave() { Vertex v = graph.addVertex("v1", VISIBILITY_EMPTY, AUTHORIZATIONS_ALL); v.setProperty("prop1", "value1-1", VISIBILITY_A, AUTHORIZATIONS_ALL); graph.flush(); ElementMutation<Vertex> m = v.prepareMutation() .setProperty("prop1", "value1-2", VISIBILITY_A) .setProperty("prop2", "value2-2", VISIBILITY_A); Assert.assertEquals(1, count(v.getProperties())); assertEquals("value1-1", v.getPropertyValue("prop1")); v = m.save(AUTHORIZATIONS_A_AND_B); Assert.assertEquals(2, count(v.getProperties())); assertEquals("value1-2", v.getPropertyValue("prop1")); assertEquals("value2-2", v.getPropertyValue("prop2")); }
@Test public void testAlterVertexWithoutIndexing() { assumeTrue("alter vertex without indexing not supported", !isDefaultSearchIndex()); graph.prepareVertex("v1", VISIBILITY_A) .setIndexHint(IndexHint.DO_NOT_INDEX) .save(AUTHORIZATIONS_A); graph.flush(); Vertex v1 = graph.getVertex("v1", AUTHORIZATIONS_A); v1.prepareMutation() .setProperty("prop1", "value1", VISIBILITY_A) .setIndexHint(IndexHint.DO_NOT_INDEX) .save(AUTHORIZATIONS_A); graph.flush(); Iterable<Vertex> vertices = graph.query(AUTHORIZATIONS_A) .has("prop1", "value1") .vertices(); assertVertexIds(vertices); }
@Test public void testElementMutationDoesntChangeObjectUntilSave() { Vertex v = graph.addVertex("v1", VISIBILITY_EMPTY, AUTHORIZATIONS_ALL); v.setProperty("prop1", "value1-1", VISIBILITY_A, AUTHORIZATIONS_ALL); graph.flush(); ElementMutation<Vertex> m = v.prepareMutation() .setProperty("prop1", "value1-2", VISIBILITY_A) .setProperty("prop2", "value2-2", VISIBILITY_A); Assert.assertEquals(1, count(v.getProperties())); assertEquals("value1-1", v.getPropertyValue("prop1")); v = m.save(AUTHORIZATIONS_A_AND_B); Assert.assertEquals(2, count(v.getProperties())); assertEquals("value1-2", v.getPropertyValue("prop1")); assertEquals("value2-2", v.getPropertyValue("prop2")); }
@Test public void testDeleteElement() { Vertex v = graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_ALL); v.prepareMutation() .setProperty("prop1", "value1", VISIBILITY_A) .save(AUTHORIZATIONS_ALL); graph.flush(); v = graph.getVertex("v1", AUTHORIZATIONS_A); assertNotNull(v); Assert.assertEquals(1, count(graph.query(AUTHORIZATIONS_A_AND_B).has("prop1", "value1").vertices())); graph.deleteVertex(v.getId(), AUTHORIZATIONS_A_AND_B); graph.flush(); v = graph.getVertex("v1", AUTHORIZATIONS_A); assertNull(v); Assert.assertEquals(0, count(graph.query(AUTHORIZATIONS_A_AND_B).has("prop1", "value1").vertices())); }
@Test public void testDeleteElement() { Vertex v = graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_ALL); v.prepareMutation() .setProperty("prop1", "value1", VISIBILITY_A) .save(AUTHORIZATIONS_ALL); graph.flush(); v = graph.getVertex("v1", AUTHORIZATIONS_A); assertNotNull(v); Assert.assertEquals(1, count(graph.query(AUTHORIZATIONS_A_AND_B).has("prop1", "value1").vertices())); graph.deleteVertex(v.getId(), AUTHORIZATIONS_A_AND_B); graph.flush(); v = graph.getVertex("v1", AUTHORIZATIONS_A); assertNull(v); Assert.assertEquals(0, count(graph.query(AUTHORIZATIONS_A_AND_B).has("prop1", "value1").vertices())); }
v1.prepareMutation() .alterPropertyVisibility("prop1", VISIBILITY_A) .setProperty("prop1", "value1New", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); v1.prepareMutation() .alterPropertyVisibility("prop1", VISIBILITY_A) .setProperty("prop1", "value1New2", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.flush();
.setProperty("location", new GeoPoint(39.0299, -77.5121, "Ashburn, VA"), VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.flush();
.setProperty("location", new GeoPoint(39.0299, -77.5121, "Ashburn, VA"), VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.flush();