Java Code Examples for com.tinkerpop.blueprints.impls.orient.OrientGraph#commit()
The following examples show how to use
com.tinkerpop.blueprints.impls.orient.OrientGraph#commit() .
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: DbService.java From light with Apache License 2.0 | 6 votes |
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; }
Example 2
Source File: AbstractProductRule.java From light with Apache License 2.0 | 6 votes |
protected void downVoteProduct(Map<String, Object> data) { OrientGraph graph = ServiceLocator.getInstance().getGraph(); try { graph.begin(); OrientVertex updateUser = (OrientVertex) graph.getVertexByKey("User.userId", data.remove("updateUserId")); OrientVertex product = (OrientVertex) graph.getVertexByKey("Product.entityId", data.get("entityId")); if (product != null && updateUser != null) { // remove UpVote edge if there is. for (Edge edge : updateUser.getEdges(product, Direction.OUT, "UpVote")) { if (edge.getVertex(Direction.IN).equals(product)) graph.removeEdge(edge); } updateUser.addEdge("DownVote", product); } graph.commit(); } catch (Exception e) { logger.error("Exception:", e); graph.rollback(); } finally { graph.shutdown(); } }
Example 3
Source File: AbstractRoleRule.java From light with Apache License 2.0 | 6 votes |
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(); } }
Example 4
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 5
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 6
Source File: AbstractCatalogRule.java From light with Apache License 2.0 | 6 votes |
protected void delProductDb(Map<String, Object> data) throws Exception { String className = "Catalog"; String id = "categoryId"; String index = className + "." + id; OrientGraph graph = ServiceLocator.getInstance().getGraph(); try{ graph.begin(); OrientVertex product = (OrientVertex)graph.getVertexByKey("Product.entityId", data.get("entityId")); if(product != null) { // TODO cascade deleting all comments belong to the product. // Need to come up a query on that to get the entire tree. /* // https://github.com/orientechnologies/orientdb/issues/1108 delete graph... */ graph.removeVertex(product); } 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 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 8
Source File: AbstractUserRule.java From light with Apache License 2.0 | 6 votes |
protected String activateUser(Map<String, Object> data) throws Exception { String email = (String)data.get("email"); String code = (String)data.get("code"); OrientGraph graph = ServiceLocator.getInstance().getGraph(); try { graph.begin(); Vertex user = graph.getVertexByKey("User.email", email); if(user != null) { String s = user.getProperty("code"); if(code.equals(s)) { user.removeProperty("code"); } } graph.commit(); } catch (Exception e) { logger.error("Exception:", e); graph.rollback(); throw e; } finally { graph.shutdown(); } return code; }
Example 9
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 10
Source File: AbstractPostRule.java From light with Apache License 2.0 | 6 votes |
protected void upVotePost(Map<String, Object> data) { OrientGraph graph = ServiceLocator.getInstance().getGraph(); try { graph.begin(); OrientVertex updateUser = (OrientVertex) graph.getVertexByKey("User.userId", data.remove("updateUserId")); OrientVertex post = (OrientVertex) graph.getVertexByKey("Post.entityId", data.get("entityId")); if (post != null && updateUser != null) { // remove DownVote edge if there is. for (Edge edge : updateUser.getEdges(post, Direction.OUT, "DownVote")) { if (edge.getVertex(Direction.IN).equals(post)) graph.removeEdge(edge); } updateUser.addEdge("UpVote", post); } graph.commit(); } catch (Exception e) { logger.error("Exception:", e); graph.rollback(); } finally { graph.shutdown(); } }
Example 11
Source File: AbstractPostRule.java From light with Apache License 2.0 | 6 votes |
protected void downVotePost(Map<String, Object> data) { OrientGraph graph = ServiceLocator.getInstance().getGraph(); try { graph.begin(); OrientVertex updateUser = (OrientVertex) graph.getVertexByKey("User.userId", data.remove("updateUserId")); OrientVertex post = (OrientVertex) graph.getVertexByKey("Post.entityId", data.get("entityId")); if (post != null && updateUser != null) { // remove UpVote edge if there is. for (Edge edge : updateUser.getEdges(post, Direction.OUT, "UpVote")) { if (edge.getVertex(Direction.IN).equals(post)) graph.removeEdge(edge); } updateUser.addEdge("DownVote", post); } graph.commit(); } catch (Exception e) { logger.error("Exception:", e); graph.rollback(); } finally { graph.shutdown(); } }
Example 12
Source File: AbstractConfigRule.java From light with Apache License 2.0 | 5 votes |
protected void updConfigDb(Map<String, Object> data) throws Exception { String configId = (String)data.get("configId"); OrientGraph graph = ServiceLocator.getInstance().getGraph(); try{ graph.begin(); Vertex updateUser = graph.getVertexByKey("User.userId", data.remove("updateUserId")); Vertex config = graph.getVertexByKey("Config.configId", 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: AbstractRuleRule.java From light with Apache License 2.0 | 5 votes |
protected void updResTransform(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("resTransforms", data.get("resTransforms")); 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 14
Source File: AbstractUserRule.java From light with Apache License 2.0 | 5 votes |
protected void logOut(Map<String, Object> data) throws Exception { String refreshToken = (String)data.get("refreshToken"); if(refreshToken != null) { OrientGraph graph = ServiceLocator.getInstance().getGraph(); try { graph.begin(); Vertex user = graph.getVertexByKey("User.userId", data.get("userId")); if(user != null) { Vertex credential = user.getProperty("credential"); if(credential != null) { // now remove the refresh token String clientId = (String)data.get("clientId"); logger.debug("logOut to remove refreshToken {} from clientId {}" , refreshToken, clientId); Map clientRefreshTokens = credential.getProperty("clientRefreshTokens"); if(clientRefreshTokens != null) { // logged in before, check if logged in from the host. List<String> refreshTokens = (List)clientRefreshTokens.get(clientId); if(refreshTokens != null) { String hashedRefreshToken = HashUtil.md5(refreshToken); refreshTokens.remove(hashedRefreshToken); } } else { logger.error("There is no refresh tokens"); } } } graph.commit(); } catch (Exception e) { logger.error("Exception:", e); graph.rollback(); throw e; } finally { graph.shutdown(); } } else { logger.debug("There is no hashedRefreshToken as user didn't pass in refresh token when logging out. Do nothing"); } }
Example 15
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 16
Source File: AbstractRuleRule.java From light with Apache License 2.0 | 5 votes |
protected void updSchema(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) { String schema = (String)data.get("schema"); if(schema != null && schema.length() > 0) { // convert it to map before setProperty. Map<String, Object> schemaMap = mapper.readValue(schema, new TypeReference<HashMap<String, Object>>() {}); rule.setProperty("schema", schemaMap); } else { rule.removeProperty("schema"); } 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 17
Source File: AbstractConfigRule.java From light with Apache License 2.0 | 5 votes |
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(); } }
Example 18
Source File: AbstractMenuRule.java From light with Apache License 2.0 | 5 votes |
protected String addMenu( Map<String, Object> data) throws Exception { String json = null; OrientGraph graph = ServiceLocator.getInstance().getGraph(); try { graph.begin(); OrientVertex menu = graph.addVertex("class:Menu", "host", data.get("host"), "createDate", data.get("createDate")); List<String> addMenuItems = (List<String>)data.get("addMenuItems"); if(addMenuItems != null && addMenuItems.size() > 0) { // find vertex for each menuItem id and create edge to it. for(String menuItemId: addMenuItems) { Vertex menuItem = graph.getVertexByKey("MenuItem.menuItemId", menuItemId); menu.addEdge("Own", menuItem); } } Vertex user = graph.getVertexByKey("User.userId", data.get("createUserId")); user.addEdge("Create", menu); graph.commit(); json = menu.getRecord().toJSON("fetchPlan:menuItems:2"); } catch (Exception e) { logger.error("Exception:", e); graph.rollback(); throw e; } finally { graph.shutdown(); } Map<String, Object> menuMap = (Map<String, Object>)ServiceLocator.getInstance().getMemoryImage("menuMap"); ConcurrentMap<Object, Object> cache = (ConcurrentMap<Object, Object>)menuMap.get("cache"); if(cache == null) { cache = new ConcurrentLinkedHashMap.Builder<Object, Object>() .maximumWeightedCapacity(100) .build(); menuMap.put("cache", cache); } cache.put(data.get("host"), json); return json; }
Example 19
Source File: AbstractBfnRule.java From light with Apache License 2.0 | 4 votes |
protected void addPostDb(String bfnType, Map<String, Object> data) throws Exception { String className = bfnType.substring(0, 1).toUpperCase() + bfnType.substring(1); String host = (String)data.get("host"); 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); // parent OrientVertex parent = getBranchByHostId(graph, bfnType, host, (String) data.get("parentId")); if(parent != null) { parent.addEdge("HasPost", post); } // tag if(tags != null && tags.size() > 0) { for(String tagId: tags) { Vertex tag = null; // get the tag is it exists 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(); } }
Example 20
Source File: AbstractCatalogRule.java From light with Apache License 2.0 | 4 votes |
protected void addProductDb(Map<String, Object> data) throws Exception { String host = (String)data.get("host"); OrientGraph graph = ServiceLocator.getInstance().getGraph(); try{ graph.begin(); OrientVertex createUser = (OrientVertex)graph.getVertexByKey("User.userId", data.remove("createUserId")); String parentId = (String)data.remove("parentId"); List<String> tags = (List<String>)data.remove("tags"); OrientVertex product = graph.addVertex("class:Product", data); createUser.addEdge("Create", product); // parent OrientVertex parent = getBranchByHostId(graph, categoryType, host, parentId); if(parent != null) { parent.addEdge("HasProduct", product); } // tag if(tags != null && tags.size() > 0) { for(String tagId: tags) { Vertex tag = null; // get the tag is it exists 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()); product.addEdge("HasTag", tag); } else { tag = graph.addVertex("class:Tag", "host", host, "tagId", tagId, "createDate", data.get("createDate")); createUser.addEdge("Create", tag); product.addEdge("HasTag", tag); } } } graph.commit(); } catch (Exception e) { logger.error("Exception:", e); graph.rollback(); } finally { graph.shutdown(); } }