/** * Checks if the Graph has been closed. * * @return True if it is closed, otherwise false */ public boolean isClosed() { return database == null || database.isClosed(); }
@Override public boolean isClosed() { return internal == null || internal.isClosed(); }
public boolean isClosed() { return database.isClosed(); }
@Override public void begin(final TxConfig config) { if (transaction.get() != null) { // transaction already in progress return; } if (config != null && config.isExternal()) { Preconditions.checkState(!ODatabaseRecordThreadLocal.instance().get().isClosed(), "Can't start external unit of work: connection bound to thread is closed"); } transaction.set(MoreObjects.firstNonNull(config, defaultConfig)); logger.trace("Transaction opened: {}", transaction.get()); }
private void fetchSchemaIfCan(ODatabaseDocumentInternal db) { if (_schema == null) { if (db != null && !db.isClosed()) { OMetadataInternal metadata = db.getMetadata(); _schema = metadata.getImmutableSchemaSnapshot(); } } }
/** * Should be used only by console commands */ protected void checkForDatabase() { if (currentDatabase == null) throw new OSystemException("Database not selected. Use 'connect <url> <user> <password>' to connect to a database."); if (currentDatabase.isClosed()) throw new ODatabaseException("Database '" + currentDatabaseName + "' is closed"); }
public void switchUser(final String iUserName, final String iUserPassword) { if (!database.isClosed()) database.close(); database.open(iUserName, iUserPassword); }
private void bindDb() { final ODatabaseDocumentInternal tlDb = ODatabaseRecordThreadLocal.instance().get(); if (tlDb != null && !tlDb.isClosed()) this.db = tlDb.copy(); }
@Override public Set<String> getPropertyNames() { checkForLoading(); if (_status == ORecordElement.STATUS.LOADED && _source != null && ODatabaseRecordThreadLocal.instance().isDefined() && !ODatabaseRecordThreadLocal.instance().get().isClosed()) { // DESERIALIZE FIELD NAMES ONLY (SUPPORTED ONLY BY BINARY SERIALIZER) final String[] fieldNames = _recordFormat.getFieldNamesRoot(this, _source); if (fieldNames != null) { Set<String> result = new HashSet<>(); Collections.addAll(result, fieldNames); return result; } } checkForFields(); if (_fields == null || _fields.size() == 0) return Collections.EMPTY_SET; return _fields.entrySet().stream().filter(s -> s.getValue().exist()).map(Entry::getKey).collect(Collectors.toSet()); }
/** * Returns the set of field names. */ public String[] fieldNames() { checkForLoading(); if (_status == ORecordElement.STATUS.LOADED && _source != null && ODatabaseRecordThreadLocal.instance().isDefined() && !ODatabaseRecordThreadLocal.instance().get().isClosed()) { // DESERIALIZE FIELD NAMES ONLY (SUPPORTED ONLY BY BINARY SERIALIZER) final String[] fieldNames = _recordFormat.getFieldNamesRoot(this, _source); if (fieldNames != null) return fieldNames; } checkForFields(); if (_fields == null || _fields.size() == 0) return EMPTY_STRINGS; final List<String> names = new ArrayList<>(_fields.size()); for (Entry<String, ODocumentEntry> entry : _fields.entrySet()) { if (entry.getValue().exist()) names.add(entry.getKey()); } return names.toArray(new String[names.size()]); }
public static DateFormat getDateTimeFormatInstance() { final ODatabaseDocumentInternal db = ODatabaseRecordThreadLocal.instance().getIfDefined(); if (db != null && !db.isClosed()) return db.getStorage().getConfiguration().getDateTimeFormatInstance(); else return new SimpleDateFormat(DEF_DATETIME_FORMAT); }
public static DateFormat getDateFormatInstance() { final ODatabaseDocumentInternal db = ODatabaseRecordThreadLocal.instance().getIfDefined(); if (db != null && !db.isClosed()) return db.getStorage().getConfiguration().getDateFormatInstance(); else return new SimpleDateFormat(DEF_DATE_FORMAT); }
public static TimeZone getDatabaseTimeZone() { final ODatabaseDocumentInternal db = ODatabaseRecordThreadLocal.instance().getIfDefined(); if (db != null && !db.isClosed()) return db.getStorage().getConfiguration().getTimeZone(); return TimeZone.getDefault(); }
private void fetchSchemaIfCan() { if (_schema == null) { ODatabaseDocumentInternal db = ODatabaseRecordThreadLocal.instance().getIfDefined(); if (db != null && !db.isClosed()) { OMetadataInternal metadata = db.getMetadata(); _schema = metadata.getImmutableSchemaSnapshot(); } } }
public static String getDateTimeFormat() { final ODatabaseDocumentInternal db = ODatabaseRecordThreadLocal.instance().getIfDefined(); if (db != null && !db.isClosed()) return db.getStorage().getConfiguration().getDateTimeFormat(); else return DEF_DATETIME_FORMAT; }
public static String getDateFormat() { final ODatabaseDocumentInternal db = ODatabaseRecordThreadLocal.instance().getIfDefined(); if (db != null && !db.isClosed()) return db.getStorage().getConfiguration().getDateFormat(); else return DEF_DATE_FORMAT; }
protected OImmutableClass getImmutableSchemaClass(ODatabaseDocumentInternal database) { if (_immutableClazz == null) { if (_className == null) fetchClassName(); if (_className != null) { if (database == null) { database = getDatabaseIfDefined(); } if (database != null && !database.isClosed()) { final OSchema immutableSchema = database.getMetadata().getImmutableSchemaSnapshot(); if (immutableSchema == null) return null; _immutableSchemaVersion = immutableSchema.getVersion(); _immutableClazz = (OImmutableClass) immutableSchema.getClass(_className); } } } return _immutableClazz; }
private void openOrCreate() { if (url == null) throw new IllegalStateException("Database is closed"); if (pool == null) { database = new ODatabaseDocumentTx(url); if (properties != null) { properties.entrySet().forEach(e -> database.setProperty(e.getKey(), e.getValue())); } if (url.startsWith("remote:") || getDatabase().exists()) { if (getDatabase().isClosed()) getDatabase().open(username, password); } else getDatabase().create(); if (getDatabase().getStorage().getUnderlying() instanceof OAbstractPaginatedStorage) ((OAbstractPaginatedStorage) getDatabase().getStorage().getUnderlying()).registerRecoverListener(this); } else { database = pool.acquire(); if (getDatabase().getStorage().getUnderlying() instanceof OAbstractPaginatedStorage) ((OAbstractPaginatedStorage) getDatabase().getStorage().getUnderlying()).registerRecoverListener(this); } makeActive(); putInInitializationStack(); }
/** * Closes a transaction. * * @param conclusion Can be SUCCESS for commit and FAILURE to rollback. */ @SuppressWarnings("deprecation") @Override public void stopTransaction(final Conclusion conclusion) { makeActive(); if (getDatabase().isClosed() || getDatabase().getTransaction() instanceof OTransactionNoTx || getDatabase().getTransaction().getStatus() != TXSTATUS.BEGUN) return; if (Conclusion.SUCCESS == conclusion) commit(); else rollback(); }
/** * @return a Non Transactional OrientGraph implementation from the current database in thread local. */ public static OrientGraphNoTx getGraphNoTx(final OModifiableBoolean shouldBeShutDown) { final ODatabaseDocumentInternal database = ODatabaseRecordThreadLocal.instance().get(); final OrientBaseGraph result = OrientBaseGraph.getActiveGraph(); if (result != null && (result instanceof OrientGraphNoTx)) { final ODatabaseDocumentInternal 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()) { ODatabaseRecordThreadLocal.instance().set(graphDb); shouldBeShutDown.setValue(false); return (OrientGraphNoTx) 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 (OrientGraphNoTx) OrientGraphFactory.getNoTxGraphImplFactory().getGraph((ODatabaseDocumentTx) database); }