@Override public void open(String name) { GraphStorageOptions storageOptions = options.getStorageOptions(); if (storageOptions == null || storageOptions.getDirectory() == null) { log.info("No graph database settings found. Fallback to in memory mode."); factory = new OrientGraphFactory("memory:tinkerpop").setupPool(16, 100); } else { factory = new OrientGraphFactory("plocal:" + new File(storageOptions.getDirectory(), DB_NAME).getAbsolutePath()).setupPool(16, 100); } }
private OrientGraph getGraph(final File dbPath) { OrientGraph g; OrientGraphFactory graphFactory = new OrientGraphFactory("plocal:" + dbPath.getAbsolutePath()); g = graphFactory.getTx(); g.setUseLightweightEdges(this.useLightWeightEdges); return g; }
@Override public void close() { factory.close(); }
/** * Gets transactional graph with the database from pool if pool is configured. Otherwise creates a graph with new db instance. The * Graph instance inherits the factory's configuration. * * @return transactional graph */ public OrientGraph getTx() { final OrientGraph g; if (pool == null) { g = (OrientGraph) getTxGraphImplFactory().getGraph(getDatabase(), user, password, settings); } else { // USE THE POOL g = (OrientGraph) getTxGraphImplFactory().getGraph(pool, settings); } initGraph(g); return g; }
@Provides @RequestScoped @Inject public ODatabaseDocumentTx provideDatabase(OrientGraphFactory orientGraphFactory) { if (logger.isTraceEnabled()) logger.trace("Getting database."); logger.debug("Available: " + orientGraphFactory.getAvailableInstancesInPool()); logger.debug("Created: " + orientGraphFactory.getCreatedInstancesInPool()); return orientGraphFactory.getDatabase(); }
final OrientGraphFactory factory = new OrientGraphFactory(dbURL, dbUser, dbPassword); if (dbAutoDropIfExists && factory.exists()) { log(OETLProcessor.LOG_LEVELS.INFO, "Dropping existent database '%s'...", dbURL); factory.drop(); final OrientBaseGraph graphDatabase = tx ? factory.getTx() : factory.getNoTx(); graphDatabase.shutdown(); break;
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(); } }
@Override public void begin() { ODatabaseDocumentTx documentDatabase = init(); if (documentDatabase == null) { switch (dbType) { case DOCUMENT: documentDatabase = new ODatabaseDocumentTx(dbURL); documentDatabase.open(dbUser, dbPassword); break; case GRAPH: final OrientGraphFactory factory = new OrientGraphFactory(dbURL, dbUser, dbPassword); final OrientBaseGraph graphDatabase = tx ? factory.getTx() : factory.getNoTx(); graphDatabase.setUseLightweightEdges(useLightweightEdges); graphDatabase.setStandardElementConstraints(standardElementConstraints); documentDatabase = graphDatabase.getRawGraph(); pipeline.setGraphDatabase(graphDatabase); break; } pipeline.setDocumentDatabase(documentDatabase); } documentDatabase.declareIntent(new OIntentMassiveInsert()); }
/** * Gives new connection to database. If current factory configured to use pool (see {@link #setupPool(int, int)} method), * retrieves connection from pool. Otherwise creates new connection each time. * <p> * Automatically creates database if database with given URL does not exist * <p> * Shortcut for {@code getDatabase(true)} * * @return database. */ public ODatabaseDocumentTx getDatabase() { return getDatabase(true, true); }
final OrientGraphFactory factory = new OrientGraphFactory(dbURL, dbUser, dbPassword); graphDatabase = factory.getNoTx(); graphDatabase.setUseLightweightEdges(useLightweightEdges); graphDatabase.setStandardElementConstraints(standardElementConstraints);
@Override public OrientGraph rawTx() { return factory.getTx(); }
/** * Gets non transactional graph with the database from pool if pool is configured. Otherwise creates a graph with new db instance. * The Graph instance inherits the factory's configuration. * * @return non transactional graph */ public OrientGraphNoTx getNoTx() { final OrientGraphNoTx g; if (pool == null) { g = (OrientGraphNoTx) getNoTxGraphImplFactory().getGraph(getDatabase(), user, password, settings); } else { // USE THE POOL g = (OrientGraphNoTx) getNoTxGraphImplFactory().getGraph(pool, settings); } initGraph(g); return g; }
@Override public OrientGraphNoTx rawNoTx() { ODatabaseSession db = context.open(DB_NAME, "admin", "admin"); return (OrientGraphNoTx) OrientGraphFactory.getNoTxGraphImplFactory().getGraph((ODatabaseDocumentInternal) db); }
public OrientGraph acquireGraph(final ODatabaseDocumentInternal database) { return (OrientGraph) OrientGraphFactory.getTxGraphImplFactory().getGraph(database); }
@Override public OrientGraphNoTx rawNoTx() { return factory.getNoTx(); }
} else if (!orientGraphFactory.exists()) { logger.info("Database " + dbPath + " did not exist: Creating it now."); try {
/** * Drops current database if such one exists. */ public void drop() { getDatabase(false, true).drop(); }
public OrientGraph getGraph() { return getFactory().getTx(); }
protected OrientGraphNoTx getGraphNoTx(final ODatabaseIdentifier databaseIdentifier) { final ODatabase database = ODatabaseUtils.openDatabase(databaseIdentifier, connectionStrategy); if (database == null) throw new IllegalArgumentException("Error on opening database " + databaseIdentifier.getName()); return (OrientGraphNoTx) OrientGraphFactory.getNoTxGraphImplFactory().getGraph((ODatabaseDocumentTx) database); }