protected long getTotalNumberUserFromDb(OrientGraph graph, Map<String, Object> criteria) throws Exception { StringBuilder sql = new StringBuilder("SELECT COUNT(*) as count FROM User"); String whereClause = DbService.getWhereClause(criteria); if(whereClause != null && whereClause.length() > 0) { sql.append(whereClause); } logger.debug("sql=" + sql); OSQLSynchQuery<ODocument> query = new OSQLSynchQuery<ODocument>(sql.toString()); List<ODocument> list = graph.getRawGraph().command(query).execute(); return list.get(0).field("count"); }
public OrientSingleInsertion(OrientGraph orientGraph, File resultsPath) { super(GraphDatabaseType.ORIENT_DB, resultsPath); this.orientGraph = orientGraph; this.index = this.orientGraph.getRawGraph().getMetadata().getIndexManager().getIndex("V.nodeId"); }
protected String execQueryCmd(OrientGraph graph, Map<String, Object> data) { OSQLSynchQuery<ODocument> query = new OSQLSynchQuery<>((String)data.get("script")); List<ODocument> accesses = graph.getRawGraph().command(query).execute(); return OJSONWriter.listToJSON(accesses, null); }
@Override public void massiveModeLoading(File dataPath) { OrientMassiveInsertion orientMassiveInsertion = new OrientMassiveInsertion(this.graph.getRawGraph().getURL()); orientMassiveInsertion.createGraph(dataPath, 0 /* scenarioNumber */); }
@Override public void start(final String database) { // test connection and let orient configure database new OrientGraph( (ODatabaseDocumentInternal) orientDB.get() .open(database, userManager.getUser(), userManager.getPassword())) .getRawGraph().close(); logger.debug("Pool {} started for database '{}'", getType(), database); }
protected String getAllPage(OrientGraph graph, String host) { String json = null; String sql = "SELECT FROM Page"; if(host != null) { sql = sql + " WHERE host = '" + host + "' OR host IS NULL"; } OSQLSynchQuery<ODocument> query = new OSQLSynchQuery<>(sql); List<ODocument> pages = graph.getRawGraph().command(query).execute(); json = OJSONWriter.listToJSON(pages, null); return json; }
@Override public void reindex() { OrientGraph tx = txProvider.rawTx(); try { OIndexManager manager = tx.getRawGraph().getMetadata().getIndexManager(); manager.getIndexes().forEach(i -> i.rebuild()); } finally { tx.shutdown(); } }
public static int incrementCounter(String name) { OrientGraph graph = ServiceLocator.getInstance().getGraph(); try { List list = graph.getRawGraph().command(new OCommandSQL("update Counter INCREMENT value = 1 return after where name = '" + name + "'")).execute(); ODocument lastDoc = (ODocument)list.get(0); return lastDoc.field("value"); } catch (Exception e) { logger.error("Exception:", e); throw e; } finally { graph.shutdown(); } }
protected String getBranchDb(String branchType, String host) { String json = null; String sql = "SELECT FROM " + branchType + " WHERE host = ? ORDER BY createDate"; OrientGraph graph = ServiceLocator.getInstance().getGraph(); try { OSQLSynchQuery<ODocument> query = new OSQLSynchQuery<ODocument>(sql); List<ODocument> docs = graph.getRawGraph().command(query).execute(host); if(docs.size() > 0) { json = OJSONWriter.listToJSON(docs, null); } } catch (Exception e) { logger.error("Exception:", e); } finally { graph.shutdown(); } return json; }
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; }
protected String getBranchTreeDb(String branchType, String host) { String json = null; String sql = "SELECT FROM " + branchType + " WHERE host = ? and in_Own IS NULL ORDER BY id"; OrientGraph graph = ServiceLocator.getInstance().getGraph(); try { OSQLSynchQuery<ODocument> query = new OSQLSynchQuery<ODocument>(sql); List<ODocument> docs = graph.getRawGraph().command(query).execute(host); if(docs.size() > 0) { json = OJSONWriter.listToJSON(docs, "rid,fetchPlan:[*]in_Create:-2 [*]out_Create:-2 [*]in_Update:-2 [*]out_Update:-2 [*]in_HasPost:-2 [*]out_HasPost:-2 [*]out_Own:5"); } } catch (Exception e) { logger.error("Exception:", e); } finally { graph.shutdown(); } return json; }
protected String getProductDb(String host) { String json = null; String sql = "select from product where host = ?"; OrientGraph graph = ServiceLocator.getInstance().getGraph(); try { OSQLSynchQuery<ODocument> query = new OSQLSynchQuery<ODocument>(sql); List<ODocument> products = graph.getRawGraph().command(query).execute(host); if(products.size() > 0) { json = OJSONWriter.listToJSON(products, null); } } catch (Exception e) { logger.error("Exception:", e); } finally { graph.shutdown(); } return json; }
protected static String getBfnTree(String bfnType, String host) { String json = null; String sql = "SELECT FROM " + bfnType + " WHERE host = ? and in_Own IS NULL ORDER BY id"; OrientGraph graph = ServiceLocator.getInstance().getGraph(); try { OSQLSynchQuery<ODocument> query = new OSQLSynchQuery<ODocument>(sql); List<ODocument> docs = graph.getRawGraph().command(query).execute(host); if(docs.size() > 0) { json = OJSONWriter.listToJSON(docs, "rid,fetchPlan:out_Own.in_Create:-2 out_Own.out_Create:-2 out_Own:-1"); } } catch (Exception e) { logger.error("Exception:", e); } finally { graph.shutdown(); } return json; }
protected String getAllConfig() { String sql = "SELECT FROM Config"; String json = null; OrientGraph graph = ServiceLocator.getInstance().getGraph(); try { OSQLSynchQuery<ODocument> query = new OSQLSynchQuery<>(sql); List<ODocument> configs = graph.getRawGraph().command(query).execute(); if(configs != null && configs.size() > 0) { json = OJSONWriter.listToJSON(configs, null); } } catch (Exception e) { logger.error("Exception:", e); throw e; } finally { graph.shutdown(); } return json; }
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(); } } }
protected ODocument getODocumentByHostId(OrientGraph graph, String index, String host, String id) { ODocument doc = null; OIndex<?> hostIdIdx = graph.getRawGraph().getMetadata().getIndexManager().getIndex(index); // this is a unique index, so it retrieves a OIdentifiable OCompositeKey key = new OCompositeKey(host, id); OIdentifiable oid = (OIdentifiable) hostIdIdx.get(key); if (oid != null) { doc = (ODocument)oid.getRecord(); } return doc; }
public static int executeSqlCommand(String sql) { int recordsUpdated = 0; OrientGraph graph = ServiceLocator.getInstance().getGraph(); try { recordsUpdated = graph.getRawGraph().command(new OCommandSQL(sql)).execute(); graph.commit(); } catch (Exception e) { graph.rollback(); logger.error("Exception:", e); throw e; } finally { graph.shutdown(); } return recordsUpdated; }
public OrientVertex getConfigByHostId(OrientGraph graph, String host, String configId) { OrientVertex config = null; OIndex<?> hostIdIdx = graph.getRawGraph().getMetadata().getIndexManager().getIndex("configHostIdIdx"); OCompositeKey key = new OCompositeKey(host, configId); OIdentifiable oid = (OIdentifiable) hostIdIdx.get(key); if (oid != null) { config = graph.getVertex(oid.getRecord()); } return config; }
public OrientVertex getBranchByHostId(OrientGraph graph, String branchType, String host, String categoryId) { OrientVertex branch = null; OIndex<?> hostIdIdx = graph.getRawGraph().getMetadata().getIndexManager().getIndex(branchType + "HostIdIdx"); OCompositeKey key = new OCompositeKey(host, categoryId); OIdentifiable oid = (OIdentifiable) hostIdIdx.get(key); if (oid != null) { branch = graph.getVertex(oid.getRecord()); } return branch; }
public static <T> T runInTx(final OrientGraph graph, final GraphCallBack<T> callBack) { final ODatabaseDocument databaseRecord = getDatabase(); final boolean txWasActive = databaseRecord.getTransaction().isActive(); if (!txWasActive) graph.getRawGraph().begin(); try { final T result = callBack.call(graph); if (!txWasActive) graph.commit(); return result; } catch (RuntimeException e) { if (!txWasActive) graph.rollback(); throw e; } }