@Override protected final Long updateKeyAfterInsert(SimpleEntity entity, long rowId) { entity.setId(rowId); return rowId; }
@Override protected SimpleEntity createEntity(Long key) { SimpleEntity entity = new SimpleEntity(); entity.setId(key); return entity; }
@Override public void readEntity(Cursor cursor, SimpleEntity entity, int offset) { entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); entity.setSimpleBoolean(cursor.isNull(offset + 1) ? null : cursor.getShort(offset + 1) != 0); entity.setSimpleByte(cursor.isNull(offset + 2) ? null : (byte) cursor.getShort(offset + 2)); entity.setSimpleShort(cursor.isNull(offset + 3) ? null : cursor.getShort(offset + 3)); entity.setSimpleInt(cursor.isNull(offset + 4) ? null : cursor.getInt(offset + 4)); entity.setSimpleLong(cursor.isNull(offset + 5) ? null : cursor.getLong(offset + 5)); entity.setSimpleFloat(cursor.isNull(offset + 6) ? null : cursor.getFloat(offset + 6)); entity.setSimpleDouble(cursor.isNull(offset + 7) ? null : cursor.getDouble(offset + 7)); entity.setSimpleString(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8)); entity.setSimpleByteArray(cursor.isNull(offset + 9) ? null : cursor.getBlob(offset + 9)); }
public void testMergeInsertAndUpdate() { SimpleEntity entity = new SimpleEntity(); entity.setId(42l); entity.setSimpleString("heho"); SimpleEntity entity2 = new SimpleEntity(); entity2.setId(42l); entity2.setSimpleString("updated"); AsyncOperation op1 = asyncSession.insert(entity, AsyncOperation.FLAG_MERGE_TX); AsyncOperation op2 = asyncSession.update(entity2, AsyncOperation.FLAG_MERGE_TX); assertWaitForCompletion1Sec(); daoSession.clear(); SimpleEntity entity3 = daoSession.load(SimpleEntity.class, 42l); assertNotNull(entity3); assertEquals(entity2.getSimpleString(), entity3.getSimpleString()); assertEquals(2, op1.getMergedOperationsCount()); assertEquals(2, op2.getMergedOperationsCount()); }