From 92f108505966d96cc5e2bc62e65218b66f5da099 Mon Sep 17 00:00:00 2001 From: Alex Baker Date: Tue, 15 Jul 2014 12:13:54 -0500 Subject: [PATCH] Remove fetchItem, returnFetchResult from database --- .../com/todoroo/andlib/data/DatabaseDao.java | 28 +------------------ .../com/todoroo/astrid/dao/TagDataDao.java | 17 +---------- .../astrid/dao/TaskListMetadataDao.java | 5 +--- 3 files changed, 3 insertions(+), 47 deletions(-) diff --git a/api/src/main/java/com/todoroo/andlib/data/DatabaseDao.java b/api/src/main/java/com/todoroo/andlib/data/DatabaseDao.java index eb5bad5e9..35136425c 100644 --- a/api/src/main/java/com/todoroo/andlib/data/DatabaseDao.java +++ b/api/src/main/java/com/todoroo/andlib/data/DatabaseDao.java @@ -144,19 +144,7 @@ public class DatabaseDao { * @return null if no item found */ public TYPE fetch(long id, Property... properties) { - TodorooCursor cursor = fetchItem(id, properties); - return returnFetchResult(cursor); - } - - protected TYPE returnFetchResult(TodorooCursor 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 { // --- helper methods - /** - * Returns cursor to object corresponding to the given identifier - * @param properties - * properties to read - * @param id - * id of item - */ - protected TodorooCursor fetchItem(long id, Property... properties) { - TodorooCursor cursor = query( - Query.select(properties).where(AbstractModel.ID_PROPERTY.eq(id))); - cursor.moveToFirst(); - return new TodorooCursor<>(cursor, properties); - } - public int count(Query query) { TodorooCursor cursor = query(query); try { diff --git a/astrid/src/main/java/com/todoroo/astrid/dao/TagDataDao.java b/astrid/src/main/java/com/todoroo/astrid/dao/TagDataDao.java index 9ef375fae..fbae1b243 100644 --- a/astrid/src/main/java/com/todoroo/astrid/dao/TagDataDao.java +++ b/astrid/src/main/java/com/todoroo/astrid/dao/TagDataDao.java @@ -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 { * Fetch a model object by UUID */ public TagData fetch(String uuid, Property... properties) { - TodorooCursor cursor = fetchItem(uuid, properties); - return returnFetchResult(cursor); - } - - /** - * Returns cursor to object corresponding to the given identifier - * - * @param properties - * properties to read - */ - private TodorooCursor fetchItem(String uuid, Property... properties) { - TodorooCursor 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))); } } diff --git a/astrid/src/main/java/com/todoroo/astrid/dao/TaskListMetadataDao.java b/astrid/src/main/java/com/todoroo/astrid/dao/TaskListMetadataDao.java index c85a5ad43..bbe811ee4 100644 --- a/astrid/src/main/java/com/todoroo/astrid/dao/TaskListMetadataDao.java +++ b/astrid/src/main/java/com/todoroo/astrid/dao/TaskListMetadataDao.java @@ -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 { } public TaskListMetadata fetchByTagId(String tagUuid, Property... properties) { - TodorooCursor 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); } }