Added a fetch by uuid method to remote model daos

pull/14/head
Sam Bosley 12 years ago
parent b6f3b0f279
commit 2e0fef2e9d

@ -150,6 +150,10 @@ public class DatabaseDao<TYPE extends AbstractModel> {
*/
public TYPE fetch(long id, Property<?>... properties) {
TodorooCursor<TYPE> cursor = fetchItem(id, properties);
return returnFetchResult(cursor);
}
protected TYPE returnFetchResult(TodorooCursor<TYPE> cursor) {
try {
if (cursor.getCount() == 0)
return null;

@ -1,6 +1,9 @@
package com.todoroo.astrid.dao;
import com.todoroo.andlib.data.DatabaseDao;
import com.todoroo.andlib.data.Property;
import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.sql.Query;
import com.todoroo.astrid.data.RemoteModel;
import com.todoroo.astrid.helper.UUIDHelper;
@ -27,5 +30,29 @@ public class RemoteModelDao<RTYPE extends RemoteModel> extends DatabaseDao<RTYPE
return super.createNew(item);
};
public RTYPE fetch(String uuid, Property<?>... properties) {
TodorooCursor<RTYPE> cursor = fetchItem(uuid, properties);
return returnFetchResult(cursor);
}
/**
* 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<RTYPE> fetchItem(String uuid, Property<?>... properties) {
TodorooCursor<RTYPE> cursor = query(
Query.select(properties).where(RemoteModel.UUID_PROPERTY.eq(uuid)));
cursor.moveToFirst();
return new TodorooCursor<RTYPE>(cursor, properties);
}
}

Loading…
Cancel
Save