Search in sources :

Example 6 with CouldNotInsertDataException

use of ve.com.abicelis.remindy.exception.CouldNotInsertDataException in project Remindy by abicelis.

the class RemindyDAO method insertReminderOfTask.

/**
     * Inserts a new Reminder into the database.
     * @param taskId The id of the Task associated to the Reminder
     * @param reminder The Reminder to insert
     */
public long insertReminderOfTask(int taskId, Reminder reminder) throws CouldNotInsertDataException {
    SQLiteDatabase db = mDatabaseHelper.getWritableDatabase();
    ContentValues values;
    String tableName;
    reminder.setTaskId(taskId);
    switch(reminder.getType()) {
        case ONE_TIME:
            values = getValuesFromOneTimeReminder((OneTimeReminder) reminder);
            tableName = RemindyContract.OneTimeReminderTable.TABLE_NAME;
            break;
        case REPEATING:
            values = getValuesFromRepeatingReminder((RepeatingReminder) reminder);
            tableName = RemindyContract.RepeatingReminderTable.TABLE_NAME;
            break;
        case LOCATION_BASED:
            values = getValuesFromLocationBasedReminder((LocationBasedReminder) reminder);
            tableName = RemindyContract.LocationBasedReminderTable.TABLE_NAME;
            break;
        default:
            throw new CouldNotInsertDataException("ReminderType is invalid. Type=" + reminder.getType());
    }
    long newRowId;
    newRowId = db.insert(tableName, null, values);
    if (newRowId == -1)
        throw new CouldNotInsertDataException("There was a problem inserting the Reminder: " + reminder.toString());
    return newRowId;
}
Also used : ContentValues(android.content.ContentValues) OneTimeReminder(ve.com.abicelis.remindy.model.reminder.OneTimeReminder) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) LocationBasedReminder(ve.com.abicelis.remindy.model.reminder.LocationBasedReminder) RepeatingReminder(ve.com.abicelis.remindy.model.reminder.RepeatingReminder) CouldNotInsertDataException(ve.com.abicelis.remindy.exception.CouldNotInsertDataException)

Aggregations

CouldNotInsertDataException (ve.com.abicelis.remindy.exception.CouldNotInsertDataException)6 ContentValues (android.content.ContentValues)4 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)4 BaseTransientBottomBar (android.support.design.widget.BaseTransientBottomBar)2 Snackbar (android.support.design.widget.Snackbar)2 RemindyDAO (ve.com.abicelis.remindy.database.RemindyDAO)2 Intent (android.content.Intent)1 CouldNotUpdateDataException (ve.com.abicelis.remindy.exception.CouldNotUpdateDataException)1 Attachment (ve.com.abicelis.remindy.model.attachment.Attachment)1 AudioAttachment (ve.com.abicelis.remindy.model.attachment.AudioAttachment)1 ImageAttachment (ve.com.abicelis.remindy.model.attachment.ImageAttachment)1 LinkAttachment (ve.com.abicelis.remindy.model.attachment.LinkAttachment)1 ListAttachment (ve.com.abicelis.remindy.model.attachment.ListAttachment)1 TextAttachment (ve.com.abicelis.remindy.model.attachment.TextAttachment)1 LocationBasedReminder (ve.com.abicelis.remindy.model.reminder.LocationBasedReminder)1 OneTimeReminder (ve.com.abicelis.remindy.model.reminder.OneTimeReminder)1 RepeatingReminder (ve.com.abicelis.remindy.model.reminder.RepeatingReminder)1