if (db.getStorage().isRemote()) { isRemote = true;
public OTransactionIndexChanges getIndexChangesInternal(final String indexName) { if (getDatabase().getStorage().isRemote()) return null; return getIndexChanges(indexName); }
@ConsoleCommand(description = "Import a database into the current one", splitInWords = false, onlineHelp = "Console-Command-Import") public void importDatabase(@ConsoleParameter(name = "options", description = "Import options") final String text) throws IOException { checkForDatabase(); message("\nImporting database " + text + "..."); final List<String> items = OStringSerializerHelper.smartSplit(text, ' '); final String fileName = items.size() <= 0 || (items.get(1)).charAt(0) == '-' ? null : items.get(1); final String options = fileName != null ? text.substring((items.get(0)).length() + (items.get(1)).length() + 1).trim() : text; try { if (currentDatabase.getStorage().isRemote()) { ODatabaseImportRemote databaseImport = new ODatabaseImportRemote(currentDatabase, fileName, this); databaseImport.setOptions(options); databaseImport.importDatabase(); databaseImport.close(); } else { ODatabaseImport databaseImport = new ODatabaseImport(currentDatabase, fileName, this); databaseImport.setOptions(options); databaseImport.importDatabase(); databaseImport.close(); } } catch (ODatabaseImportException e) { printError(e); } }
public void end(final ODatabaseDocumentInternal iDatabase) { ODatabaseInternal<?> ownerDb = iDatabase.getDatabaseOwner(); if (disableSecurity) if (currentUser != null) // RE-ENABLE CHECK OF SECURITY ownerDb.setUser(currentUser); if (!enableCache) { ownerDb.getLocalCache().setEnable(!enableCache); } if (ownerDb instanceof ODatabaseDocument) { ((ODatabaseDocument) ownerDb).setRetainRecords(previousRetainRecords); if (disableValidation && !iDatabase.getStorage().isRemote()) ((ODatabaseDocument) ownerDb).setValidationEnabled(previousValidation); } while (ownerDb.getDatabaseOwner() != ownerDb) ownerDb = ownerDb.getDatabaseOwner(); if (disableHooks) if (removedHooks != null) { // RESTORE ALL REMOVED HOOKS for (Map.Entry<ORecordHook, ORecordHook.HOOK_POSITION> hook : removedHooks.entrySet()) { ownerDb.registerHook(hook.getKey(), hook.getValue()); } } }
@ConsoleCommand(description = "Commits transaction changes to the database") public void commit() throws IOException { checkForDatabase(); if (!currentDatabase.getTransaction().isActive()) { message("\nError: no active transaction is currently open."); return; } if (currentDatabase.getStorage().isRemote()) { message( "\nWARNING - Transactions are not supported from console in remote, please use an sql script: \neg.\n\nscript sql\nbegin;\n<your commands here>\ncommit;\nend\n\n"); return; } final long begin = System.currentTimeMillis(); final int txId = currentDatabase.getTransaction().getId(); currentDatabase.commit(); message("\nTransaction " + txId + " has been committed in " + (System.currentTimeMillis() - begin) + "ms"); }
if (disableValidation && !iDatabase.getStorage().isRemote()) {
@ConsoleCommand(description = "Rolls back transaction changes to the previous state") public void rollback() throws IOException { checkForDatabase(); if (!currentDatabase.getTransaction().isActive()) { message("\nError: no active transaction is running right now."); return; } if (currentDatabase.getStorage().isRemote()) { message( "\nWARNING - Transactions are not supported from console in remote, please use an sql script: \neg.\n\nscript sql\nbegin;\n<your commands here>\ncommit;\nend\n\n"); return; } final long begin = System.currentTimeMillis(); final int txId = currentDatabase.getTransaction().getId(); currentDatabase.rollback(); message("\nTransaction " + txId + " has been rollbacked in " + (System.currentTimeMillis() - begin) + "ms"); }
public void onPostIndexManagement() { final OIndex<?> autoShardingIndex = getAutoShardingIndex(); if (autoShardingIndex != null) { if (!getDatabase().getStorage().isRemote()) { // OVERRIDE CLUSTER SELECTION acquireSchemaWriteLock(); try { this.clusterSelection = new OAutoShardingClusterSelectionStrategy(this, autoShardingIndex); } finally { releaseSchemaWriteLock(); } } } else if (clusterSelection instanceof OAutoShardingClusterSelectionStrategy) { // REMOVE AUTO SHARDING CLUSTER SELECTION acquireSchemaWriteLock(); try { this.clusterSelection = owner.getClusterSelectionFactory().newInstanceOfDefaultClass(); } finally { releaseSchemaWriteLock(); } } }
@Override public <RET> RET execute(Object... iArgs) { ODatabaseDocumentInternal database = ODatabaseRecordThreadLocal.instance().get(); if (database.getStorage().isRemote()) { BackwardOLiveQueryResultListener listener = new BackwardOLiveQueryResultListener(); OLiveQueryMonitor monitor = database.live(getText(), listener, iArgs); listener.token = (int) monitor.getMonitorId(); ODocument doc = new ODocument(); doc.setProperty("token", listener.token); OLegacyResultSet<ODocument> result = new OBasicLegacyResultSet<>(); result.add(doc); return (RET) result; } return super.execute(iArgs); }
@ConsoleCommand(description = "Begins a transaction. All the changes will remain local") public void begin() throws IOException { checkForDatabase(); if (currentDatabase.getTransaction().isActive()) { message("\nError: an active transaction is currently open (id=" + currentDatabase.getTransaction().getId() + "). Commit or rollback before starting a new one."); return; } if (currentDatabase.getStorage().isRemote()) { message( "\nWARNING - Transactions are not supported from console in remote, please use an sql script: \neg.\n\nscript sql\nbegin;\n<your commands here>\ncommit;\nend\n\n"); return; } currentDatabase.begin(); message("\nTransaction " + currentDatabase.getTransaction().getId() + " is running"); }
public String getClusterName(final ORecord record) { if (ODatabaseRecordThreadLocal.instance().get().getStorage().isRemote()) // DON'T ASSIGN CLUSTER WITH REMOTE: SERVER KNOWS THE RIGHT CLUSTER BASED ON LOCALITY return null; int clusterId = record.getIdentity().getClusterId(); if (clusterId == ORID.CLUSTER_ID_INVALID) { // COMPUTE THE CLUSTER ID OClass schemaClass = null; if (record instanceof ODocument) schemaClass = ODocumentInternal.getImmutableSchemaClass(getDatabase(), (ODocument) record); if (schemaClass != null) { // FIND THE RIGHT CLUSTER AS CONFIGURED IN CLASS if (schemaClass.isAbstract()) throw new OSchemaException("Document belongs to abstract class '" + schemaClass.getName() + "' and cannot be saved"); clusterId = schemaClass.getClusterForNewInstance((ODocument) record); return database.getClusterNameById(clusterId); } else { return database.getClusterNameById(database.getStorage().getDefaultClusterId()); } } else { return database.getClusterNameById(clusterId); } }
public void checkAndConvert() { ODatabaseInternal database = ODatabaseRecordThreadLocal.instance().getIfDefined(); if (database != null && !database.getStorage().isRemote()) { if (isEmbedded() && ODatabaseRecordThreadLocal.instance().get().getSbTreeCollectionManager() != null && delegate.size() >= topThreshold) {