protected String getMenuItemMap(OrientGraph graph, String host) throws Exception { String sql = "SELECT FROM MenuItem"; if(host != null) { sql += " WHERE host = ? OR host IS NULL"; } List<Map<String, String>> list = new ArrayList<Map<String, String>>(); for (Vertex menuItem : (Iterable<Vertex>) graph.command(new OCommandSQL(sql)).execute()) { Map<String, String> map = new HashMap<String, String>(); map.put("label", (String)menuItem.getProperty("menuItemId")); map.put("value", menuItem.getId().toString()); list.add(map); } return mapper.writeValueAsString(list); }
protected String getPageMap(OrientGraph graph, String host) throws Exception { String sql = "SELECT FROM Page"; if(host != null) { sql = sql + " WHERE host = '" + host + "' OR host IS NULL"; } Map<String, String> map = new HashMap<String, String>(); for (Vertex page : (Iterable<Vertex>) graph.command(new OCommandSQL(sql)).execute()) { map.put(page.getProperty("pageId"), page.getProperty("content")); } return mapper.writeValueAsString(map); }
protected String getRuleMap(OrientGraph graph, String host) throws Exception { String sql = "SELECT FROM Rule"; if(host != null) { sql = sql + " WHERE host = '" + host; } String json = null; try { Map<String, String> ruleMap = new HashMap<String, String> (); for (Vertex rule : (Iterable<Vertex>) graph.command(new OCommandSQL(sql)).execute()) { ruleMap.put((String) rule.getProperty("ruleClass"), (String) rule.getProperty("sourceCode")); } json = mapper.writeValueAsString(ruleMap); } catch (Exception e) { logger.error("Exception:", e); throw e; } finally { graph.shutdown(); } return json; }
public static long getCount(String className, Map<String, Object> criteria) { long count = 0; StringBuilder sql = new StringBuilder("SELECT COUNT(*) as count FROM ").append(className); String whereClause = DbService.getWhereClause(criteria); if(whereClause != null && whereClause.length() > 0) { sql.append(whereClause); } logger.debug("sql={}", sql); OrientGraph graph = ServiceLocator.getInstance().getGraph(); try { Iterable<Vertex> it = graph.command(new OCommandSQL(sql.toString())).execute(); if(it != null) { Vertex v = it.iterator().next(); count = v.getProperty("count"); } } catch (Exception e) { logger.error("Exception:", e); throw e; } finally { graph.shutdown(); } return count; }
protected String getFormMap(String host) throws Exception { String sql = "SELECT FROM Form"; if(host != null) { sql = sql + " WHERE host = '" + host + "' OR host IS NULL"; } String json = null; OrientGraph graph = ServiceLocator.getInstance().getGraph(); try { Map<String, Map<String, Object>> formMap = new HashMap<String, Map<String, Object>>(); for (Vertex v : (Iterable<Vertex>) graph.command( new OCommandSQL(sql)).execute()) { Map<String, Object> contentMap = new HashMap<String, Object>(); contentMap.put("action", v.getProperty("action")); contentMap.put("schema", v.getProperty("schema")); contentMap.put("form", v.getProperty("form")); contentMap.put("modelData", v.getProperty("modelData")); formMap.put(v.getProperty("formId"), contentMap); } json = mapper.writeValueAsString(formMap); } catch (Exception e) { logger.error("Exception:", e); throw e; } finally { graph.shutdown(); } return json; }
protected String execUpdateCmd(Map<String, Object> data, boolean commit) { String result = ""; String script = (String) data.get("script"); OrientGraph graph = ServiceLocator.getInstance().getGraph(); try{ graph.command(new OCommandScript("sql", script)).execute(); if(commit) { graph.commit(); } else { graph.rollback(); } } catch (Exception e) { logger.error("Exception:", e); graph.rollback(); result = e.getMessage(); } finally { graph.shutdown(); } return result; }
public static void loadCompileCache() { String sql = "SELECT FROM Rule"; Map<String, Object> compileMap = ServiceLocator.getInstance().getMemoryImage("compileMap"); ConcurrentMap<String, String> cache = (ConcurrentMap<String, String>)compileMap.get("cache"); if(cache == null) { cache = new ConcurrentLinkedHashMap.Builder<String, String>() .maximumWeightedCapacity(10000) .build(); compileMap.put("cache", cache); } OrientGraph graph = ServiceLocator.getInstance().getGraph(); try { for (Vertex rule : (Iterable<Vertex>) graph.command(new OCommandSQL(sql)).execute()) { cache.put((String) rule.getProperty("ruleClass"), (String) rule.getProperty("sourceCode")); } } catch (Exception e) { logger.error("Exception:", e); throw e; } finally { graph.shutdown(); } }