use of com.orientechnologies.orient.core.db.ODatabase in project orientdb by orientechnologies.
the class OStressTester method dumpHaMetrics.
private void dumpHaMetrics() {
if (settings.haMetrics) {
final ODatabase db = ODatabaseUtils.openDatabase(databaseIdentifier, OStorageRemote.CONNECTION_STRATEGY.STICKY);
try {
final String output = db.command(new OCommandSQL("ha status -latency -messages -output=text")).execute();
System.out.println("HA METRICS");
System.out.println(output);
} catch (Exception e) {
// IGNORE IT
} finally {
db.close();
}
}
}
use of com.orientechnologies.orient.core.db.ODatabase in project orientdb by orientechnologies.
the class OIndexOneValue method checkEntry.
@Override
public ODocument checkEntry(final OIdentifiable record, Object key) {
key = getCollatingValue(key);
final ODatabase database = getDatabase();
final boolean txIsActive = database.getTransaction().isActive();
if (!txIsActive)
keyLockManager.acquireSharedLock(key);
try {
// CHECK IF ALREADY EXIST
final OIdentifiable indexedRID = get(key);
if (indexedRID != null && !indexedRID.getIdentity().equals(record.getIdentity())) {
final Boolean mergeSameKey = metadata != null && (Boolean) metadata.field(OIndex.MERGE_KEYS);
if (mergeSameKey != null && mergeSameKey)
return (ODocument) indexedRID.getRecord();
else
throw new ORecordDuplicatedException(String.format("Cannot index record %s: found duplicated key '%s' in index '%s' previously assigned to the record %s", record, key, getName(), indexedRID), getName(), indexedRID.getIdentity());
}
return null;
} finally {
if (!txIsActive)
keyLockManager.releaseSharedLock(key);
}
}
use of com.orientechnologies.orient.core.db.ODatabase in project orientdb by orientechnologies.
the class OIndexOneValue method get.
public OIdentifiable get(Object iKey) {
iKey = getCollatingValue(iKey);
final ODatabase database = getDatabase();
final boolean txIsActive = database.getTransaction().isActive();
if (!txIsActive)
keyLockManager.acquireSharedLock(iKey);
try {
acquireSharedLock();
try {
while (true) try {
return (OIdentifiable) storage.getIndexValue(indexId, iKey);
} catch (OInvalidIndexEngineIdException e) {
doReloadIndexEngine();
}
} finally {
releaseSharedLock();
}
} finally {
if (!txIsActive)
keyLockManager.releaseSharedLock(iKey);
}
}
use of com.orientechnologies.orient.core.db.ODatabase in project orientdb by orientechnologies.
the class BaseTest method createBasicTestSchema.
protected void createBasicTestSchema() {
ODatabase database = this.database;
if (database instanceof OObjectDatabaseTx)
database = ((OObjectDatabaseTx) database).getUnderlying();
if (database.getMetadata().getSchema().existsClass("Whiz"))
return;
database.addCluster("csv");
database.addCluster("flat");
database.addCluster("binary");
// database.addBlobCluster("blobCluster");
OClass account = database.getMetadata().getSchema().createClass("Account", 1, null);
account.createProperty("id", OType.INTEGER);
account.createProperty("birthDate", OType.DATE);
account.createProperty("binary", OType.BINARY);
database.getMetadata().getSchema().createClass("Company", account);
OClass profile = database.getMetadata().getSchema().createClass("Profile", 1, null);
profile.createProperty("nick", OType.STRING).setMin("3").setMax("30").createIndex(OClass.INDEX_TYPE.UNIQUE, new ODocument().field("ignoreNullValues", true));
profile.createProperty("name", OType.STRING).setMin("3").setMax("30").createIndex(OClass.INDEX_TYPE.NOTUNIQUE);
profile.createProperty("surname", OType.STRING).setMin("3").setMax("30");
profile.createProperty("registeredOn", OType.DATETIME).setMin("2010-01-01 00:00:00");
profile.createProperty("lastAccessOn", OType.DATETIME).setMin("2010-01-01 00:00:00");
profile.createProperty("photo", OType.TRANSIENT);
OClass whiz = database.getMetadata().getSchema().createClass("Whiz", 1, null);
whiz.createProperty("id", OType.INTEGER);
whiz.createProperty("account", OType.LINK, account);
whiz.createProperty("date", OType.DATE).setMin("2010-01-01");
whiz.createProperty("text", OType.STRING).setMandatory(true).setMin("1").setMax("140").createIndex(OClass.INDEX_TYPE.FULLTEXT);
whiz.createProperty("replyTo", OType.LINK, account);
OClass strictTest = database.getMetadata().getSchema().createClass("StrictTest", 1, null);
strictTest.setStrictMode(true);
strictTest.createProperty("id", OType.INTEGER).isMandatory();
strictTest.createProperty("name", OType.STRING);
OClass animalRace = database.getMetadata().getSchema().createClass("AnimalRace", 1, null);
animalRace.createProperty("name", OType.STRING);
OClass animal = database.getMetadata().getSchema().createClass("Animal", 1, null);
animal.createProperty("races", OType.LINKSET, animalRace);
animal.createProperty("name", OType.STRING);
}
use of com.orientechnologies.orient.core.db.ODatabase in project orientdb by orientechnologies.
the class ODESEncryptionTest method testCreatedDESEncryptedDatabase.
public void testCreatedDESEncryptedDatabase() {
OFileUtils.deleteRecursively(new File("target/" + DBNAME_DATABASETEST));
final ODatabase db = new ODatabaseDocumentTx("plocal:target/" + DBNAME_DATABASETEST);
db.setProperty(OGlobalConfiguration.STORAGE_ENCRYPTION_METHOD.getKey(), "des");
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");
db.close();
Orient.instance().getStorage(DBNAME_DATABASETEST).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);
db.close();
Orient.instance().getStorage(DBNAME_DATABASETEST).close(true, false);
db.setProperty(OGlobalConfiguration.STORAGE_ENCRYPTION_KEY.getKey(), "invalidPassword");
try {
db.open("admin", "admin");
Assert.fail();
} catch (OSecurityException e) {
Assert.assertTrue(true);
} finally {
db.activateOnCurrentThread();
db.close();
Orient.instance().getStorage(DBNAME_DATABASETEST).close(true, false);
}
db.setProperty(OGlobalConfiguration.STORAGE_ENCRYPTION_KEY.getKey(), "T1JJRU5UREJfSVNfQ09PTA=-");
try {
db.open("admin", "admin");
Assert.fail();
} catch (OSecurityException e) {
Assert.assertTrue(true);
} finally {
db.activateOnCurrentThread();
db.close();
Orient.instance().getStorage(DBNAME_DATABASETEST).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();
db.drop();
}
}
Aggregations