@Test public void testAddData() throws IOException { DatabaseHelper<Data, Batch<Data>> databaseHelper; Context context; GsonSerializationStrategy<Data, Batch<Data>> gsonSerializationStrategy; gsonSerializationStrategy = new GsonSerializationStrategy<>(); gsonSerializationStrategy.build(); context = RuntimeEnvironment.application; databaseHelper = new DatabaseHelper<>(gsonSerializationStrategy, "test", context); Collection<Data> dataArrayList = Utils.fakeCollection(5); databaseHelper.addData(dataArrayList); assertEquals(databaseHelper.getAllData(), dataArrayList); }
public void addData(Collection<E> dataCollection) throws IOException { SQLiteDatabase db = this.getWritableDatabase(); try { db.beginTransaction(); for (E data : dataCollection) { if (!isDataInDB(String.valueOf(data.getEventId()))) { ContentValues values = new ContentValues(); values.put(KEY_ID, data.getEventId()); values.put(KEY_DATA, serializationStrategy.serializeData(data)); values.put(KEY_EXPIRY, 0); db.insertWithOnConflict(TABLE_EVENT_DATA, null, values, SQLiteDatabase.CONFLICT_REPLACE); } } db.setTransactionSuccessful(); } finally { db.endTransaction(); } }
DatabaseHelper extends SQLiteOpenHelper { public void addData(Collection<E> dataCollection) throws IOException { SQLiteDatabase db = this.getWritableDatabase(); try { db.beginTransaction(); for (E data : dataCollection) { if (!isDataInDB(String.valueOf(data.getEventId()))) { ContentValues values = new ContentValues(); values.put(KEY_ID, data.getEventId()); values.put(KEY_DATA, serializationStrategy.serializeData(data)); values.put(KEY_EXPIRY, 0); db.insertWithOnConflict(TABLE_EVENT_DATA, null, values, SQLiteDatabase.CONFLICT_REPLACE); } } db.setTransactionSuccessful(); } finally { db.endTransaction(); } } }
DatabaseHelper extends SQLiteOpenHelper { public void addData(Collection<E> dataCollection) throws IOException { SQLiteDatabase db = this.getWritableDatabase(); try { db.beginTransaction(); for (E data : dataCollection) { if (!isDataInDB(String.valueOf(data.getEventId()))) { ContentValues values = new ContentValues(); values.put(KEY_ID, data.getEventId()); values.put(KEY_DATA, serializationStrategy.serializeData(data)); values.put(KEY_EXPIRY, 0); db.insertWithOnConflict(TABLE_EVENT_DATA, null, values, SQLiteDatabase.CONFLICT_REPLACE); } } db.setTransactionSuccessful(); } finally { db.endTransaction(); } } DatabaseHelper(SerializationStrategy<E, T> serializationStrategy, String databaseName, Context context); }
DatabaseHelper extends SQLiteOpenHelper { public void addData(Collection<E> dataCollection) throws IOException { SQLiteDatabase db = this.getWritableDatabase(); try { db.beginTransaction(); for (E data : dataCollection) { if (!isDataInDB(String.valueOf(data.getEventId()))) { ContentValues values = new ContentValues(); values.put(KEY_ID, data.getEventId()); values.put(KEY_DATA, serializationStrategy.serializeData(data)); values.put(KEY_EXPIRY, 0); db.insertWithOnConflict(TABLE_EVENT_DATA, null, values, SQLiteDatabase.CONFLICT_REPLACE); } } db.setTransactionSuccessful(); } finally { db.endTransaction(); } } DatabaseHelper(SerializationStrategy<E, T> serializationStrategy, String databaseName, Context context); @Override void onCreate(SQLiteDatabase db); @Override void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion); void addData(Collection<E> dataCollection); Collection<E> getAllData(); void deleteDataList(Collection<E> dataCollection); void deleteAll(); boolean isDataInDB(String id); }
DatabaseHelper extends SQLiteOpenHelper { public void addData(Collection<E> dataCollection) throws IOException { SQLiteDatabase db = this.getWritableDatabase(); try { db.beginTransaction(); for (E data : dataCollection) { if (!isDataInDB(String.valueOf(data.getEventId()))) { ContentValues values = new ContentValues(); values.put(KEY_ID, data.getEventId()); values.put(KEY_DATA, serializationStrategy.serializeData(data)); values.put(KEY_EXPIRY, 0); db.insertWithOnConflict(TABLE_EVENT_DATA, null, values, SQLiteDatabase.CONFLICT_REPLACE); } } db.setTransactionSuccessful(); } finally { db.endTransaction(); } } DatabaseHelper(SerializationStrategy<E, T> serializationStrategy, String databaseName, Context context); @Override void onCreate(SQLiteDatabase db); @Override void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion); void addData(Collection<E> dataCollection); Collection<E> getAllData(); void deleteDataList(Collection<E> dataCollection); void deleteAll(); boolean isDataInDB(String id);  }