Exemple #1
0
  /** Reads all properties from the supplied cursor and store */
  public synchronized void readPropertiesFromCursor(TodorooCursor<? extends AbstractModel> cursor) {
    if (values == null) {
      values = new ContentValues();
    }

    // clears user-set values
    setValues = null;
    transitoryData = null;

    for (Property<?> property : cursor.getProperties()) {
      try {
        saver.save(property, values, cursor.get(property));
      } catch (IllegalArgumentException e) {
        // underlying cursor may have changed, suppress
      }
    }
  }
 /**
  * Returns object corresponding to the given identifier
  *
  * @param database
  * @param table name of table
  * @param properties properties to read
  * @param id id of item
  * @return null if no item found
  */
 public TYPE fetch(long id, Property<?>... properties) {
   TodorooCursor<TYPE> cursor = fetchItem(id, properties);
   try {
     if (cursor.getCount() == 0) return null;
     Constructor<TYPE> constructor = modelClass.getConstructor(TodorooCursor.class);
     return constructor.newInstance(cursor);
   } catch (SecurityException e) {
     throw new RuntimeException(e);
   } catch (NoSuchMethodException e) {
     throw new RuntimeException(e);
   } catch (IllegalArgumentException e) {
     throw new RuntimeException(e);
   } catch (InstantiationException e) {
     throw new RuntimeException(e);
   } catch (IllegalAccessException e) {
     throw new RuntimeException(e);
   } catch (InvocationTargetException e) {
     throw new RuntimeException(e);
   } finally {
     cursor.close();
   }
 }
 /**
  * Returns cursor to object corresponding to the given identifier
  *
  * @param database
  * @param table name of table
  * @param properties properties to read
  * @param id id of item
  * @return
  */
 protected TodorooCursor<TYPE> fetchItem(long id, Property<?>... properties) {
   TodorooCursor<TYPE> cursor =
       query(Query.select(properties).where(AbstractModel.ID_PROPERTY.eq(id)));
   cursor.moveToFirst();
   return new TodorooCursor<TYPE>(cursor, properties);
 }