@Override
 public boolean log(HistorianBroadcastReceiver.LogType type, Map objectMap) {
   JSONObject object = new JSONObject(objectMap);
   SQLiteDatabase sqLiteDatabase = this.openDatabase();
   Log.d("historian log:", object.toString());
   String query =
       "INSERT INTO "
           + TABLE_NAME
           + " ("
           + KEY_HISTORIAN_TYPE
           + COMMA_SEP
           + KEY_HISTORIAN_LOG
           + ") "
           + "values"
           + " ("
           + "\'"
           + type.toString()
           + "\'"
           + COMMA_SEP
           + "\'"
           + object.toString()
           + "\'"
           + ");";
   sqLiteDatabase.execSQL(query);
   this.closeDatabase();
   return true;
 }
  @Override
  public List<JSONObject> getAllByDateAndType(
      String from, String to, HistorianBroadcastReceiver.LogType type) {
    // obtain thread-safe database access
    SQLiteDatabase sqLiteDatabase = this.openDatabase();

    // build a query
    String query =
        "SELECT * FROM "
            + TABLE_NAME
            + "WHERE "
            + KEY_HISTORIAN_TYPE
            + " = "
            + type.toString()
            + " AND "
            + " BETWEEN "
            + from
            + " AND "
            + to
            + " ORDER BY "
            + KEY_HISTORIAN_TIMESTAMP;
    Cursor cursor = sqLiteDatabase.rawQuery(query, null);

    // prepare structured data
    ArrayList<JSONObject> logs = new ArrayList<JSONObject>();
    if (cursor.moveToFirst()) {
      do {
        try {
          JSONObject newLog = new JSONObject();
          newLog.put(TYPE, cursor.getString(1));
          newLog.put(TIMESTAMP, cursor.getString(3));
          newLog.put(LOG, new JSONObject(cursor.getString(2)));
          logs.add(newLog);
        } catch (JSONException e) {
          e.printStackTrace();
          return logs;
        }
      } while (cursor.moveToNext());
    }
    // close database connection and release resources
    this.closeDatabase();
    cursor.close();
    // return rooms
    return logs;
  }