Beispiel #1
0
 public Serie loadSerieFromCursor(Cursor cursor) {
   Serie serie = new Serie();
   int columnIndex;
   if ((columnIndex = cursor.getColumnIndex(MySQLiteOpenHelper.COL_SERIES_ID)) >= 0)
     serie.setId(cursor.getInt(columnIndex));
   if ((columnIndex = cursor.getColumnIndex(MySQLiteOpenHelper.COL_SERIES_NAME)) >= 0)
     serie.setName(cursor.getString(columnIndex));
   if ((columnIndex = cursor.getColumnIndex(MySQLiteOpenHelper.COL_SERIES_STATUS)) >= 0)
     serie.setStatus(Status.getValue(cursor.getInt(columnIndex)));
   return serie;
 }
Beispiel #2
0
  public boolean insertSerie(Handler handler, Serie serie) {
    if (serie == null) return false;
    Hashtable<String, String> editions = serie.getEditions();
    Log.d(
        Global.getLogTag(MyDbAdaptor.class),
        "insertSerie " + serie.getName() + "(" + serie.getId() + ") - " + serie.getTomeCount());
    Enumeration<String> e = editions.keys();
    while (e.hasMoreElements()) {
      String key = e.nextElement();
      String value = editions.get(key);
      Log.d(Global.getLogTag(MyDbAdaptor.class), "id_edition = " + key + " count=" + value);
    }

    boolean result = false;
    ContentValues values = new ContentValues();
    values.put(MySQLiteOpenHelper.COL_SERIES_ID, serie.getId());
    values.put(MySQLiteOpenHelper.COL_SERIES_NAME, serie.getName());
    values.put(MySQLiteOpenHelper.COL_SERIES_STATUS, serie.getStatus().getValue());

    // Find row
    Cursor cursor =
        database.query(
            MySQLiteOpenHelper.TABLE_SERIES,
            null,
            new StringBuilder().append(MySQLiteOpenHelper.COL_SERIES_ID).append("=?").toString(),
            new String[] {Integer.toString(serie.getId())},
            null,
            null,
            null);

    Enumeration<String> key = serie.getEditions().keys();
    int tome_count;
    String id_edition;
    if (cursor.getCount() == 0) {
      result = (database.insert(MySQLiteOpenHelper.TABLE_SERIES, null, values) >= 0);
      while (key.hasMoreElements()) {
        id_edition = key.nextElement();
        tome_count = Integer.parseInt(serie.getEditions().get(id_edition));
        if (tome_count != getTomesCountFromEditionId(id_edition)) {
          // sync editions tomes
          ServerConnector.syncEdition(handler, id_edition, serie.getId());
        }
      }
    } else {
      cursor.moveToFirst();
      int tomeCount = 0;
      if (serie.getTomeCount() != (tomeCount = getTomesCountFromSerieId(serie.getId()))) {
        while (key.hasMoreElements()) {
          id_edition = key.nextElement();
          tome_count = Integer.parseInt(serie.getEditions().get(id_edition));
          if (tome_count != getTomesCountFromEditionId(id_edition)) {
            // sync editions tomes
            ServerConnector.syncEdition(handler, id_edition, serie.getId());
          }
        }
      } else if (tomeCount > 0) checkTomeIcons(handler, serie.getId());

      Serie saved = loadSerieFromCursor(cursor);
      if (!(result = saved.equals(serie)))
        result =
            (database.update(
                    MySQLiteOpenHelper.TABLE_SERIES,
                    values,
                    new StringBuilder()
                        .append(MySQLiteOpenHelper.COL_SERIES_ID)
                        .append("=?")
                        .toString(),
                    new String[] {Integer.toString(serie.getId())})
                >= 0);
    }
    cursor.close();
    return result;
  }