Exemplo n.º 1
0
  public List<ValueVO<objectType>> runQuery(String pQuery, int labelField) {
    List<ValueVO<objectType>> items = new ArrayList<ValueVO<objectType>>();
    Cursor cursor = null;
    try {
      cursor = database.rawQuery(pQuery, null);
      cursor.moveToFirst();
      while (!cursor.isAfterLast()) {

        objectType item = objectClass.newInstance();
        ((ICursorDecoder) item).decode(cursor);
        items.add(new ValueVO<objectType>(item, cursor.getString(labelField)));
        cursor.moveToNext();
      }
    } catch (Exception error) {
      Log.e("Error", error.toString());
    } finally {
      if (cursor != null) cursor.close();
    }
    return items;
  }
Exemplo n.º 2
0
  public List<objectType> runQuery(String pQuery) {
    List<objectType> items = new ArrayList<objectType>();
    Cursor cursor = null;
    try {
      cursor = database.rawQuery(pQuery, null);
      cursor.moveToFirst();
      while (!cursor.isAfterLast()) {

        objectType item = objectClass.newInstance();
        ((ICursorDecoder) item).decode(cursor);
        items.add(item);
        cursor.moveToNext();
      }
    } catch (Exception error) {
      Log.e("Error", error.toString());
    } finally {
      // Make sure to close the cursor
      if (cursor != null) cursor.close();
    }
    return items;
  }
Exemplo n.º 3
0
  public List<objectType> getAllItems() {
    List<objectType> items = new ArrayList<objectType>();

    Cursor cursor = database.query(tableId, null, null, null, null, null, null);

    cursor.moveToFirst();

    try {
      while (!cursor.isAfterLast()) {
        objectType item = objectClass.newInstance();
        ((ICursorDecoder) item).decode(cursor);
        items.add(item);
        cursor.moveToNext();
      }
    } catch (Exception error) {

    } finally {
      cursor.close();
    }
    return items;
  }
Exemplo n.º 4
0
  public objectType createItem(Map<String, ?> objectMap) {
    ContentValues values = new ContentValues();
    objectType newObject = null;
    for (String key : objectMap.keySet()) {
      values.put(key, "" + objectMap.get(key));
    }
    long insertId = database.insert(tableId, null, values);
    Cursor cursor = database.query(tableId, null, null, null, null, null, null);

    cursor.moveToFirst();
    try {
      newObject = objectClass.newInstance();
      ((ICursorDecoder) newObject).decode(cursor);
    } catch (Exception e) {
      Log.e("ERROR", e.getMessage());
    } finally {

      cursor.close();
    }
    return newObject;
  }