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