Introducing Room
Direct use of SQLite requires a huge amount of code dedicated to converting the SQLite structured data into Java objects, and then preparing SQL statements to store those objects back into the database. Mapping an SQL record to a Java object normally takes the following form:
public Attachment selectById(final long id) { final Cursor cursor = db.query( "attachments", new String[]{"file", "type"}, "_id=?", new String[]{Long.toString(id)}, null, null, null); try { if (cursor.moveToFirst()) { return new Attachment( new File(cursor.getString(0)), Attachment.Type.valueOf(cursor.getString(1)) ); } } finally { cursor.close(); } return null; }
As you can immediately see, there's a lot of code there that you will need to repeat again and again for every one of your data-model objects.
Fortunately, Google has produced a solution to this...