Search in sources :

Example 21 with ODatabase

use of com.orientechnologies.orient.core.db.ODatabase in project orientdb by orientechnologies.

the class ONothingEncryptionTest method testCreatedNothingEncryptedDatabase.

public void testCreatedNothingEncryptedDatabase() {
    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)

Example 22 with ODatabase

use of com.orientechnologies.orient.core.db.ODatabase in project orientdb by orientechnologies.

the class ONothingEncryptionTest method testCreatedNothingEncryptedCluster.

public void testCreatedNothingEncryptedCluster() {
    OFileUtils.deleteRecursively(new File("target/" + DBNAME_CLUSTERTEST));
    final ODatabase db = new ODatabaseDocumentTx("plocal:target/" + DBNAME_CLUSTERTEST);
    db.setProperty(OGlobalConfiguration.STORAGE_ENCRYPTION_KEY.getKey(), "T1JJRU5UREJfSVNfQ09PTA==");
    db.create();
    try {
        db.command(new OCommandSQL("create class TestEncryption")).execute();
        db.command(new OCommandSQL("alter cluster TestEncryption encryption nothing")).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_CLUSTERTEST).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_CLUSTERTEST).close(true, false);
        db.setProperty(OGlobalConfiguration.STORAGE_ENCRYPTION_KEY.getKey(), "invalidPassword");
        try {
            db.open("admin", "admin");
            db.query(new OSQLSynchQuery<ODocument>("select from TestEncryption"));
            result = db.query(new OSQLSynchQuery<ODocument>("select from OUser"));
            Assert.assertFalse(result.isEmpty());
        } finally {
            db.close();
            Orient.instance().getStorage(DBNAME_CLUSTERTEST).close(true, false);
        }
        db.setProperty(OGlobalConfiguration.STORAGE_ENCRYPTION_KEY.getKey(), "T1JJRU5UREJfSVNfQ09PTA=-");
        try {
            db.open("admin", "admin");
            db.query(new OSQLSynchQuery<ODocument>("select from TestEncryption"));
        } finally {
            db.close();
            Orient.instance().getStorage(DBNAME_CLUSTERTEST).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) ODatabase(com.orientechnologies.orient.core.db.ODatabase) File(java.io.File) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 23 with ODatabase

use of com.orientechnologies.orient.core.db.ODatabase in project orientdb by orientechnologies.

the class OConfigurableHooksManager method onOpen.

public void onOpen(ODatabaseInternal iDatabase) {
    if (!iDatabase.getStorage().isRemote()) {
        final ODatabase<?> db = (ODatabase<?>) iDatabase;
        for (OServerHookConfiguration hook : configuredHooks) {
            try {
                final ORecordHook.HOOK_POSITION pos = ORecordHook.HOOK_POSITION.valueOf(hook.position);
                final ORecordHook h = (ORecordHook) Class.forName(hook.clazz).newInstance();
                if (hook.parameters != null && hook.parameters.length > 0)
                    try {
                        final Method m = h.getClass().getDeclaredMethod("config", new Class[] { OServerParameterConfiguration[].class });
                        m.invoke(h, new Object[] { hook.parameters });
                    } catch (Exception e) {
                        OLogManager.instance().warn(this, "[configure] Failed to configure hook '%s'. Parameters specified but hook don support parameters. Should have a method config with parameters OServerParameterConfiguration[] ", hook.clazz);
                    }
                db.registerHook(h, pos);
            } catch (Exception e) {
                OLogManager.instance().error(this, "[configure] Failed to configure hook '%s' due to the an error : ", e, hook.clazz, e.getMessage());
            }
        }
    }
}
Also used : OServerHookConfiguration(com.orientechnologies.orient.server.config.OServerHookConfiguration) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODatabase(com.orientechnologies.orient.core.db.ODatabase) Method(java.lang.reflect.Method) ORecordHook(com.orientechnologies.orient.core.hook.ORecordHook)

Example 24 with ODatabase

use of com.orientechnologies.orient.core.db.ODatabase in project orientdb by orientechnologies.

the class OBaseGraphWorkload method getGraph.

protected OrientGraph getGraph(final ODatabaseIdentifier databaseIdentifier) {
    final ODatabase database = ODatabaseUtils.openDatabase(databaseIdentifier, connectionStrategy);
    if (database == null)
        throw new IllegalArgumentException("Error on opening database " + databaseIdentifier.getName());
    database.setProperty(OStorageRemote.PARAM_CONNECTION_STRATEGY, connectionStrategy.toString());
    final OrientGraph g = (OrientGraph) OrientGraphFactory.getTxGraphImplFactory().getGraph((ODatabaseDocumentTx) database);
    g.setAutoStartTx(false);
    return g;
}
Also used : ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) ODatabase(com.orientechnologies.orient.core.db.ODatabase)

Example 25 with ODatabase

use of com.orientechnologies.orient.core.db.ODatabase in project orientdb by orientechnologies.

the class OCRUDWorkload method createSchema.

protected void createSchema(ODatabaseIdentifier databaseIdentifier) {
    final ODatabase database = getDocumentDatabase(databaseIdentifier, OStorageRemote.CONNECTION_STRATEGY.STICKY);
    try {
        final OSchema schema = database.getMetadata().getSchema();
        if (!schema.existsClass(OCRUDWorkload.CLASS_NAME)) {
            final OClass cls = schema.createClass(OCRUDWorkload.CLASS_NAME);
            cls.createProperty("name", OType.STRING);
            // cls.createIndex(INDEX_NAME, OClass.INDEX_TYPE.UNIQUE_HASH_INDEX.toString(), "name");
            cls.createIndex(INDEX_NAME, OClass.INDEX_TYPE.UNIQUE.toString(), (OProgressListener) null, (ODocument) null, "AUTOSHARDING", new String[] { "name" });
        }
    } finally {
        database.close();
    }
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODatabase(com.orientechnologies.orient.core.db.ODatabase)

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