public void close() throws SQLException { status = ODatabase.STATUS.CLOSED; if (database != null) { database.activateOnCurrentThread(); database.close(); database = null; } if (orientDBisPrivate) { orientDB.close(); } }
/** * Check if the database with path given to the factory exists. * <p> * this api can be used only in embedded mode, and has no need of authentication. * * @return true if database is exists */ public boolean exists() { final ODatabaseDocument db = getDatabase(false, false); try { return db.exists(); } finally { db.close(); } }
@Override public void onAfterInitialized(Application application) { OrientDbWebApplication app = (OrientDbWebApplication)application; ODatabaseDocument db = getDatabase(app); try { installData(app, db); } catch(Exception ex) { LOG.error("Data can't be installed", ex); } finally { db.close(); } }
@Override public void onAfterInitialized(Application application) { OrientDbWebApplication app = (OrientDbWebApplication)application; ODatabaseDocument db = getDatabase(app); try { installData(app, db); } catch(Exception ex) { LOG.error("Data can't be installed", ex); } finally { db.close(); } }
@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(); } }
@Override public void commit() { final ODatabaseDocument db = transaction.get(); if (db == null) { // pool not participate in current transaction return; } // this is an error for external transaction too because external unit of work must end // before manual connection close if (db.isClosed()) { // connection was closed manually, no need for rollback transaction.remove(); checkOpened(db); } if (!transactionManager.isExternalTransaction()) { // may not cause actual commit/close because force parameter not used // in case of commit exception, transaction manager must perform rollback // (and close will take effect in rollback) db.commit(); db.close(); } transaction.remove(); logger.trace("Pool {} commit successful", getType()); }
public synchronized void begin() { loader.beginLoader(this); for (OETLTransformer transformer : transformers) { transformer.setContext(context); ODatabaseDocument db = pool.acquire(); transformer.begin(db); db.close(); } }
@Override public void rollback() { final ODatabaseDocument db = transaction.get(); if (db == null) { // pool not participate in current transaction or already committed (may happen if one other pool's // transaction fail: in this case all other transactions will be committed and after that // transactional manager call rollback, which will affect only failed pool and others will simply ignore it) return; } final boolean externalTransaction = transactionManager.isExternalTransaction(); try { // do nothing fo external transaction if (!externalTransaction) { // may not cause actual rollback immediately because force not used checkOpened(db).rollback(); } logger.trace("Pool {} rollback successful", getType()); } finally { // don't touch external tx if (!externalTransaction && !db.isClosed()) { try { // release connection back to pool in any case db.close(); } catch (Throwable ignored) { logger.trace(String.format("Pool %s failed to close database", getType()), ignored); } } transaction.remove(); } }
db.activateOnCurrentThread(); db.declareIntent(null); db.close(); if (walActive) OGlobalConfiguration.USE_WAL.setValue(true);
@Override public synchronized void beginLoader(OETLPipeline pipeline) { ODatabaseDocument db = pool.acquire(); db.activateOnCurrentThread(); createSchema(db); db.close(); pipeline.setPool(pool); }
@Override public void onDetach(RequestCycle cycle) { ODatabaseDocument db = ODatabaseRecordThreadLocal.INSTANCE.getIfDefined(); if(db!=null) { if(db.getTransaction().isActive()) db.commit(true); db.close(); ODatabaseRecordThreadLocal.INSTANCE.remove(); } }
private <R> R executeOutsideTx(Function<ODatabaseDocument, R> lamba) { if (this.tx().isOpen()) { ODatabaseDocument oldDb = getRawDatabase(); ODatabaseDocument newDb = null; try { newDb = ((ODatabaseDocumentInternal) oldDb).copy(); newDb.activateOnCurrentThread(); return lamba.apply(newDb); } finally { if (newDb != null) { newDb.close(); } oldDb.activateOnCurrentThread(); } } else { return lamba.apply(getRawDatabase()); } }
@Override public void onDetach(RequestCycle cycle) { ODatabaseDocument db = ODatabaseRecordThreadLocal.instance().getIfDefined(); if(db!=null) { if(db.getTransaction().isActive()) db.commit(true); db.close(); ODatabaseRecordThreadLocal.instance().remove(); } }
@Override public void onBeforeDestroyed(Application application) { super.onBeforeDestroyed(application); OrienteerWebApplication app = (OrienteerWebApplication)application; ODatabaseDocument db = (ODatabaseDocument)getDatabase(app); try { Map<String, ODocument> installedModules = getInstalledModules(db); for(IOrienteerModule module: app.getRegisteredModules()) { try { db.begin(); module.onDestroy(app, db, installedModules.get(module.getName())); db.commit(); } catch (Exception e) { LOG.error("Exception during destroying module '"+module.getName()+"'", e); db.rollback(); } } } finally { db.close(); } }
@Override public void close() { makeActive(); String url = database.getURL(); try { this.tx().close(); } finally { try { if (!database.isClosed()) { database.close(); if (shouldCloseFactory) { factory.close(); } } } catch (Exception e) { OLogManager.instance().error(this, "Error during context close for db " + url, e); } } }
public void onLiveResultEnd() { if (request.getResultListener() instanceof OLiveResultListener) { ((OLiveResultListener) request.getResultListener()).onUnsubscribe(token); } if (execDb != null) { ODatabaseDocumentInternal oldThreadDB = ODatabaseRecordThreadLocal.instance().getIfDefined(); execDb.activateOnCurrentThread(); execDb.close(); if (oldThreadDB == null) { ODatabaseRecordThreadLocal.instance().remove(); } else { ODatabaseRecordThreadLocal.instance().set(oldThreadDB); } } }
/** * @return result of execution */ public final V execute() { ODatabaseDocument db = null; ODatabaseDocument oldDb = ODatabaseRecordThreadLocal.INSTANCE.getIfDefined(); if(oldDb!=null) ODatabaseRecordThreadLocal.INSTANCE.remove(); //Required to avoid stack of transactions try { db = getSettings().getDatabasePoolFactory().get(getDBUrl(), getUsername(), getPassword()).acquire(); db.activateOnCurrentThread(); return execute(db); } finally { if(db!=null) db.close(); if(oldDb!=null) ODatabaseRecordThreadLocal.INSTANCE.set((ODatabaseDocumentInternal)oldDb); else ODatabaseRecordThreadLocal.INSTANCE.remove(); } }
/** * @return result of execution */ public final V execute() { ODatabaseDocument db = null; ODatabaseRecordThreadLocal orientDbThreadLocal = ODatabaseRecordThreadLocal.instance(); ODatabaseDocument oldDb = orientDbThreadLocal.getIfDefined(); if(oldDb!=null) orientDbThreadLocal.remove(); //Required to avoid stack of transactions try { db = getSettings().getDatabasePoolFactory().get(getDBUrl(), getUsername(), getPassword()).acquire(); db.activateOnCurrentThread(); return execute(db); } finally { if(db!=null) db.close(); if(oldDb!=null) orientDbThreadLocal.set((ODatabaseDocumentInternal)oldDb); else orientDbThreadLocal.remove(); } }
@Test @Ignore public void testClassChange() { ODatabaseDocument db = wicket.getTester().getDatabase(); OSchema schema = db.getMetadata().getSchema(); OClass classA = schema.createClass("TestClassChangeA"); OClass classB = schema.createClass("TestClassChangeB"); ODocument doc = new ODocument(classA); doc.save(); doc = doc.getIdentity().getRecord(); doc.setClassName(classB.getName()); assertEquals(classB.getName(), doc.getClassName()); doc = doc.getIdentity().getRecord(); assertEquals(classB.getName(), doc.getClassName()); ORID id = doc.getIdentity(); db.commit(true); db.close(); db = wicket.getTester().getDatabase(); doc = id.getRecord(); assertEquals(classB.getName(), doc.getClassName()); }