com.tinkerpop.blueprints.impls.orient.OrientGraph Java Examples

The following examples show how to use com.tinkerpop.blueprints.impls.orient.OrientGraph. 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: AbstractCommentRule.java    From light with Apache License 2.0 6 votes vote down vote up
protected long getTotal(Map<String, Object> data, Map<String, Object> criteria) {
    long total = 0;
    StringBuilder sb = new StringBuilder("SELECT COUNT(*) as count FROM (TRAVERSE out_HasComment FROM ").append(data.get("@rid")).append(") ");
    String whereClause = DbService.getWhereClause(criteria);
    if(whereClause != null && whereClause.length() > 0) {
        sb.append(whereClause);
    }
    //System.out.println("sql=" + sb);
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try {
        total = ((ODocument)graph.getRawGraph().query(new OSQLSynchQuery<ODocument>(sb.toString())).get(0)).field("count");
    } catch (Exception e) {
        logger.error("Exception:", e);
    } finally {
        graph.shutdown();
    }
    return total;
}
 
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: 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 #4
Source File: AbstractRuleRule.java    From light with Apache License 2.0 6 votes vote down vote up
protected String getRules(String host) {
    String sql = "SELECT FROM Rule";
    if(host != null) {
        sql = sql + " WHERE host = '" + host;
    }
    String json = null;
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try {
        OSQLSynchQuery<ODocument> query = new OSQLSynchQuery<>(sql);
        List<ODocument> rules = graph.getRawGraph().command(query).execute();
        json = OJSONWriter.listToJSON(rules, null);
    } catch (Exception e) {
        logger.error("Exception:", e);
        throw e;
    } finally {
        graph.shutdown();
    }
    return json;
}
 
Example #5
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 #6
Source File: AbstractUserRule.java    From light with Apache License 2.0 6 votes vote down vote up
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 #7
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 #8
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 #9
Source File: AbstractCommentRule.java    From light with Apache License 2.0 6 votes vote down vote up
protected String getCommentTreeDb(String rid, String sortedBy, String sortDir) {
    String sql = "select from Comment where in_HasComment[0] = " + rid + " ORDER BY " + sortedBy + " " + sortDir;
    String json = null;
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try {
        OSQLSynchQuery<ODocument> query = new OSQLSynchQuery<ODocument>(sql);
        List<ODocument> list = graph.getRawGraph().command(query).execute();
        if(list.size() > 0) {
            json = OJSONWriter.listToJSON(list, "rid,fetchPlan:[*]in_HasComment:-2 [*]out_ReportSpam:-2 [*]out_UpVote:-2 [*]out_DownVote:-2 in_Create[]:0 [*]out_Create:-2 [*]out_Update:-2 [*]out_HasComment:-1");
            // need to fixed the in_Create within the json using json path.
            DocumentContext dc = JsonPath.parse(json);
            MapFunction propsFunction = new StripPropsMapFunction();
            dc.map("$..in_UpVote[*]", propsFunction);
            dc.map("$..in_DownVote[*]", propsFunction);
            dc.map("$..in_ReportSpam[*]", propsFunction);

            MapFunction createFunction = new StripInCreateMapFunction();
            json = dc.map("$..in_Create[0]", createFunction).jsonString();
        }
    } catch (Exception e) {
        logger.error("Exception:", e);
    } finally {
        graph.shutdown();
    }
    return json;
}
 
Example #10
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 #11
Source File: AbstractBfnRule.java    From light with Apache License 2.0 6 votes vote down vote up
protected List<String> getRecentEntityListDb(String host, String categoryType, String sortedBy, String sortDir) {
    List<String> entityList = null;
    String sql = "select @rid from Post where host = ? and in_HasPost[0].@class = ? order by " + sortedBy + " " + sortDir;
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try {
        OSQLSynchQuery<ODocument> query = new OSQLSynchQuery<ODocument>(sql);
        List<ODocument> entities = graph.getRawGraph().command(query).execute(host, categoryType);
        if(entities.size() > 0) {
            entityList = new ArrayList<String>();
            for(ODocument entity: entities) {
                entityList.add(((ODocument)entity.field("rid")).field("@rid").toString());
            }
        }
    } catch (Exception e) {
        logger.error("Exception:", e);
    } finally {
        graph.shutdown();
    }
    return entityList;
}
 
