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();
}
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");
}
Aggregations