/** * Checks if the Graph has been closed. * * @return True if it is closed, otherwise false */ public boolean isClosed() { makeActive(); return database == null || database.isClosed(); }
/** * @param create if true automatically creates database if database with given * URL does not exist * @param open if true automatically opens the database */ protected ODatabaseDocument acquireFromPool(boolean create, boolean open) { if (create && type.isPresent()) { this.factory.createIfNotExists(dbName, type.get()); } final ODatabaseDocument databaseDocument = this.pool.acquire(); if (databaseDocument.isClosed()) { throw new IllegalStateException("Database returned from document is closed"); } return databaseDocument; }
/** * To early catch inconsistency errors it's better to check here (should reduce scope to search for problem). * It's so easy to call close directly on connection, but it shouldn't be done manually: either use unit of work * or completely manage connection yourself. * * @param db database connection instance * @return connection instance if its opened, otherwise error thrown */ private ODatabaseDocument checkOpened(final ODatabaseDocument db) { Preconditions.checkState(orientDB.get().isOpen(), "Global OrientDB object is closed. " + "This must be the result of manual object closing."); Preconditions.checkState(!db.isClosed(), String.format( "Inconsistent %s pool state: thread-bound database closed! " + "This may happen if close, commit or rollback was called directly on " + "database connection object, which is not allowed (if you need full control " + "on connection use manual setup and not pool managed connection)", getType())); return db; }
@Override public IRequestHandler onException(RequestCycle cycle, Exception ex) { ODatabaseDocument db = ODatabaseRecordThreadLocal.INSTANCE.getIfDefined(); if(db!=null && !db.isClosed()) db.rollback(); return null; }
void internalAcquireExclusiveLock() { final ODatabaseDocument databaseRecord = getDatabaseIfDefined(); if (databaseRecord != null && !databaseRecord.isClosed()) { final OMetadataInternal metadata = (OMetadataInternal) databaseRecord.getMetadata(); if (metadata != null) metadata.makeThreadLocalSchemaSnapshot(); } lock.writeLock().lock(); }
void internalReleaseExclusiveLock() { lock.writeLock().unlock(); final ODatabaseDocument databaseRecord = getDatabaseIfDefined(); if (databaseRecord != null && !databaseRecord.isClosed()) { final OMetadata metadata = databaseRecord.getMetadata(); if (metadata != null) ((OMetadataInternal) metadata).clearThreadLocalSchemaSnapshot(); } }
@Override public IRequestHandler onException(RequestCycle cycle, Exception ex) { ODatabaseDocument db = ODatabaseRecordThreadLocal.instance().getIfDefined(); if(db!=null && !db.isClosed()) db.rollback(); return null; }
public static void removePendingDatabaseOps(ODatabaseDocument database) { try { if (database.isClosed() || Boolean.FALSE.equals(database.getConfiguration().getValue(QUERY_LIVE_SUPPORT))) return; OLiveQueryOps ops = getOpsReference((ODatabaseInternal) database); synchronized (ops.pendingOps) { ops.pendingOps.remove(database); } } catch (ODatabaseException ex) { //This catch and log the exception because in some case is suppressing the real exception OLogManager.instance().error(database, "Error cleaning the live query resources", ex); } }
if (db != null && !db.isClosed()) { final String clsName = getClassName(); if (clsName != null)
@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()); }
/** * Its definitely not normal that pool returns closed connections, but possible if used improperly. * * @return connection itself or new valid connection */ private ODatabaseDocument checkAndAcquireConnection() { final ODatabaseDocument res; if (userManager.isSpecificUser()) { // non pool-managed connection for different user res = orientDB.get().open(database, userManager.getUser(), userManager.getPassword()); } else { res = pool.acquire(); } if (res.isClosed()) { final String message = String.format( "Pool %s return closed connection something is terribly wrong", getType()); logger.error(message); throw new IllegalStateException(message); } return res; }
@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(); } }
@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); } } }
@Provides public ODatabaseDocument getDatabaseRecord() { ODatabaseDocument db = DefaultODatabaseThreadLocalFactory.castToODatabaseDocument(ODatabaseRecordThreadLocal.instance().get().getDatabaseOwner()); if(db.isClosed()) { ODatabaseRecordThreadLocal.instance().remove(); db = DefaultODatabaseThreadLocalFactory.castToODatabaseDocument(ODatabaseRecordThreadLocal.instance().get().getDatabaseOwner()); } return db; }
/** * @return any graph if available, otherwise a Non Transactional OrientGraph implementation from the current database in thread * local. */ public static OrientBaseGraph getAnyGraph(final OModifiableBoolean shouldBeShutDown) { final ODatabaseDocumentInternal database = ODatabaseRecordThreadLocal.instance().get(); final OrientBaseGraph result = OrientBaseGraph.getActiveGraph(); if (result != null) { final ODatabaseDocument graphDb = result.getRawGraph(); // CHECK IF THE DATABASE + USER IN TL IS THE SAME IN ORDER TO USE IT if (canReuseActiveGraph(graphDb, database)) { if (!graphDb.isClosed()) { graphDb.activateOnCurrentThread(); shouldBeShutDown.setValue(false); return result; } } } // Set it again on ThreadLocal because the getRawGraph() may have set a closed db in the thread-local shouldBeShutDown.setValue(true); ODatabaseRecordThreadLocal.instance().set(database); return OrientGraphFactory.getNoTxGraphImplFactory().getGraph(database); }
protected OGlobalProperty getGlobalPropertyById(int id) { if (_schema == null) { OMetadataInternal metadata = getDatabase().getMetadata(); _schema = metadata.getImmutableSchemaSnapshot(); } OGlobalProperty prop = _schema.getGlobalPropertyById(id); if (prop == null) { ODatabaseDocument db = getDatabase(); if (db == null || db.isClosed()) throw new ODatabaseException( "Cannot unmarshall the document because no database is active, use detach for use the document outside the database session scope"); OMetadataInternal metadata = (OMetadataInternal) db.getMetadata(); if (metadata.getImmutableSchemaSnapshot() != null) metadata.clearThreadLocalSchemaSnapshot(); metadata.reload(); metadata.makeThreadLocalSchemaSnapshot(); _schema = metadata.getImmutableSchemaSnapshot(); prop = _schema.getGlobalPropertyById(id); } return prop; }
OSchema schema = db.getMetadata().getSchema(); assertFalse(db.isClosed()); db.commit(); if(schema.existsClass(TEST_CLASS_C)) schema.dropClass(TEST_CLASS_C);
OSchema schema = db.getMetadata().getSchema(); assertFalse(db.isClosed()); db.commit(); if(schema.existsClass(TEST_CLASS_C)) schema.dropClass(TEST_CLASS_C);
assertTrue(OrientDbWebSession.get().signIn("admin", "admin")); ODatabaseDocument db = OrientDbWebSession.get().getDatabase(); assertFalse(db.isClosed()); db.commit(); try
assertTrue(OrientDbWebSession.get().signIn("admin", "admin")); ODatabaseDocument db = OrientDbWebSession.get().getDatabase(); assertFalse(db.isClosed()); db.commit();