Java Code Examples for com.tinkerpop.blueprints.Vertex#addEdge()

The following examples show how to use com.tinkerpop.blueprints.Vertex#addEdge() . 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: AbstractRoleRule.java    From light with Apache License 2.0 6 votes vote down vote up
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 2
Source File: AbstractMenuRule.java    From light with Apache License 2.0 6 votes vote down vote up
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 3
Source File: AbstractPaymentRule.java    From light with Apache License 2.0 6 votes vote down vote up
/**
 * To save the customer transaction into database.
 *
 * @param data
 * @throws Exception
 */
protected void addTransaction(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.
            Map<String, Object> transaction = (Map<String, Object>)data.get("transaction");
            order.setProperty("nonce", transaction.get("nonce"));
            //order.setProperty
        }
        user.addEdge("Update", order);
        graph.commit();
    } catch (Exception e) {
        logger.error("Exception:", e);
        graph.rollback();
        throw e;
    } finally {
        graph.shutdown();
    }
}
 
Example 4
Source File: AbstractRuleRule.java    From light with Apache License 2.0 6 votes vote down vote up
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: AbstractUserRule.java    From light with Apache License 2.0 6 votes vote down vote up
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 6
Source File: AbstractUserRule.java    From light with Apache License 2.0 6 votes vote down vote up
protected void updLockByUserId(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("locked", data.get("locked"));
            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 7
Source File: AbstractConfigRule.java    From light with Apache License 2.0 5 votes vote down vote up
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 8
Source File: AbstractConfigRule.java    From light with Apache License 2.0 5 votes vote down vote up
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 9
Source File: AbstractRuleRule.java    From light with Apache License 2.0 5 votes vote down vote up
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 10
Source File: AbstractRuleRule.java    From light with Apache License 2.0 5 votes vote down vote up
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 11
Source File: AbstractRuleRule.java    From light with Apache License 2.0 5 votes vote down vote up
protected void updSubscriber(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("isSubscriber", data.get("isSubscriber"));
            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 12
Source File: BranchRule.java    From light with Apache License 2.0 5 votes vote down vote up
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 13
Source File: FunctionAlocCreator.java    From bjoern with GNU General Public License v3.0 5 votes vote down vote up
private Vertex createAlocForRegister(String registerName) throws
		IOException {
	Vertex aloc;
	if (isFlag(registerName)) {
		aloc = createFlagAloc(registerName);
	} else {
		aloc = createRegisterAloc(registerName);
		Vertex family = getRegisterFamilyNode(registerName);
		aloc.addEdge(BELONGS_TO_EDGE, family);
	}
	return aloc;
}
 
Example 14
Source File: AbstractPageRule.java    From light with Apache License 2.0 5 votes vote down vote up
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 15
Source File: AbstractMenuRule.java    From light with Apache License 2.0 5 votes vote down vote up
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 16
Source File: AbstractPageRule.java    From light with Apache License 2.0 5 votes vote down vote up
protected void updPage(Map<String, Object> data) {
    String pageId = (String)data.get("pageId");
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try {
        graph.begin();
        OrientVertex page = (OrientVertex)graph.getVertexByKey("Page.pageId", pageId);
        if(page != null) {
            page.setProperty("content", data.get("content"));
            page.setProperty("updateDate", data.get("updateDate"));
            Vertex updateUser = graph.getVertexByKey("User.userId", data.get("updateUserId"));
            updateUser.addEdge("Update", 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 17
Source File: AbstractRoleRule.java    From light with Apache License 2.0 5 votes vote down vote up
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 18
Source File: GraphWriterTestBase.java    From SciGraph with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
  Vertex v = graph.addVertex(0);
  Vertex w = graph.addVertex(1);
  v.setProperty(CommonProperties.IRI, "http://x.org/v");
  v.setProperty("list", newArrayList("elt1", "elt2"));
  v.setProperty("array", new String[]{"elt1", "elt2"});
  w.setProperty(CommonProperties.IRI, "http://x.org/w");
  v.addEdge("edge", w);
}
 
Example 19
Source File: TitanMassiveInsertion.java    From graphdb-benchmarks with Apache License 2.0 4 votes vote down vote up
@Override
public void relateNodes(Vertex src, Vertex dest)
{
    src.addEdge("similar", dest);
}
 
Example 20
Source File: AbstractAccessRule.java    From light with Apache License 2.0 4 votes vote down vote up
protected void updAccess(Map<String, Object> data) throws Exception {
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    String json = null;
    try {
        graph.begin();
        OrientVertex access = (OrientVertex)graph.getVertexByKey("Access.ruleClass", data.get("ruleClass"));
        if(access != null) {
            access.setProperty("accessLevel", data.get("accessLevel"));
            List<String> clients = (List)data.get("clients");
            if(clients != null && clients.size() > 0) {
                access.setProperty("clients", clients);
            } else {
                access.removeProperty("clients");
            }
            List<String> roles = (List)data.get("roles");
            if(roles != null && roles.size() > 0) {
                access.setProperty("roles", roles);
            } else {
                access.removeProperty("roles");
            }
            List<String> users = (List)data.get("users");
            if(users != null && users.size() > 0) {
                access.setProperty("users", users);
            } else {
                access.removeProperty("users");
            }
            access.setProperty("updateDate", data.get("updateDate"));
            Vertex updateUser = graph.getVertexByKey("User.userId", data.get("updateUserId"));
            updateUser.addEdge("Update", access);
        }
        graph.commit();
        json = access.getRecord().toJSON();
    } 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 = new ConcurrentLinkedHashMap.Builder<Object, Object>()
                .maximumWeightedCapacity(1000)
                .build();
        accessMap.put("cache", cache);
    }
    cache.put(data.get("ruleClass"), mapper.readValue(json,
            new TypeReference<HashMap<String, Object>>() {
            }));
}