Remove fetchItem, returnFetchResult from database

pull/189/head
Alex Baker 10 years ago
parent 22ef1e24be
commit 92f1085059

@ -144,19 +144,7 @@ public class DatabaseDao<TYPE extends AbstractModel> {
* @return null if no item found
*/
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;
}
return fromCursor(cursor);
} finally {
cursor.close();
}
return getFirst(Query.select(properties).where(AbstractModel.ID_PROPERTY.eq(id)));
}
/**
@ -282,20 +270,6 @@ public class DatabaseDao<TYPE extends AbstractModel> {
// --- helper methods
/**
* Returns cursor to object corresponding to the given identifier
* @param properties
* properties to read
* @param id
* id of item
*/
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<>(cursor, properties);
}
public int count(Query query) {
TodorooCursor<TYPE> cursor = query(query);
try {

@ -6,7 +6,6 @@
package com.todoroo.astrid.dao;
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.data.TagData;
@ -32,21 +31,7 @@ public class TagDataDao extends RemoteModelDao<TagData> {
* Fetch a model object by UUID
*/
public TagData fetch(String uuid, Property<?>... properties) {
TodorooCursor<TagData> cursor = fetchItem(uuid, properties);
return returnFetchResult(cursor);
}
/**
* Returns cursor to object corresponding to the given identifier
*
* @param properties
* properties to read
*/
private TodorooCursor<TagData> fetchItem(String uuid, Property<?>... properties) {
TodorooCursor<TagData> cursor = query(
Query.select(properties).where(RemoteModel.UUID_PROPERTY.eq(uuid)));
cursor.moveToFirst();
return new TodorooCursor<>(cursor, properties);
return getFirst(Query.select(properties).where(RemoteModel.UUID_PROPERTY.eq(uuid)));
}
}

@ -6,7 +6,6 @@
package com.todoroo.astrid.dao;
import com.todoroo.andlib.data.Property;
import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.sql.Criterion;
import com.todoroo.andlib.sql.Query;
import com.todoroo.astrid.data.TagData;
@ -30,10 +29,8 @@ public class TaskListMetadataDao extends RemoteModelDao<TaskListMetadata> {
}
public TaskListMetadata fetchByTagId(String tagUuid, Property<?>... properties) {
TodorooCursor<TaskListMetadata> taskListMetadata = query(Query.select(properties).where(Criterion.or(TaskListMetadata.TAG_UUID.eq(tagUuid),
return getFirst(Query.select(properties).where(Criterion.or(TaskListMetadata.TAG_UUID.eq(tagUuid),
TaskListMetadata.FILTER.eq(tagUuid))));
taskListMetadata.moveToFirst();
return returnFetchResult(taskListMetadata);
}
}

Loading…
Cancel
Save