Search in sources :

Example 11 with ODatabaseSession

use of com.orientechnologies.orient.core.db.ODatabaseSession in project wicket-orientdb by OrienteerBAP.

the class TestInAppOrientDBCompatibility method testDeletionOfDependentClass2.

@Test
public void testDeletionOfDependentClass2() {
    ODatabaseSession db = wicket.getTester().getDatabaseSession();
    OSchema schema = db.getMetadata().getSchema();
    OClass classAbs = schema.createAbstractClass("TestDeletionAbst");
    OClass classA = schema.createClass("TestDeletionA", classAbs);
    ODocument doc = new ODocument(classA);
    doc.save();
    assertEquals(1, classA.count());
    OClass classB = schema.createClass("TestDeletionB", classA);
    doc = new ODocument(classB);
    doc.save();
    assertEquals(1, classB.count());
    assertEquals(2, classA.count());
    schema.dropClass(classB.getName());
    assertEquals(1, classA.count());
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODatabaseSession(com.orientechnologies.orient.core.db.ODatabaseSession) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Example 12 with ODatabaseSession

use of com.orientechnologies.orient.core.db.ODatabaseSession in project wicket-orientdb by OrienteerBAP.

the class AbstractDataInstallator method onAfterInitialized.

@Override
public void onAfterInitialized(Application application) {
    OrientDbWebApplication app = (OrientDbWebApplication) application;
    ODatabaseSession db = getDatabase(app);
    try {
        installData(app, db);
    } catch (Exception ex) {
        LOG.error("Data can't be installed", ex);
    } finally {
        db.close();
        app.getOrientDbSettings().getContext().invalidateCachedPools();
    }
}
Also used : ODatabaseSession(com.orientechnologies.orient.core.db.ODatabaseSession)

Example 13 with ODatabaseSession

use of com.orientechnologies.orient.core.db.ODatabaseSession in project wicket-orientdb by OrienteerBAP.

the class OQueryModel method size.

/**
 * Get the size of the data
 * @return results size
 */
public long size() {
    if (size == null) {
        ODatabaseSession db = OrientDbWebSession.get().getDatabaseSession();
        try (OResultSet result = db.query(queryManager.getCountSql(), prepareParams())) {
            if (result.hasNext()) {
                Number sizeNumber = result.next().getProperty("count");
                size = sizeNumber != null ? sizeNumber.longValue() : 0;
            } else {
                size = 0L;
            }
        }
    }
    return size;
}
Also used : OResultSet(com.orientechnologies.orient.core.sql.executor.OResultSet) ODatabaseSession(com.orientechnologies.orient.core.db.ODatabaseSession)

Example 14 with ODatabaseSession

use of com.orientechnologies.orient.core.db.ODatabaseSession in project wicket-orientdb by OrienteerBAP.

the class TestInAppOrientDBCompatibility method testRemovingReadonlyField.

@Test
public void testRemovingReadonlyField() {
    ODatabaseSession db = wicket.getTester().getDatabaseSession();
    OSchema schema = db.getMetadata().getSchema();
    OClass classA = schema.createClass("TestRemovingField");
    classA.createProperty("name", OType.STRING);
    OProperty property = classA.createProperty("property", OType.STRING);
    property.setReadonly(true);
    ODocument doc = new ODocument(classA);
    doc.field("name", "My Name");
    doc.field("property", "value1");
    doc.save();
    doc.field("name", "My Name 2");
    doc.field("property", "value2");
    doc.undo("property");
    doc.save();
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OProperty(com.orientechnologies.orient.core.metadata.schema.OProperty) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODatabaseSession(com.orientechnologies.orient.core.db.ODatabaseSession) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Example 15 with ODatabaseSession

use of com.orientechnologies.orient.core.db.ODatabaseSession in project wicket-orientdb by OrienteerBAP.

the class TestInAppOrientDBCompatibility method testCreationInHook.

@Test
public void testCreationInHook() {
    ODatabaseSession db = wicket.getTester().getDatabaseSession();
    OSchema schema = db.getMetadata().getSchema();
    final OClass classA = schema.createClass("TestCreationInHookMain");
    final OClass classB = schema.createClass("TestCreationInHookReflect");
    classA.createProperty("name", OType.STRING);
    classA.createProperty("mirror", OType.LINK).setLinkedClass(classB);
    classB.createProperty("name", OType.STRING);
    db.registerHook(new ODocumentHookAbstract(db) {

        {
            setIncludeClasses(classA.getName());
        }

        @Override
        public RESULT onRecordBeforeCreate(ODocument iDocument) {
            ODocument mirror = new ODocument(classB);
            mirror.field("name", (Object) iDocument.field("name"));
            iDocument.field("mirror", mirror);
            return RESULT.RECORD_CHANGED;
        }

        @Override
        public DISTRIBUTED_EXECUTION_MODE getDistributedExecutionMode() {
            return DISTRIBUTED_EXECUTION_MODE.SOURCE_NODE;
        }
    });
    for (int i = 0; i < 10; i++) {
        String name = "name-" + RANDOM.nextLong();
        ODocument doc = new ODocument(classA);
        doc.field("name", name);
        doc.save();
    }
    db.commit();
    db.close();
    db = wicket.getTester().getDatabaseSession();
    for (ODocument doc : db.browseClass(classA.getName())) {
        String name = doc.field("name");
        assertNotNull(name);
        ODocument mirror = doc.field("mirror");
        assertNotNull(mirror);
        assertEquals(name, mirror.field("name"));
    }
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) ODocumentHookAbstract(com.orientechnologies.orient.core.hook.ODocumentHookAbstract) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODatabaseSession(com.orientechnologies.orient.core.db.ODatabaseSession) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Aggregations

ODatabaseSession (com.orientechnologies.orient.core.db.ODatabaseSession)31 Test (org.junit.Test)23 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)21 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)19 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)17 Ignore (org.junit.Ignore)10 ORID (com.orientechnologies.orient.core.id.ORID)6 ODocumentHookAbstract (com.orientechnologies.orient.core.hook.ODocumentHookAbstract)5 OResultSet (com.orientechnologies.orient.core.sql.executor.OResultSet)4 OProperty (com.orientechnologies.orient.core.metadata.schema.OProperty)3 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)2 ORecordId (com.orientechnologies.orient.core.id.ORecordId)2 ORecord (com.orientechnologies.orient.core.record.ORecord)2 OSchemaHelper (ru.ydn.wicket.wicketorientdb.utils.OSchemaHelper)2 Function (com.google.common.base.Function)1 Maps (com.google.common.collect.Maps)1 OResettable (com.orientechnologies.common.util.OResettable)1 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)1 ODatabaseRecordThreadLocal (com.orientechnologies.orient.core.db.ODatabaseRecordThreadLocal)1 OrientDB (com.orientechnologies.orient.core.db.OrientDB)1