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

The following examples show how to use com.tinkerpop.blueprints.impls.orient.OrientGraph#rollback() . 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: 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 2
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 3
Source File: BranchRule.java    From light with Apache License 2.0 6 votes vote down vote up
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: 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: 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 6
Source File: AbstractOrderRule.java    From light with Apache License 2.0 6 votes vote down vote up
/**
 * 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 7
Source File: AbstractCommentRule.java    From light with Apache License 2.0 6 votes vote down vote up
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: 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 9
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 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 10
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 11
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 12
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 13
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 14
Source File: AbstractProductRule.java    From light with Apache License 2.0 6 votes vote down vote up
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 15
Source File: AbstractUserRule.java    From light with Apache License 2.0 5 votes vote down vote up
protected void updUser(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) {
            String firstName = (String)data.get("firstName");
            if(firstName != null && !firstName.equals(user.getProperty("firstName"))) {
                user.setProperty("firstName", firstName);
            }
            String lastName = (String)data.get("lastName");
            if(lastName != null && !lastName.equals(user.getProperty("lastName"))) {
                user.setProperty("lastName", lastName);
            }
            // TODO update shipping address and payment address here.
            Map<String, Object> shippingAddress = (Map<String, Object>)data.get("shippingAddress");
            if(shippingAddress != null) {
                user.setProperty("shippingAddress", shippingAddress);
            }
            Map<String, Object> paymentAddress = (Map<String, Object>)data.get("paymentAddress");
            if(paymentAddress != null) {
                user.setProperty("paymentAddress", paymentAddress);
            }
            user.setProperty("updateDate", data.get("updateDate"));
        }
        graph.commit();
    } catch (Exception e) {
        logger.error("Exception:", e);
        graph.rollback();
        throw e;
    } finally {
        graph.shutdown();
    }
}
 
Example 16
Source File: AbstractDependencyRule.java    From light with Apache License 2.0 5 votes vote down vote up
protected void addDependency(Map<String, Object> data) throws Exception {
    String json = null;
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try {
        graph.begin();
        Vertex sourceRule = graph.getVertexByKey("Rule.ruleClass", data.get("sourceRuleClass"));
        Vertex destRule = graph.getVertexByKey("Rule.ruleClass", data.get("destRuleClass"));
        Edge edge = sourceRule.addEdge("Depend", destRule);
        edge.setProperty("content", data.get("content"));
        graph.commit();
        //json = edge.getRecord().toJSON();
    } 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 = new ConcurrentLinkedHashMap.Builder<Object, Object>()
                .maximumWeightedCapacity(1000)
                .build();
        pageMap.put("cache", cache);
    }
    cache.put(data.get("pageId"), json);
}
 
Example 17
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 18
Source File: AbstractUserRule.java    From light with Apache License 2.0 5 votes vote down vote up
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 19
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 20
Source File: AbstractRuleRule.java    From light with Apache License 2.0 5 votes vote down vote up
protected void updCors(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("enableCors", data.get("enableCors"));
            String corsHosts = (String)data.get("corsHosts");
            if(corsHosts != null) {
                rule.setProperty("corsHosts", corsHosts);
            } else {
                rule.removeProperty("corsHosts");
            }
            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();
    }
}