Search in sources :

Example 1 with OObjectDatabaseTx

use of com.orientechnologies.orient.object.db.OObjectDatabaseTx in project orientdb by orientechnologies.

the class CustomDatatypeTest method reproduce.

@Test
public void reproduce() throws Exception {
    final OObjectDatabaseTx db = new OObjectDatabaseTx("memory:CustomDatatypeTest");
    db.create();
    // WrappedString custom datatype registration (storing it as
    // OType.STRING)
    OObjectSerializerContext serializerContext = new OObjectSerializerContext();
    serializerContext.bind(new OObjectSerializer<WrappedString, String>() {

        @Override
        public String serializeFieldValue(Class<?> iClass, WrappedString iFieldValue) {
            return iFieldValue.getValue();
        }

        @Override
        public WrappedString unserializeFieldValue(Class<?> iClass, String iFieldValue) {
            final WrappedString result = new WrappedString();
            result.setValue(iFieldValue);
            return result;
        }
    }, db);
    OObjectSerializerHelper.bindSerializerContext(WrappedString.class, serializerContext);
    // we want schema to be generated
    db.setAutomaticSchemaGeneration(true);
    // register our entity
    db.getEntityManager().registerEntityClass(Entity.class);
    // Validate DB did figure out schema properly
    Assert.assertEquals(db.getMetadata().getSchema().getClass(Entity.class).getProperty("data").getType(), OType.STRING);
}
Also used : OObjectSerializerContext(com.orientechnologies.orient.object.serialization.OObjectSerializerContext) OObjectDatabaseTx(com.orientechnologies.orient.object.db.OObjectDatabaseTx) Test(org.testng.annotations.Test)

Example 2 with OObjectDatabaseTx

use of com.orientechnologies.orient.object.db.OObjectDatabaseTx in project orientdb by orientechnologies.

the class OObjectEntitySerializerTest method setUp.

@BeforeClass
protected void setUp() throws Exception {
    databaseTx = new OObjectDatabaseTx("memory:OObjectEntitySerializerTest");
    databaseTx.create();
    databaseTx.getEntityManager().registerEntityClass(ExactEntity.class);
}
Also used : OObjectDatabaseTx(com.orientechnologies.orient.object.db.OObjectDatabaseTx)

Example 3 with OObjectDatabaseTx

use of com.orientechnologies.orient.object.db.OObjectDatabaseTx in project orientdb by orientechnologies.

the class OObjectEnumLazyListTest method setUp.

@BeforeClass
protected void setUp() throws Exception {
    databaseTx = new OObjectDatabaseTx("memory:OObjectEnumLazyListTest");
    databaseTx.create();
    databaseTx.getEntityManager().registerEntityClass(EntityWithEnumList.class);
}
Also used : OObjectDatabaseTx(com.orientechnologies.orient.object.db.OObjectDatabaseTx) BeforeClass(org.testng.annotations.BeforeClass)

Example 4 with OObjectDatabaseTx

use of com.orientechnologies.orient.object.db.OObjectDatabaseTx in project orientdb by orientechnologies.

the class JSONTest method testFetchedJson.

@Test
public void testFetchedJson() {
    OObjectDatabaseTx database = new OObjectDatabaseTx(url);
    database.open("admin", "admin");
    try {
        database.getEntityManager().registerEntityClasses("com.orientechnologies.orient.test.domain.business");
        database.getEntityManager().registerEntityClasses("com.orientechnologies.orient.test.domain.whiz");
        database.getEntityManager().registerEntityClasses("com.orientechnologies.orient.test.domain.base");
        List<ODocument> result = database.getUnderlying().command(new OSQLSynchQuery<ODocument>("select * from Profile where name = 'Barack' and surname = 'Obama'")).execute();
        for (ODocument doc : result) {
            String jsonFull = doc.toJSON("type,rid,version,class,keepTypes,attribSameRow,indent:0,fetchPlan:*:-1");
            ODocument loadedDoc = new ODocument().fromJSON(jsonFull);
            Assert.assertTrue(doc.hasSameContentOf(loadedDoc));
        }
    } finally {
        database.close();
    }
}
Also used : OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) OObjectDatabaseTx(com.orientechnologies.orient.object.db.OObjectDatabaseTx) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 5 with OObjectDatabaseTx

use of com.orientechnologies.orient.object.db.OObjectDatabaseTx in project orientdb by orientechnologies.

the class SQLSelectProjectionsTest method queryProjectionObjectLevel.

@Test
public void queryProjectionObjectLevel() {
    OObjectDatabaseTx db = new OObjectDatabaseTx(url);
    db.open("admin", "admin");
    List<ODocument> result = db.getUnderlying().query(new OSQLSynchQuery<ODocument>(" select nick, followings, followers from Profile "));
    Assert.assertTrue(result.size() != 0);
    for (ODocument d : result) {
        Assert.assertTrue(d.fieldNames().length <= 3);
        Assert.assertNull(d.getClassName());
        Assert.assertEquals(ORecordInternal.getRecordType(d), ODocument.RECORD_TYPE);
    }
    db.close();
}
Also used : OObjectDatabaseTx(com.orientechnologies.orient.object.db.OObjectDatabaseTx) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Aggregations

OObjectDatabaseTx (com.orientechnologies.orient.object.db.OObjectDatabaseTx)48 Test (org.testng.annotations.Test)25 ORID (com.orientechnologies.orient.core.id.ORID)15 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)14 HashMap (java.util.HashMap)11 HashSet (java.util.HashSet)11 Map (java.util.Map)9 ORecordId (com.orientechnologies.orient.core.id.ORecordId)8 EnumTest (com.orientechnologies.orient.test.domain.base.EnumTest)8 JavaAttachDetachTestClass (com.orientechnologies.orient.test.domain.base.JavaAttachDetachTestClass)8 Planet (com.orientechnologies.orient.test.domain.base.Planet)8 Satellite (com.orientechnologies.orient.test.domain.base.Satellite)8 Child (com.orientechnologies.orient.test.domain.business.Child)8 Set (java.util.Set)8 ArrayList (java.util.ArrayList)5 Proxy (javassist.util.proxy.Proxy)5 BeforeClass (org.testng.annotations.BeforeClass)5 CycleChild (com.orientechnologies.orient.test.domain.cycle.CycleChild)4 GrandChild (com.orientechnologies.orient.test.domain.cycle.GrandChild)4 LazyChild (com.orientechnologies.orient.test.domain.lazy.LazyChild)4