private boolean update(Context context, ActionEvent ae, final ContentValues target) {
    DatabaseHelper dh = new DatabaseHelper(context, TABLE_NAME);
    SQLiteDatabase db = dh.getWritableDatabase();

    if (db.isOpen()) {
      db.update(
          TABLE_NAME,
          target,
          KEY_START_TIMESTAMP + "=?",
          new String[] {Long.toString(ae.getStartTimestamp())});
      db.close();
      return true;
    } else {
      db.close();
      return false;
    }
  }
 private boolean isInsert(SQLiteDatabase db, ActionEvent ae) {
   Cursor c =
       db.query(
           TABLE_NAME,
           new String[] {KEY_START_TIMESTAMP},
           KEY_START_TIMESTAMP + "=" + ae.getStartTimestamp(),
           null,
           null,
           null,
           null);
   // check the record
   if (c.getCount() > 0) {
     c.close();
     db.close();
     return true;
   } else {
     c.close();
     db.close();
     return false;
   }
 }
  public boolean insert(Context context, ActionEvent ae) {
    DatabaseHelper dh = new DatabaseHelper(context, TABLE_NAME);
    SQLiteDatabase db = dh.getWritableDatabase();

    ContentValues target = null;
    if (db.isOpen()) {
      target = new ContentValues();
      target.put(KEY_ACTION_NAME, ae.getActionEventName());
      target.put(KEY_START_TIMESTAMP, ae.getStartTimestamp());
      target.put(KEY_STATE, ae.getEventState());
      target.put(KEY_BREAK_TIMESTAMP, ae.getBreakTimestamp());
      target.put(KEY_IS_HISTORY, getBooleanToLong(ae.isHistory()));
      target.put(KEY_ACTION_NOTE, ae.getNoteContent());
      target.put(KEY_START_DEALY, ae.getStartDelay());
      target.put(KEY_BREAK_DEALY, ae.getBreakDelay());
      db.insert(TABLE_NAME, null, target);
    } else {
      db.close();
      return false;
    }
    target = null;
    return isInsert(db, ae);
  }