use of com.orientechnologies.orient.core.storage.OStorage in project orientdb by orientechnologies.
the class OTransactionAbstract method lockRecord.
@Override
public OTransaction lockRecord(final OIdentifiable iRecord, final OStorage.LOCKING_STRATEGY lockingStrategy) {
final OStorage stg = database.getStorage();
if (!(stg.getUnderlying() instanceof OAbstractPaginatedStorage))
throw new OLockException("Cannot lock record across remote connections");
final ORID rid = new ORecordId(iRecord.getIdentity());
LockedRecordMetadata lockedRecordMetadata = locks.get(rid);
boolean addItem = false;
if (lockedRecordMetadata == null) {
lockedRecordMetadata = new LockedRecordMetadata(lockingStrategy);
addItem = true;
} else if (lockedRecordMetadata.strategy != lockingStrategy) {
assert lockedRecordMetadata.locksCount == 0;
lockedRecordMetadata = new LockedRecordMetadata(lockingStrategy);
addItem = true;
}
if (lockingStrategy == OStorage.LOCKING_STRATEGY.EXCLUSIVE_LOCK)
((OAbstractPaginatedStorage) stg.getUnderlying()).acquireWriteLock(rid);
else if (lockingStrategy == OStorage.LOCKING_STRATEGY.SHARED_LOCK)
((OAbstractPaginatedStorage) stg.getUnderlying()).acquireReadLock(rid);
else
throw new IllegalStateException("Unsupported locking strategy " + lockingStrategy);
lockedRecordMetadata.locksCount++;
if (addItem) {
locks.put(rid, lockedRecordMetadata);
}
return this;
}
use of com.orientechnologies.orient.core.storage.OStorage in project orientdb by orientechnologies.
the class OTransactionAbstract method unlockRecord.
@Override
public OTransaction unlockRecord(final OIdentifiable iRecord) {
final OStorage stg = database.getStorage();
if (!(stg.getUnderlying() instanceof OAbstractPaginatedStorage))
throw new OLockException("Cannot lock record across remote connections");
final ORID rid = iRecord.getIdentity();
final LockedRecordMetadata lockedRecordMetadata = locks.get(rid);
if (lockedRecordMetadata == null || lockedRecordMetadata.locksCount == 0)
throw new OLockException("Cannot unlock a never acquired lock");
else if (lockedRecordMetadata.strategy == OStorage.LOCKING_STRATEGY.EXCLUSIVE_LOCK)
((OAbstractPaginatedStorage) stg.getUnderlying()).releaseWriteLock(rid);
else if (lockedRecordMetadata.strategy == OStorage.LOCKING_STRATEGY.SHARED_LOCK)
((OAbstractPaginatedStorage) stg.getUnderlying()).releaseReadLock(rid);
else
throw new IllegalStateException("Unsupported locking strategy " + lockedRecordMetadata.strategy);
lockedRecordMetadata.locksCount--;
if (lockedRecordMetadata.locksCount == 0)
locks.remove(rid);
return this;
}
use of com.orientechnologies.orient.core.storage.OStorage in project orientdb by orientechnologies.
the class OrientBaseGraph method shutdown.
/**
* Closes the Graph. After closing the Graph cannot be used.
*/
public void shutdown(boolean closeDb, boolean commitTx) {
makeActive();
try {
if (!isClosed() && commitTx) {
final OStorage storage = getDatabase().getStorage().getUnderlying();
if (storage instanceof OAbstractPaginatedStorage) {
if (((OAbstractPaginatedStorage) storage).getWALInstance() != null)
getDatabase().commit();
}
}
} catch (RuntimeException e) {
OLogManager.instance().error(this, "Error during context close for db " + url, e);
throw e;
} catch (Exception e) {
OLogManager.instance().error(this, "Error during context close for db " + url, e);
throw OException.wrapException(new ODatabaseException("Error during context close for db " + url), e);
} finally {
try {
if (closeDb) {
getDatabase().close();
if (getDatabase().isPooled()) {
database = null;
}
}
} catch (Exception e) {
OLogManager.instance().error(this, "Error during context close for db " + url, e);
}
}
url = null;
username = null;
password = null;
pollGraphFromStack(closeDb);
if (!closeDb)
getDatabase().activateOnCurrentThread();
}
use of com.orientechnologies.orient.core.storage.OStorage in project orientdb by orientechnologies.
the class OServer method getAvailableStorageNames.
public Map<String, String> getAvailableStorageNames() {
final OServerConfiguration configuration = serverCfg.getConfiguration();
// SEARCH IN CONFIGURED PATHS
final Map<String, String> storages = new HashMap<String, String>();
if (configuration.storages != null && configuration.storages.length > 0)
for (OServerStorageConfiguration s : configuration.storages) storages.put(OIOUtils.getDatabaseNameFromPath(s.name), s.path);
// SEARCH IN DEFAULT DATABASE DIRECTORY
final String rootDirectory = getDatabaseDirectory();
scanDatabaseDirectory(new File(rootDirectory), storages);
for (OStorage storage : Orient.instance().getStorages()) {
final String storageUrl = storage.getURL();
// TEST IT'S OF CURRENT SERVER INSTANCE BY CHECKING THE PATH
if (storage instanceof OAbstractPaginatedStorage && storage.exists() && !storages.containsValue(storageUrl) && isStorageOfCurrentServerInstance(storage))
storages.put(OIOUtils.getDatabaseNameFromPath(storage.getName()), storageUrl);
}
if (storages != null)
storages.remove(OSystemDatabase.SYSTEM_DB_NAME);
return storages;
}
use of com.orientechnologies.orient.core.storage.OStorage in project orientdb by orientechnologies.
the class OServer method getStoragePath.
public String getStoragePath(final String iName) {
if (iName == null)
throw new IllegalArgumentException("Storage path is null");
final String name = iName.indexOf(':') > -1 ? iName.substring(iName.indexOf(':') + 1) : iName;
final String dbName = Orient.isRegisterDatabaseByPath() ? getDatabaseDirectory() + name : name;
final String dbPath = Orient.isRegisterDatabaseByPath() ? dbName : getDatabaseDirectory() + name;
if (dbPath.contains(".."))
throw new IllegalArgumentException("Storage path is invalid because it contains '..'");
if (dbPath.contains("*"))
throw new IllegalArgumentException("Storage path is invalid because of the wildcard '*'");
if (dbPath.startsWith("/")) {
if (!dbPath.startsWith(getDatabaseDirectory()))
throw new IllegalArgumentException("Storage path is invalid because it points to an absolute directory");
}
final OStorage stg = Orient.instance().getStorage(dbName);
if (stg != null)
// ALREADY OPEN
return stg.getURL();
// SEARCH IN CONFIGURED PATHS
final OServerConfiguration configuration = serverCfg.getConfiguration();
String dbURL = configuration.getStoragePath(name);
if (dbURL == null) {
// SEARCH IN DEFAULT DATABASE DIRECTORY
if (new File(OIOUtils.getPathFromDatabaseName(dbPath) + "/database.ocf").exists())
dbURL = "plocal:" + dbPath;
else
throw new OConfigurationException("Database '" + name + "' is not configured on server (home=" + getDatabaseDirectory() + ")");
}
return dbURL;
}
Aggregations