Java Code Examples for com.tinkerpop.blueprints.impls.orient.OrientGraph#removeVertex()

The following examples show how to use com.tinkerpop.blueprints.impls.orient.OrientGraph#removeVertex() . 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 delRole(String roleId) throws Exception {
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try {
        graph.begin();
        Vertex role = graph.getVertexByKey("Role.roleId", roleId);
        if(role != null) {
            graph.removeVertex(role);
        }
        graph.commit();
    } catch (Exception e) {
        logger.error("Exception:", e);
        graph.rollback();
        throw e;
    } finally {
        graph.shutdown();
    }
}
 
Example 2
Source File: AbstractCatalogRule.java    From light with Apache License 2.0 6 votes vote down vote up
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 3
Source File: AbstractBfnRule.java    From light with Apache License 2.0 6 votes vote down vote up
protected void delPostDb(String bfnType, Map<String, Object> data) throws Exception {
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try{
        graph.begin();
        OrientVertex post = (OrientVertex)graph.getVertexByKey("Post.entityId", data.get("entityId"));
        if(post != null) {
            // TODO cascade deleting all comments belong to the post.
            // Need to come up a query on that to get the entire tree.
            /*
            // https://github.com/orientechnologies/orientdb/issues/1108
            delete graph...
            */
            // TODO remove tags edge. Do I need to?
            graph.removeVertex(post);
        }
        graph.commit();
    } catch (Exception e) {
        logger.error("Exception:", e);
        graph.rollback();
    } finally {
        graph.shutdown();
    }
}
 
Example 4
Source File: AbstractUserRule.java    From light with Apache License 2.0 6 votes vote down vote up
protected void delUser(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) {
            graph.removeVertex(user.getProperty("credential"));
            graph.removeVertex(user);
        }
    } catch (Exception e) {
        logger.error("Exception:", e);
        graph.rollback();
        throw e;
    } finally {
        graph.shutdown();
    }
}
 
Example 5
Source File: AbstractAccessRule.java    From light with Apache License 2.0 6 votes vote down vote up
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 6
Source File: BranchRule.java    From light with Apache License 2.0 6 votes vote down vote up
protected void delBranchDb(String branchType, Map<String, Object> data) throws Exception {
    String className = branchType.substring(0, 1).toUpperCase() + branchType.substring(1);
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try{
        graph.begin();
        OrientVertex branch = getBranchByHostId(graph, branchType, (String)data.get("host"), (String)data.get("categoryId"));
        if(branch != null) {
            graph.removeVertex(branch);
        }
        graph.commit();
    } catch (Exception e) {
        logger.error("Exception:", e);
        graph.rollback();
    } finally {
        graph.shutdown();
    }
}
 
Example 7
Source File: AbstractRuleRule.java    From light with Apache License 2.0 6 votes vote down vote up
protected void delRule(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) {
            graph.removeVertex(rule);
        }
        graph.commit();
        // check if the rule is in compile cache, remove it.
        Map<String, Object> compileMap = ServiceLocator.getInstance().getMemoryImage("compileMap");
        ConcurrentMap<String, String> cache = (ConcurrentMap<String, String>)compileMap.get("cache");
        if(cache != null) {
            cache.remove(ruleClass);
        }
    } catch (Exception e) {
        logger.error("Exception:", e);
        graph.rollback();
        throw e;
    } finally {
        graph.shutdown();
    }
}
 
Example 8
Source File: AbstractCommentRule.java    From light with Apache License 2.0 6 votes vote down vote up
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 9
Source File: AbstractConfigRule.java    From light with Apache License 2.0 6 votes vote down vote up
protected void delConfigDb(Map<String, Object> data) throws Exception {
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try{
        graph.begin();
        Vertex config = graph.getVertexByKey("Config.configId", (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 10
Source File: AbstractConfigRule.java    From light with Apache License 2.0 6 votes vote down vote up
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 11
Source File: AbstractMenuRule.java    From light with Apache License 2.0 6 votes vote down vote up
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 12
Source File: AbstractPageRule.java    From light with Apache License 2.0 6 votes vote down vote up
protected void delPage(String pageId) {
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try {
        graph.begin();
        Vertex page = graph.getVertexByKey("Page.pageId", pageId);
        if(page != null) {
            graph.removeVertex(page);
        }
        graph.commit();
    } catch (Exception e) {
        logger.error("Exception:", e);
        graph.rollback();
        throw e;
    } finally {
        graph.shutdown();
    }
    Map<String, Object> pageMap = ServiceLocator.getInstance().getMemoryImage("pageMap");
    ConcurrentMap<Object, Object> cache = (ConcurrentMap<Object, Object>)pageMap.get("cache");
    if(cache != null) {
        cache.remove(pageId);
    }
}
 
Example 13
Source File: DbService.java    From light with Apache License 2.0 6 votes vote down vote up
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 14
Source File: AbstractMenuRule.java    From light with Apache License 2.0 5 votes vote down vote up
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 15
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 16
Source File: DeleteVertexCommand.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
@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();
}