Search in sources :

Example 1 with ODocumentModel

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"));
}
Also used : ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) ODocumentModel(ru.ydn.wicket.wicketorientdb.model.ODocumentModel) ORecordId(com.orientechnologies.orient.core.id.ORecordId) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Example 2 with ODocumentModel

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));
}
Also used : IFilterCriteriaManager(ru.ydn.wicket.wicketorientdb.utils.query.filter.IFilterCriteriaManager) OProperty(com.orientechnologies.orient.core.metadata.schema.OProperty) IFilterCriteriaManager(ru.ydn.wicket.wicketorientdb.utils.query.filter.IFilterCriteriaManager) FilterCriteriaManager(ru.ydn.wicket.wicketorientdb.utils.query.filter.FilterCriteriaManager) ODocumentModel(ru.ydn.wicket.wicketorientdb.model.ODocumentModel) IFilterCriteria(ru.ydn.wicket.wicketorientdb.utils.query.filter.IFilterCriteria) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Example 3 with ODocumentModel

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());
}
Also used : OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODocumentModel(ru.ydn.wicket.wicketorientdb.model.ODocumentModel) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) OQueryModel(ru.ydn.wicket.wicketorientdb.model.OQueryModel) Test(org.junit.Test)

Example 4 with ODocumentModel

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();
    }
}
Also used : ODocumentLinksDataProvider(ru.ydn.wicket.wicketorientdb.model.ODocumentLinksDataProvider) OPropertyModel(ru.ydn.wicket.wicketorientdb.model.OPropertyModel) ODocumentModel(ru.ydn.wicket.wicketorientdb.model.ODocumentModel) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Example 5 with ODocumentModel

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"));
}
Also used : ODocumentModel(ru.ydn.wicket.wicketorientdb.model.ODocumentModel) ORecordId(com.orientechnologies.orient.core.id.ORecordId) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)6 ODocumentModel (ru.ydn.wicket.wicketorientdb.model.ODocumentModel)6 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)5 ORecordId (com.orientechnologies.orient.core.id.ORecordId)2 OProperty (com.orientechnologies.orient.core.metadata.schema.OProperty)2 FilterCriteriaManager (ru.ydn.wicket.wicketorientdb.utils.query.filter.FilterCriteriaManager)2 IFilterCriteria (ru.ydn.wicket.wicketorientdb.utils.query.filter.IFilterCriteria)2 IFilterCriteriaManager (ru.ydn.wicket.wicketorientdb.utils.query.filter.IFilterCriteriaManager)2 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)1 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)1 ODocumentLinksDataProvider (ru.ydn.wicket.wicketorientdb.model.ODocumentLinksDataProvider)1 ODocumentLinksQueryDataProvider (ru.ydn.wicket.wicketorientdb.model.ODocumentLinksQueryDataProvider)1 OPropertyModel (ru.ydn.wicket.wicketorientdb.model.OPropertyModel)1 OQueryModel (ru.ydn.wicket.wicketorientdb.model.OQueryModel)1