@Override protected final Long updateKeyAfterInsert(JoinManyToDateEntity entity, long rowId) { entity.setId(rowId); return rowId; }
@Override public Long getKey(JoinManyToDateEntity entity) { if(entity != null) { return entity.getId(); } else { return null; } }
@Override public void readEntity(Cursor cursor, JoinManyToDateEntity entity, int offset) { entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); entity.setIdToMany(cursor.isNull(offset + 1) ? null : cursor.getLong(offset + 1)); entity.setIdDate(cursor.isNull(offset + 2) ? null : cursor.getLong(offset + 2)); }
@Override protected JoinManyToDateEntity createEntity(Long key) { JoinManyToDateEntity entity = new JoinManyToDateEntity(); entity.setId(key); return entity; }
@Override protected final void bindValues(DatabaseStatement stmt, JoinManyToDateEntity entity) { stmt.clearBindings(); Long id = entity.getId(); if (id != null) { stmt.bindLong(1, id); } Long idToMany = entity.getIdToMany(); if (idToMany != null) { stmt.bindLong(2, idToMany); } Long idDate = entity.getIdDate(); if (idDate != null) { stmt.bindLong(3, idDate); } }
@Override public JoinManyToDateEntity readEntity(Cursor cursor, int offset) { JoinManyToDateEntity entity = new JoinManyToDateEntity( // cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id cursor.isNull(offset + 1) ? null : cursor.getLong(offset + 1), // idToMany cursor.isNull(offset + 2) ? null : cursor.getLong(offset + 2) // idDate ); return entity; }
@Override protected final void bindValues(SQLiteStatement stmt, JoinManyToDateEntity entity) { stmt.clearBindings(); Long id = entity.getId(); if (id != null) { stmt.bindLong(1, id); } Long idToMany = entity.getIdToMany(); if (idToMany != null) { stmt.bindLong(2, idToMany); } Long idDate = entity.getIdDate(); if (idDate != null) { stmt.bindLong(3, idDate); } }
public void testToManyWithJoin() { ToManyEntity entity = new ToManyEntity(1L); daoSession.insert(entity); List<DateEntity> dateEntities = entity.getDateEntityList(); assertEquals(0, dateEntities.size()); DateEntityDao dateDao = daoSession.getDateEntityDao(); Date now = new Date(); DateEntity date1 = new DateEntity(1L, null, now); DateEntity date2 = new DateEntity(2L, null, now); DateEntity date3 = new DateEntity(3L, null, now); DateEntity date4 = new DateEntity(4L, null, now); dateDao.insertInTx(date1, date2, date3, date4); daoSession.insert(new JoinManyToDateEntity(1L,2L,1L)); daoSession.insert(new JoinManyToDateEntity(2L,1L,3L)); entity.resetDateEntityList(); dateEntities = entity.getDateEntityList(); assertEquals(1, dateEntities.size()); assertEquals(3L, (long) dateEntities.get(0).getId()); daoSession.insert(new JoinManyToDateEntity(3L, 1L, 4L)); entity.resetDateEntityList(); dateEntities = entity.getDateEntityList(); assertEquals(2, dateEntities.size()); }
@Override public boolean hasKey(JoinManyToDateEntity entity) { return entity.getId() != null; }