Java Code Examples for com.tinkerpop.blueprints.impls.orient.OrientGraph#addVertex()
The following examples show how to use
com.tinkerpop.blueprints.impls.orient.OrientGraph#addVertex() .
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: TestPeopleDao.java From thorntail with Apache License 2.0 | 6 votes |
public OrientEdge addFriend(String outName, String inName) { OrientGraph database = new OrientGraph(databasePool); try { Vertex outVertex = database.addVertex(null); Vertex inVertex = database.addVertex(null); outVertex.setProperty("name", outName); inVertex.setProperty("name", inName); OrientEdge edge = database.addEdge(null, outVertex, inVertex, "knows"); database.commit(); return edge; } catch (Exception e) { database.rollback(); } finally { database.shutdown(); } return null; }
Example 2
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 3
Source File: AbstractOrderRule.java From light with Apache License 2.0 | 6 votes |
/** * To save the order right before routing to payment gateway * * @param data * @throws Exception */ protected void addOrder(Map<String, Object> data) throws Exception { logger.entry(data); OrientGraph graph = ServiceLocator.getInstance().getGraph(); try { graph.begin(); Vertex user = graph.getVertexByKey("User.userId", data.remove("createUserId")); OrientVertex order = graph.addVertex("class:Order", data); user.addEdge("Create", order); graph.commit(); } catch (Exception e) { logger.error("Exception:", e); graph.rollback(); throw e; } finally { graph.shutdown(); } }
Example 4
Source File: AbstractCommentRule.java From light with Apache License 2.0 | 6 votes |
protected void addComment(Map<String, Object> data) throws Exception { OrientGraph graph = ServiceLocator.getInstance().getGraph(); try{ graph.begin(); Vertex createUser = graph.getVertexByKey("User.userId", data.remove("createUserId")); String parentId = (String)data.remove("parentId"); String parentClassName = (String)data.remove("parentClassName"); Vertex parent = null; if("Post".equals(parentClassName)) { parent = graph.getVertexByKey("Post.entityId", parentId); } else { parent = graph.getVertexByKey("Comment.commentId", parentId); } OrientVertex comment = graph.addVertex("class:Comment", data); createUser.addEdge("Create", comment); parent.addEdge("HasComment", comment); 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 addMenuItem(Map<String, Object> data) throws Exception { OrientGraph graph = ServiceLocator.getInstance().getGraph(); try { graph.begin(); Vertex user = graph.getVertexByKey("User.userId", data.remove("createUserId")); List<String> addMenuItems = (List<String>)data.remove("addMenuItems"); OrientVertex menuItem = graph.addVertex("class:MenuItem", data); if(addMenuItems != null && addMenuItems.size() > 0) { // find vertex for each menuItem id and create edge to it. for(String menuItemId: addMenuItems) { Vertex childMenuItem = graph.getVertexByKey("MenuItem.menuItemId", menuItemId); menuItem.addEdge("Own", childMenuItem); } } user.addEdge("Create", menuItem); graph.commit(); } catch (Exception e) { logger.error("Exception:", e); graph.rollback(); throw e; } finally { graph.shutdown(); } }
Example 6
Source File: AbstractPageRule.java From light with Apache License 2.0 | 6 votes |
protected void addPage(Map<String, Object> data) throws Exception { OrientGraph graph = ServiceLocator.getInstance().getGraph(); try { graph.begin(); Vertex createUser = graph.getVertexByKey("User.userId", data.remove("createUserId")); OrientVertex 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); } cache.put(data.get("pageId"), new CacheObject(page.getProperty("@version").toString(), json)); } catch (Exception e) { logger.error("Exception:", e); graph.rollback(); throw e; } finally { graph.shutdown(); } }
Example 7
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 8
Source File: BranchRule.java From light with Apache License 2.0 | 5 votes |
protected void addBranchDb(String branchType, Map<String, Object> data) throws Exception { String className = branchType.substring(0, 1).toUpperCase() + branchType.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> parentIds = (List<String>)data.remove("in_Own"); List<String> childrenIds = (List<String>)data.remove("out_Own"); OrientVertex branch = graph.addVertex("class:" + className, data); createUser.addEdge("Create", branch); // parent if(parentIds != null && parentIds.size() == 1) { OrientVertex parent = getBranchByHostId(graph, branchType, host, parentIds.get(0)); if(parent != null) { parent.addEdge("Own", branch); } } // children if(childrenIds != null) { for(String childId: childrenIds) { OrientVertex child = getBranchByHostId(graph, branchType, host, childId); if(child != null) { branch.addEdge("Own", child); } } } graph.commit(); } catch (Exception e) { logger.error("Exception:", e); graph.rollback(); } finally { graph.shutdown(); } }
Example 9
Source File: AbstractConfigRule.java From light with Apache License 2.0 | 5 votes |
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(); } }
Example 10
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 11
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 12
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(); } }
Example 13
Source File: DbService.java From light with Apache License 2.0 | 5 votes |
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(); } }
Example 14
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 15
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(); } }
Example 16
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(); } }