Search in sources :

Example 11 with OSchemaProxy

use of com.orientechnologies.orient.core.metadata.schema.OSchemaProxy in project orientdb by orientechnologies.

the class OMetadataDefault method init.

private void init(final boolean iLoad) {
    final ODatabaseDocumentInternal database = getDatabase();
    schemaClusterId = database.getClusterIdByName(CLUSTER_INTERNAL_NAME);
    final AtomicBoolean schemaLoaded = new AtomicBoolean(false);
    schema = new OSchemaProxy(database.getStorage().getResource(OSchema.class.getSimpleName(), new Callable<OSchemaShared>() {

        public OSchemaShared call() {
            ODatabaseDocumentInternal database = getDatabase();
            final OSchemaShared instance = new OSchemaShared(database.getStorageVersions().classesAreDetectedByClusterId());
            if (iLoad)
                instance.load();
            schemaLoaded.set(true);
            return instance;
        }
    }), database);
    indexManager = new OIndexManagerProxy(database.getStorage().getResource(OIndexManager.class.getSimpleName(), new Callable<OIndexManager>() {

        public OIndexManager call() {
            OIndexManager instance;
            if (database.getStorage() instanceof OStorageProxy)
                instance = new OIndexManagerRemote(database);
            else
                instance = new OIndexManagerShared(database);
            if (iLoad)
                try {
                    instance.load();
                } catch (Exception e) {
                    OLogManager.instance().error(this, "[OMetadata] Error on loading index manager, reset index configuration", e);
                    instance.create();
                }
            return instance;
        }
    }), database);
    security = new OSecurityProxy(database.getStorage().getResource(OSecurity.class.getSimpleName(), new Callable<OSecurity>() {

        public OSecurity call() {
            final OSecurity instance = OSecurityManager.instance().newSecurity();
            if (iLoad) {
                security = instance;
                instance.load();
            }
            return instance;
        }
    }), database);
    commandCache = database.getStorage().getResource(OCommandCache.class.getSimpleName(), new Callable<OCommandCache>() {

        public OCommandCache call() {
            return new OCommandCacheSoftRefs(database.getName());
        }
    });
    final Class<? extends OSecurity> securityClass = (Class<? extends OSecurity>) database.getProperty(ODatabase.OPTIONS.SECURITY.toString());
    if (securityClass != null)
        // INSTALL CUSTOM WRAPPED SECURITY
        try {
            final OSecurity wrapped = security;
            security = securityClass.getDeclaredConstructor(OSecurity.class, ODatabaseDocumentInternal.class).newInstance(wrapped, database);
        } catch (Exception e) {
            throw OException.wrapException(new OSecurityException("Cannot install custom security implementation (" + securityClass + ")"), e);
        }
    functionLibrary = new OFunctionLibraryProxy(database.getStorage().getResource(OFunctionLibrary.class.getSimpleName(), new Callable<OFunctionLibrary>() {

        public OFunctionLibrary call() {
            final OFunctionLibraryImpl instance = new OFunctionLibraryImpl();
            if (iLoad && !(database.getStorage() instanceof OStorageProxy))
                instance.load();
            return instance;
        }
    }), database);
    sequenceLibrary = new OSequenceLibraryProxy(database.getStorage().getResource(OSequenceLibrary.class.getSimpleName(), new Callable<OSequenceLibrary>() {

        @Override
        public OSequenceLibrary call() throws Exception {
            final OSequenceLibraryImpl instance = new OSequenceLibraryImpl();
            if (iLoad) {
                instance.load();
            }
            return instance;
        }
    }), database);
    scheduler = new OSchedulerProxy(database.getStorage().getResource(OScheduler.class.getSimpleName(), new Callable<OScheduler>() {

        public OScheduler call() {
            final OSchedulerImpl instance = new OSchedulerImpl();
            if (iLoad && !(database.getStorage() instanceof OStorageProxy))
                instance.load();
            return instance;
        }
    }), database);
    if (schemaLoaded.get())
        schema.onPostIndexManagement();
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OIndexManagerShared(com.orientechnologies.orient.core.index.OIndexManagerShared) OIndexManagerRemote(com.orientechnologies.orient.core.index.OIndexManagerRemote) OFunctionLibraryImpl(com.orientechnologies.orient.core.metadata.function.OFunctionLibraryImpl) OSequenceLibraryProxy(com.orientechnologies.orient.core.metadata.sequence.OSequenceLibraryProxy) OStorageProxy(com.orientechnologies.orient.core.storage.OStorageProxy) OFunctionLibraryProxy(com.orientechnologies.orient.core.metadata.function.OFunctionLibraryProxy) OSecurityException(com.orientechnologies.orient.core.exception.OSecurityException) OCommandCacheSoftRefs(com.orientechnologies.orient.core.cache.OCommandCacheSoftRefs) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal) OIndexManagerProxy(com.orientechnologies.orient.core.index.OIndexManagerProxy) Callable(java.util.concurrent.Callable) OSequenceLibrary(com.orientechnologies.orient.core.metadata.sequence.OSequenceLibrary) OSchemaProxy(com.orientechnologies.orient.core.metadata.schema.OSchemaProxy) OFunctionLibrary(com.orientechnologies.orient.core.metadata.function.OFunctionLibrary) OSchemaShared(com.orientechnologies.orient.core.metadata.schema.OSchemaShared) OSecurity(com.orientechnologies.orient.core.metadata.security.OSecurity) OSequenceLibraryImpl(com.orientechnologies.orient.core.metadata.sequence.OSequenceLibraryImpl) OSchedulerImpl(com.orientechnologies.orient.core.schedule.OSchedulerImpl) OScheduler(com.orientechnologies.orient.core.schedule.OScheduler) OException(com.orientechnologies.common.exception.OException) OSecurityException(com.orientechnologies.orient.core.exception.OSecurityException) IOException(java.io.IOException) OIndexManager(com.orientechnologies.orient.core.index.OIndexManager) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) OSecurityProxy(com.orientechnologies.orient.core.metadata.security.OSecurityProxy) OSchedulerProxy(com.orientechnologies.orient.core.schedule.OSchedulerProxy)

