Persistent Data on a Mobile Client

In this lab you will implement a local SQLite database on the mobile device to store the notes. The application will allow the user to add new notes, delete existing notes, and clear the entire notes list.

Getting Started

Download CS496_Lab16.zip and import it into your Eclipse workspace.

Create a SQLite Database

We will first add code to create a database when the app is first launched. This is done in the MySQLiteHelper class which subclasses SQLiteOpenHelper. Note that fields have already been added which specify the name of the database, name of the table, and names of the columns in the table. These fields will be used in the database class when the various persistence operations are performed.

Note that onUpgrade() for this application will simply delete the old table and recreate a new one (which may have an updated schema). It would probably be better to write code to attempt some form of data migration rather than simply deleting all the previous data in the database.

Add Database Operations

You may wish to examine the IDatabase interface for the database operation method signatures.

In the NotesDataSource class, complete the methods getNotes(), addNote(), deleteNote(), and deleteAllNotes(). Note: The utility method cursorToNote() has been provide to perform the ORM operation of converting a Cursor object to a Note, i.e. converts a database row to a Java object.

Perform Database Operations