@Override public T get() throws InterruptedException, ExecutionException { if (element == null) { element = this.elementUpdateContext.getMutation().save(authorizations); } return element; }
@Test public void testSaveMultipleTimestampedValuesInSameMutationVertex() { String vertexId = "v1"; String propertyKey = "k1"; String propertyName = "p1"; Map<String, Long> values = ImmutableMap.of( "value1", createDate(2016, 4, 6, 9, 20, 0).getTime(), "value2", createDate(2016, 5, 6, 9, 20, 0).getTime(), "value3", createDate(2016, 6, 6, 9, 20, 0).getTime(), "value4", createDate(2016, 7, 6, 9, 20, 0).getTime(), "value5", createDate(2016, 8, 6, 9, 20, 0).getTime() ); ElementMutation<Vertex> vertexMutation = graph.prepareVertex(vertexId, VISIBILITY_EMPTY); for (Map.Entry<String, Long> entry : values.entrySet()) { vertexMutation.addPropertyValue(propertyKey, propertyName, entry.getKey(), Metadata.create(), entry.getValue(), VISIBILITY_EMPTY); } vertexMutation.save(AUTHORIZATIONS_EMPTY); graph.flush(); Vertex retrievedVertex = graph.getVertex(vertexId, AUTHORIZATIONS_EMPTY); Iterable<HistoricalPropertyValue> historicalPropertyValues = retrievedVertex.getHistoricalPropertyValues(propertyKey, propertyName, VISIBILITY_EMPTY, null, null, AUTHORIZATIONS_EMPTY); compareHistoricalValues(values, historicalPropertyValues); }
public final void setProperty(ElementMutation<?> mutation, TRaw value, Visibility visibility) { mutation.setProperty(getPropertyName(), wrap(value), visibility); }
@Override public Iterable<Element> saveElementMutations(Iterable<ElementMutation> mutations, Authorizations authorizations) { List<Element> elements = new ArrayList<>(); for (ElementMutation m : mutations) { if (m instanceof ExistingElementMutation && !m.hasChanges()) { elements.add(((ExistingElementMutation) m).getElement()); continue; } Element element = m.save(authorizations); elements.add(element); } return elements; }
@Override public Iterable<Element> saveElementMutations(Iterable<ElementMutation> mutations, Authorizations authorizations) { List<Element> elements = new ArrayList<>(); List<Element> elementsToAddToIndex = new ArrayList<>(); List<ElementAndIterableExtendedDataMutation> extendedDataToIndex = new ArrayList<>(); for (ElementMutation m : mutations) { if (m instanceof ExistingElementMutation && !m.hasChanges()) { elements.add(((ExistingElementMutation) m).getElement()); continue; } IndexHint indexHint = m.getIndexHint(); m.setIndexHint(IndexHint.DO_NOT_INDEX); Element element = m.save(authorizations); elements.add(element); if (indexHint == IndexHint.INDEX) { elementsToAddToIndex.add(element); //noinspection unchecked extendedDataToIndex.add(new ElementAndIterableExtendedDataMutation(element, m.getExtendedData())); } } getSearchIndex().addElements(this, elementsToAddToIndex, authorizations); for (ElementAndIterableExtendedDataMutation ed : extendedDataToIndex) { getSearchIndex().addElementExtendedData(this, ed.element, ed.extendedData, authorizations); } return elements; }
v1.prepareMutation() .addExtendedData("table1", "row4", "name", "value4", VISIBILITY_A) .addExtendedData("table2", "row1", "name", "value1", VISIBILITY_A) .save(AUTHORIZATIONS_A); graph.flush();
@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")); }
.deleteExtendedData("table1", "row2", "color", "junit", VISIBILITY_B) .addExtendedData("table1", "row1", "color", "junit2", "blue", VISIBILITY_C) .save(AUTHORIZATIONS_A_AND_B_AND_C); 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 testRemoveValuesFromMultivalueProperties() { graph.defineProperty("p1").dataType(String.class).sortable(true).textIndexHint(TextIndexHint.ALL).define(); Vertex v1 = graph.prepareVertex("v1", VISIBILITY_A) .addPropertyValue("k1", "p1", "v1", VISIBILITY_A) .addPropertyValue("k2", "p1", "v2", VISIBILITY_A) .save(AUTHORIZATIONS_ALL); getGraph().flush(); assertIdsAnyOrder(getGraph().query(AUTHORIZATIONS_ALL).has("p1", "v1").vertexIds(), "v1"); assertIdsAnyOrder(getGraph().query(AUTHORIZATIONS_ALL).has("p1", "v2").vertexIds(), "v1"); assertResultsCount(0, 0, getGraph().query(AUTHORIZATIONS_ALL).has("p1", "v3").vertexIds()); v1.prepareMutation() .addPropertyValue("k3", "p1", "v3", VISIBILITY_A) .deleteProperty("k1", "p1", VISIBILITY_A) .save(AUTHORIZATIONS_ALL); getGraph().flush(); assertIdsAnyOrder(getGraph().query(AUTHORIZATIONS_ALL).has("p1", "v2").vertexIds(), "v1"); assertIdsAnyOrder(getGraph().query(AUTHORIZATIONS_ALL).has("p1", "v3").vertexIds(), "v1"); assertResultsCount(0, 0, getGraph().query(AUTHORIZATIONS_ALL).has("p1", "v1").vertexIds()); v1.deleteProperty("k2", "p1", VISIBILITY_A, AUTHORIZATIONS_ALL); getGraph().flush(); assertIdsAnyOrder(getGraph().query(AUTHORIZATIONS_ALL).has("p1", "v3").vertexIds(), "v1"); assertResultsCount(0, 0, getGraph().query(AUTHORIZATIONS_ALL).has("p1", "v1").vertexIds()); assertResultsCount(0, 0, getGraph().query(AUTHORIZATIONS_ALL).has("p1", "v2").vertexIds()); }
public final void addPropertyValue( ElementMutation<?> mutation, String multiKey, TRaw value, Metadata metadata, Long timestamp, Visibility visibility ) { mutation.addPropertyValue(multiKey, getPropertyName(), wrap(value), metadata, timestamp, visibility); }
public <T extends Element> void addExtendedData( ElementMutation<T> m, String row, TRaw newValue, PropertyMetadata propertyMetadata, Long timestamp ) { checkNotNull(newValue, "null values are not allowed"); m.addExtendedData(tableName, row, columnName, rawToGraph(newValue), timestamp, propertyMetadata.getPropertyVisibility()); }
v1.prepareMutation() .addExtendedData("table1", "row4", "name", "value4", VISIBILITY_A) .addExtendedData("table2", "row1", "name", "value1", VISIBILITY_A) .save(AUTHORIZATIONS_A); graph.flush();
@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")); }
@Override public Iterable<Element> saveElementMutations(Iterable<ElementMutation> mutations, Authorizations authorizations) { List<Element> elements = new ArrayList<>(); List<Element> elementsToAddToIndex = new ArrayList<>(); List<ElementAndIterableExtendedDataMutation> extendedDataToIndex = new ArrayList<>(); for (ElementMutation m : mutations) { if (m instanceof ExistingElementMutation && !m.hasChanges()) { elements.add(((ExistingElementMutation) m).getElement()); continue; } IndexHint indexHint = m.getIndexHint(); m.setIndexHint(IndexHint.DO_NOT_INDEX); Element element = m.save(authorizations); elements.add(element); if (indexHint == IndexHint.INDEX) { elementsToAddToIndex.add(element); //noinspection unchecked extendedDataToIndex.add(new ElementAndIterableExtendedDataMutation(element, m.getExtendedData())); } } getSearchIndex().addElements(this, elementsToAddToIndex, authorizations); for (ElementAndIterableExtendedDataMutation ed : extendedDataToIndex) { getSearchIndex().addElementExtendedData(this, ed.element, ed.extendedData, authorizations); } return elements; }
.deleteExtendedData("table1", "row2", "color", "junit", VISIBILITY_B) .addExtendedData("table1", "row1", "color", "junit2", "blue", VISIBILITY_C) .save(AUTHORIZATIONS_A_AND_B_AND_C); 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); }
@Override public Iterable<Element> saveElementMutations(Iterable<ElementMutation> mutations, Authorizations authorizations) { List<Element> elements = new ArrayList<>(); for (ElementMutation m : mutations) { if (m instanceof ExistingElementMutation && !m.hasChanges()) { elements.add(((ExistingElementMutation) m).getElement()); continue; } Element element = m.save(authorizations); elements.add(element); } return elements; }
@Test public void testRemoveValuesFromMultivalueProperties() { graph.defineProperty("p1").dataType(String.class).sortable(true).textIndexHint(TextIndexHint.ALL).define(); Vertex v1 = graph.prepareVertex("v1", VISIBILITY_A) .addPropertyValue("k1", "p1", "v1", VISIBILITY_A) .addPropertyValue("k2", "p1", "v2", VISIBILITY_A) .save(AUTHORIZATIONS_ALL); getGraph().flush(); assertIdsAnyOrder(getGraph().query(AUTHORIZATIONS_ALL).has("p1", "v1").vertexIds(), "v1"); assertIdsAnyOrder(getGraph().query(AUTHORIZATIONS_ALL).has("p1", "v2").vertexIds(), "v1"); assertResultsCount(0, 0, getGraph().query(AUTHORIZATIONS_ALL).has("p1", "v3").vertexIds()); v1.prepareMutation() .addPropertyValue("k3", "p1", "v3", VISIBILITY_A) .deleteProperty("k1", "p1", VISIBILITY_A) .save(AUTHORIZATIONS_ALL); getGraph().flush(); assertIdsAnyOrder(getGraph().query(AUTHORIZATIONS_ALL).has("p1", "v2").vertexIds(), "v1"); assertIdsAnyOrder(getGraph().query(AUTHORIZATIONS_ALL).has("p1", "v3").vertexIds(), "v1"); assertResultsCount(0, 0, getGraph().query(AUTHORIZATIONS_ALL).has("p1", "v1").vertexIds()); v1.deleteProperty("k2", "p1", VISIBILITY_A, AUTHORIZATIONS_ALL); getGraph().flush(); assertIdsAnyOrder(getGraph().query(AUTHORIZATIONS_ALL).has("p1", "v3").vertexIds(), "v1"); assertResultsCount(0, 0, getGraph().query(AUTHORIZATIONS_ALL).has("p1", "v1").vertexIds()); assertResultsCount(0, 0, getGraph().query(AUTHORIZATIONS_ALL).has("p1", "v2").vertexIds()); }
public final void setProperty( ElementMutation<?> mutation, TRaw value, Metadata metadata, Long timestamp, Visibility visibility ) { // Vertexium's ElementMutation doesn't have a setProperty that takes a timestamp. Calling addPropertyValue // is effectively the same thing mutation.addPropertyValue( ElementMutation.DEFAULT_KEY, getPropertyName(), wrap(value), metadata, timestamp, visibility ); }