Search in sources :

Example 1 with OrientDB

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

the class TestStandaloneOrientDBCompatibility method testOrientDbLifeCycle.

public void testOrientDbLifeCycle(String dbName, ODatabaseType type, boolean createDb, boolean dropDb) throws Exception {
    Orient.instance().startup();
    assertNotNull(ODatabaseRecordThreadLocal.instance());
    Orient.instance().removeShutdownHook();
    OServer server = OServerMain.create();
    server.startup(OrientDbTestWebApplication.class.getResource("db.config.xml").openStream());
    server.activate();
    OrientDB orientDB = server.getContext();
    if (createDb && !orientDB.exists(dbName)) {
        orientDB.create(dbName, type);
    }
    assertNotNull(ODatabaseRecordThreadLocal.instance());
    ODatabaseDocument db = orientDB.cachedPool(dbName, "admin", "admin").acquire();
    db.close();
    assertNotNull(ODatabaseRecordThreadLocal.instance());
    if (dropDb) {
        orientDB.drop(dbName);
    }
    server.shutdown();
    Orient.instance().shutdown();
}
Also used : OrientDB(com.orientechnologies.orient.core.db.OrientDB) OServer(com.orientechnologies.orient.server.OServer) ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument)

Example 2 with OrientDB

use of com.orientechnologies.orient.core.db.OrientDB 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

OrientDB (com.orientechnologies.orient.core.db.OrientDB)2 ODatabaseSession (com.orientechnologies.orient.core.db.ODatabaseSession)1 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)1 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)1 OServer (com.orientechnologies.orient.server.OServer)1 Date (java.sql.Date)1 Random (java.util.Random)1 AbstractDataInstallator (ru.ydn.wicket.wicketorientdb.AbstractDataInstallator)1 EmbeddOrientDbApplicationListener (ru.ydn.wicket.wicketorientdb.EmbeddOrientDbApplicationListener)1 OrientDbWebApplication (ru.ydn.wicket.wicketorientdb.OrientDbWebApplication)1 OSchemaHelper (ru.ydn.wicket.wicketorientdb.utils.OSchemaHelper)1