Example 12 with OSchemaProxy

use of com.orientechnologies.orient.core.metadata.schema.OSchemaProxy in project orientdb by orientechnologies.

the class ODatabaseDocumentTxTest method testDocFromJsonEmbedded.

@Test
public void testDocFromJsonEmbedded() {
    ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory: testDocFromJsonEmbedded_" + ODatabaseDocumentTxTest.class.getSimpleName());
    db.create();
    try {
        OSchemaProxy schema = db.getMetadata().getSchema();
        OClass c0 = schema.createClass("Class0");
        OClass c1 = schema.createClass("Class1");
        c1.createProperty("account", OType.STRING);
        c1.createProperty("meta", OType.EMBEDDED, c0);
        ODocument doc = new ODocument("Class1");
        doc.fromJSON("{\n" + "    \"account\": \"#25:0\",\n" + "    " + "\"meta\": {" + "   \"created\": \"2016-10-03T21:10:21.77-07:00\",\n" + "        \"ip\": \"0:0:0:0:0:0:0:1\",\n" + "   \"contentType\": \"application/x-www-form-urlencoded\"," + "   \"userAgent\": \"PostmanRuntime/2.5.2\"" + "}," + "\"data\": \"firstName=Jessica&lastName=Smith\"\n" + "}");
        db.save(doc);
        List<ODocument> result = db.query(new OSQLSynchQuery<Object>("select from Class0"));
        Assert.assertEquals(result.size(), 0);
        result = db.query(new OSQLSynchQuery<Object>("select from Class1"));
        Assert.assertEquals(result.size(), 1);
        ODocument item = result.get(0);
        ODocument meta = item.field("meta");
        Assert.assertEquals(meta.getClassName(), "Class0");
        Assert.assertEquals(meta.field("ip"), "0:0:0:0:0:0:0:1");
    } finally {
        db.drop();
    }
}
Also used : OSchemaProxy(com.orientechnologies.orient.core.metadata.schema.OSchemaProxy) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 13 with OSchemaProxy

use of com.orientechnologies.orient.core.metadata.schema.OSchemaProxy in project orientdb by orientechnologies.

the class OCommandExecutorSQLDropPropertyTest method test.

