Search in sources :

Example 1 with OSchemaHelper

use of ru.ydn.wicket.wicketorientdb.utils.OSchemaHelper in project wicket-orientdb by OrienteerBAP.

the class TestInAppOrientDBCompatibility method testLinkListAndODocumentConversion.

@Test
@Ignore
public // TODO: Enable when https://github.com/orientechnologies/orientdb/issues/9421 will be in OrientDB
void testLinkListAndODocumentConversion() {
    ODatabaseSession db = wicket.getTester().getDatabaseSession();
    OSchemaHelper helper = OSchemaHelper.bind(db);
    helper.oClass("TestODocumentConverstion").oProperty("name", OType.STRING).oProperty("items", OType.LINKLIST);
    ODocument mainDoc = helper.oDocument("name", "document").saveDocument().getODocument();
    helper.oClass("TestODocumentConverstionItems").oProperty("name", OType.STRING);
    ODocument doc1 = helper.oDocument("name", "item1").saveDocument().getODocument();
    ODocument doc2 = helper.oDocument("name", "item2").saveDocument().getODocument();
    ODocument doc3 = helper.oDocument("name", "item3").saveDocument().getODocument();
    List<ODocument> items = Arrays.asList(doc1, doc2, doc3);
    mainDoc.field("items", items);
    mainDoc.save();
    db.commit();
    db.begin();
    mainDoc = (ODocument) mainDoc.reload();
    items = mainDoc.field("items", List.class);
    Iterator<ODocument> it = items.iterator();
    it.next();
    if (it instanceof OResettable)
        ((OResettable) it).reset();
    assertTrue(items.get(0) instanceof ODocument);
    assertEquals(doc1, items.get(0));
    assertTrue(items.get(1) instanceof ODocument);
    assertEquals(doc2, items.get(1));
    assertTrue(items.get(2) instanceof ODocument);
    assertEquals(doc3, items.get(2));
    db.commit();
}
Also used : OSchemaHelper(ru.ydn.wicket.wicketorientdb.utils.OSchemaHelper) OResettable(com.orientechnologies.common.util.OResettable) List(java.util.List) ODatabaseSession(com.orientechnologies.orient.core.db.ODatabaseSession) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with OSchemaHelper

use of ru.ydn.wicket.wicketorientdb.utils.OSchemaHelper in project wicket-orientdb by OrienteerBAP.

the class WicketApplication method init.

/**
 * @see org.apache.wicket.Application#init()
 */
@Override
public void init() {
    super.init();
    getApplicationListeners().add(new EmbeddOrientDbApplicationListener(WicketApplication.class.getResource("db.config.xml")) {

        @Override
        public void onAfterServerStartupAndActivation(OrientDbWebApplication app) throws Exception {
            OrientDB orientDB = getServer().getContext();
            orientDB.createIfNotExists(getOrientDbSettings().getDbName(), getOrientDbSettings().getDbType());
        }
    });
    getOrientDbSettings().setDbName(DB_NAME);
    getOrientDbSettings().setDbType(ODatabaseType.MEMORY);
    getOrientDbSettings().setGuestUserName("admin");
    getOrientDbSettings().setGuestPassword("admin");
    OrientDBHttpAPIResource.mountOrientDbRestApi(this);
    getApplicationListeners().add(new AbstractDataInstallator() {

        @Override
        protected void installData(OrientDbWebApplication app, ODatabaseSession db) {
            OSchemaHelper helper = OSchemaHelper.bind(db);
            helper.oClass(CLASS_NAME).oProperty(PROP_NAME, OType.STRING).oProperty(PROP_INT, OType.INTEGER).oProperty(PROP_DATE, OType.DATE);
            if (helper.getOClass().count() == 0) {
                Random random = new Random();
                Date today = new Date(System.currentTimeMillis());
                int delta = 365 * 24 * 60 * 60;
                for (int i = 0; i < 50; i++) {
                    ODocument doc = new ODocument(helper.getOClass());
                    doc.field(PROP_NAME, "Name for #" + i);
                    doc.field(PROP_INT, i);
                    doc.field(PROP_DATE, new Date(today.getTime() + (random.nextInt(2 * delta) - delta) * 1000));
                    doc.save();
                }
            }
        }
    });
    LOG.info("Wicket-OrientDB Demo Web App has been started");
}
Also used : OrientDB(com.orientechnologies.orient.core.db.OrientDB) AbstractDataInstallator(ru.ydn.wicket.wicketorientdb.AbstractDataInstallator) OSchemaHelper(ru.ydn.wicket.wicketorientdb.utils.OSchemaHelper) Random(java.util.Random) EmbeddOrientDbApplicationListener(ru.ydn.wicket.wicketorientdb.EmbeddOrientDbApplicationListener) ODatabaseSession(com.orientechnologies.orient.core.db.ODatabaseSession) Date(java.sql.Date) OrientDbWebApplication(ru.ydn.wicket.wicketorientdb.OrientDbWebApplication) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Aggregations

ODatabaseSession (com.orientechnologies.orient.core.db.ODatabaseSession)2 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)2 OSchemaHelper (ru.ydn.wicket.wicketorientdb.utils.OSchemaHelper)2 OResettable (com.orientechnologies.common.util.OResettable)1 OrientDB (com.orientechnologies.orient.core.db.OrientDB)1 Date (java.sql.Date)1 List (java.util.List)1 Random (java.util.Random)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1 AbstractDataInstallator (ru.ydn.wicket.wicketorientdb.AbstractDataInstallator)1 EmbeddOrientDbApplicationListener (ru.ydn.wicket.wicketorientdb.EmbeddOrientDbApplicationListener)1 OrientDbWebApplication (ru.ydn.wicket.wicketorientdb.OrientDbWebApplication)1