use of com.orientechnologies.orient.core.storage.OStorage in project orientdb by orientechnologies.
the class OPropertyImpl method setMandatory.
public OPropertyImpl setMandatory(final boolean isMandatory) {
getDatabase().checkSecurity(ORule.ResourceGeneric.SCHEMA, ORole.PERMISSION_UPDATE);
acquireSchemaWriteLock();
try {
final ODatabaseDocumentInternal database = getDatabase();
final OStorage storage = database.getStorage();
if (storage instanceof OStorageProxy) {
final String cmd = String.format("alter property %s mandatory %s", getFullNameQuoted(), isMandatory);
database.command(new OCommandSQL(cmd)).execute();
} else if (isDistributedCommand()) {
final String cmd = String.format("alter property %s mandatory %s", getFullNameQuoted(), isMandatory);
final OCommandSQL commandSQL = new OCommandSQL(cmd);
commandSQL.addExcludedNode(((OAutoshardedStorage) storage).getNodeId());
database.command(commandSQL).execute();
setMandatoryInternal(isMandatory);
} else
setMandatoryInternal(isMandatory);
} finally {
releaseSchemaWriteLock();
}
return this;
}
use of com.orientechnologies.orient.core.storage.OStorage in project orientdb by orientechnologies.
the class OSchemaShared method addClusterForClass.
void addClusterForClass(final int clusterId, final OClass cls) {
acquireSchemaWriteLock();
try {
if (!clustersCanNotBeSharedAmongClasses)
return;
if (clusterId < 0)
return;
final OStorage storage = getDatabase().getStorage();
checkEmbedded(storage);
final OClass existingCls = clustersToClasses.get(clusterId);
if (existingCls != null && !cls.equals(existingCls))
throw new OSchemaException("Cluster with id " + clusterId + " already belongs to class " + clustersToClasses.get(clusterId));
clustersToClasses.put(clusterId, cls);
} finally {
releaseSchemaWriteLock();
}
}
use of com.orientechnologies.orient.core.storage.OStorage in project orientdb by orientechnologies.
the class OAESEncryptionTest method testCreatedAESEncryptedCluster.
public void testCreatedAESEncryptedCluster() {
final String buildDirectory = System.getProperty("buildDirectory", ".");
final String dbPath = buildDirectory + File.separator + DBNAME_CLUSTERTEST;
OFileUtils.deleteRecursively(new File(dbPath));
final ODatabase db = new ODatabaseDocumentTx("plocal:" + dbPath);
db.setProperty(OGlobalConfiguration.STORAGE_ENCRYPTION_KEY.getKey(), "T1JJRU5UREJfSVNfQ09PTA==");
db.create();
try {
db.command(new OCommandSQL("create class TestEncryption")).execute();
db.command(new OCommandSQL("alter class TestEncryption encryption aes")).execute();
db.command(new OCommandSQL("insert into TestEncryption set name = 'Jay'")).execute();
List result = db.query(new OSQLSynchQuery<ODocument>("select from TestEncryption"));
Assert.assertEquals(result.size(), 1);
db.close();
db.open("admin", "admin");
OStorage storage = ((ODatabaseDocumentInternal) db).getStorage();
db.close();
storage.close(true, false);
db.setProperty(OGlobalConfiguration.STORAGE_ENCRYPTION_KEY.getKey(), "T1JJRU5UREJfSVNfQ09PTA==");
db.open("admin", "admin");
result = db.query(new OSQLSynchQuery<ODocument>("select from TestEncryption"));
Assert.assertEquals(result.size(), 1);
storage = ((ODatabaseDocumentInternal) db).getStorage();
db.close();
storage.close(true, false);
db.setProperty(OGlobalConfiguration.STORAGE_ENCRYPTION_KEY.getKey(), "invalidPassword");
try {
db.open("admin", "admin");
storage = ((ODatabaseDocumentInternal) db).getStorage();
db.query(new OSQLSynchQuery<ODocument>("select from TestEncryption"));
result = db.query(new OSQLSynchQuery<ODocument>("select from OUser"));
Assert.assertFalse(result.isEmpty());
Assert.fail();
} catch (OSecurityException e) {
Assert.assertTrue(true);
} finally {
db.close();
storage.close(true, false);
}
db.setProperty(OGlobalConfiguration.STORAGE_ENCRYPTION_KEY.getKey(), "T1JJRU5UREJfSVNfQ09PTA=-");
try {
db.open("admin", "admin");
storage = ((ODatabaseDocumentInternal) db).getStorage();
db.query(new OSQLSynchQuery<ODocument>("select from TestEncryption"));
Assert.fail();
} catch (OSecurityException e) {
Assert.assertTrue(true);
} finally {
db.activateOnCurrentThread();
db.close();
storage.close(true, false);
}
db.setProperty(OGlobalConfiguration.STORAGE_ENCRYPTION_KEY.getKey(), "T1JJRU5UREJfSVNfQ09PTA==");
db.open("admin", "admin");
result = db.query(new OSQLSynchQuery<ODocument>("select from TestEncryption"));
Assert.assertEquals(result.size(), 1);
} catch (Exception e) {
e.printStackTrace();
} finally {
db.activateOnCurrentThread();
if (db.isClosed())
db.open("admin", "admin");
db.drop();
}
}
use of com.orientechnologies.orient.core.storage.OStorage in project orientdb by orientechnologies.
the class OAESEncryptionTest method testCreatedAESEncryptedDatabase.
public void testCreatedAESEncryptedDatabase() {
String buildDirectory = System.getProperty("buildDirectory", ".");
final String dbPath = buildDirectory + File.separator + DBNAME_DATABASETEST;
OFileUtils.deleteRecursively(new File(dbPath));
final ODatabase db = new ODatabaseDocumentTx("plocal:" + dbPath);
db.setProperty(OGlobalConfiguration.STORAGE_ENCRYPTION_METHOD.getKey(), "aes");
db.setProperty(OGlobalConfiguration.STORAGE_ENCRYPTION_KEY.getKey(), "T1JJRU5UREJfSVNfQ09PTA==");
db.create();
try {
db.command(new OCommandSQL("create class TestEncryption")).execute();
db.command(new OCommandSQL("insert into TestEncryption set name = 'Jay'")).execute();
List result = db.query(new OSQLSynchQuery<ODocument>("select from TestEncryption"));
Assert.assertEquals(result.size(), 1);
db.close();
db.open("admin", "admin");
OStorage storage = ((ODatabaseDocumentInternal) db).getStorage();
db.close();
storage.close(true, false);
db.setProperty(OGlobalConfiguration.STORAGE_ENCRYPTION_KEY.getKey(), "T1JJRU5UREJfSVNfQ09PTA==");
db.open("admin", "admin");
result = db.query(new OSQLSynchQuery<ODocument>("select from TestEncryption"));
Assert.assertEquals(result.size(), 1);
storage = ((ODatabaseDocumentInternal) db).getStorage();
db.close();
storage.close(true, false);
db.setProperty(OGlobalConfiguration.STORAGE_ENCRYPTION_KEY.getKey(), "invalidPassword");
try {
db.open("admin", "admin");
storage = ((ODatabaseDocumentInternal) db).getStorage();
Assert.fail();
} catch (OSecurityException e) {
Assert.assertTrue(true);
} finally {
db.activateOnCurrentThread();
db.close();
storage.close(true, false);
}
db.setProperty(OGlobalConfiguration.STORAGE_ENCRYPTION_KEY.getKey(), "T1JJRU5UREJfSVNfQ09PTA=-");
try {
db.open("admin", "admin");
storage = ((ODatabaseDocumentInternal) db).getStorage();
Assert.fail();
} catch (OSecurityException e) {
Assert.assertTrue(true);
} finally {
db.activateOnCurrentThread();
db.close();
storage.close(true, false);
}
db.setProperty(OGlobalConfiguration.STORAGE_ENCRYPTION_KEY.getKey(), "T1JJRU5UREJfSVNfQ09PTA==");
db.open("admin", "admin");
result = db.query(new OSQLSynchQuery<ODocument>("select from TestEncryption"));
Assert.assertEquals(result.size(), 1);
} finally {
db.activateOnCurrentThread();
if (db.isClosed())
db.open("admin", "admin");
db.drop();
}
}
use of com.orientechnologies.orient.core.storage.OStorage in project orientdb by orientechnologies.
the class OSBTreeBonsaiWALTest method assertFileRestoreFromWAL.
private void assertFileRestoreFromWAL() throws IOException {
OStorage storage = databaseDocumentTx.getStorage();
databaseDocumentTx.activateOnCurrentThread();
databaseDocumentTx.close();
storage.close(true, false);
restoreDataFromWAL();
expectedDatabaseDocumentTx.activateOnCurrentThread();
expectedDatabaseDocumentTx.close();
storage = expectedDatabaseDocumentTx.getStorage();
storage.close(true, false);
expectedReadCache.clear();
assertFileContentIsTheSame("expectedSBTree", sbTree.getName());
}
Aggregations