/** * Adds or updates a property. * <p> * The added property will also be indexed in the configured search provider. The type of the value * will determine how it gets indexed. * * @param key The unique key given to the property allowing for multi-valued properties. * @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. */ public ElementBuilder<T> addPropertyValue(String key, String name, Object value, Metadata metadata, Visibility visibility) { return addPropertyValue(key, name, value, metadata, null, visibility); }
/** * Adds or updates a property. * <p> * The added property will also be indexed in the configured search provider. The type of the value * will determine how it gets indexed. * * @param key The unique key given to the property allowing for multi-valued properties. * @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. */ public ElementBuilder<T> addPropertyValue(String key, String name, Object value, Metadata metadata, Visibility visibility) { return addPropertyValue(key, name, value, metadata, null, visibility); }
/** * 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. * <p> * The added property will also be indexed in the configured search provider. The type of the value * will determine how it gets indexed. * * @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. */ public ElementBuilder<T> setProperty(String name, Object value, Metadata metadata, Visibility visibility) { return addPropertyValue(ElementMutation.DEFAULT_KEY, name, value, metadata, visibility); }
/** * 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. * <p> * The added property will also be indexed in the configured search provider. The type of the value * will determine how it gets indexed. * * @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. */ public ElementBuilder<T> setProperty(String name, Object value, Metadata metadata, Visibility visibility) { return addPropertyValue(ElementMutation.DEFAULT_KEY, name, value, metadata, visibility); }
/** * Adds or updates a property. * <p> * The added property will also be indexed in the configured search provider. The type of the value * will determine how it gets indexed. * * @param key The unique key given to the property allowing for multi-valued properties. * @param name The name of the property. * @param value The value of the property. * @param visibility The visibility to give this property. */ public ElementBuilder<T> addPropertyValue(String key, String name, Object value, Visibility visibility) { return addPropertyValue(key, name, value, Metadata.create(FetchHints.ALL), visibility); }
/** * Adds or updates a property. * <p> * The added property will also be indexed in the configured search provider. The type of the value * will determine how it gets indexed. * * @param key The unique key given to the property allowing for multi-valued properties. * @param name The name of the property. * @param value The value of the property. * @param visibility The visibility to give this property. */ public ElementBuilder<T> addPropertyValue(String key, String name, Object value, Visibility visibility) { return addPropertyValue(key, name, value, Metadata.create(FetchHints.ALL), visibility); }
private void benchmarkAddVertices(int vertexCount) { double startTime = System.currentTimeMillis(); for (int i = 0; i < vertexCount; i++) { String vertexId = "v" + i; graph.prepareVertex(vertexId, VISIBILITY_A) .addPropertyValue("k1", "prop1", "value1 " + i, VISIBILITY_A) .addPropertyValue("k1", "prop2", "value2 " + i, VISIBILITY_A) .addPropertyValue("k1", "prop3", "value3 " + i, VISIBILITY_A) .addPropertyValue("k1", "prop4", "value4 " + i, VISIBILITY_A) .addPropertyValue("k1", "prop5", "value5 " + i, VISIBILITY_A) .save(AUTHORIZATIONS_ALL); } graph.flush(); double endTime = System.currentTimeMillis(); LOGGER.info("add vertices in %.3fs", (endTime - startTime) / 1000); }
private void benchmarkAddVertices(int vertexCount) { double startTime = System.currentTimeMillis(); for (int i = 0; i < vertexCount; i++) { String vertexId = "v" + i; graph.prepareVertex(vertexId, VISIBILITY_A) .addPropertyValue("k1", "prop1", "value1 " + i, VISIBILITY_A) .addPropertyValue("k1", "prop2", "value2 " + i, VISIBILITY_A) .addPropertyValue("k1", "prop3", "value3 " + i, VISIBILITY_A) .addPropertyValue("k1", "prop4", "value4 " + i, VISIBILITY_A) .addPropertyValue("k1", "prop5", "value5 " + i, VISIBILITY_A) .save(AUTHORIZATIONS_ALL); } graph.flush(); double endTime = System.currentTimeMillis(); LOGGER.info("add vertices in %.3fs", (endTime - startTime) / 1000); }
private void benchmarkAddEdges(Random random, int vertexCount, int edgeCount) { double startTime = System.currentTimeMillis(); for (int i = 0; i < edgeCount; i++) { String edgeId = "e" + i; String outVertexId = "v" + random.nextInt(vertexCount); String inVertexId = "v" + random.nextInt(vertexCount); graph.prepareEdge(edgeId, outVertexId, inVertexId, LABEL_LABEL1, VISIBILITY_A) .addPropertyValue("k1", "prop1", "value1 " + i, VISIBILITY_A) .addPropertyValue("k1", "prop2", "value2 " + i, VISIBILITY_A) .addPropertyValue("k1", "prop3", "value3 " + i, VISIBILITY_A) .addPropertyValue("k1", "prop4", "value4 " + i, VISIBILITY_A) .addPropertyValue("k1", "prop5", "value5 " + i, VISIBILITY_A) .save(AUTHORIZATIONS_ALL); } graph.flush(); double endTime = System.currentTimeMillis(); LOGGER.info("add edges in %.3fs", (endTime - startTime) / 1000); }
private void benchmarkAddVerticesSaveElementMutations(int vertexCount) { double startTime = System.currentTimeMillis(); List<ElementMutation> mutations = new ArrayList<>(); for (int i = 0; i < vertexCount; i++) { String vertexId = "v" + i; ElementBuilder<Vertex> m = graph.prepareVertex(vertexId, VISIBILITY_A) .addPropertyValue("k1", "prop1", "value1 " + i, VISIBILITY_A) .addPropertyValue("k1", "prop2", "value2 " + i, VISIBILITY_A) .addPropertyValue("k1", "prop3", "value3 " + i, VISIBILITY_A) .addPropertyValue("k1", "prop4", "value4 " + i, VISIBILITY_A) .addPropertyValue("k1", "prop5", "value5 " + i, VISIBILITY_A); mutations.add(m); } graph.saveElementMutations(mutations, AUTHORIZATIONS_ALL); graph.flush(); double endTime = System.currentTimeMillis(); LOGGER.info("save element mutations in %.3fs", (endTime - startTime) / 1000); }
private void benchmarkAddVerticesSaveElementMutations(int vertexCount) { double startTime = System.currentTimeMillis(); List<ElementMutation> mutations = new ArrayList<>(); for (int i = 0; i < vertexCount; i++) { String vertexId = "v" + i; ElementBuilder<Vertex> m = graph.prepareVertex(vertexId, VISIBILITY_A) .addPropertyValue("k1", "prop1", "value1 " + i, VISIBILITY_A) .addPropertyValue("k1", "prop2", "value2 " + i, VISIBILITY_A) .addPropertyValue("k1", "prop3", "value3 " + i, VISIBILITY_A) .addPropertyValue("k1", "prop4", "value4 " + i, VISIBILITY_A) .addPropertyValue("k1", "prop5", "value5 " + i, VISIBILITY_A); mutations.add(m); } graph.saveElementMutations(mutations, AUTHORIZATIONS_ALL); graph.flush(); double endTime = System.currentTimeMillis(); LOGGER.info("save element mutations in %.3fs", (endTime - startTime) / 1000); }
private void benchmarkAddEdges(Random random, int vertexCount, int edgeCount) { double startTime = System.currentTimeMillis(); for (int i = 0; i < edgeCount; i++) { String edgeId = "e" + i; String outVertexId = "v" + random.nextInt(vertexCount); String inVertexId = "v" + random.nextInt(vertexCount); graph.prepareEdge(edgeId, outVertexId, inVertexId, LABEL_LABEL1, VISIBILITY_A) .addPropertyValue("k1", "prop1", "value1 " + i, VISIBILITY_A) .addPropertyValue("k1", "prop2", "value2 " + i, VISIBILITY_A) .addPropertyValue("k1", "prop3", "value3 " + i, VISIBILITY_A) .addPropertyValue("k1", "prop4", "value4 " + i, VISIBILITY_A) .addPropertyValue("k1", "prop5", "value5 " + i, VISIBILITY_A) .save(AUTHORIZATIONS_ALL); } graph.flush(); double endTime = System.currentTimeMillis(); LOGGER.info("add edges in %.3fs", (endTime - startTime) / 1000); }
@Test public void testMultivaluedPropertyOrder() { graph.prepareVertex("v1", VISIBILITY_A) .addPropertyValue("a", "prop", "a", VISIBILITY_A) .addPropertyValue("aa", "prop", "aa", VISIBILITY_A) .addPropertyValue("b", "prop", "b", VISIBILITY_A) .addPropertyValue("0", "prop", "0", VISIBILITY_A) .addPropertyValue("A", "prop", "A", VISIBILITY_A) .addPropertyValue("Z", "prop", "Z", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); Vertex v1 = graph.getVertex("v1", AUTHORIZATIONS_A); assertEquals("0", v1.getPropertyValue("prop", 0)); assertEquals("A", v1.getPropertyValue("prop", 1)); assertEquals("Z", v1.getPropertyValue("prop", 2)); assertEquals("a", v1.getPropertyValue("prop", 3)); assertEquals("aa", v1.getPropertyValue("prop", 4)); assertEquals("b", v1.getPropertyValue("prop", 5)); }
@Test public void testMultivaluedPropertyOrder() { graph.prepareVertex("v1", VISIBILITY_A) .addPropertyValue("a", "prop", "a", VISIBILITY_A) .addPropertyValue("aa", "prop", "aa", VISIBILITY_A) .addPropertyValue("b", "prop", "b", VISIBILITY_A) .addPropertyValue("0", "prop", "0", VISIBILITY_A) .addPropertyValue("A", "prop", "A", VISIBILITY_A) .addPropertyValue("Z", "prop", "Z", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); Vertex v1 = graph.getVertex("v1", AUTHORIZATIONS_A); assertEquals("0", v1.getPropertyValue("prop", 0)); assertEquals("A", v1.getPropertyValue("prop", 1)); assertEquals("Z", v1.getPropertyValue("prop", 2)); assertEquals("a", v1.getPropertyValue("prop", 3)); assertEquals("aa", v1.getPropertyValue("prop", 4)); assertEquals("b", v1.getPropertyValue("prop", 5)); }
private void addProperties( IngestOptions ingestOptions, Visibility elementVisibility, ElementBuilder elementBuilder, EntityBuilder entityBuilder ) { VisalloProperties.MODIFIED_BY.setProperty(elementBuilder, ingestOptions.getIngestUser().getUserId(), visibilityTranslator.getDefaultVisibility()); VisalloProperties.MODIFIED_DATE.setProperty(elementBuilder, new Date(), visibilityTranslator.getDefaultVisibility()); VisalloProperties.VISIBILITY_JSON.setProperty(elementBuilder, new VisibilityJson(elementVisibility.getVisibilityString()), visibilityTranslator.getDefaultVisibility()); for (PropertyAddition<?> propertyAddition : entityBuilder.getPropertyAdditions()) { if (propertyAddition.getValue() != null) { elementBuilder.addPropertyValue( propertyAddition.getKey(), propertyAddition.getIri(), propertyAddition.getValue(), buildMetadata(ingestOptions, propertyAddition.getMetadata(), propertyAddition.getVisibility()), getTimestamp(ingestOptions, propertyAddition.getTimestamp()), getVisibility(ingestOptions, propertyAddition.getVisibility()) ); } } }
@Test public void testSoftDeletePropertyWithVisibility() { Vertex v1 = graph.prepareVertex("v1", VISIBILITY_A) .addPropertyValue("key1", "name1", "value1", VISIBILITY_A) .addPropertyValue("key1", "name1", "value2", VISIBILITY_B) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); assertEquals(2, count(graph.getVertex("v1", AUTHORIZATIONS_A_AND_B).getProperties())); org.vertexium.test.util.IterableUtils.assertContains("value1", v1.getPropertyValues("name1")); org.vertexium.test.util.IterableUtils.assertContains("value2", v1.getPropertyValues("name1")); graph.getVertex("v1", AUTHORIZATIONS_A_AND_B).softDeleteProperty("key1", "name1", VISIBILITY_A, AUTHORIZATIONS_A_AND_B); graph.flush(); assertEquals(1, count(graph.getVertex("v1", AUTHORIZATIONS_A_AND_B).getProperties())); assertEquals(1, count(graph.getVertex("v1", AUTHORIZATIONS_A_AND_B).getPropertyValues("key1", "name1"))); org.vertexium.test.util.IterableUtils.assertContains("value2", graph.getVertex("v1", AUTHORIZATIONS_A_AND_B).getPropertyValues("name1")); }
@Test public void testSoftDeletePropertyThroughMutationWithVisibility() { Vertex v1 = graph.prepareVertex("v1", VISIBILITY_A) .addPropertyValue("key1", "name1", "value1", VISIBILITY_A) .addPropertyValue("key1", "name1", "value2", VISIBILITY_B) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); assertEquals(2, count(graph.getVertex("v1", AUTHORIZATIONS_A_AND_B).getProperties())); org.vertexium.test.util.IterableUtils.assertContains("value1", v1.getPropertyValues("name1")); org.vertexium.test.util.IterableUtils.assertContains("value2", v1.getPropertyValues("name1")); v1 = graph.getVertex("v1", AUTHORIZATIONS_A_AND_B) .prepareMutation() .softDeleteProperty("key1", "name1", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); assertEquals(1, count(v1.getProperties())); assertEquals(1, count(v1.getPropertyValues("key1", "name1"))); org.vertexium.test.util.IterableUtils.assertContains("value2", v1.getPropertyValues("name1")); }
@Test public void testSoftDeletePropertyWithVisibility() { Vertex v1 = graph.prepareVertex("v1", VISIBILITY_A) .addPropertyValue("key1", "name1", "value1", VISIBILITY_A) .addPropertyValue("key1", "name1", "value2", VISIBILITY_B) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); assertEquals(2, count(graph.getVertex("v1", AUTHORIZATIONS_A_AND_B).getProperties())); org.vertexium.test.util.IterableUtils.assertContains("value1", v1.getPropertyValues("name1")); org.vertexium.test.util.IterableUtils.assertContains("value2", v1.getPropertyValues("name1")); graph.getVertex("v1", AUTHORIZATIONS_A_AND_B).softDeleteProperty("key1", "name1", VISIBILITY_A, AUTHORIZATIONS_A_AND_B); graph.flush(); assertEquals(1, count(graph.getVertex("v1", AUTHORIZATIONS_A_AND_B).getProperties())); assertEquals(1, count(graph.getVertex("v1", AUTHORIZATIONS_A_AND_B).getPropertyValues("key1", "name1"))); org.vertexium.test.util.IterableUtils.assertContains("value2", graph.getVertex("v1", AUTHORIZATIONS_A_AND_B).getPropertyValues("name1")); }
@Test public void testSoftDeletePropertyThroughMutationWithVisibility() { Vertex v1 = graph.prepareVertex("v1", VISIBILITY_A) .addPropertyValue("key1", "name1", "value1", VISIBILITY_A) .addPropertyValue("key1", "name1", "value2", VISIBILITY_B) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); assertEquals(2, count(graph.getVertex("v1", AUTHORIZATIONS_A_AND_B).getProperties())); org.vertexium.test.util.IterableUtils.assertContains("value1", v1.getPropertyValues("name1")); org.vertexium.test.util.IterableUtils.assertContains("value2", v1.getPropertyValues("name1")); v1 = graph.getVertex("v1", AUTHORIZATIONS_A_AND_B) .prepareMutation() .softDeleteProperty("key1", "name1", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); assertEquals(1, count(v1.getProperties())); assertEquals(1, count(v1.getPropertyValues("key1", "name1"))); org.vertexium.test.util.IterableUtils.assertContains("value2", v1.getPropertyValues("name1")); }
@Test public void testDeleteGeoLocationProperty() { graph.defineProperty("prop1").dataType(String.class).textIndexHint(TextIndexHint.ALL).define(); graph.defineProperty("prop2").dataType(GeoPoint.class).textIndexHint(TextIndexHint.ALL).define(); graph.prepareVertex("v1", VISIBILITY_EMPTY) .addPropertyValue("key1", "prop1", "value1", VISIBILITY_A) .addPropertyValue("key1", "prop2", new GeoPoint(38.9186, -77.2297, "Reston, VA"), VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); Vertex v1 = graph.getVertex("v1", FetchHints.ALL, AUTHORIZATIONS_A); v1.prepareMutation() .deleteProperties("key1", "prop1") .deleteProperties("key1", "prop2") .save(AUTHORIZATIONS_A_AND_B); graph.flush(); QueryResultsIterable<Vertex> vertices = graph.query(AUTHORIZATIONS_A).has("prop1", "value1").vertices(); assertResultsCount(0, 0, vertices); vertices = graph.query(AUTHORIZATIONS_A).has("prop2", "reston, va").vertices(); assertResultsCount(0, 0, vertices); vertices = graph.query(AUTHORIZATIONS_A).has("prop2", GeoCompare.WITHIN, new GeoCircle(38.9186, -77.2297, 1)).vertices(); assertResultsCount(0, 0, vertices); QueryResultsIterable<String> vertexIds = graph.query(AUTHORIZATIONS_A).has("prop2", GeoCompare.WITHIN, new GeoCircle(38.9186, -77.2297, 1)).vertexIds(); assertResultsCount(0, 0, vertexIds); }