use of org.vertexium.mutation.ElementMutation in project vertexium by visallo.
the class GraphBase method saveElementMutations.
@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;
}
use of org.vertexium.mutation.ElementMutation in project vertexium by visallo.
the class GraphBaseWithSearchIndex method saveElementMutations.
@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;
}
use of org.vertexium.mutation.ElementMutation in project vertexium by visallo.
the class GraphTestBase method benchmarkAddVerticesSaveElementMutations.
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);
}
use of org.vertexium.mutation.ElementMutation in project vertexium by visallo.
the class GraphTestBase method testSaveElementMutations.
@Test
public void testSaveElementMutations() {
List<ElementMutation> mutations = new ArrayList<>();
for (int i = 0; i < 2; i++) {
ElementBuilder<Vertex> m = graph.prepareVertex("v" + i, VISIBILITY_A).addPropertyValue("k1", "name", "joe", VISIBILITY_A).addExtendedData("table1", "row1", "col1", "extended", VISIBILITY_A);
mutations.add(m);
}
List<Element> saveVertices = toList(graph.saveElementMutations(mutations, AUTHORIZATIONS_ALL));
graph.flush();
assertEvents(new AddVertexEvent(graph, (Vertex) saveVertices.get(0)), new AddPropertyEvent(graph, saveVertices.get(0), saveVertices.get(0).getProperty("k1", "name")), new AddExtendedDataEvent(graph, saveVertices.get(0), "table1", "row1", "col1", null, "extended", VISIBILITY_A), new AddVertexEvent(graph, (Vertex) saveVertices.get(1)), new AddPropertyEvent(graph, saveVertices.get(1), saveVertices.get(1).getProperty("k1", "name")), new AddExtendedDataEvent(graph, saveVertices.get(1), "table1", "row1", "col1", null, "extended", VISIBILITY_A));
clearGraphEvents();
QueryResultsIterable<Vertex> vertices = graph.query(AUTHORIZATIONS_ALL).vertices();
assertResultsCount(2, 2, vertices);
QueryResultsIterable<? extends VertexiumObject> items = graph.query(AUTHORIZATIONS_ALL).has("col1", "extended").search();
assertResultsCount(2, 2, items);
mutations.clear();
mutations.add(((Vertex) saveVertices.get(0)).prepareMutation());
graph.saveElementMutations(mutations, AUTHORIZATIONS_ALL);
graph.flush();
assertEvents();
}
Aggregations