Example #12
Source File: AbstractTagRule.java    From light with Apache License 2.0 6 votes vote down vote up
protected List<String> getTagEntityListDb(String host, String tagId) {
    List<String> entityList = null;
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try {
        OIndex<?> tagHostIdIdx = graph.getRawGraph().getMetadata().getIndexManager().getIndex("tagHostIdIdx");
        OCompositeKey key = new OCompositeKey(host, tagId);
        OIdentifiable oid = (OIdentifiable) tagHostIdIdx.get(key);
        if (oid != null) {
            ODocument doc = (ODocument)oid.getRecord();
            entityList = new ArrayList<String>();
            ORidBag entities = doc.field("in_HasTag");
            Iterator<OIdentifiable> iterator = entities.iterator();
            while (iterator.hasNext()) {
                OIdentifiable identifiable = iterator.next();
                entityList.add(identifiable.getIdentity().toString());
            }
        }
    } catch (Exception e) {
        logger.error("Exception:", e);
    } finally {
        graph.shutdown();
    }
    return entityList;
}
 
Example #13
Source File: BranchRule.java    From light with Apache License 2.0 6 votes vote down vote up
protected void downBranchDb(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 UpVote edge if there is.
            for (Edge edge : updateUser.getEdges(branch, Direction.OUT, "UpVote")) {
                if(edge.getVertex(Direction.IN).equals(branch)) graph.removeEdge(edge);
            }
            updateUser.addEdge("DownVote", branch);
        }
        graph.commit();
    } catch (Exception e) {
        logger.error("Exception:", e);
        graph.rollback();
    } finally {
        graph.shutdown();
    }
}
 
Example #14
Source File: IntegrationTestClass.java    From bjoern with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void csvBatchImporterTest() throws java.lang.Exception
{

    CSVBatchImporter importer = new CSVBatchImporter();

    importer.setDbName("__TEST__1");
    try {
        importer.importCSVFiles(
                "test/src/resources/nodes.csv",
                "test/src/resources/edges.csv");
    }
    catch (OSchemaException exception) {
        exception.printStackTrace();
        throw exception;
    }

    OrientGraph graph = new OrientGraph(
            "plocal:" + System.getProperty("ORIENTDB_HOME") + "/databases/" + "__TEST__1");

    Pipe pipe = Gremlin.compile("_().map");
    pipe.setStarts(graph.getVertices());
}
 
Example #15
Source File: ExportDatabase.java    From light with Apache License 2.0 6 votes vote down vote up
public static void exp() {
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try{
        OCommandOutputListener listener = new OCommandOutputListener() {
            @Override
            public void onMessage(String iText) {
                System.out.print(iText);
            }
        };

        ODatabaseExport export = new ODatabaseExport(graph.getRawGraph(), "/tmp/export", listener);
        export.exportDatabase();
        export.close();
    } catch(IOException ioe) {
        ioe.printStackTrace();
    } finally {
        graph.shutdown();
    }
}
 
Example #16
Source File: AbstractBfnRule.java    From light with Apache License 2.0 6 votes vote down vote up
protected List<String> getCategoryEntityListDb(String categoryRid, String sortedBy, String sortDir) {
    List<String> entityList = null;
    String sql = "select @rid from (traverse out_Own, out_HasPost from ?) where @class = 'Post' order by " + sortedBy + " " + sortDir;
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try {
        OSQLSynchQuery<ODocument> query = new OSQLSynchQuery<ODocument>(sql);
        List<ODocument> entities = graph.getRawGraph().command(query).execute(categoryRid);
        if(entities.size() > 0) {
            entityList = new ArrayList<String>();
            for(ODocument entity: entities) {
                entityList.add(((ODocument)entity.field("rid")).field("@rid").toString());
            }
        }
    } catch (Exception e) {
        logger.error("Exception:", e);
    } finally {
        graph.shutdown();
    }
    return entityList;
}
 
Example #17
Source File: GraphTest.java    From light with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
    String sql = "select from Comment where in_HasComment[0] = #35:22";

    OrientGraphFactory factory = new OrientGraphFactory("plocal:/home/steve/lightdb").setupPool(1,10);
    //OrientGraphFactory factory = new OrientGraphFactory("plocal:/Users/HUS5/lightdb").setupPool(1,10);
    OrientGraph graph = factory.getTx();
    try {
        //System.out.println(graph.getVertex("#11:0").getRecord().toJSON("rid, fetchPlan:*:-1"));

        //String result = graph.getVertex("#37:0").getRecord().toJSON("rid,fetchPlan:[*]in_Create:-2 out_HasComment:5");
        //String result = graph.getVertex("#35:22").getRecord().toJSON("rid,version,fetchPlan:out_HasComment:-1 out_HasComment.out_HasComment:-1 out_HasComment.in_Create:0");
        //String result = graph.getVertex("#35:22").getRecord().toJSON("rid,in_Create.userId, fetchPlan:out_HasComment:5");
        //System.out.println(result);
        OSQLSynchQuery<ODocument> query = new OSQLSynchQuery<ODocument>(sql);
        List<ODocument> list = graph.getRawGraph().command(query).execute();
        String json = OJSONWriter.listToJSON(list, "rid,fetchPlan:[*]in_HasComment:-2 [*]out_ReportSpam:-2 [*]out_UpVote:-2 [*]out_DownVote:-2 in_Create[]:0 [*]out_Create:-2 [*]out_Update:-2 [*]out_HasComment:-1");
        System.out.println(json);
        //System.out.println(getBfnTree("forum", "example"));
    } finally {
        graph.shutdown();
    }
}
 
