Search in sources :

Example 11 with RelationEntity

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

the class JoinTest method testJoinOfJoin.

public void testJoinOfJoin() {
    prepareData();
    List<RelationEntity> relationEntities = relationEntityDao.loadAll();
    relationEntities.get(2).setParent(relationEntities.get(4));
    relationEntities.get(3).setParent(relationEntities.get(5));
    relationEntities.get(7).setParent(relationEntities.get(5));
    relationEntityDao.updateInTx(relationEntities);
    QueryBuilder<RelationEntity> queryBuilder = relationEntityDao.queryBuilder();
    Join<RelationEntity, RelationEntity> join1 = queryBuilder.join(RelationEntityDao.Properties.ParentId, RelationEntity.class);
    queryBuilder.join(join1, RelationEntityDao.Properties.TestIdNotNull, TestEntity.class, Properties.Id).where(Properties.SimpleInt.lt(6));
    Query<RelationEntity> query = queryBuilder.build();
    RelationEntity entity = query.uniqueOrThrow();
    assertEquals(relationEntities.get(2).getSimpleString(), entity.getSimpleString());
    query.setParameter(0, 99);
    assertEquals(3, query.list().size());
}
Also used : TestEntity(org.greenrobot.greendao.daotest.TestEntity) RelationEntity(org.greenrobot.greendao.daotest.RelationEntity)

Example 12 with RelationEntity

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

the class JoinTest method testJoinSimple.

public void testJoinSimple() {
    prepareData();
    QueryBuilder<RelationEntity> queryBuilder = createQueryBuilder(5);
    RelationEntity unique = queryBuilder.uniqueOrThrow();
    assertEquals("entity-5", unique.getSimpleString());
}
Also used : RelationEntity(org.greenrobot.greendao.daotest.RelationEntity)

Example 13 with RelationEntity

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

the class RelationEntityTest method testToOneLoadDeep.

public void testToOneLoadDeep() {
    RelationEntity entity = insertEntityWithRelations(42l);
    entity = dao.loadDeep(entity.getId());
    assertTestEntity(entity);
}
Also used : RelationEntity(org.greenrobot.greendao.daotest.RelationEntity)

Example 14 with RelationEntity

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

the class RelationEntityTest method testToOneLoadDeepNull.

public void testToOneLoadDeepNull() {
    RelationEntity entity = insertEntityWithRelations(42l);
    entity.setParentId(null);
    entity.setTestId(null);
    dao.update(entity);
    entity = dao.loadDeep(entity.getId());
    assertNull(entity.getParent());
    assertNull(entity.getTestEntity());
}
Also used : RelationEntity(org.greenrobot.greendao.daotest.RelationEntity)

Example 15 with RelationEntity

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

the class RelationEntityTest method testToOneClearKey.

public void testToOneClearKey() {
    RelationEntity entity = insertEntityWithRelations(42l);
    assertNotNull(entity.getParent());
    entity.setParentId(null);
    assertNull(entity.getParent());
}
Also used : 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