From ea4bbe7de5123688979c4270cdc0e3554fd5a95c Mon Sep 17 00:00:00 2001 From: Tglman Date: Mon, 27 Jan 2025 15:29:41 +0000 Subject: [PATCH] cleanup: removed legacy ODatabaseDocumentTx with relative OServerAdmin and helper APIs --- .../orient/client/db/ODatabaseHelper.java | 202 -- .../orient/client/remote/OServerAdmin.java | 262 --- .../core/db/document/ODatabaseDocumentTx.java | 1753 ----------------- .../document/ODatabaseDocumentTxInternal.java | 50 - 4 files changed, 2267 deletions(-) delete mode 100755 client/src/main/java/com/orientechnologies/orient/client/db/ODatabaseHelper.java delete mode 100755 client/src/main/java/com/orientechnologies/orient/client/remote/OServerAdmin.java delete mode 100755 core/src/main/java/com/orientechnologies/orient/core/db/document/ODatabaseDocumentTx.java delete mode 100644 core/src/main/java/com/orientechnologies/orient/core/db/document/ODatabaseDocumentTxInternal.java diff --git a/client/src/main/java/com/orientechnologies/orient/client/db/ODatabaseHelper.java b/client/src/main/java/com/orientechnologies/orient/client/db/ODatabaseHelper.java deleted file mode 100755 index 9ae6df2c888..00000000000 --- a/client/src/main/java/com/orientechnologies/orient/client/db/ODatabaseHelper.java +++ /dev/null @@ -1,202 +0,0 @@ -/* - * - * * Copyright 2010-2016 OrientDB LTD (http://orientdb.com) - * * - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * - * * For more information: http://orientdb.com - * - */ -package com.orientechnologies.orient.client.db; - -import com.orientechnologies.common.parser.OSystemVariableResolver; -import com.orientechnologies.orient.client.remote.OEngineRemote; -import com.orientechnologies.orient.client.remote.OServerAdmin; -import com.orientechnologies.orient.core.OConstants; -import com.orientechnologies.orient.core.Orient; -import com.orientechnologies.orient.core.db.ODatabase; -import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; -import com.orientechnologies.orient.core.exception.OConfigurationException; -import java.io.File; -import java.io.FileReader; -import java.io.IOException; - -@Deprecated -public class ODatabaseHelper { - @Deprecated - public static void createDatabase(ODatabase database, final String url) throws IOException { - createDatabase(database, url, "server", "plocal"); - } - - @Deprecated - public static void createDatabase(ODatabase database, final String url, String type) - throws IOException { - createDatabase(database, url, "server", type); - } - - @Deprecated - public static void openDatabase(ODatabase database) { - database.open("admin", "admin"); - } - - @Deprecated - public static void createDatabase( - ODatabase database, final String url, String directory, String type) throws IOException { - if (url.startsWith(OEngineRemote.NAME)) { - new OServerAdmin(url) - .connect("root", getServerRootPassword(directory)) - .createDatabase("document", type) - .close(); - } else { - database.create(); - database.close(); - } - } - - @Deprecated - public static void deleteDatabase(final ODatabase database, String storageType) - throws IOException { - deleteDatabase(database, "server", storageType); - } - - @Deprecated - public static void deleteDatabase( - final ODatabase database, final String directory, String storageType) throws IOException { - dropDatabase(database, directory, storageType); - } - - @Deprecated - public static void dropDatabase(final ODatabase database, String storageType) throws IOException { - dropDatabase(database, "server", storageType); - } - - @Deprecated - public static void dropDatabase( - final ODatabase database, final String directory, String storageType) throws IOException { - if (existsDatabase(database, storageType)) { - if (database.getURL().startsWith("remote:")) { - database.activateOnCurrentThread(); - database.close(); - OServerAdmin admin = - new OServerAdmin(database.getURL()).connect("root", getServerRootPassword(directory)); - admin.dropDatabase(storageType); - admin.close(); - } else { - if (database.isClosed()) openDatabase(database); - else database.activateOnCurrentThread(); - database.drop(); - } - } - } - - @Deprecated - public static boolean existsDatabase(final ODatabase database, String storageType) - throws IOException { - database.activateOnCurrentThread(); - if (database.getURL().startsWith("remote")) { - OServerAdmin admin = - new OServerAdmin(database.getURL()).connect("root", getServerRootPassword()); - boolean exist = admin.existsDatabase(storageType); - admin.close(); - return exist; - } - - return database.exists(); - } - - @Deprecated - public static boolean existsDatabase(final String url) throws IOException { - if (url.startsWith("remote")) { - OServerAdmin admin = new OServerAdmin(url).connect("root", getServerRootPassword()); - boolean exist = admin.existsDatabase(); - admin.close(); - return exist; - } - return new ODatabaseDocumentTx(url).exists(); - } - - @Deprecated - public static String getServerRootPassword() throws IOException { - return getServerRootPassword("server"); - } - - @Deprecated - protected static String getServerRootPassword(final String iDirectory) throws IOException { - String passwd = System.getProperty("ORIENTDB_ROOT_PASSWORD"); - if (passwd != null) return passwd; - - final File file = getConfigurationFile(iDirectory); - - final FileReader f = new FileReader(file); - final char[] buffer = new char[(int) file.length()]; - f.read(buffer); - f.close(); - - final String fileContent = new String(buffer); - // TODO search is wrong because if first user is not root tests will fail - int pos = fileContent.indexOf("password=\""); - pos += "password=\"".length(); - return fileContent.substring(pos, fileContent.indexOf('"', pos)); - } - - @Deprecated - protected static File getConfigurationFile(final String iDirectory) { - // LOAD SERVER CONFIG FILE TO EXTRACT THE ROOT'S PASSWORD - String sysProperty = System.getProperty("orientdb.config.file"); - File file = new File(sysProperty != null ? sysProperty : ""); - if (!file.exists()) { - sysProperty = System.getenv("CONFIG_FILE"); - file = new File(sysProperty != null ? sysProperty : ""); - } - if (!file.exists()) - file = - new File( - "../releases/orientdb-" - + OConstants.getRawVersion() - + "/config/orientdb-server-config.xml"); - if (!file.exists()) - file = - new File( - "../releases/orientdb-community-" - + OConstants.getRawVersion() - + "/config/orientdb-server-config.xml"); - if (!file.exists()) - file = - new File( - "../../releases/orientdb-" - + OConstants.getRawVersion() - + "/config/orientdb-server-config.xml"); - if (!file.exists()) - file = - new File( - "../../releases/orientdb-community-" - + OConstants.getRawVersion() - + "/config/orientdb-server-config.xml"); - if (!file.exists() && iDirectory != null) { - file = new File(iDirectory + "/config/orientdb-server-config.xml"); - if (!file.exists()) - file = new File("../" + iDirectory + "/config/orientdb-server-config.xml"); - } - if (!file.exists()) - file = - new File( - OSystemVariableResolver.resolveSystemVariables( - "${" + Orient.ORIENTDB_HOME + "}/config/orientdb-server-config.xml")); - if (!file.exists()) - throw new OConfigurationException( - "Cannot load file orientdb-server-config.xml to execute remote tests. Current directory" - + " is " - + new File(".").getAbsolutePath()); - return file; - } -} diff --git a/client/src/main/java/com/orientechnologies/orient/client/remote/OServerAdmin.java b/client/src/main/java/com/orientechnologies/orient/client/remote/OServerAdmin.java deleted file mode 100755 index 68dac7dca65..00000000000 --- a/client/src/main/java/com/orientechnologies/orient/client/remote/OServerAdmin.java +++ /dev/null @@ -1,262 +0,0 @@ -/* - * - * * Copyright 2010-2016 OrientDB LTD (http://orientdb.com) - * * - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * - * * For more information: http://orientdb.com - * - */ -package com.orientechnologies.orient.client.remote; - -import com.orientechnologies.orient.core.config.OGlobalConfiguration; -import com.orientechnologies.orient.core.db.ODatabaseType; -import com.orientechnologies.orient.core.db.OrientDBConfig; -import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTxInternal; -import com.orientechnologies.orient.core.exception.OStorageException; -import com.orientechnologies.orient.core.record.impl.ODocument; -import java.io.IOException; -import java.util.Map; -import java.util.Optional; - -/** Remote administration class of OrientDB Server instances. */ -@Deprecated -public class OServerAdmin { - protected OStorageRemoteSession session = new OStorageRemoteSession(-1); - protected String clientType = OStorageRemote.DRIVER_NAME; - protected boolean collectStats = true; - private final ORemoteURLs urls; - private final OrientDBRemote remote; - private String user; - private String password; - private Optional database; - - /** - * Creates the object passing a remote URL to connect. sessionToken - * - * @param iURL URL to connect. It supports only the "remote" storage type. - * @throws IOException - */ - @Deprecated - public OServerAdmin(String iURL) throws IOException { - String url = iURL; - if (url.startsWith(OEngineRemote.NAME)) url = url.substring(OEngineRemote.NAME.length() + 1); - - if (!url.contains("/")) url += "/"; - - remote = (OrientDBRemote) ODatabaseDocumentTxInternal.getOrCreateRemoteFactory(url); - urls = new ORemoteURLs(new String[] {}, remote.getContextConfiguration()); - String name = urls.parseServerUrls(url, remote.getContextConfiguration()); - if (name != null && name.length() != 0) { - this.database = Optional.of(name); - } else { - this.database = Optional.empty(); - } - } - - /** - * Connects to a remote server. - * - * @param iUserName Server's user name - * @param iUserPassword Server's password for the user name used - * @return The instance itself. Useful to execute method in chain - * @throws IOException - */ - @Deprecated - public synchronized OServerAdmin connect(final String iUserName, final String iUserPassword) - throws IOException { - - this.user = iUserName; - this.password = iUserPassword; - - return this; - } - - private void checkConnected() { - if (user == null || password == null) { - throw new OStorageException("OServerAdmin not connect use connect before do an operation"); - } - } - - /** - * Returns the list of databases on the connected remote server. - * - * @throws IOException - */ - @Deprecated - public synchronized Map listDatabases() throws IOException { - checkConnected(); - return remote.getDatabases(user, password); - } - - /** - * Creates a database in a remote server. - * - * @param iDatabaseType 'document' or 'graph' - * @param iStorageMode local or memory - * @return The instance itself. Useful to execute method in chain - * @throws IOException - */ - @Deprecated - public synchronized OServerAdmin createDatabase(final String iDatabaseType, String iStorageMode) - throws IOException { - return createDatabase(getStorageName(), iDatabaseType, iStorageMode); - } - - public synchronized String getStorageName() { - return database.get(); - } - - public synchronized OServerAdmin createDatabase( - final String iDatabaseName, final String iDatabaseType, final String iStorageMode) - throws IOException { - return createDatabase(iDatabaseName, iDatabaseType, iStorageMode, null); - } - - /** - * Creates a database in a remote server. - * - * @param iDatabaseName The database name - * @param iDatabaseType 'document' or 'graph' - * @param iStorageMode local or memory - * @param backupPath path to incremental backup which will be used to create database (optional) - * @return The instance itself. Useful to execute method in chain - * @throws IOException - */ - public synchronized OServerAdmin createDatabase( - final String iDatabaseName, - final String iDatabaseType, - final String iStorageMode, - final String backupPath) - throws IOException { - checkConnected(); - ODatabaseType storageMode; - if (iStorageMode == null) storageMode = ODatabaseType.PLOCAL; - else storageMode = ODatabaseType.valueOf(iStorageMode.toUpperCase()); - OrientDBConfig config = - OrientDBConfig.builder().addConfig(OGlobalConfiguration.CREATE_DEFAULT_USERS, true).build(); - if (backupPath != null) { - remote.restore(iDatabaseName, user, password, storageMode, backupPath, null); - } else { - remote.create(iDatabaseName, user, password, storageMode, config); - } - - return this; - } - - /** - * Checks if a database exists in the remote server. - * - * @return true if exists, otherwise false - */ - public synchronized boolean existsDatabase() throws IOException { - return existsDatabase(database.get(), null); - } - - /** - * Checks if a database exists in the remote server. - * - * @param iDatabaseName The database name - * @param storageType Storage type between "plocal" or "memory". - * @return true if exists, otherwise false - * @throws IOException - */ - public synchronized boolean existsDatabase(final String iDatabaseName, final String storageType) - throws IOException { - checkConnected(); - return remote.exists(iDatabaseName, user, password); - } - - /** - * Checks if a database exists in the remote server. - * - * @param storageType Storage type between "plocal" or "memory". - * @return true if exists, otherwise false - * @throws IOException - */ - public synchronized boolean existsDatabase(final String storageType) throws IOException { - checkConnected(); - return existsDatabase(getStorageName(), storageType); - } - - /** - * Drops a database from a remote server instance. - * - * @param iDatabaseName The database name - * @param storageType Storage type between "plocal" or "memory". - * @return The instance itself. Useful to execute method in chain - * @throws IOException - */ - public synchronized OServerAdmin dropDatabase( - final String iDatabaseName, final String storageType) throws IOException { - checkConnected(); - remote.drop(iDatabaseName, user, password); - return this; - } - - /** - * Drops a database from a remote server instance. - * - * @param storageType Storage type between "plocal" or "memory". - * @return The instance itself. Useful to execute method in chain - * @throws IOException - */ - public synchronized OServerAdmin dropDatabase(final String storageType) throws IOException { - return dropDatabase(getStorageName(), storageType); - } - - /** - * Gets the cluster status. - * - * @return the JSON containing the current cluster structure - */ - public ODocument clusterStatus() { - checkConnected(); - return remote.getClusterStatus(user, password); - } - - public synchronized Map getGlobalConfigurations() throws IOException { - checkConnected(); - return remote.getGlobalConfigurations(user, password); - } - - public synchronized String getGlobalConfiguration(final OGlobalConfiguration config) - throws IOException { - checkConnected(); - return remote.getGlobalConfiguration(user, password, config); - } - - public synchronized OServerAdmin setGlobalConfiguration( - final OGlobalConfiguration config, final Object iValue) throws IOException { - checkConnected(); - remote.setGlobalConfiguration(user, password, config, iValue.toString()); - return this; - } - - /** Close the connection if open. */ - public synchronized void close() {} - - public synchronized void close(boolean iForce) {} - - public synchronized String getURL() { - String url = String.join(";", this.urls.getUrls()); - if (database.isPresent()) { - url += "/" + database.get(); - } - return "remote:" + url; - } - - public boolean isConnected() { - return user != null && password != null; - } -} diff --git a/core/src/main/java/com/orientechnologies/orient/core/db/document/ODatabaseDocumentTx.java b/core/src/main/java/com/orientechnologies/orient/core/db/document/ODatabaseDocumentTx.java deleted file mode 100755 index 243d587c76c..00000000000 --- a/core/src/main/java/com/orientechnologies/orient/core/db/document/ODatabaseDocumentTx.java +++ /dev/null @@ -1,1753 +0,0 @@ -package com.orientechnologies.orient.core.db.document; - -import static com.orientechnologies.orient.core.db.document.ODatabaseDocumentTxInternal.closeAllOnShutdown; - -import com.orientechnologies.common.concur.lock.OLockException; -import com.orientechnologies.orient.core.Orient; -import com.orientechnologies.orient.core.cache.OLocalRecordCache; -import com.orientechnologies.orient.core.command.OCommandOutputListener; -import com.orientechnologies.orient.core.command.script.OCommandScriptException; -import com.orientechnologies.orient.core.config.OContextConfiguration; -import com.orientechnologies.orient.core.config.OGlobalConfiguration; -import com.orientechnologies.orient.core.conflict.ORecordConflictStrategy; -import com.orientechnologies.orient.core.db.ODatabase; -import com.orientechnologies.orient.core.db.ODatabaseDocumentInternal; -import com.orientechnologies.orient.core.db.ODatabaseInternal; -import com.orientechnologies.orient.core.db.ODatabaseListener; -import com.orientechnologies.orient.core.db.ODatabaseRecordThreadLocal; -import com.orientechnologies.orient.core.db.ODatabaseType; -import com.orientechnologies.orient.core.db.OLiveQueryMonitor; -import com.orientechnologies.orient.core.db.OLiveQueryResultListener; -import com.orientechnologies.orient.core.db.OSharedContext; -import com.orientechnologies.orient.core.db.OrientDB; -import com.orientechnologies.orient.core.db.OrientDBConfig; -import com.orientechnologies.orient.core.db.OrientDBConfigBuilder; -import com.orientechnologies.orient.core.db.OrientDBInternal; -import com.orientechnologies.orient.core.db.record.OCurrentStorageComponentsFactory; -import com.orientechnologies.orient.core.db.record.OIdentifiable; -import com.orientechnologies.orient.core.dictionary.ODictionary; -import com.orientechnologies.orient.core.exception.OCommandExecutionException; -import com.orientechnologies.orient.core.exception.ODatabaseException; -import com.orientechnologies.orient.core.exception.ORecordNotFoundException; -import com.orientechnologies.orient.core.exception.OTransactionException; -import com.orientechnologies.orient.core.hook.ORecordHook; -import com.orientechnologies.orient.core.id.ORID; -import com.orientechnologies.orient.core.id.ORecordId; -import com.orientechnologies.orient.core.iterator.ORecordIteratorClass; -import com.orientechnologies.orient.core.iterator.ORecordIteratorCluster; -import com.orientechnologies.orient.core.metadata.OMetadataInternal; -import com.orientechnologies.orient.core.metadata.schema.OClass; -import com.orientechnologies.orient.core.metadata.schema.OView; -import com.orientechnologies.orient.core.metadata.security.ORule; -import com.orientechnologies.orient.core.metadata.security.OSecurityUser; -import com.orientechnologies.orient.core.metadata.security.OToken; -import com.orientechnologies.orient.core.metadata.sequence.OSequenceAction; -import com.orientechnologies.orient.core.record.OEdge; -import com.orientechnologies.orient.core.record.OElement; -import com.orientechnologies.orient.core.record.ORecord; -import com.orientechnologies.orient.core.record.OVertex; -import com.orientechnologies.orient.core.record.impl.OBlob; -import com.orientechnologies.orient.core.record.impl.ODocument; -import com.orientechnologies.orient.core.record.impl.ORecordBytes; -import com.orientechnologies.orient.core.serialization.serializer.binary.OBinarySerializerFactory; -import com.orientechnologies.orient.core.serialization.serializer.record.ORecordSerializer; -import com.orientechnologies.orient.core.serialization.serializer.record.ORecordSerializerFactory; -import com.orientechnologies.orient.core.shutdown.OShutdownHandler; -import com.orientechnologies.orient.core.sql.OCommandSQLParsingException; -import com.orientechnologies.orient.core.sql.executor.OResultSet; -import com.orientechnologies.orient.core.storage.ORecordCallback; -import com.orientechnologies.orient.core.storage.ORecordMetadata; -import com.orientechnologies.orient.core.storage.OStorage; -import com.orientechnologies.orient.core.storage.OStorageInfo; -import com.orientechnologies.orient.core.storage.ridbag.sbtree.OBonsaiCollectionPointer; -import com.orientechnologies.orient.core.storage.ridbag.sbtree.OSBTreeCollectionManager; -import com.orientechnologies.orient.core.tx.OTransaction; -import com.orientechnologies.orient.core.tx.OTransactionAbstract; -import com.orientechnologies.orient.core.tx.OTransactionInternal; -import com.orientechnologies.orient.core.tx.OTransactionOptimistic; -import com.orientechnologies.orient.core.util.OURLConnection; -import com.orientechnologies.orient.core.util.OURLHelper; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; -import java.util.UUID; -import java.util.concurrent.Callable; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicReference; -import java.util.concurrent.locks.Lock; -import java.util.concurrent.locks.ReentrantLock; - -/** Created by tglman on 20/07/16. @Deprecated use {@link OrientDB} instead. */ -@Deprecated -public class ODatabaseDocumentTx implements ODatabaseDocumentInternal { - - protected static ConcurrentMap embedded = new ConcurrentHashMap<>(); - protected static ConcurrentMap remote = new ConcurrentHashMap<>(); - - protected static final Lock embeddedLock = new ReentrantLock(); - protected static final Lock remoteLock = new ReentrantLock(); - - protected ODatabaseDocumentInternal internal; - private final String url; - private OrientDBInternal factory; - private final String type; - private final String dbName; - private final String baseUrl; - private final Map preopenProperties = new HashMap<>(); - private final Map preopenAttributes = new HashMap<>(); - // TODO review for the case of browseListener before open. - private final Set preopenListener = new HashSet<>(); - private ODatabaseInternal databaseOwner; - private OStorage delegateStorage; - private ORecordConflictStrategy conflictStrategy; - private ORecordSerializer serializer; - protected final AtomicReference owner = new AtomicReference(); - private final boolean ownerProtection; - - private static final OShutdownHandler shutdownHandler = - new OShutdownHandler() { - @Override - public void shutdown() throws Exception { - closeAllOnShutdown(); - } - - @Override - public int getPriority() { - return 1000; - } - }; - - static { - Orient.instance() - .registerOrientStartupListener(() -> Orient.instance().addShutdownHandler(shutdownHandler)); - Orient.instance().addShutdownHandler(shutdownHandler); - } - - public static void closeAll() { - embeddedLock.lock(); - try { - for (OrientDBInternal factory : embedded.values()) { - factory.close(); - } - embedded.clear(); - } finally { - embeddedLock.unlock(); - } - - remoteLock.lock(); - try { - for (OrientDBInternal factory : remote.values()) { - factory.close(); - } - remote.clear(); - } finally { - remoteLock.unlock(); - } - } - - protected static OrientDBInternal getOrCreateRemoteFactory(String baseUrl) { - OrientDBInternal factory; - - remoteLock.lock(); - try { - factory = remote.get(baseUrl); - if (factory == null || !factory.isOpen()) { - factory = OrientDBInternal.fromUrl("remote:" + baseUrl, null); - remote.put(baseUrl, factory); - } - } finally { - remoteLock.unlock(); - } - return factory; - } - - protected static OrientDBInternal getOrCreateEmbeddedFactory( - String baseUrl, OrientDBConfig config) { - if (!baseUrl.endsWith("/")) { - baseUrl += "/"; - } - OrientDBInternal factory; - embeddedLock.lock(); - try { - factory = embedded.get(baseUrl); - if (factory == null || !factory.isOpen()) { - try { - factory = OrientDBInternal.distributed(baseUrl, config); - } catch (ODatabaseException ignore) { - factory = OrientDBInternal.embedded(baseUrl, config); - } - embedded.put(baseUrl, factory); - } - } finally { - embeddedLock.unlock(); - } - - return factory; - } - - /** @Deprecated use {{@link OrientDB}} instead. */ - @Deprecated - public ODatabaseDocumentTx(String url) { - this(url, true); - } - - protected ODatabaseDocumentTx(String url, boolean ownerProtection) { - - OURLConnection connection = OURLHelper.parse(url); - this.url = connection.getUrl(); - type = connection.getType(); - baseUrl = connection.getPath(); - dbName = connection.getDbName(); - this.ownerProtection = ownerProtection; - } - - protected ODatabaseDocumentTx(ODatabaseDocumentInternal ref, String baseUrl) { - url = ref.getURL(); - type = ref.getType(); - this.baseUrl = baseUrl; - dbName = ref.getName(); - internal = ref; - this.ownerProtection = true; - } - - public static ORecordSerializer getDefaultSerializer() { - return ODatabaseDocumentAbstract.getDefaultSerializer(); - } - - public static void setDefaultSerializer(ORecordSerializer defaultSerializer) { - ODatabaseDocumentAbstract.setDefaultSerializer(defaultSerializer); - } - - @Override - public OCurrentStorageComponentsFactory getStorageVersions() { - if (internal == null) { - return null; - } - return internal.getStorageVersions(); - } - - @Override - public OSBTreeCollectionManager getSbTreeCollectionManager() { - if (internal == null) { - return null; - } - return internal.getSbTreeCollectionManager(); - } - - @Override - public OBinarySerializerFactory getSerializerFactory() { - checkOpenness(); - return internal.getSerializerFactory(); - } - - @Override - public ORecordSerializer getSerializer() { - if (internal == null) { - if (serializer != null) { - return serializer; - } - return ORecordSerializerFactory.instance().getDefaultRecordSerializer(); - } - return internal.getSerializer(); - } - - @Override - public int assignAndCheckCluster(ORecord record, String iClusterName) { - return internal.assignAndCheckCluster(record, iClusterName); - } - - @Override - public RET loadIfVersionIsNotLatest( - ORID rid, int recordVersion, String fetchPlan, boolean ignoreCache) - throws ORecordNotFoundException { - checkOpenness(); - return internal.loadIfVersionIsNotLatest(rid, recordVersion, fetchPlan, ignoreCache); - } - - @Override - public void reloadUser() { - checkOpenness(); - internal.reloadUser(); - } - - @Override - public ORecordHook.RESULT callbackHooks(ORecordHook.TYPE type, OIdentifiable id) { - checkOpenness(); - return internal.callbackHooks(type, id); - } - - @Override - public RET executeReadRecord( - ORecordId rid, - ORecord iRecord, - int recordVersion, - String fetchPlan, - boolean ignoreCache, - boolean iUpdateCache, - boolean loadTombstones, - OStorage.LOCKING_STRATEGY lockingStrategy, - RecordReader recordReader) { - checkOpenness(); - return internal.executeReadRecord( - rid, - iRecord, - recordVersion, - fetchPlan, - ignoreCache, - iUpdateCache, - loadTombstones, - lockingStrategy, - recordReader); - } - - @Override - public void executeDeleteRecord( - OIdentifiable record, - int iVersion, - boolean iRequired, - OPERATION_MODE iMode, - boolean prohibitTombstones) { - checkOpenness(); - internal.executeDeleteRecord(record, iVersion, iRequired, iMode, prohibitTombstones); - } - - @Override - public void setDefaultTransactionMode( - Map noTxLocks) { - checkOpenness(); - internal.setDefaultTransactionMode(noTxLocks); - } - - @Override - public OMetadataInternal getMetadata() { - checkOpenness(); - return internal.getMetadata(); - } - - @Override - public > DB registerHook(ORecordHook iHookImpl) { - checkOpenness(); - internal.registerHook(iHookImpl); - return (DB) this; - } - - @Override - public > DB registerHook( - ORecordHook iHookImpl, ORecordHook.HOOK_POSITION iPosition) { - checkOpenness(); - internal.registerHook(iHookImpl, iPosition); - return (DB) this; - } - - @Override - public Map getHooks() { - checkOpenness(); - return internal.getHooks(); - } - - @Override - public > DB unregisterHook(ORecordHook iHookImpl) { - checkOpenness(); - internal.unregisterHook(iHookImpl); - return (DB) this; - } - - @Override - public boolean isMVCC() { - return false; - } - - @Override - public Iterable getListeners() { - return internal.getListeners(); - } - - @Override - public > DB setMVCC(boolean iValue) { - return null; - } - - @Override - public String getType() { - return this.type; - } - - @Override - public ORecordConflictStrategy getConflictStrategy() { - return internal.getConflictStrategy(); - } - - @Override - public > DB setConflictStrategy(String iStrategyName) { - if (internal != null) { - internal.setConflictStrategy(iStrategyName); - } else { - conflictStrategy = Orient.instance().getRecordConflictStrategy().getStrategy(iStrategyName); - } - return (DB) this; - } - - @Override - public > DB setConflictStrategy(ORecordConflictStrategy iResolver) { - if (internal != null) { - internal.setConflictStrategy(iResolver); - } else { - conflictStrategy = iResolver; - } - return (DB) this; - } - - @Override - public String incrementalBackup(String path) { - checkOpenness(); - return internal.incrementalBackup(path); - } - - @Override - public ODatabaseDocumentTx copy() { - checkOpenness(); - return new ODatabaseDocumentTx(this.internal.copy(), this.baseUrl); - } - - @Override - public void checkIfActive() { - internal.checkIfActive(); - } - - protected void checkOpenness() { - if (internal == null) { - throw new ODatabaseException("Database '" + getURL() + "' is closed"); - } - } - - @Override - public void callOnOpenListeners() { - checkOpenness(); - internal.callOnOpenListeners(); - } - - @Override - public void callOnCloseListeners() { - checkOpenness(); - internal.callOnCloseListeners(); - } - - @Override - @Deprecated - public OStorage getStorage() { - if (internal == null) { - return delegateStorage; - } - return internal.getStorage(); - } - - @Override - public void setUser(OSecurityUser user) { - internal.setUser(user); - } - - @Override - public void replaceStorage(OStorage iNewStorage) { - internal.replaceStorage(iNewStorage); - } - - @Override - public void resetInitialization() { - if (internal != null) { - internal.resetInitialization(); - } - } - - @Override - public ODatabaseInternal getDatabaseOwner() { - ODatabaseInternal current = databaseOwner; - - while (current != null && current != this && current.getDatabaseOwner() != current) { - current = current.getDatabaseOwner(); - } - if (current == null) { - return this; - } - return current; - } - - @Override - public ODatabaseInternal setDatabaseOwner(ODatabaseInternal iOwner) { - databaseOwner = iOwner; - if (internal != null) { - internal.setDatabaseOwner(iOwner); - } - return this; - } - - @Override - public DB getUnderlying() { - return internal.getUnderlying(); - } - - @Override - public void setInternal(ATTRIBUTES attribute, Object iValue) { - checkOpenness(); - internal.setInternal(attribute, iValue); - } - - @Override - public DB open(OToken iToken) { - throw new UnsupportedOperationException(); - } - - @Override - public OSharedContext getSharedContext() { - if (internal == null) { - return null; - } - return internal.getSharedContext(); - } - - @Override - public ORecordIteratorClass browseClass(String iClassName) { - checkOpenness(); - return internal.browseClass(iClassName); - } - - @Override - public ORecordIteratorClass browseClass(String iClassName, boolean iPolymorphic) { - checkOpenness(); - return internal.browseClass(iClassName, iPolymorphic); - } - - @Override - public void freeze() { - checkOpenness(); - internal.freeze(); - } - - @Override - public void release() { - checkOpenness(); - internal.release(); - } - - @Override - public void freeze(boolean throwException) { - checkOpenness(); - internal.freeze(throwException); - } - - public OVertex newVertex(final String iClassName) { - checkOpenness(); - return internal.newVertex(iClassName); - } - - @Override - public OVertex newVertex(OClass type) { - checkOpenness(); - return internal.newVertex(type); - } - - @Override - public OEdge newEdge(OVertex from, OVertex to, String type) { - checkOpenness(); - return internal.newEdge(from, to, type); - } - - @Override - public OEdge newEdge(OVertex from, OVertex to, OClass type) { - checkOpenness(); - return internal.newEdge(from, to, type); - } - - @Override - public OElement newElement() { - checkOpenness(); - return internal.newInstance(); - } - - @Override - public OElement newElement(String className) { - checkOpenness(); - return internal.newElement(className); - } - - @Override - public OElement newEmbeddedElement() { - checkOpenness(); - return internal.newEmbeddedElement(); - } - - @Override - public OElement newEmbeddedElement(String className) { - checkOpenness(); - return internal.newEmbeddedElement(className); - } - - public boolean isUseLightweightEdges() { - return internal.isUseLightweightEdges(); - } - - public void setUseLightweightEdges(boolean b) { - internal.setUseLightweightEdges(b); - } - - @Override - public ODocument newInstance() { - checkOpenness(); - return internal.newInstance(); - } - - /** {@inheritDoc} */ - @Override - @Deprecated - public ODictionary getDictionary() { - checkOpenness(); - return internal.getDictionary(); - } - - @Override - public OSecurityUser getUser() { - if (internal != null) { - return internal.getUser(); - } - return null; - } - - @Override - public RET load(ORecord iObject) { - checkOpenness(); - return internal.load(iObject); - } - - @Override - public RET load(ORecord iObject, String iFetchPlan) { - checkOpenness(); - return internal.load(iObject, iFetchPlan); - } - - @Override - public RET load(ORecord iObject, String iFetchPlan, boolean iIgnoreCache) { - checkOpenness(); - return internal.load(iObject, iFetchPlan, iIgnoreCache); - } - - @Override - public RET reload( - ORecord iObject, String iFetchPlan, boolean iIgnoreCache) { - checkOpenness(); - return internal.reload(iObject, iFetchPlan, iIgnoreCache); - } - - @Override - public RET reload( - ORecord iObject, String iFetchPlan, boolean iIgnoreCache, boolean force) { - checkOpenness(); - return internal.reload(iObject, iFetchPlan, iIgnoreCache, force); - } - - @Override - public RET load(ORID recordId) { - checkOpenness(); - return internal.load(recordId); - } - - @Override - public RET load(ORID iRecordId, String iFetchPlan) { - checkOpenness(); - return internal.load(iRecordId, iFetchPlan); - } - - @Override - public RET load(ORID iRecordId, String iFetchPlan, boolean iIgnoreCache) { - checkOpenness(); - return internal.load(iRecordId, iFetchPlan, iIgnoreCache); - } - - @Override - public RET save(ORecord iObject) { - checkOpenness(); - return internal.save(iObject); - } - - @Override - public RET save( - ORecord iObject, - OPERATION_MODE iMode, - boolean iForceCreate, - ORecordCallback iRecordCreatedCallback, - ORecordCallback iRecordUpdatedCallback) { - checkOpenness(); - return internal.save( - iObject, iMode, iForceCreate, iRecordCreatedCallback, iRecordUpdatedCallback); - } - - @Override - public RET save(ORecord iObject, String iClusterName) { - checkOpenness(); - return internal.save(iObject, iClusterName); - } - - @Override - public RET save( - ORecord iObject, - String iClusterName, - OPERATION_MODE iMode, - boolean iForceCreate, - ORecordCallback iRecordCreatedCallback, - ORecordCallback iRecordUpdatedCallback) { - checkOpenness(); - return internal.save( - iObject, iClusterName, iMode, iForceCreate, iRecordCreatedCallback, iRecordUpdatedCallback); - } - - @Override - public ODatabase delete(ORecord iObject) { - checkOpenness(); - internal.delete(iObject); - return this; - } - - @Override - public ODatabase delete(ORID iRID) { - checkOpenness(); - internal.delete(iRID); - return this; - } - - @Override - public ODatabase delete(ORID iRID, int iVersion) { - checkOpenness(); - internal.delete(iRID, iVersion); - return this; - } - - @Override - public ODatabaseDocumentInternal cleanOutRecord(ORID rid, int version) { - checkOpenness(); - internal.cleanOutRecord(rid, version); - return this; - } - - @Override - public OTransaction getTransaction() { - checkOpenness(); - return internal.getTransaction(); - } - - @Override - public ODatabase begin() { - checkOpenness(); - internal.begin(); - return this; - } - - @Override - public ODatabase begin(OTransaction.TXTYPE iStatus) { - checkOpenness(); - internal.begin(iStatus); - return this; - } - - @Override - public ODatabase begin(OTransaction iTx) throws OTransactionException { - checkOpenness(); - internal.begin(iTx); - return this; - } - - @Override - public void rawBegin(OTransaction transaction) { - throw new UnsupportedOperationException("private api"); - } - - @Override - public ODatabase commit() throws OTransactionException { - checkOpenness(); - internal.commit(); - return this; - } - - @Override - public ODatabase commit(boolean force) throws OTransactionException { - checkOpenness(); - internal.commit(force); - return this; - } - - @Override - public ODatabase rollback() throws OTransactionException { - checkOpenness(); - internal.rollback(); - return this; - } - - @Override - public ODatabase rollback(boolean force) throws OTransactionException { - checkOpenness(); - internal.rollback(force); - return this; - } - - @Override - public ORecordIteratorCluster browseCluster(String iClusterName) { - checkOpenness(); - return internal.browseCluster(iClusterName); - } - - @Override - public ORecordIteratorCluster browseCluster( - String iClusterName, - long startClusterPosition, - long endClusterPosition, - boolean loadTombstones) { - checkOpenness(); - return internal.browseCluster( - iClusterName, startClusterPosition, endClusterPosition, loadTombstones); - } - - @Override - public ORecordIteratorCluster browseCluster( - String iClusterName, Class iRecordClass) { - checkOpenness(); - return internal.browseCluster(iClusterName, iRecordClass); - } - - @Override - public ORecordIteratorCluster browseCluster( - String iClusterName, - Class iRecordClass, - long startClusterPosition, - long endClusterPosition) { - checkOpenness(); - return internal.browseCluster( - iClusterName, iRecordClass, startClusterPosition, endClusterPosition); - } - - @Override - public ORecordIteratorCluster browseCluster( - String iClusterName, - Class iRecordClass, - long startClusterPosition, - long endClusterPosition, - boolean loadTombstones) { - checkOpenness(); - return internal.browseCluster( - iClusterName, iRecordClass, startClusterPosition, endClusterPosition, loadTombstones); - } - - @Override - public RET getRecord(OIdentifiable iIdentifiable) { - checkOpenness(); - return internal.getRecord(iIdentifiable); - } - - @Override - public byte getRecordType() { - checkOpenness(); - return internal.getRecordType(); - } - - @Override - public boolean isRetainRecords() { - checkOpenness(); - return internal.isRetainRecords(); - } - - @Override - public ODatabaseDocument setRetainRecords(boolean iValue) { - checkOpenness(); - return internal.setRetainRecords(iValue); - } - - @Override - public DB checkSecurity( - ORule.ResourceGeneric resourceGeneric, String resourceSpecific, int iOperation) { - checkOpenness(); - internal.checkSecurity(resourceGeneric, resourceSpecific, iOperation); - return (DB) this; - } - - @Override - public DB checkSecurity( - ORule.ResourceGeneric iResourceGeneric, int iOperation, Object iResourceSpecific) { - checkOpenness(); - internal.checkSecurity(iResourceGeneric, iOperation, iResourceSpecific); - return (DB) this; - } - - @Override - public DB checkSecurity( - ORule.ResourceGeneric iResourceGeneric, int iOperation, Object... iResourcesSpecific) { - checkOpenness(); - internal.checkSecurity(iResourceGeneric, iOperation, iResourcesSpecific); - return (DB) this; - } - - @Override - public boolean isValidationEnabled() { - checkOpenness(); - return internal.isValidationEnabled(); - } - - @Override - public DB setValidationEnabled(boolean iEnabled) { - checkOpenness(); - internal.setValidationEnabled(iEnabled); - return (DB) this; - } - - @Override - public DB checkSecurity(String iResource, int iOperation) { - checkOpenness(); - internal.checkSecurity(iResource, iOperation); - return (DB) this; - } - - @Override - public DB checkSecurity( - String iResourceGeneric, int iOperation, Object iResourceSpecific) { - checkOpenness(); - internal.checkSecurity(iResourceGeneric, iOperation, iResourceSpecific); - return (DB) this; - } - - @Override - public DB checkSecurity( - String iResourceGeneric, int iOperation, Object... iResourcesSpecific) { - checkOpenness(); - internal.checkSecurity(iResourceGeneric, iOperation, iResourcesSpecific); - return (DB) this; - } - - @Override - public boolean isPooled() { - return false; - } - - @Override - public DB open(String iUserName, String iUserPassword) { - try { - if ("remote".equals(type)) { - factory = getOrCreateRemoteFactory(baseUrl); - OrientDBConfig config = buildConfig(null); - internal = factory.open(dbName, iUserName, iUserPassword, config); - - } else { - factory = getOrCreateEmbeddedFactory(baseUrl, null); - OrientDBConfig config = buildConfig(null); - internal = factory.open(dbName, iUserName, iUserPassword, config); - } - if (databaseOwner != null) { - internal.setDatabaseOwner(databaseOwner); - } - if (conflictStrategy != null) { - internal.setConflictStrategy(conflictStrategy); - } - if (serializer != null) { - internal.setSerializer(serializer); - } - for (Entry pro : preopenProperties.entrySet()) { - internal.setProperty(pro.getKey(), pro.getValue()); - } - } catch (RuntimeException e) { - clearOwner(); - throw e; - } - return (DB) this; - } - - protected void setupThreadOwner() { - if (!ownerProtection) { - return; - } - - final Thread current = Thread.currentThread(); - final Thread o = owner.get(); - - if (o != null || !owner.compareAndSet(null, current)) { - throw new IllegalStateException( - "Current instance is owned by other thread '" + (o != null ? o.getName() : "?") + "'"); - } - } - - protected void clearOwner() { - if (!ownerProtection) { - return; - } - owner.set(null); - } - - @Override - public DB create() { - return create((Map) null); - } - - @Override - @Deprecated - public DB create(String incrementalBackupPath) { - throw new UnsupportedOperationException(); - } - - @Override - public DB create(Map iInitialSettings) { - try { - OrientDBConfig config = buildConfig(iInitialSettings); - if ("remote".equals(type)) { - throw new UnsupportedOperationException(); - } else if ("memory".equals(type)) { - factory = getOrCreateEmbeddedFactory(baseUrl, null); - factory.create(dbName, null, null, ODatabaseType.MEMORY, config); - OrientDBConfig openConfig = - OrientDBConfig.builder().fromContext(config.getConfigurations()).build(); - internal = factory.open(dbName, "admin", "admin", openConfig); - for (Map.Entry attr : preopenAttributes.entrySet()) { - internal.set(attr.getKey(), attr.getValue()); - } - - for (ODatabaseListener oDatabaseListener : preopenListener) { - internal.registerListener(oDatabaseListener); - } - - } else { - factory = getOrCreateEmbeddedFactory(baseUrl, null); - factory.create(dbName, null, null, ODatabaseType.PLOCAL, config); - OrientDBConfig openConfig = - OrientDBConfig.builder().fromContext(config.getConfigurations()).build(); - internal = factory.open(dbName, "admin", "admin", openConfig); - for (Map.Entry attr : preopenAttributes.entrySet()) { - internal.set(attr.getKey(), attr.getValue()); - } - - for (ODatabaseListener oDatabaseListener : preopenListener) { - internal.registerListener(oDatabaseListener); - } - } - if (databaseOwner != null) { - internal.setDatabaseOwner(databaseOwner); - } - if (conflictStrategy != null) { - internal.setConflictStrategy(conflictStrategy); - } - if (serializer != null) { - internal.setSerializer(serializer); - } - for (Entry pro : preopenProperties.entrySet()) { - internal.setProperty(pro.getKey(), pro.getValue()); - } - } catch (RuntimeException e) { - clearOwner(); - throw e; - } - return (DB) this; - } - - @Override - public ODatabase activateOnCurrentThread() { - if (internal != null) { - internal.activateOnCurrentThread(); - } - return this; - } - - @Override - public boolean isActiveOnCurrentThread() { - if (internal != null) { - return internal.isActiveOnCurrentThread(); - } - return false; - } - - @Override - public void reload() { - checkOpenness(); - internal.reload(); - } - - @Override - public void drop() { - checkOpenness(); - internal.callOnDropListeners(); - ODatabaseRecordThreadLocal.instance().remove(); - factory.drop(this.getName(), null, null); - this.internal = null; - clearOwner(); - } - - @Override - public OContextConfiguration getConfiguration() { - checkOpenness(); - return internal.getConfiguration(); - } - - @Override - public boolean exists() { - if (internal != null) { - return true; - } - if ("remote".equals(type)) { - throw new UnsupportedOperationException(); - } else { - factory = getOrCreateEmbeddedFactory(baseUrl, null); - return factory.exists(dbName, null, null); - } - } - - @Override - public void close() { - clearOwner(); - if (internal != null) { - delegateStorage = internal.getStorage(); - internal.close(); - internal = null; - } - } - - @Override - public STATUS getStatus() { - return internal.getStatus(); - } - - @Override - public DB setStatus(STATUS iStatus) { - checkOpenness(); - internal.setStatus(iStatus); - return (DB) this; - } - - @Override - public long getSize() { - checkOpenness(); - return internal.getSize(); - } - - @Override - public String getName() { - return dbName; - } - - @Override - public String getURL() { - return url; - } - - @Override - public OLocalRecordCache getLocalCache() { - checkOpenness(); - return internal.getLocalCache(); - } - - @Override - public int getDefaultClusterId() { - checkOpenness(); - return internal.getDefaultClusterId(); - } - - @Override - public int getClusters() { - checkOpenness(); - return internal.getClusters(); - } - - @Override - public boolean existsCluster(String iClusterName) { - checkOpenness(); - return internal.existsCluster(iClusterName); - } - - @Override - public Collection getClusterNames() { - checkOpenness(); - return internal.getClusterNames(); - } - - @Override - public int getClusterIdByName(String iClusterName) { - checkOpenness(); - return internal.getClusterIdByName(iClusterName); - } - - @Override - public String getClusterNameById(int iClusterId) { - checkOpenness(); - return internal.getClusterNameById(iClusterId); - } - - @Override - public long getClusterRecordSizeByName(String iClusterName) { - checkOpenness(); - return internal.getClusterRecordSizeByName(iClusterName); - } - - @Override - public long getClusterRecordSizeById(int iClusterId) { - checkOpenness(); - return internal.getClusterRecordSizeById(iClusterId); - } - - @Override - public boolean isClosed() { - return internal == null || internal.isClosed(); - } - - @Override - public void truncateCluster(String clusterName) { - checkOpenness(); - internal.truncateCluster(clusterName); - } - - @Override - public long countClusterElements(int iCurrentClusterId) { - checkOpenness(); - return internal.countClusterElements(iCurrentClusterId); - } - - @Override - public long countClusterElements(int iCurrentClusterId, boolean countTombstones) { - checkOpenness(); - return internal.countClusterElements(iCurrentClusterId, countTombstones); - } - - @Override - public long countClusterElements(int[] iClusterIds) { - checkOpenness(); - return internal.countClusterElements(iClusterIds); - } - - @Override - public long countClusterElements(int[] iClusterIds, boolean countTombstones) { - checkOpenness(); - return internal.countClusterElements(iClusterIds, countTombstones); - } - - @Override - public long countClusterElements(String iClusterName) { - checkOpenness(); - return internal.countClusterElements(iClusterName); - } - - @Override - public int addCluster(String iClusterName, Object... iParameters) { - checkOpenness(); - return internal.addCluster(iClusterName, iParameters); - } - - @Override - public int addBlobCluster(String iClusterName, Object... iParameters) { - checkOpenness(); - return internal.addBlobCluster(iClusterName, iParameters); - } - - @Override - public Set getBlobClusterIds() { - checkOpenness(); - return internal.getBlobClusterIds(); - } - - @Override - public int addCluster(String iClusterName, int iRequestedId) { - checkOpenness(); - return internal.addCluster(iClusterName, iRequestedId); - } - - @Override - public boolean dropCluster(String iClusterName) { - checkOpenness(); - return internal.dropCluster(iClusterName); - } - - @Override - public boolean dropCluster(int iClusterId) { - checkOpenness(); - return internal.dropCluster(iClusterId); - } - - @Override - public Object setProperty(String iName, Object iValue) { - if (internal != null) { - return internal.setProperty(iName, iValue); - } else { - return preopenProperties.put(iName, iValue); - } - } - - @Override - public Object getProperty(String iName) { - if (internal != null) { - return internal.getProperty(iName); - } else { - return preopenProperties.get(iName); - } - } - - @Override - public Iterator> getProperties() { - checkOpenness(); - return internal.getProperties(); - } - - @Override - public Object get(ATTRIBUTES iAttribute) { - if (internal != null) { - return internal.get(iAttribute); - } else { - return preopenAttributes.get(iAttribute); - } - } - - @Override - public DB set(ATTRIBUTES iAttribute, Object iValue) { - if (internal != null) { - internal.set(iAttribute, iValue); - } else { - preopenAttributes.put(iAttribute, iValue); - } - return (DB) this; - } - - @Override - public void registerListener(ODatabaseListener iListener) { - if (internal != null) { - internal.registerListener(iListener); - } else { - preopenListener.add(iListener); - } - } - - @Override - public void unregisterListener(ODatabaseListener iListener) { - checkOpenness(); - internal.unregisterListener(iListener); - } - - @Override - public ORecordMetadata getRecordMetadata(ORID rid) { - checkOpenness(); - return internal.getRecordMetadata(rid); - } - - @Override - public ODocument newInstance(String iClassName) { - checkOpenness(); - return internal.newInstance(iClassName); - } - - @Override - public OBlob newBlob(byte[] bytes) { - checkOpenness(); - return internal.newBlob(bytes); - } - - @Override - public OBlob newBlob() { - return new ORecordBytes(); - } - - public OEdge newLightweightEdge(String iClassName, OVertex from, OVertex to) { - checkOpenness(); - return internal.newLightweightEdge(iClassName, from, to); - } - - public OEdge newRegularEdge(String iClassName, OVertex from, OVertex to) { - checkOpenness(); - return internal.newRegularEdge(iClassName, from, to); - } - - @Override - public long countClass(String iClassName) { - checkOpenness(); - return internal.countClass(iClassName); - } - - @Override - public long countClass(String iClassName, boolean iPolymorphic) { - checkOpenness(); - return internal.countClass(iClassName, iPolymorphic); - } - - @Override - public long countView(String viewName) { - return internal.countView(viewName); - } - - @Override - public List backup( - OutputStream out, - Map options, - Callable callable, - OCommandOutputListener iListener, - int compressionLevel, - int bufferSize) - throws IOException { - checkOpenness(); - return internal.backup(out, options, callable, iListener, compressionLevel, bufferSize); - } - - @Override - public void restore( - InputStream in, - Map options, - Callable callable, - OCommandOutputListener iListener) - throws IOException { - checkOpenness(); - internal.restore(in, options, callable, iListener); - } - - public void setSerializer(ORecordSerializer serializer) { - if (internal != null) { - internal.setSerializer(serializer); - } else { - this.serializer = serializer; - } - } - - @Override - public OResultSet query(String query, Object... args) { - checkOpenness(); - return internal.query(query, args); - } - - @Override - public OResultSet query(String query, Map args) - throws OCommandSQLParsingException, OCommandExecutionException { - checkOpenness(); - return internal.query(query, args); - } - - private OrientDBConfig buildConfig(final Map iProperties) { - Map pars = new HashMap<>(preopenProperties); - if (iProperties != null) { - for (Map.Entry par : iProperties.entrySet()) { - pars.put(par.getKey().getKey(), par.getValue()); - } - } - OrientDBConfigBuilder builder = OrientDBConfig.builder(); - final String connectionStrategy = - pars != null - ? (String) pars.get(OGlobalConfiguration.CLIENT_CONNECTION_STRATEGY.getKey()) - : null; - if (connectionStrategy != null) { - builder.addConfig(OGlobalConfiguration.CLIENT_CONNECTION_STRATEGY, connectionStrategy); - } - - final String compressionMethod = - pars != null - ? (String) pars.get(OGlobalConfiguration.STORAGE_COMPRESSION_METHOD.getKey()) - : null; - if (compressionMethod != null) - // SAVE COMPRESSION METHOD IN CONFIGURATION - { - builder.addConfig(OGlobalConfiguration.STORAGE_COMPRESSION_METHOD, compressionMethod); - } - - final String encryptionMethod = - pars != null - ? (String) pars.get(OGlobalConfiguration.STORAGE_ENCRYPTION_METHOD.getKey()) - : null; - if (encryptionMethod != null) - // SAVE ENCRYPTION METHOD IN CONFIGURATION - { - builder.addConfig(OGlobalConfiguration.STORAGE_ENCRYPTION_METHOD, encryptionMethod); - } - - final String encryptionKey = - pars != null - ? (String) pars.get(OGlobalConfiguration.STORAGE_ENCRYPTION_KEY.getKey()) - : null; - if (encryptionKey != null) - // SAVE ENCRYPTION KEY IN CONFIGURATION - { - builder.addConfig(OGlobalConfiguration.STORAGE_ENCRYPTION_KEY, encryptionKey); - } - - for (Map.Entry attr : preopenAttributes.entrySet()) { - builder.addAttribute(attr.getKey(), attr.getValue()); - } - builder.addConfig(OGlobalConfiguration.CREATE_DEFAULT_USERS, true); - - for (ODatabaseListener oDatabaseListener : preopenListener) { - builder.addListener(oDatabaseListener); - } - - return builder.build(); - } - - @Override - public OResultSet command(String query, Object... args) - throws OCommandSQLParsingException, OCommandExecutionException { - checkOpenness(); - return internal.command(query, args); - } - - public OResultSet command(String query, Map args) - throws OCommandSQLParsingException, OCommandExecutionException { - checkOpenness(); - return internal.command(query, args); - } - - @Override - public DB setCustom(String name, Object iValue) { - return internal.setCustom(name, iValue); - } - - @Override - public void callOnDropListeners() { - checkOpenness(); - internal.callOnDropListeners(); - } - - @Override - public boolean isPrefetchRecords() { - checkOpenness(); - return internal.isPrefetchRecords(); - } - - public void setPrefetchRecords(boolean prefetchRecords) { - checkOpenness(); - internal.setPrefetchRecords(prefetchRecords); - } - - public void checkForClusterPermissions(String name) { - checkOpenness(); - internal.checkForClusterPermissions(name); - } - - @Override - public OResultSet execute(String language, String script, Object... args) - throws OCommandExecutionException, OCommandScriptException { - checkOpenness(); - return internal.execute(language, script, args); - } - - @Override - public OResultSet execute(String language, String script, Map args) - throws OCommandExecutionException, OCommandScriptException { - checkOpenness(); - return internal.execute(language, script, args); - } - - @Override - public OLiveQueryMonitor live(String query, OLiveQueryResultListener listener, Object... args) { - checkOpenness(); - return internal.live(query, listener, args); - } - - @Override - public OLiveQueryMonitor live( - String query, OLiveQueryResultListener listener, Map args) { - checkOpenness(); - return internal.live(query, listener, args); - } - - @Override - public void recycle(ORecord record) { - checkOpenness(); - internal.recycle(record); - } - - @Override - public void internalCommit(OTransactionInternal transaction) { - internal.internalCommit(transaction); - } - - @Override - public boolean isClusterVertex(int cluster) { - checkOpenness(); - return internal.isClusterVertex(cluster); - } - - @Override - public boolean isClusterEdge(int cluster) { - checkOpenness(); - return internal.isClusterEdge(cluster); - } - - @Override - public boolean isClusterView(int cluster) { - return internal.isClusterView(cluster); - } - - @Override - public OIdentifiable beforeCreateOperations(OIdentifiable id, String iClusterName) { - return internal.beforeCreateOperations(id, iClusterName); - } - - @Override - public OIdentifiable beforeUpdateOperations(OIdentifiable id, String iClusterName) { - return internal.beforeUpdateOperations(id, iClusterName); - } - - @Override - public void beforeDeleteOperations(OIdentifiable id, String iClusterName) { - internal.beforeDeleteOperations(id, iClusterName); - } - - @Override - public void afterCreateOperations(OIdentifiable id) { - internal.afterCreateOperations(id); - } - - @Override - public void afterDeleteOperations(OIdentifiable id) { - internal.afterDeleteOperations(id); - } - - @Override - public void afterUpdateOperations(OIdentifiable id) { - internal.afterUpdateOperations(id); - } - - @Override - public void afterReadOperations(OIdentifiable identifiable) { - internal.afterReadOperations(identifiable); - } - - @Override - public boolean beforeReadOperations(OIdentifiable identifiable) { - return internal.beforeReadOperations(identifiable); - } - - @Override - public void internalClose(boolean recycle) { - internal.internalClose(true); - } - - public ORecord saveAll( - ORecord iRecord, - String iClusterName, - OPERATION_MODE iMode, - boolean iForceCreate, - ORecordCallback iRecordCreatedCallback, - ORecordCallback iRecordUpdatedCallback) { - return internal.saveAll( - iRecord, iClusterName, iMode, iForceCreate, iRecordCreatedCallback, iRecordUpdatedCallback); - } - - @Override - public String getClusterName(ORecord record) { - return internal.getClusterName(record); - } - - @Override - public OView getViewFromCluster(int cluster) { - return internal.getViewFromCluster(cluster); - } - - @Override - public void internalLockRecord(OIdentifiable iRecord, OStorage.LOCKING_STRATEGY lockingStrategy) { - internal.internalLockRecord(iRecord, lockingStrategy); - } - - @Override - public void internalUnlockRecord(OIdentifiable iRecord) { - internal.internalUnlockRecord(iRecord); - } - - @Override - public RET lock(ORID recordId) throws OLockException { - checkOpenness(); - return internal.lock(recordId); - } - - @Override - public RET lock(ORID recordId, long timeout, TimeUnit timeoutUnit) - throws OLockException { - checkOpenness(); - return internal.lock(recordId, timeout, timeoutUnit); - } - - @Override - public void unlock(ORID recordId) throws OLockException { - checkOpenness(); - internal.unlock(recordId); - } - - @Override - public T sendSequenceAction(OSequenceAction action) - throws ExecutionException, InterruptedException { - throw new UnsupportedOperationException( - "Not supported yet."); // To change body of generated methods, choose Tools | Templates. - } - - @Override - public Map getCollectionsChanges() { - return internal.getCollectionsChanges(); - } - - @Override - public boolean isRemote() { - if (internal == null) { - return "remote".equals(type); - } - return internal.isRemote(); - } - - @Override - public OStorageInfo getStorageInfo() { - return internal.getStorageInfo(); - } - - @Override - public boolean dropClusterInternal(int clusterId) { - return internal.dropClusterInternal(clusterId); - } - - @Override - public long[] getClusterDataRange(int currentClusterId) { - return internal.getClusterDataRange(currentClusterId); - } - - @Override - public long getLastClusterPosition(int clusterId) { - return internal.getLastClusterPosition(clusterId); - } - - @Override - public void setDefaultClusterId(int addCluster) { - internal.setDefaultClusterId(addCluster); - } - - @Override - public String getClusterRecordConflictStrategy(int clusterId) { - return internal.getClusterRecordConflictStrategy(clusterId); - } - - @Override - public int[] getClustersIds(Set filterClusters) { - return internal.getClustersIds(filterClusters); - } - - @Override - public void truncateClass(String name) { - internal.truncateClass(name); - } - - @Override - public long truncateClusterInternal(String name) { - return internal.truncateClusterInternal(name); - } - - @Override - public long truncateClass(String name, boolean polimorfic) { - return internal.truncateClass(name, polimorfic); - } - - @Override - public void commitPreallocate() { - internal.commitPreallocate(); - } - - @Override - public void internalCommitPreallocate(OTransactionOptimistic oTransactionOptimistic) { - internal.internalCommitPreallocate(oTransactionOptimistic); - } -} diff --git a/core/src/main/java/com/orientechnologies/orient/core/db/document/ODatabaseDocumentTxInternal.java b/core/src/main/java/com/orientechnologies/orient/core/db/document/ODatabaseDocumentTxInternal.java deleted file mode 100644 index 6c40cfb6789..00000000000 --- a/core/src/main/java/com/orientechnologies/orient/core/db/document/ODatabaseDocumentTxInternal.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.orientechnologies.orient.core.db.document; - -import com.orientechnologies.orient.core.db.ODatabaseDocumentInternal; -import com.orientechnologies.orient.core.db.OrientDBConfig; -import com.orientechnologies.orient.core.db.OrientDBInternal; - -/** Created by tglman on 31/03/16. */ -public class ODatabaseDocumentTxInternal { - - private ODatabaseDocumentTxInternal() {} - - public static ODatabaseDocumentInternal getInternal(ODatabaseDocumentInternal db) { - if (db instanceof ODatabaseDocumentTx) { - db = ((ODatabaseDocumentTx) db).internal; - } - return db; - } - - public static ODatabaseDocumentTx wrap(ODatabaseDocumentInternal database) { - return new ODatabaseDocumentTx(database, null); - } - - public static OrientDBInternal getOrCreateEmbeddedFactory( - String databaseDirectory, OrientDBConfig config) { - return ODatabaseDocumentTx.getOrCreateEmbeddedFactory(databaseDirectory, config); - } - - public static OrientDBInternal getOrCreateRemoteFactory(String url) { - return ODatabaseDocumentTx.getOrCreateRemoteFactory(url); - } - - public static void closeAllOnShutdown() { - ODatabaseDocumentTx.embeddedLock.lock(); - try { - for (OrientDBInternal factory : ODatabaseDocumentTx.embedded.values()) { - factory.internalClose(); - } - ODatabaseDocumentTx.embedded.clear(); - } finally { - ODatabaseDocumentTx.embeddedLock.unlock(); - } - - ODatabaseDocumentTx.remoteLock.lock(); - try { - ODatabaseDocumentTx.remote.clear(); - } finally { - ODatabaseDocumentTx.remoteLock.unlock(); - } - } -}