use of ru.ydn.wicket.wicketorientdb.model.ODocumentModel in project wicket-orientdb by OrienteerBAP.
the class TestModels method testODocumentModel.
@Test
public void testODocumentModel() {
ODatabaseDocument db = wicket.getTester().getDatabase();
ORecordId recordId = new ORecordId("#5:0");
ODocumentModel model = new ODocumentModel(recordId);
assertModelObjectEquals(recordId.getRecord(), model);
recordId = new ORecordId("#5:1");
model.setObject((ODocument) recordId.getRecord());
assertModelObjectEquals(recordId.getRecord(), model);
model.setObject(null);
assertModelObjectEquals(null, model);
// Test persistence between calls
db.begin();
ODocument doc = new ODocument("ClassA");
doc.field("name", "test1");
model = new ODocumentModel(doc);
assertEquals("test1", model.getObject().field("name"));
interupt(db, model);
assertEquals("test1", model.getObject().field("name"));
model.getObject().save();
interupt(db, model);
// Test that document actually reloaded from DB after closing transaction
assertEquals("test1", model.getObject().field("name"));
model.getObject().field("name", "test2");
assertEquals("test2", model.getObject().field("name"));
interupt(db, model);
assertEquals("test1", model.getObject().field("name"));
// Test autoSave feature
model.getObject().field("name", "test3");
model.setAutoSave(true);
interupt(db, model);
assertEquals("test3", model.getObject().field("name"));
}
use of ru.ydn.wicket.wicketorientdb.model.ODocumentModel in project wicket-orientdb by OrienteerBAP.
the class TestFilters method testLinkFilter.
@Test
public void testLinkFilter() {
IModel<OProperty> property = wicket.getProperty(NUMBER_FIELD);
IFilterCriteriaManager manager = new FilterCriteriaManager(property);
IFilterCriteria equalsFilterCriteria = manager.createEqualsFilterCriteria(Model.of(NUM_VALUE_1), Model.of(true));
manager.addFilterCriteria(equalsFilterCriteria);
queryModel.addFilterCriteriaManager(property.getObject().getName(), manager);
ODocument document = queryModel.getObject().get(0).field(LINK_FIELD);
queryModel.clearFilterCriteriaManagers();
queryModel.detach();
property = wicket.getProperty(LINK_FIELD);
manager = new FilterCriteriaManager(property);
equalsFilterCriteria = manager.createEqualsFilterCriteria(new ODocumentModel(document), Model.of(true));
manager.addFilterCriteria(equalsFilterCriteria);
queryModel.addFilterCriteriaManager(property.getObject().getName(), manager);
assertTrue(queryModel.size() == 1);
assertTrue(queryModel.getObject().get(0).field(STRING_FIELD).equals(STR_VALUE_1));
}
use of ru.ydn.wicket.wicketorientdb.model.ODocumentModel in project wicket-orientdb by OrienteerBAP.
the class TestModels method testOQueryModelDBTouch.
@Test
public void testOQueryModelDBTouch() {
OClass classA = wicket.getTester().getSchema().getClass("ClassA");
ODocument doc = new ODocument(classA);
doc.field("other", Arrays.asList(doc));
OQueryModel<ODocument> queryModel = new OQueryModel<ODocument>("select from ClassA where :doc in other");
queryModel.setParameter("doc", new ODocumentModel(doc));
long was = classA.count();
assertTrue(doc.getIdentity().isNew());
assertEquals(0, queryModel.size());
assertTrue(doc.getIdentity().isNew());
assertEquals(was, classA.count());
}
use of ru.ydn.wicket.wicketorientdb.model.ODocumentModel in project wicket-orientdb by OrienteerBAP.
the class TestModels method testODocumentLinksDataProvider.
@Test
public void testODocumentLinksDataProvider() {
ODocument doc1 = new ODocument("ClassA");
doc1.field("name", "doc1Ext");
doc1.save();
ODocument doc2 = new ODocument("ClassA");
doc2.field("name", "doc2Ext");
doc2.field("other", Arrays.asList(doc1));
try {
ODocumentModel documentModel = new ODocumentModel(doc2);
OPropertyModel propertyModel = new OPropertyModel("ClassA", "other");
ODocumentLinksDataProvider provider = new ODocumentLinksDataProvider(documentModel, propertyModel);
assertEquals(1, provider.size());
assertEquals(doc1, provider.iterator(0, 1).next());
doc2.save();
provider.detach();
assertEquals(1, provider.size());
assertEquals(doc1, provider.iterator(0, 1).next());
} finally {
doc1.delete();
doc2.delete();
}
}
use of ru.ydn.wicket.wicketorientdb.model.ODocumentModel in project wicket-orientdb by OrienteerBAP.
the class TestModels method testODocumentPropertyLocator.
@Test
public void testODocumentPropertyLocator() {
ORecordId recordId = new ORecordId("#5:0");
assertModelObjectEquals("admin", new PropertyModel<>(new ODocumentModel(recordId), "name"));
assertModelObjectEquals("OUser", new PropertyModel<>(new ODocumentModel(recordId), "@schemaClass.name"));
}
Aggregations