public void commit() { if (this.baseGraph instanceof TransactionalGraph) { ((TransactionalGraph) baseGraph).commit(); } }
public void testVertexReattachment() { TransactionalGraph graph = (TransactionalGraph) graphTest.generateGraph(); Vertex a = graph.addVertex(null); Vertex b = graph.addVertex(null); Edge e = graph.addEdge(null, a, b, "friend"); graph.commit(); a = graph.getVertex(a); Assert.assertNotNull(a); Assert.assertEquals(1, BaseTest.count(a.getVertices(Direction.OUT))); graph.shutdown(); }
public void rollback() { if (this.baseGraph instanceof TransactionalGraph) { ((TransactionalGraph) baseGraph).rollback(); } }
@Override public void applyInTx() { long count = 0; Iterable<Vertex> it = getGraph().getVertices("@class", "NodeGraphFieldContainerImpl"); for (Vertex nodeContainer : it) { migrateContainer(nodeContainer); count++; if (count % 1000 == 0) { log.info("Migrated {" + count + "} contents"); getGraph().commit(); } } }
private void migrateVertices(String from, String to) { log.info("Migrating vertex type {" + from + "} to {" + to + "}"); Iterable<Vertex> it = getGraph().getVertices("@class", from); long count = 0; for (Vertex fromV : it) { Vertex toV = getGraph().addVertex("class:" + to); if (count % 1000 == 0) { log.info("Migrated {" + count + "} vertices."); getGraph().commit();
/** * Add the change to the list of executed changes. * * @param change */ public void add(Change change) { Vertex vertex = graph.addVertex(ChangeWrapper.class); ChangeWrapper graphChange = new ChangeWrapper(vertex); graphChange.update(change); rootVertex.addEdge(HAS_CHANGE, vertex); } }
if (loadingFromScratch) return null; else { if (baseGraph.getFeatures().ignoresSuppliedIds) { assert vertexIdKey != null; Iterator<Vertex> iter = baseGraph.getVertices(vertexIdKey, id).iterator(); if (!iter.hasNext()) return null; v = iter.next(); throw new IllegalArgumentException("There are multiple vertices with the provided id in the database: " + id); } else { v = baseGraph.getVertex(id); if (v == null) return null;
Vertex releaseRoot = getGraph().addVertex("class:ReleaseRootImpl"); releaseRoot.setProperty("ferma_type", "ReleaseRootImpl"); releaseRoot.setProperty("uuid", randomUUID()); Vertex release = getGraph().addVertex("class:ReleaseImpl"); release.setProperty("ferma_type", "ReleaseImpl"); release.setProperty("uuid", branchUuid); for (Vertex vertex : getGraph().getVertices()) { migrateType(vertex); for (Edge edge : getGraph().getEdges()) { migrateType(edge); for (Edge edge : getGraph().getEdges("ferma_type", "TranslatedImpl")) { edge.setProperty("ferma_type", "GraphFieldContainerEdgeImpl");
@Override public void applyInTx() { // Move the data directory away try { log.info("Moving current data directory away to {" + dataSourceFolder().getAbsolutePath() + "}"); FileUtils.moveDirectory(dataTargetFolder(), dataSourceFolder()); } catch (Exception e) { throw new RuntimeException("Could not move data folder to backup location {" + dataTargetFolder().getAbsolutePath() + "}. Maybe the permissions not allowing this?"); } // Create binary root Vertex meshRoot = getMeshRootVertex(); Vertex binaryRoot = getGraph().addVertex("class:BinaryRootImpl"); binaryRoot.setProperty("ferma_type", "BinaryRootImpl"); binaryRoot.setProperty("uuid", randomUUID()); meshRoot.addEdge("HAS_BINARY_ROOT", binaryRoot).setProperty("uuid", randomUUID()); // Iterate over all binary fields and convert them to edges to binaries Iterable<Vertex> it = getGraph().getVertices("@class", "BinaryGraphFieldImpl"); for (Vertex binaryField : it) { migrateField(binaryField, binaryRoot); } }
@Override @Deprecated public void stopTransaction(Conclusion conclusion) { getBaseGraph().stopTransaction(conclusion); }
@Override public boolean isApplied() { TransactionalGraph graph = db.rawTx(); setGraph(graph); ChangelogRootWrapper changelogRoot = changelogRoot(); boolean hasChange = changelogRoot.hasChange(getUuid()); graph.shutdown(); setGraph(null); return hasChange; }
public Edge addEdge(final Object id, final Vertex outVertex, final Vertex inVertex, final String label, final Object... properties) { if (!BatchVertex.class.isInstance(outVertex) || !BatchVertex.class.isInstance(inVertex)) throw new IllegalArgumentException("Given element was not created in this baseGraph"); nextElement(); final Vertex ov = getCachedVertex(outVertex.getId()); final Vertex iv = getCachedVertex(inVertex.getId()); previousOutVertexId = outVertex.getId(); //keep track of the previous out vertex id currentEdgeCached = baseGraph.addEdge(id, ov, iv, label); if (edgeIdKey != null && id != null) { currentEdgeCached.setProperty(edgeIdKey, id); } currentEdge = new BatchEdge(); setProperties(currentEdge, properties); return currentEdge; }
private Vertex retrieveFromCache(final Object externalID) { Object internal = cache.getEntry(externalID); if (internal instanceof Vertex) { return (Vertex) internal; } else if (internal != null) { //its an internal id Vertex v = baseGraph.getVertex(internal); cache.set(v, externalID); return v; } else return null; }
@Override public void doRollbackTransaction(Graph currentTransaction) { if (currentTransaction instanceof TransactionalGraph) { ((TransactionalGraph) graph).rollback(); } }
public void convertViaSchema(String schemaVersionClassName, String label) { for (Vertex schemaVertex : getGraph().getVertices("@class", schemaVersionClassName)) { Schema schema = buildSchemaFromVertex(schemaVertex, schemaVersionClassName); if (!schema.fieldMap.isEmpty()) { log.info("Update vertices for {}", schema); updateVerticesForSchema(schemaVertex, schema.fieldMap, label); log.debug("Commit the changes for the remaining vertices of schema {} to database...", schema); getGraph().commit(); } } }