Search in sources :

Example 6 with RelationEntity

use of org.greenrobot.greendao.daotest.RelationEntity in project greenDAO by greenrobot.

the class RelationEntityTest method testToOneClearEntity.

public void testToOneClearEntity() {
    RelationEntity entity = insertEntityWithRelations(42l);
    assertNotNull(entity.getParentId());
    entity.setParent(null);
    assertNull(entity.getParentId());
}
Also used : RelationEntity(org.greenrobot.greendao.daotest.RelationEntity)

Example 7 with RelationEntity

use of org.greenrobot.greendao.daotest.RelationEntity in project greenDAO by greenrobot.

the class RelationEntityTest method insertEntityWithRelations.

protected RelationEntity insertEntityWithRelations(Long testEntityId) {
    TestEntity testEntity = daoSession.getTestEntityDao().load(testEntityId);
    if (testEntity == null) {
        testEntity = new TestEntity(testEntityId);
        testEntity.setSimpleStringNotNull("mytest");
        daoSession.getTestEntityDao().insert(testEntity);
    }
    RelationEntity parentEntity = createEntity(null);
    parentEntity.setSimpleString("I'm a parent");
    parentEntity.setTestNotNull(testEntity);
    dao.insert(parentEntity);
    RelationEntity entity = createEntity(null);
    entity.setTestId(testEntityId);
    entity.setParentId(parentEntity.getId());
    entity.setSimpleString("findMe");
    entity.setTestNotNull(testEntity);
    dao.insert(entity);
    return entity;
}
Also used : TestEntity(org.greenrobot.greendao.daotest.TestEntity) RelationEntity(org.greenrobot.greendao.daotest.RelationEntity)

Example 8 with RelationEntity

use of org.greenrobot.greendao.daotest.RelationEntity in project greenDAO by greenrobot.

the class RelationEntityTestIdentityScope method testQueryDeepIdentityScope.

public void testQueryDeepIdentityScope() {
    RelationEntity entity = insertEntityWithRelations(42l);
    String columnName = RelationEntityDao.Properties.SimpleString.columnName;
    List<RelationEntity> entityList = dao.queryDeep("WHERE T." + columnName + "=?", "findMe");
    RelationEntity entity2 = entityList.get(0);
    entityList = dao.queryDeep("WHERE T." + columnName + "=?", "findMe");
    RelationEntity entity3 = entityList.get(0);
    assertSame(entity, entity2);
    assertSame(entity, entity3);
    assertTestEntity(entity);
}
Also used : RelationEntity(org.greenrobot.greendao.daotest.RelationEntity)

Example 9 with RelationEntity

use of org.greenrobot.greendao.daotest.RelationEntity in project greenDAO by greenrobot.

the class RelationEntityTestIdentityScope method testToOneLoadDeepIdentityScope.

public void testToOneLoadDeepIdentityScope() {
    RelationEntity entity = insertEntityWithRelations(42l);
    RelationEntity entity2 = insertEntityWithRelations(42l);
    entity = dao.loadDeep(entity.getId());
    entity2 = dao.loadDeep(entity2.getId());
    assertFalse(entity.getId().equals(entity2.getId()));
    assertTestEntity(entity);
    assertTestEntity(entity2);
    assertSame(entity.getTestEntity(), entity2.getTestEntity());
}
Also used : RelationEntity(org.greenrobot.greendao.daotest.RelationEntity)

Example 10 with RelationEntity

use of org.greenrobot.greendao.daotest.RelationEntity in project greenDAO by greenrobot.

the class JoinTest method prepareData.

private void prepareData() {
    List<TestEntity> targetEntities = new ArrayList<TestEntity>();
    for (int i = 0; i < 10; i++) {
        TestEntity testEntity = new TestEntity();
        testEntity.setSimpleInt(i + 1);
        testEntity.setSimpleStringNotNull("string-" + (i + 1));
        targetEntities.add(testEntity);
    }
    testEntityDao.insertInTx(targetEntities);
    List<RelationEntity> entities = new ArrayList<RelationEntity>();
    for (int i = 0; i < 10; i++) {
        RelationEntity entity = new RelationEntity();
        entity.setSimpleString("entity-" + (i + 1));
        entity.setTestNotNull(targetEntities.get(i));
        entities.add(entity);
    }
    relationEntityDao.insertInTx(entities);
}
Also used : TestEntity(org.greenrobot.greendao.daotest.TestEntity) ArrayList(java.util.ArrayList) RelationEntity(org.greenrobot.greendao.daotest.RelationEntity)

Aggregations

RelationEntity (org.greenrobot.greendao.daotest.RelationEntity)20 TestEntity (org.greenrobot.greendao.daotest.TestEntity)5 ArrayList (java.util.ArrayList)1