Search in sources :

Example 1 with ODatabase

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();
        }
    }
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) ODatabase(com.orientechnologies.orient.core.db.ODatabase) IOException(java.io.IOException)

Example 2 with ODatabase

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);
    }
}
Also used : ORecordDuplicatedException(com.orientechnologies.orient.core.storage.ORecordDuplicatedException) ODatabase(com.orientechnologies.orient.core.db.ODatabase) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable)

Example 3 with ODatabase

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);
    }
}
Also used : OInvalidIndexEngineIdException(com.orientechnologies.orient.core.exception.OInvalidIndexEngineIdException) ODatabase(com.orientechnologies.orient.core.db.ODatabase)

Example 4 with ODatabase

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);
}
Also used : OObjectDatabaseTx(com.orientechnologies.orient.object.db.OObjectDatabaseTx) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODatabase(com.orientechnologies.orient.core.db.ODatabase) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 5 with ODatabase

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();
    }
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) List(java.util.List) OSecurityException(com.orientechnologies.orient.core.exception.OSecurityException) ODatabase(com.orientechnologies.orient.core.db.ODatabase) File(java.io.File) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Aggregations

ODatabase (com.orientechnologies.orient.core.db.ODatabase)29 OInvalidIndexEngineIdException (com.orientechnologies.orient.core.exception.OInvalidIndexEngineIdException)13 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)9 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)9 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)8 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)7 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)6 File (java.io.File)6 List (java.util.List)6 OSecurityException (com.orientechnologies.orient.core.exception.OSecurityException)5 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)3 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)3 OStorage (com.orientechnologies.orient.core.storage.OStorage)3 OModifiableBoolean (com.orientechnologies.common.types.OModifiableBoolean)2 OIndexRIDContainer (com.orientechnologies.orient.core.db.record.ridbag.sbtree.OIndexRIDContainer)2 ORID (com.orientechnologies.orient.core.id.ORID)2 IOException (java.io.IOException)2 OCommandExecutor (com.orientechnologies.orient.core.command.OCommandExecutor)1 OCommandRequestText (com.orientechnologies.orient.core.command.OCommandRequestText)1 ODatabaseListener (com.orientechnologies.orient.core.db.ODatabaseListener)1