Appendix A - source code TeaTime application on Android 108
* Return a Cursor over the list of all Teas in the database
*
* @return Cursor over all Teas
*/
public Cursor callUpAllTeas() {
return myDb.query(DATABASE_TABLE, new String[]{ KEY_ROWID, KEY_NAME,
KEY_BREWTIME_MINUTES, KEY_BREWTIME_SECONDS }, null,
null, null, null, null);
}
/**
* Return a Cursor positioned at the Tea that matches the given rowId
*
* @param rowId id of Tea to retrieve
* @return Cursor positioned to matching Tea, if found
* @throws SQLException if Tea could not be found/retrieved
*/
public Cursor catchUpTea(long rowId) throws SQLException {
Cursor result = myDb.query(true, DATABASE_TABLE,
new String[]{ KEY_ROWID, KEY_NAME, KEY_BREWTIME_MINUTES,
KEY_BREWTIME_SECONDS }, KEY_ROWID + "=" +
rowId, null, null, null, null);
if ((result.count() == 0) || !result.first()) {
throw new SQLException("No Tea matching ID: " + rowId);
}
return result;
}
/**
* Update the Tea using the details provided. The Tea to be updated is
* specified using the rowId, and it is altered to use the Name and
* BrewTime values passed in
*
* @param rowId id of note to update
* @param name value to set Tea name to
* @param brewTime value to set Tea brewTime to
* @return true if the Tea was successfully updated, false otherwise
*/
public boolean updateTea(long rowId, String name, long brewTimeMinutes,
long brewTimeSeconds) {
ContentValues args = new ContentValues();
args.put(KEY_NAME, name);
args.put(KEY_BREWTIME_MINUTES, brewTimeMinutes);
args.put(KEY_BREWTIME_MINUTES, brewTimeSeconds);
return myDb.update(DATABASE_TABLE, args, KEY_ROWID + "=" + rowId,
null) > 0;
}
/**
* Get the minutes of the tea.
*
* @param rowId id of tea to get the minutes of it
* @return minutes of the tea sort in regard to the tea ID
*/
public long getMinutes(long rowId) {
long minutes = 0;
Cursor result = myDb.query(true, DATABASE_TABLE,