@Override protected void post() { super.post(); if (orientGraph instanceof TransactionalGraph) { orientGraph.commit(); } } }
@Override protected Vertex getOrCreate(final String value) { final int key = Integer.parseInt(value); Vertex v; final OIdentifiable rec = (OIdentifiable) index.get(key); if (rec != null) { return orientGraph.getVertex(rec); } v = orientGraph.addVertex(key, "nodeId", key); if (orientGraph instanceof TransactionalGraph) { orientGraph.commit(); } return v; }
@Override protected void performMultiAction(AjaxRequestTarget target, List<ODocument> objects) { OrientGraph tx = orientGraphProvider.get(); for (ODocument doc : objects) { ORID id = doc.getIdentity(); OrientEdge edge = tx.getEdge(id); tx.removeEdge(edge); } tx.commit();tx.begin(); sendActionPerformed(); }
public static void persistEvent(Map<String, Object> eventMap) throws Exception { OrientGraph graph = ServiceLocator.getInstance().getGraph(); try { eventMap.put("eventId", incrementCounter("eventId")); graph.addVertex("class:Event", eventMap); graph.commit(); } catch (Exception e) { graph.rollback(); logger.error("Exception:", e); throw e; } finally { graph.shutdown(); } }
private OrientVertex createVertex(OClass vertexClass, OClass edgeClass) { OrientGraph tx = orientGraphProvider.get(); OrientVertex newVertex = tx.addVertex(vertexClass.getName(), (String) null); OrientVertex vertex = tx.getVertex(documentModel.getObject().getIdentity()); tx.addEdge(null, vertex, newVertex, edgeClass.getName()); tx.commit();tx.begin(); return newVertex; }
private void createEdge(List<ODocument> documents, OClass edgeClass) { OrientGraph tx = orientGraphProvider.get(); for (ODocument createTo : documents) { tx.addEdge(null, tx.getVertex(documentModel.getObject().getIdentity()), tx.getVertex(createTo.getIdentity()), edgeClass.getName()); } tx.commit();tx.begin(); }
protected void delHostConfigDb(Map<String, Object> data) throws Exception { OrientGraph graph = ServiceLocator.getInstance().getGraph(); try{ graph.begin(); OrientVertex config = getConfigByHostId(graph, (String)data.get("host"), (String)data.get("configId")); if(config != null) { graph.removeVertex(config); } graph.commit(); } catch (Exception e) { logger.error("Exception:", e); graph.rollback(); } finally { graph.shutdown(); } }
protected void updComment(Map<String, Object> data) throws Exception { OrientGraph graph = ServiceLocator.getInstance().getGraph(); try{ graph.begin(); String commentId = (String)data.get("commentId"); OrientVertex comment = (OrientVertex)graph.getVertexByKey("Comment.commentId", commentId); if(comment != null) { comment.setProperty("content", data.get("content")); } graph.commit(); } catch (Exception e) { logger.error("Exception:", e); graph.rollback(); } finally { graph.shutdown(); } }
@Override protected void performMultiAction(AjaxRequestTarget target, List<ODocument> objects) { super.performMultiAction(target, objects); OrientGraph tx = orientGraphProvider.get(); for (ODocument doc : objects) { ORID id = doc.getIdentity(); OrientVertex vertex = tx.getVertex(id); removeEdges(tx, vertex); } tx.commit();tx.begin(); sendActionPerformed(); }
@Override protected void performMultiAction(AjaxRequestTarget target, List<ODocument> objects) { super.performMultiAction(target, objects); OrientGraph tx = orientGraphProvider.get(); for (ODocument doc : objects) { ORID id = doc.getIdentity(); tx.removeVertex(tx.getVertex(id)); } tx.commit();tx.begin(); sendActionPerformed(); }
protected void delConfigDb(Map<String, Object> data) throws Exception { OrientGraph graph = ServiceLocator.getInstance().getGraph(); try{ graph.begin(); Vertex config = graph.getVertexByKey("Config.configId", (String)data.get("configId")); if(config != null) { graph.removeVertex(config); } graph.commit(); } catch (Exception e) { logger.error("Exception:", e); graph.rollback(); } finally { graph.shutdown(); } }
protected void addConfigDb(Map<String, Object> data) throws Exception { OrientGraph graph = ServiceLocator.getInstance().getGraph(); try{ graph.begin(); Vertex createUser = graph.getVertexByKey("User.userId", data.remove("createUserId")); OrientVertex config = graph.addVertex("class:Config", data); createUser.addEdge("Create", config); graph.commit(); } catch (Exception e) { logger.error("Exception:", e); graph.rollback(); } finally { graph.shutdown(); } }
protected void addHostConfigDb(Map<String, Object> data) throws Exception { OrientGraph graph = ServiceLocator.getInstance().getGraph(); try{ graph.begin(); Vertex createUser = graph.getVertexByKey("User.userId", data.remove("createUserId")); OrientVertex hostConfig = graph.addVertex("class:HostConfig", data); createUser.addEdge("Create", hostConfig); graph.commit(); } catch (Exception e) { logger.error("Exception:", e); graph.rollback(); } finally { graph.shutdown(); } }
protected void addRole(Map<String, Object> data) throws Exception { OrientGraph graph = ServiceLocator.getInstance().getGraph(); try { graph.begin(); Vertex createUser = graph.getVertexByKey("User.userId", data.remove("createUserId")); OrientVertex role = graph.addVertex("class:Role", data); createUser.addEdge("Create", role); graph.commit(); } catch (Exception e) { logger.error("Exception:", e); graph.rollback(); throw e; } finally { graph.shutdown(); } }
protected void delRole(String roleId) throws Exception { OrientGraph graph = ServiceLocator.getInstance().getGraph(); try { graph.begin(); Vertex role = graph.getVertexByKey("Role.roleId", roleId); if(role != null) { graph.removeVertex(role); } graph.commit(); } catch (Exception e) { logger.error("Exception:", e); graph.rollback(); throw e; } finally { graph.shutdown(); } }
public static Vertex delVertexByRid(String rid) throws Exception { Vertex v = null; OrientGraph graph = ServiceLocator.getInstance().getGraph(); try { graph.begin(); v = graph.getVertex(rid); graph.removeVertex(v); graph.commit(); } catch (Exception e) { graph.rollback(); logger.error("Exception:", e); throw e; } finally { graph.shutdown(); } return v; }
public static int executeSqlCommand(String sql) { int recordsUpdated = 0; OrientGraph graph = ServiceLocator.getInstance().getGraph(); try { recordsUpdated = graph.getRawGraph().command(new OCommandSQL(sql)).execute(); graph.commit(); } catch (Exception e) { graph.rollback(); logger.error("Exception:", e); throw e; } finally { graph.shutdown(); } return recordsUpdated; }
public static <T> T runInTx(final OrientGraph graph, final GraphCallBack<T> callBack) { final ODatabaseDocument databaseRecord = getDatabase(); final boolean txWasActive = databaseRecord.getTransaction().isActive(); if (!txWasActive) graph.getRawGraph().begin(); try { final T result = callBack.call(graph); if (!txWasActive) graph.commit(); return result; } catch (RuntimeException e) { if (!txWasActive) graph.rollback(); throw e; } }
public static <T> T runInTx(final GraphCallBack<T> callBack) { final OModifiableBoolean shutdownFlag = new OModifiableBoolean(); final ODatabaseDocumentInternal curDb = ODatabaseRecordThreadLocal.instance().get(); final boolean txAlreadyBegun = curDb.getTransaction().isActive(); final OrientGraph graph = OGraphCommandExecutorSQLFactory.getGraph(true, shutdownFlag); try { return runInTx(graph, callBack); } finally { if (!txAlreadyBegun) { graph.commit(); if (shutdownFlag.getValue()) graph.shutdown(false, false); } ODatabaseRecordThreadLocal.instance().set(curDb); } }