@Override public void readEntity(Cursor cursor, ToManyTargetEntity entity, int offset) { entity.setToManyId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); entity.setToManyIdDesc(cursor.isNull(offset + 1) ? null : cursor.getLong(offset + 1)); entity.setId(cursor.isNull(offset + 2) ? null : cursor.getLong(offset + 2)); entity.setTargetJoinProperty(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); }
private ToManyTargetEntity[] insertTargetEntities(Long toManyId, int count, String joinProperty) { ToManyTargetEntity[] targetEntities = new ToManyTargetEntity[count]; for (int i = 0; i < count; i++) { ToManyTargetEntity target = new ToManyTargetEntity(); target.setToManyId(toManyId); target.setToManyIdDesc(toManyId); target.setTargetJoinProperty(joinProperty); targetEntities[i] = target; } toManyTargetEntityDao.insertInTx(targetEntities); return targetEntities; }
public void testJoinProperty() { ToManyEntity entity = new ToManyEntity(1L); entity.setSourceJoinProperty("JOIN ME"); daoSession.insert(entity); insertTargetEntities(null, 3, "JOIN ME"); ToManyEntity testEntity = toManyEntityDao.load(1L); List<ToManyTargetEntity> targetEntities = testEntity.getToManyByJoinProperty(); assertEquals(3, targetEntities.size()); ToManyTargetEntity middleEntity = targetEntities.get(1); middleEntity.setTargetJoinProperty("DON'T JOIN ME"); toManyTargetEntityDao.update(middleEntity); testEntity.resetToManyByJoinProperty(); targetEntities = testEntity.getToManyByJoinProperty(); assertEquals(2, targetEntities.size()); assertFalse(middleEntity.getId() == targetEntities.get(0).getId()); assertFalse(middleEntity.getId() == targetEntities.get(1).getId()); }
public void testTwoJoinProperty() { ToManyEntity entity = new ToManyEntity(1L); entity.setSourceJoinProperty("JOIN ME"); daoSession.insert(entity); insertTargetEntities(1L, 3, "JOIN ME"); ToManyEntity testEntity = toManyEntityDao.load(1L); List<ToManyTargetEntity> targetEntities = testEntity.getToManyJoinTwo(); assertEquals(3, targetEntities.size()); ToManyTargetEntity middleEntity = targetEntities.get(1); middleEntity.setTargetJoinProperty("DON'T JOIN ME"); toManyTargetEntityDao.update(middleEntity); testEntity.resetToManyJoinTwo(); targetEntities = testEntity.getToManyJoinTwo(); assertEquals(2, targetEntities.size()); assertFalse(middleEntity.getId() == targetEntities.get(0).getId()); assertFalse(middleEntity.getId() == targetEntities.get(1).getId()); }