Esempio n. 1
0
 /**
  * Creates the given item.
  *
  * @param database
  * @param table table name
  * @param item item model
  * @return returns true on success.
  */
 public boolean createNew(TYPE item) {
   item.clearValue(AbstractModel.ID_PROPERTY);
   long newRow =
       database.insert(table.name, AbstractModel.ID_PROPERTY.name, item.getMergedValues());
   boolean result = newRow >= 0;
   if (result) {
     item.setId(newRow);
     onModelUpdated(item);
     item.markSaved();
   }
   return result;
 }
Esempio n. 2
0
 /**
  * Saves the given item. Will not create a new item!
  *
  * @param database
  * @param table table name
  * @param item item model
  * @return returns true on success.
  */
 public boolean saveExisting(TYPE item) {
   ContentValues values = item.getSetValues();
   if (values == null || values.size() == 0) // nothing changed
   return true;
   boolean result =
       database.update(
               table.name, values, AbstractModel.ID_PROPERTY.eq(item.getId()).toString(), null)
           > 0;
   if (result) {
     onModelUpdated(item);
     item.markSaved();
   }
   return result;
 }