Example #18
Source File: AbstractRoleRule.java    From light with Apache License 2.0 6 votes vote down vote up
protected String getRoleById(String roleId) {
    String json = null;
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try {
        OrientVertex role = (OrientVertex)graph.getVertexByKey("Role.roleId", roleId);
        if(role != null) {
            json = role.getRecord().toJSON();
        }
    } catch (Exception e) {
        logger.error("Exception:", e);
        throw e;
    } finally {
        graph.shutdown();
    }
    return json;
}
 
Example #19
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 #20
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 #21
Source File: GetMenuRule.java    From light with Apache License 2.0 6 votes vote down vote up
public boolean execute (Object ...objects) throws Exception {
    Map<String, Object> inputMap = (Map<String, Object>) objects[0];
    Map<String, Object> data = (Map<String, Object>) inputMap.get("data");
    String host = (String) data.get("host");
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    String json = null;
    try {
        json = getMenu(graph, host);
    } catch (Exception e) {
        logger.error("Exception:", e);
        throw e;
    } finally {
        graph.shutdown();
    }
    if(json != null) {
        inputMap.put("result", json);
        return true;
    } else {
        inputMap.put("result", "Menu for host " + host + " cannot be found.");
        return false;
    }
}
 
Example #22
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 #23
Source File: AbstractPageRule.java    From light with Apache License 2.0 6 votes vote down vote up
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 #24
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 #25
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 #26
Source File: AbstractCatalogRule.java    From light with Apache License 2.0 6 votes vote down vote up
@Override
protected List<String> getCategoryEntityListDb(String categoryRid, String sortedBy, String sortDir) {
    List<String> entityList = null;
    String sql = "select @rid from (traverse out_Own, out_HasProduct from ?) where @class = 'Product' order by " + sortedBy + " " + sortDir;
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try {
        OSQLSynchQuery<ODocument> query = new OSQLSynchQuery<ODocument>(sql);
        List<ODocument> entities = graph.getRawGraph().command(query).execute(categoryRid);
        if(entities.size() > 0) {
            entityList = new ArrayList<String>();
            for(ODocument entity: entities) {
                entityList.add(((ODocument)entity.field("rid")).field("@rid").toString());
            }
        }
    } catch (Exception e) {
        logger.error("Exception:", e);
    } finally {
        graph.shutdown();
    }
    return entityList;
}
 
Example #27
Source File: GetAllPageRule.java    From light with Apache License 2.0 6 votes vote down vote up
public boolean execute (Object ...objects) throws Exception {
    Map<String, Object> inputMap = (Map<String, Object>) objects[0];
    Map<String, Object> data = (Map<String, Object>) inputMap.get("data");
    Map<String, Object> user = (Map<String, Object>) inputMap.get("user");
    String host = (String)user.get("host");
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    String pages = null;
    try {
        pages = getAllPage(graph, host);
    } catch (Exception e) {
        logger.error("Exception:", e);
        throw e;
    } finally {
        graph.shutdown();
    }
    if(pages != null) {
        inputMap.put("result", pages);
        return true;
    } else {
        inputMap.put("result", "No page can be found.");
        inputMap.put("responseCode", 404);
        return false;
    }
}
 
Example #28
Source File: AbstractCatalogRule.java    From light with Apache License 2.0 6 votes vote down vote up
protected String getProductDb() {
    String json = null;
    String sql = "select from product";
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try {
        OSQLSynchQuery<ODocument> query = new OSQLSynchQuery<ODocument>(sql);
        List<ODocument> products = graph.getRawGraph().command(query).execute();
        if(products.size() > 0) {
            json = OJSONWriter.listToJSON(products, null);
        }
    } catch (Exception e) {
        logger.error("Exception:", e);
    } finally {
        graph.shutdown();
    }
    return json;
}
 
Example #29
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 #30
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();
    }
}