@Test
public void test() {
    OSchemaProxy schema = db.getMetadata().getSchema();
    OClass foo = schema.createClass("Foo");
    foo.createProperty("name", OType.STRING);
    Assert.assertTrue(schema.getClass("Foo").existsProperty("name"));
    db.command(new OCommandSQL("DROP PROPERTY Foo.name")).execute();
    schema.reload();
    Assert.assertFalse(schema.getClass("Foo").existsProperty("name"));
    foo.createProperty("name", OType.STRING);
    Assert.assertTrue(schema.getClass("Foo").existsProperty("name"));
    db.command(new OCommandSQL("DROP PROPERTY `Foo`.name")).execute();
    schema.reload();
    Assert.assertFalse(schema.getClass("Foo").existsProperty("name"));
    foo.createProperty("name", OType.STRING);
    Assert.assertTrue(schema.getClass("Foo").existsProperty("name"));
    db.command(new OCommandSQL("DROP PROPERTY Foo.`name`")).execute();
    schema.reload();
    Assert.assertFalse(schema.getClass("Foo").existsProperty("name"));
    foo.createProperty("name", OType.STRING);
    Assert.assertTrue(schema.getClass("Foo").existsProperty("name"));
    db.command(new OCommandSQL("DROP PROPERTY `Foo`.`name`")).execute();
    schema.reload();
    Assert.assertFalse(schema.getClass("Foo").existsProperty("name"));
}
Also used : OSchemaProxy(com.orientechnologies.orient.core.metadata.schema.OSchemaProxy) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) Test(org.testng.annotations.Test)

Example 14 with OSchemaProxy

use of com.orientechnologies.orient.core.metadata.schema.OSchemaProxy in project orientdb by orientechnologies.

the class OCommandExecutorSQLDropPropertyTest method testIfExists.

@Test
public void testIfExists() {
    OSchemaProxy schema = db.getMetadata().getSchema();
    OClass testIfExistsClass = schema.createClass("testIfExists");
    testIfExistsClass.createProperty("name", OType.STRING);
    Assert.assertTrue(schema.getClass("testIfExists").existsProperty("name"));
    db.command(new OCommandSQL("DROP PROPERTY testIfExists.name if exists")).execute();
    schema.reload();
    Assert.assertFalse(schema.getClass("testIfExists").existsProperty("name"));
    db.command(new OCommandSQL("DROP PROPERTY testIfExists.name if exists")).execute();
    schema.reload();
    Assert.assertFalse(schema.getClass("testIfExists").existsProperty("name"));
}
Also used : OSchemaProxy(com.orientechnologies.orient.core.metadata.schema.OSchemaProxy) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) Test(org.testng.annotations.Test)

Example 15 with OSchemaProxy

use of com.orientechnologies.orient.core.metadata.schema.OSchemaProxy in project orientdb by orientechnologies.

the class OMatchStatementExecutionTest method testBigEntryPoint.

@Test
public void testBigEntryPoint() {
    //issue #6890
    OSchemaProxy schema = db.getMetadata().getSchema();
    schema.createClass("testBigEntryPoint1");
    schema.createClass("testBigEntryPoint2");
    for (int i = 0; i < 1000; i++) {
        ODocument doc = db.newInstance("testBigEntryPoint1");
        doc.field("a", i);
        doc.save();
    }
    ODocument doc = db.newInstance("testBigEntryPoint2");
    doc.field("b", "b");
    doc.save();
    List<ODocument> qResult = db.command(new OCommandSQL("MATCH {class: testBigEntryPoint1, as: a}, {class: testBigEntryPoint2, as: b} return $elements limit 1")).execute();
    assertEquals(1, qResult.size());
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OSchemaProxy(com.orientechnologies.orient.core.metadata.schema.OSchemaProxy) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Aggregations

OSchemaProxy (com.orientechnologies.orient.core.metadata.schema.OSchemaProxy)17 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)14 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)10 Test (org.testng.annotations.Test)10 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)7 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)6 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)3 Test (org.junit.Test)3 Date (java.util.Date)2 OException (com.orientechnologies.common.exception.OException)1 OCommandCacheSoftRefs (com.orientechnologies.orient.core.cache.OCommandCacheSoftRefs)1 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)1 OSecurityException (com.orientechnologies.orient.core.exception.OSecurityException)1 OIndexManager (com.orientechnologies.orient.core.index.OIndexManager)1 OIndexManagerProxy (com.orientechnologies.orient.core.index.OIndexManagerProxy)1 OIndexManagerRemote (com.orientechnologies.orient.core.index.OIndexManagerRemote)1 OIndexManagerShared (com.orientechnologies.orient.core.index.OIndexManagerShared)1 OFunctionLibrary (com.orientechnologies.orient.core.metadata.function.OFunctionLibrary)1 OFunctionLibraryImpl (com.orientechnologies.orient.core.metadata.function.OFunctionLibraryImpl)1 OFunctionLibraryProxy (com.orientechnologies.orient.core.metadata.function.OFunctionLibraryProxy)1