Java Code Examples for com.tinkerpop.blueprints.impls.orient.OrientGraph#begin()
The following examples show how to use
com.tinkerpop.blueprints.impls.orient.OrientGraph#begin() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractMenuRule.java From light with Apache License 2.0 | 6 votes |
protected void delMenuItem(Map<String, Object> data) throws Exception { OrientGraph graph = ServiceLocator.getInstance().getGraph(); try { graph.begin(); Vertex menuItem = graph.getVertexByKey("MenuItem.menuItemId",data.get("menuItemId")); if(menuItem != null) { graph.removeVertex(menuItem); } graph.commit(); } catch (Exception e) { logger.error("Exception:", e); graph.rollback(); throw e; } finally { graph.shutdown(); } // no need to refresh cache as there is no reference to this menuItem anywhere. }
Example 2
Source File: AbstractUserRule.java From light with Apache License 2.0 | 6 votes |
protected void updRole(Map<String, Object> data) throws Exception { OrientGraph graph = ServiceLocator.getInstance().getGraph(); try { graph.begin(); Vertex user = graph.getVertexByKey("User.userId", data.get("userId")); if(user != null) { user.setProperty("roles", data.get("roles")); user.setProperty("updateDate", data.get("updateDate")); Vertex updateUser = graph.getVertexByKey("User.userId", data.get("updateUserId")); updateUser.addEdge("Update", user); } graph.commit(); } catch (Exception e) { logger.error("Exception:", e); graph.rollback(); throw e; } finally { graph.shutdown(); } }
Example 3
Source File: BranchRule.java From light with Apache License 2.0 | 6 votes |
protected void upBranchDb(String branchType, Map<String, Object> data) throws Exception { String className = branchType.substring(0, 1).toUpperCase() + branchType.substring(1); String index = className + ".categoryId"; OrientGraph graph = ServiceLocator.getInstance().getGraph(); try{ graph.begin(); OrientVertex updateUser = (OrientVertex)graph.getVertexByKey("User.userId", data.remove("updateUserId")); OrientVertex branch = (OrientVertex)graph.getVertexByKey(index, data.get("categoryId")); if(branch != null && updateUser != null) { // remove DownVote edge if there is. for (Edge edge : updateUser.getEdges(branch, Direction.OUT, "DownVote")) { if(edge.getVertex(Direction.IN).equals(branch)) graph.removeEdge(edge); } updateUser.addEdge("UpVote", branch); } graph.commit(); } catch (Exception e) { logger.error("Exception:", e); graph.rollback(); } finally { graph.shutdown(); } }
Example 4
Source File: AbstractRuleRule.java From light with Apache License 2.0 | 6 votes |
protected void updRule(Map<String, Object> data) throws Exception { OrientGraph graph = ServiceLocator.getInstance().getGraph(); try { graph.begin(); Vertex rule = graph.getVertexByKey("Rule.ruleClass", data.get("ruleClass")); if(rule != null) { String sourceCode = (String)data.get("sourceCode"); if(sourceCode != null && !sourceCode.equals(rule.getProperty("sourceCode"))) { rule.setProperty("sourceCode", sourceCode); } rule.setProperty("updateDate", data.get("updateDate")); Vertex updateUser = graph.getVertexByKey("User.userId", data.get("updateUserId")); if(updateUser != null) { updateUser.addEdge("Update", rule); } // there is no need to put updated rule into compileMap. } graph.commit(); } catch (Exception e) { logger.error("Exception:", e); graph.rollback(); throw e; } finally { graph.shutdown(); } }
Example 5
Source File: AbstractPaymentRule.java From light with Apache License 2.0 | 6 votes |
/** * To save the customer transaction into database. * * @param data * @throws Exception */ protected void addSubscription(Map<String, Object> data) throws Exception { OrientGraph graph = ServiceLocator.getInstance().getGraph(); try { graph.begin(); Vertex user = graph.getVertexByKey("User.userId", data.remove("createUserId")); Vertex order = graph.getVertexByKey("Order.orderId", data.get("orderId")); if(order != null) { order.setProperty("paymentStatus", 1); // update payment status to paid. List<Map<String, Object>> subscriptions = (List<Map<String, Object>>)data.get("subscriptions"); order.setProperty("subscriptions", subscriptions); //order.setProperty } user.addEdge("Update", order); graph.commit(); } catch (Exception e) { logger.error("Exception:", e); graph.rollback(); throw e; } finally { graph.shutdown(); } }
Example 6
Source File: AbstractCommentRule.java From light with Apache License 2.0 | 6 votes |
protected void delComment(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); // remove the edge to this comment for (Edge edge : comment.getEdges(Direction.IN)) { graph.removeEdge(edge); } graph.removeVertex(comment); graph.commit(); } catch (Exception e) { logger.error("Exception:", e); graph.rollback(); } finally { graph.shutdown(); } }
Example 7
Source File: AbstractCommentRule.java From light with Apache License 2.0 | 6 votes |
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(); } }
Example 8
Source File: AbstractConfigRule.java From light with Apache License 2.0 | 6 votes |
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(); } }
Example 9
Source File: AbstractRuleRule.java From light with Apache License 2.0 | 6 votes |
protected void updPublisher(Map<String, Object> data) throws Exception { String ruleClass = (String)data.get("ruleClass"); OrientGraph graph = ServiceLocator.getInstance().getGraph(); try { graph.begin(); Vertex rule = graph.getVertexByKey("Rule.ruleClass", ruleClass); if(rule != null) { rule.setProperty("isPublisher", data.get("isPublisher")); rule.setProperty("updateDate", data.get("updateDate")); Map<String, Object> ruleMap = ServiceLocator.getInstance().getMemoryImage("ruleMap"); ConcurrentMap<String, Map<String, Object>> cache = (ConcurrentMap<String, Map<String, Object>>)ruleMap.get("cache"); if(cache != null) { cache.remove(ruleClass); } } graph.commit(); } catch (Exception e) { logger.error("Exception:", e); graph.rollback(); throw e; } finally { graph.shutdown(); } }
Example 10
Source File: AbstractAccessRule.java From light with Apache License 2.0 | 6 votes |
protected void delAccess(Map<String, Object> data) throws Exception { OrientGraph graph = ServiceLocator.getInstance().getGraph(); try { graph.begin(); Vertex access = graph.getVertexByKey("Access.ruleClass", data.get("ruleClass")); if(access != null) { graph.removeVertex(access); } graph.commit(); } catch (Exception e) { logger.error("Exception:", e); graph.rollback(); throw e; } finally { graph.shutdown(); } Map<String, Object> accessMap = ServiceLocator.getInstance().getMemoryImage("accessMap"); ConcurrentMap<Object, Object> cache = (ConcurrentMap<Object, Object>)accessMap.get("cache"); if(cache != null) { cache.remove(data.get("ruleClass")); } }
Example 11
Source File: DeleteEdgeCommand.java From Orienteer with Apache License 2.0 | 5 votes |
@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(); }
Example 12
Source File: AbstractConfigRule.java From light with Apache License 2.0 | 5 votes |
protected void updHostConfigDb(Map<String, Object> data) throws Exception { String host = (String)data.get("host"); String configId = (String)data.get("configId"); OrientGraph graph = ServiceLocator.getInstance().getGraph(); try{ graph.begin(); Vertex updateUser = graph.getVertexByKey("User.userId", data.remove("updateUserId")); OrientVertex config = getConfigByHostId(graph, host, configId); if(config != null) { if(data.get("description") != null) { config.setProperty("description", data.get("description")); } else { config.removeProperty("description"); } if(data.get("properties") != null) { config.setProperty("properties", data.get("properties")); } else { config.removeProperty("properties"); } config.setProperty("updateDate", data.get("updateDate")); // updateUser updateUser.addEdge("Update", config); } graph.commit(); } catch (Exception e) { logger.error("Exception:", e); graph.rollback(); } finally { graph.shutdown(); } }
Example 13
Source File: AbstractCommentRule.java From light with Apache License 2.0 | 5 votes |
protected void spmComment(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) { String userId = (String)data.get("userId"); OrientVertex user = (OrientVertex)graph.getVertexByKey("User.userId", userId); if(user != null) { // check if this user has reported spam for this comment. boolean reported = false; for (Edge edge : user.getEdges(comment, Direction.OUT, "ReportSpam")) { if(edge.getVertex(Direction.IN).equals(comment)) { reported = true; graph.removeEdge(edge); } } if(!reported) { user.addEdge("ReportSpam", comment); } } } graph.commit(); } catch (Exception e) { logger.error("Exception:", e); graph.rollback(); } finally { graph.shutdown(); } }
Example 14
Source File: DeleteVertexCommand.java From Orienteer with Apache License 2.0 | 5 votes |
@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(); }
Example 15
Source File: AbstractUserRule.java From light with Apache License 2.0 | 5 votes |
protected Vertex addUser(Map<String, Object> data) throws Exception { Vertex user = null; if(data.size() == 0) { return user; } OrientGraph graph = ServiceLocator.getInstance().getGraph(); try { graph.begin(); // password might not be available if google or facebook login String password = (String)data.remove("password"); if(password != null) { OrientVertex credential = graph.addVertex("class:Credential", "password", password); data.put("credential", credential); } // calculate gravatar md5 data.put("gravatar", HashUtil.md5Hex((String)data.get("email"))); user = graph.addVertex("class:User", data); graph.commit(); } catch (Exception e) { logger.error("Exception:", e); graph.rollback(); throw e; } finally { graph.shutdown(); } return user; }
Example 16
Source File: AbstractRuleRule.java From light with Apache License 2.0 | 5 votes |
protected void updReqTransform(Map<String, Object> data) throws Exception { String ruleClass = (String)data.get("ruleClass"); OrientGraph graph = ServiceLocator.getInstance().getGraph(); try { graph.begin(); Vertex rule = graph.getVertexByKey("Rule.ruleClass", ruleClass); if(rule != null) { rule.setProperty("reqTransforms", data.get("reqTransforms")); rule.setProperty("updateDate", data.get("updateDate")); Vertex updateUser = graph.getVertexByKey("User.userId", data.get("updateUserId")); if(updateUser != null) { updateUser.addEdge("Update", rule); } Map<String, Object> ruleMap = ServiceLocator.getInstance().getMemoryImage("ruleMap"); ConcurrentMap<String, Map<String, Object>> cache = (ConcurrentMap<String, Map<String, Object>>)ruleMap.get("cache"); if(cache != null) { cache.remove(ruleClass); } } graph.commit(); } catch (Exception e) { logger.error("Exception:", e); graph.rollback(); throw e; } finally { graph.shutdown(); } }
Example 17
Source File: CreateVertexCommand.java From Orienteer with Apache License 2.0 | 5 votes |
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; }
Example 18
Source File: AbstractMenuRule.java From light with Apache License 2.0 | 5 votes |
protected void delMenu(Map<String, Object> data) throws Exception { String host = (String)data.get("host"); OrientGraph graph = ServiceLocator.getInstance().getGraph(); try { graph.begin(); Vertex menu = graph.getVertexByKey("Menu.host", host); if(menu != null) { // cascade deleting all menuItems belong to the host only. for (Vertex menuItem : graph.getVerticesOfClass("MenuItem")) { if(host.equals(menuItem.getProperty("host"))) { graph.removeVertex(menuItem); } } graph.removeVertex(menu); } graph.commit(); } catch (Exception e) { logger.error("Exception:", e); graph.rollback(); throw e; } finally { graph.shutdown(); } Map<String, Object> menuMap = ServiceLocator.getInstance().getMemoryImage("menuMap"); ConcurrentMap<Object, Object> cache = (ConcurrentMap<Object, Object>)menuMap.get("cache"); if(cache != null) { cache.remove(host); } }
Example 19
Source File: AbstractRoleRule.java From light with Apache License 2.0 | 5 votes |
protected void updRole(Map<String, Object> data) throws Exception { OrientGraph graph = ServiceLocator.getInstance().getGraph(); try { graph.begin(); Vertex updateUser = graph.getVertexByKey("User.userId", data.remove("updateUserId")); Vertex role = graph.getVertexByKey("Role.roleId", data.get("roleId")); if(role != null) { String host = (String)data.get("host"); if(host != null && host.length() > 0) { if(!host.equals(role.getProperty("host"))) role.setProperty("host", host); } else { role.removeProperty("host"); } String description = (String)data.get("description"); if(description != null && !description.equals(role.getProperty("description"))) { role.setProperty("description", description); } role.setProperty("updateDate", data.get("updateDate")); updateUser.addEdge("Update", role); } graph.commit(); } catch (Exception e) { logger.error("Exception:", e); graph.rollback(); throw e; } finally { graph.shutdown(); } }
Example 20
Source File: AbstractPageRule.java From light with Apache License 2.0 | 5 votes |
protected void impPage(Map<String, Object> data) throws Exception { OrientGraph graph = ServiceLocator.getInstance().getGraph(); String pageId = (String)data.get("pageId"); try { graph.begin(); OrientVertex page = (OrientVertex)graph.getVertexByKey("Page.pageId", pageId); if(page != null) { graph.removeVertex(page); } Vertex createUser = graph.getVertexByKey("User.userId", data.remove("createUserId")); page = graph.addVertex("class:Page", data); createUser.addEdge("Create", page); graph.commit(); String json = page.getRecord().toJSON(); Map<String, Object> pageMap = ServiceLocator.getInstance().getMemoryImage("pageMap"); ConcurrentMap<Object, Object> cache = (ConcurrentMap<Object, Object>)pageMap.get("cache"); if(cache == null) { cache = new ConcurrentLinkedHashMap.Builder<Object, Object>() .maximumWeightedCapacity(1000) .build(); pageMap.put("cache", cache); } CacheObject co = (CacheObject)cache.get(pageId); if(co != null) { co.setEtag(page.getProperty("@version").toString()); co.setData(json); } else { cache.put(pageId, new CacheObject(page.getProperty("@version").toString(), json)); } } catch (Exception e) { logger.error("Exception:", e); graph.rollback(); throw e; } finally { graph.shutdown(); } }