@Override public void run() { ODatabaseDocument db = new ODatabaseDocumentTx(dbUrl); try { db.open(userName, password); run(db); } finally { runningThreads.decrementAndGet(); synchronized (runningThreads) { runningThreads.notifyAll(); } db.activateOnCurrentThread(); db.close(); } }
public OrientDBDao(){ this.db = new ODatabaseDocumentTx(DEFAULT_CONFIG); if(this.db.exists()){ db.open("admin","admin"); } else { db.create(); } }
/** * 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. * * @param iCreate if true automatically creates database if database with given URL does not exist * @param iOpen if true automatically opens the database * * @return database */ public ODatabaseDocumentTx getDatabase(final boolean iCreate, final boolean iOpen) { if (pool != null) return pool.acquire(); final ODatabaseDocument db = new ODatabaseDocumentTx(url); if (properties != null) { properties.entrySet().forEach(e -> db.setProperty(e.getKey(), e.getValue())); } if (!db.getURL().startsWith("remote:") && !db.exists()) { if (iCreate) db.create(); else if (iOpen) throw new ODatabaseException("Database '" + url + "' not found"); } else if (iOpen) db.open(user, password); return (ODatabaseDocumentTx) db; }
db.open(userName, password); } else { db.create();
public static ODatabase openDatabase(final ODatabaseIdentifier databaseIdentifier, final OStorageRemote.CONNECTION_STRATEGY connectionStrategy) { ODatabaseDocument database = null; switch (databaseIdentifier.getMode()) { case PLOCAL: case MEMORY: database = new ODatabaseDocumentTx(databaseIdentifier.getUrl()).open("admin", "admin"); break; case REMOTE: database = new ODatabaseDocumentTx(databaseIdentifier.getUrl()); database.setProperty(OStorageRemote.PARAM_CONNECTION_STRATEGY, connectionStrategy.toString()); database.open("root", databaseIdentifier.getPassword()); break; } return database; }
public void testOrientDbLifeCycle(String dbURL, boolean createDb, boolean dropDb) throws Exception { Orient.instance().startup(); assertNotNull(ODatabaseRecordThreadLocal.instance()); Orient.instance().removeShutdownHook(); OServer server = OServerMain.create(); server.startup(OrientDbTestWebApplication.class.getResource("db.config.xml").openStream()); server.activate(); if(createDb) { ODatabaseDocument dbToCreate = new ODatabaseDocumentTx(dbURL); if(!dbToCreate.exists()) dbToCreate.create(); dbToCreate.close(); } assertNotNull(ODatabaseRecordThreadLocal.instance()); ODatabaseDocument db = new OPartitionedDatabasePoolFactory().get(dbURL, "admin", "admin").acquire(); db.close(); assertNotNull(ODatabaseRecordThreadLocal.instance()); if(dropDb) { ODatabaseDocument dbToDrop = new ODatabaseDocumentTx(dbURL); dbToDrop.open("admin", "admin"); dbToDrop.drop(); } server.shutdown(); Orient.instance().shutdown(); // Thread.sleep(50); }