@Override public ODatabase activateOnCurrentThread() { if (internal != null) internal.activateOnCurrentThread(); return this; }
public static <T> T makeDbCall(final ODatabaseDocumentInternal databaseRecord, final ODbRelatedCall<T> function) { databaseRecord.activateOnCurrentThread(); return function.call(databaseRecord); } }
static <V> V supplyWithDatabase(final ODatabaseDocumentInternal database, final Supplier<V> callable) { if (!database.isActiveOnCurrentThread()) database.activateOnCurrentThread(); try { return callable.get(); } finally { ODatabaseRecordThreadLocal.INSTANCE.remove(); } }
static void runWithDatabase(final ODatabaseDocumentInternal database, final Runnable runnable) { if (!database.isActiveOnCurrentThread()) database.activateOnCurrentThread(); try { runnable.run(); } finally { ODatabaseRecordThreadLocal.INSTANCE.remove(); } }
/** * Closes the console freeing all the used resources. */ public void close() { if (currentDatabase != null) { currentDatabase.activateOnCurrentThread(); currentDatabase.close(); currentDatabase = null; } if (orientDB != null) { orientDB.close(); } currentResultSet = null; currentRecord = null; currentResult = null; commandBuffer.setLength(0); }
@Override protected String getContext() { final StringBuilder buffer = new StringBuilder(64); if (currentDatabase != null && currentDatabaseName != null) { currentDatabase.activateOnCurrentThread(); buffer.append(" {db="); buffer.append(currentDatabaseName); if (currentDatabase.getTransaction().isActive()) { buffer.append(" tx=["); buffer.append(currentDatabase.getTransaction().getEntryCount()); buffer.append(" entries]"); } } else if (urlConnection != null) { buffer.append(" {server="); buffer.append(urlConnection.getUrl()); } final String promptDateFormat = properties.get("promptDateFormat"); if (promptDateFormat != null) { buffer.append(" ("); final SimpleDateFormat df = new SimpleDateFormat(promptDateFormat); buffer.append(df.format(new Date())); buffer.append(")"); } if (buffer.length() > 0) buffer.append("}"); return buffer.toString(); }
@Override public ORID map(ORID rid) { if (rid == null) return null; if (!rid.isPersistent()) return null; databaseTwo.activateOnCurrentThread(); final OIdentifiable result = exportImportHashTable.get(rid); if (result == null) return null; return result.getIdentity(); } };
db.activateOnCurrentThread(); db.declareIntent(null); db.close();
if (tx) { db = mainDb.copy(); db.activateOnCurrentThread(); mainDb.activateOnCurrentThread();
if (tx) { db = mainDb.copy(); db.activateOnCurrentThread(); mainDb.activateOnCurrentThread();
if (tx) { db = mainDb.copy(); db.activateOnCurrentThread(); mainDb.activateOnCurrentThread();
protected void internalOpen() { if(internal == null ) { super.open(userName, password); }else { internal.activateOnCurrentThread(); internal.setStatus(STATUS.OPEN); } if (getMetadata().getSchema().countClasses() == 0) getMetadata().reload(); }
@Override public void unSubscribe() { ODatabaseDocumentInternal prev = ODatabaseRecordThreadLocal.instance().getIfDefined(); db.activateOnCurrentThread(); OLiveQueryHookV2.unsubscribe(token, db); if (prev != null) { ODatabaseRecordThreadLocal.instance().set(prev); } else { ODatabaseRecordThreadLocal.instance().remove(); } }
@ConsoleCommand(aliases = { "close database" }, description = "Disconnect from the current database", onlineHelp = "Console-Command-Disconnect") public void disconnect() { if (currentDatabase != null) { message("\nDisconnecting from the database [" + currentDatabaseName + "]..."); final OStorage stg = currentDatabase.getStorage(); currentDatabase.activateOnCurrentThread(); if (!currentDatabase.isClosed()) currentDatabase.close(); // FORCE CLOSING OF STORAGE: THIS CLEAN UP REMOTE CONNECTIONS if (stg != null) stg.close(true, false); currentDatabase = null; currentDatabaseName = null; currentRecord = null; message("OK"); out.println(); } urlConnection = null; if (orientDB != null) { orientDB.close(); } }
@Override public boolean authenticate(String username, String password) { ODatabaseDocumentInternal currentDB = getDatabase(); try { boolean inTransaction = currentDB.getTransaction().isActive(); IOrientDbSettings settings = OrientDbWebApplication.get().getOrientDbSettings(); ODatabaseDocumentInternal newDB = settings.getDatabasePoolFactory().get(settings.getDBUrl(), username, password).acquire(); if(newDB!=currentDB) { currentDB.activateOnCurrentThread(); currentDB.commit(); currentDB.close(); newDB.activateOnCurrentThread(); } setUser(username, password); userModel.setObject(newDB.getUser().getDocument()); // user = newDB.getMetadata().getSecurity().getUser(username); // newDB.setUser(user); if(inTransaction && !newDB.getTransaction().isActive()) newDB.begin(); return true; } catch (OSecurityAccessException e) { currentDB.activateOnCurrentThread(); return false; } }
@Override public boolean authenticate(String username, String password) { ODatabaseDocumentInternal currentDB = getDatabase(); try { boolean inTransaction = currentDB.getTransaction().isActive(); IOrientDbSettings settings = OrientDbWebApplication.get().getOrientDbSettings(); ODatabaseDocumentInternal newDB = settings.getDatabasePoolFactory().get(settings.getDBUrl(), username, password).acquire(); if(newDB!=currentDB) { currentDB.activateOnCurrentThread(); currentDB.commit(); currentDB.close(); newDB.activateOnCurrentThread(); } setUser(username, password); userModel.setObject(newDB.getUser().getDocument()); // user = newDB.getMetadata().getSecurity().getUser(username); // newDB.setUser(user); if(inTransaction && !newDB.getTransaction().isActive()) newDB.begin(); return true; } catch (OSecurityAccessException e) { currentDB.activateOnCurrentThread(); return false; } }
localDatabase.activateOnCurrentThread();
final ODatabaseDocumentInternal db = database.copy(); if (currentThreadLocal != null) { currentThreadLocal.activateOnCurrentThread(); } else { ODatabaseRecordThreadLocal.instance().set(null); db.activateOnCurrentThread(); try { OSQLAsynchQuery<T> query = new OSQLAsynchQuery<T>(OSQLNonBlockingQuery.this.getText(),