@Override protected final Long updateKeyAfterInsert(CustomTypeEntity entity, long rowId) { entity.setId(rowId); return rowId; }
@Override public Long getKey(CustomTypeEntity entity) { if(entity != null) { return entity.getId(); } else { return null; } }
@Override protected CustomTypeEntity createEntity(Long key) { CustomTypeEntity entity = new CustomTypeEntity(); entity.setId(key); MyTimestamp myCustomTimestamp = new MyTimestamp(); myCustomTimestamp.timestamp = System.currentTimeMillis(); entity.setMyCustomTimestamp(myCustomTimestamp); return entity; }
@Override public void readEntity(Cursor cursor, CustomTypeEntity entity, int offset) { entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); entity.setMyCustomTimestamp(cursor.isNull(offset + 1) ? null : myCustomTimestampConverter.convertToEntityProperty(cursor.getLong(offset + 1))); }
public void testCustomTypeValueNull() { CustomTypeEntity entity = createEntityWithRandomPk(); entity.setMyCustomTimestamp(null); dao.insert(entity); List<CustomTypeEntity> all = dao.loadAll(); assertEquals(1, all.size()); assertNull(all.get(0).getMyCustomTimestamp()); }
@Override protected final void bindValues(DatabaseStatement stmt, CustomTypeEntity entity) { stmt.clearBindings(); Long id = entity.getId(); if (id != null) { stmt.bindLong(1, id); } MyTimestamp myCustomTimestamp = entity.getMyCustomTimestamp(); if (myCustomTimestamp != null) { stmt.bindLong(2, myCustomTimestampConverter.convertToDatabaseValue(myCustomTimestamp)); } }
@Override public CustomTypeEntity readEntity(Cursor cursor, int offset) { CustomTypeEntity entity = new CustomTypeEntity( // cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id cursor.isNull(offset + 1) ? null : myCustomTimestampConverter.convertToEntityProperty(cursor.getLong(offset + 1)) // myCustomTimestamp ); return entity; }
public void testCustomTypeValue() { CustomTypeEntity entity = createEntityWithRandomPk(); long timestamp = entity.getMyCustomTimestamp().timestamp; dao.insert(entity); List<CustomTypeEntity> all = dao.loadAll(); assertEquals(1, all.size()); assertEquals(timestamp, all.get(0).getMyCustomTimestamp().timestamp); }
@Override protected final void bindValues(SQLiteStatement stmt, CustomTypeEntity entity) { stmt.clearBindings(); Long id = entity.getId(); if (id != null) { stmt.bindLong(1, id); } MyTimestamp myCustomTimestamp = entity.getMyCustomTimestamp(); if (myCustomTimestamp != null) { stmt.bindLong(2, myCustomTimestampConverter.convertToDatabaseValue(myCustomTimestamp)); } }
@Override public boolean hasKey(CustomTypeEntity entity) { return entity.getId() != null; }