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; }
@Override public OrientBaseGraph getGraph(final ODatabaseDocumentInternal database, final String user, final String password, final Settings settings) { return new OrientGraph(database, user, password, settings); }
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; }
@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(); }
OrientGraph graph = ServiceLocator.getInstance().getGraph(); try{ graph.begin(); Vertex createUser = graph.getVertexByKey("User.userId", data.remove("createUserId")); List<String> tags = (List<String>)data.remove("tags"); OrientVertex post = graph.addVertex("class:Post", data); createUser.addEdge("Create", post); Vertex tag = null; OIndex<?> tagHostIdIdx = graph.getRawGraph().getMetadata().getIndexManager().getIndex("tagHostIdIdx"); OCompositeKey tagKey = new OCompositeKey(host, tagId); OIdentifiable tagOid = (OIdentifiable) tagHostIdIdx.get(tagKey); if (tagOid != null) { tag = graph.getVertex(tagOid.getRecord()); post.addEdge("HasTag", tag); } else { tag = graph.addVertex("class:Tag", "host", host, "tagId", tagId, "createDate", data.get("createDate")); createUser.addEdge("Create", tag); post.addEdge("HasTag", tag); graph.commit(); } catch (Exception e) { logger.error("Exception:", e); graph.rollback(); } finally { graph.shutdown();
@Override public void reindex() { OrientGraph tx = txProvider.rawTx(); try { OIndexManager manager = tx.getRawGraph().getMetadata().getIndexManager(); manager.getIndexes().forEach(i -> i.rebuild()); } finally { tx.shutdown(); } }
final OrientGraph graph = OGraphCommandExecutorSQLFactory.getGraph(true, shutdownGraph); try { final Set<OIdentifiable> sourceRIDs = OSQLEngine.getInstance().parseRIDTarget(graph.getRawGraph(), source, context, iArgs); final OrientVertex fromVertex = graph.getVertex(from); if (fromVertex == null) continue; graph.commit(); if (!graph.isAutoStartTx()) graph.begin(); graph.commit(); graph.commit(); graph.shutdown(false);
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; }
protected String execUpdateCmd(Map<String, Object> data, boolean commit) { String result = ""; String script = (String) data.get("script"); OrientGraph graph = ServiceLocator.getInstance().getGraph(); try{ graph.command(new OCommandScript("sql", script)).execute(); if(commit) { graph.commit(); } else { graph.rollback(); } } catch (Exception e) { logger.error("Exception:", e); graph.rollback(); result = e.getMessage(); } finally { graph.shutdown(); } return result; }
@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(); }
@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; }
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; } }
protected boolean isUserInDbByEmail(String email) { boolean userInDb = false; OrientGraph graph = ServiceLocator.getInstance().getGraph(); try { Vertex user = graph.getVertexByKey("User.email", email); if(user != null) { userInDb = true; } } catch (Exception e) { e.printStackTrace(); } finally { graph.shutdown(); } return userInDb; }
@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(); }
protected long getTotalNumberUserFromDb(OrientGraph graph, Map<String, Object> criteria) throws Exception { StringBuilder sql = new StringBuilder("SELECT COUNT(*) as count FROM User"); String whereClause = DbService.getWhereClause(criteria); if(whereClause != null && whereClause.length() > 0) { sql.append(whereClause); } logger.debug("sql=" + sql); OSQLSynchQuery<ODocument> query = new OSQLSynchQuery<ODocument>(sql.toString()); List<ODocument> list = graph.getRawGraph().command(query).execute(); return list.get(0).field("count"); }
public OrientVertex getBranchByHostId(OrientGraph graph, String branchType, String host, String categoryId) { OrientVertex branch = null; OIndex<?> hostIdIdx = graph.getRawGraph().getMetadata().getIndexManager().getIndex(branchType + "HostIdIdx"); OCompositeKey key = new OCompositeKey(host, categoryId); OIdentifiable oid = (OIdentifiable) hostIdIdx.get(key); if (oid != null) { branch = graph.getVertex(oid.getRecord()); } return branch; }
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); } }
public static String getJsonByRid(String rid) { String json = null; OrientGraph graph = ServiceLocator.getInstance().getGraph(); try { ODocument doc = graph.getVertex(rid).getRecord(); if(doc != null) json = doc.toJSON(); } catch (Exception e) { logger.error("Exception:", e); throw e; } finally { graph.shutdown(); } return json; }
@Override public void start(final String database) { // test connection and let orient configure database new OrientGraph( (ODatabaseDocumentInternal) orientDB.get() .open(database, userManager.getUser(), userManager.getPassword())) .getRawGraph().close(); logger.debug("Pool {} started for database '{}'", getType(), database); }