@Override public Long getKey(ToManyTargetEntity entity) { if(entity != null) { return entity.getId(); } else { return null; } }
@Override public boolean hasKey(ToManyTargetEntity entity) { return entity.getId() != null; }
private void assertSameEntities(ToManyTargetEntity[] targetEntities, List<ToManyTargetEntity> resolvedToMany) { int count = targetEntities.length; assertEquals(count, resolvedToMany.size()); Map<Long, ToManyTargetEntity> resolvedMap = new HashMap<>(); for (ToManyTargetEntity resolvedEntity : resolvedToMany) { resolvedMap.put(resolvedEntity.getId(), resolvedEntity); } for (int i = 0; i < count; i++) { long entityId = targetEntities[i].getId(); assertTrue("ID=" + entityId, resolvedMap.containsKey(entityId)); assertSame(targetEntities[i], resolvedMap.get(entityId)); } }
public void testToManyOrder() { prepareToMany(1, 3); ToManyEntity testEntity = toManyEntityDao.load(1L); List<ToManyTargetEntity> resolvedToManyAsc = testEntity.getToManyTargetEntityList(); List<ToManyTargetEntity> resolvedToManyDesc = testEntity.getToManyDescList(); assertNotSame(resolvedToManyAsc, resolvedToManyDesc); assertEquals(resolvedToManyAsc.get(0).getId(), resolvedToManyDesc.get(2).getId()); assertSame(resolvedToManyAsc.get(0), resolvedToManyDesc.get(2)); assertSame(resolvedToManyAsc.get(1), resolvedToManyDesc.get(1)); assertSame(resolvedToManyAsc.get(2), resolvedToManyDesc.get(0)); }
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()); }
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()); }
@Override protected final void bindValues(DatabaseStatement stmt, ToManyTargetEntity entity) { stmt.clearBindings(); Long toManyId = entity.getToManyId(); if (toManyId != null) { stmt.bindLong(1, toManyId); } Long toManyIdDesc = entity.getToManyIdDesc(); if (toManyIdDesc != null) { stmt.bindLong(2, toManyIdDesc); } Long id = entity.getId(); if (id != null) { stmt.bindLong(3, id); } String targetJoinProperty = entity.getTargetJoinProperty(); if (targetJoinProperty != null) { stmt.bindString(4, targetJoinProperty); } }
@Override protected final void bindValues(SQLiteStatement stmt, ToManyTargetEntity entity) { stmt.clearBindings(); Long toManyId = entity.getToManyId(); if (toManyId != null) { stmt.bindLong(1, toManyId); } Long toManyIdDesc = entity.getToManyIdDesc(); if (toManyIdDesc != null) { stmt.bindLong(2, toManyIdDesc); } Long id = entity.getId(); if (id != null) { stmt.bindLong(3, id); } String targetJoinProperty = entity.getTargetJoinProperty(); if (targetJoinProperty != null) { stmt.bindString(4, targetJoinProperty); } }