Move methods out of RemoteModelDao

pull/189/head
Alex Baker 10 years ago
parent 0cdff3a9bb
commit 004f1dd83e

@ -1,10 +1,6 @@
package com.todoroo.astrid.dao;
import com.todoroo.andlib.data.AbstractModel;
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;
@ -30,40 +26,4 @@ public class RemoteModelDao<RTYPE extends RemoteModel> extends DatabaseDao<RTYPE
}
return super.createNew(item);
}
/**
* Fetch a model object by UUID
*/
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 properties
* properties to read
*/
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<>(cursor, properties);
}
public String uuidFromLocalId(long localId) {
TodorooCursor<RTYPE> cursor = query(Query.select(RemoteModel.UUID_PROPERTY).where(AbstractModel.ID_PROPERTY.eq(localId)));
try {
if (cursor.getCount() == 0) {
return RemoteModel.NO_UUID;
}
cursor.moveToFirst();
return cursor.get(RemoteModel.UUID_PROPERTY);
} finally {
cursor.close();
}
}
}

@ -5,6 +5,10 @@
*/
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;
import javax.inject.Inject;
@ -23,5 +27,26 @@ public class TagDataDao extends RemoteModelDao<TagData> {
super(TagData.class);
setDatabase(database);
}
/**
* 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);
}
}

@ -8,6 +8,7 @@ package com.todoroo.astrid.dao;
import android.content.ContentValues;
import android.database.sqlite.SQLiteConstraintException;
import com.todoroo.andlib.data.AbstractModel;
import com.todoroo.andlib.data.Property;
import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.sql.Criterion;
@ -15,6 +16,7 @@ import com.todoroo.andlib.sql.Functions;
import com.todoroo.andlib.sql.Query;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.dao.MetadataDao.MetadataCriteria;
import com.todoroo.astrid.data.RemoteModel;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.data.TaskApiDao;
import com.todoroo.astrid.reminders.ReminderService;
@ -107,6 +109,19 @@ public class TaskDao extends RemoteModelDao<Task> {
}
}
public String uuidFromLocalId(long localId) {
TodorooCursor<Task> cursor = query(Query.select(RemoteModel.UUID_PROPERTY).where(AbstractModel.ID_PROPERTY.eq(localId)));
try {
if (cursor.getCount() == 0) {
return RemoteModel.NO_UUID;
}
cursor.moveToFirst();
return cursor.get(RemoteModel.UUID_PROPERTY);
} finally {
cursor.close();
}
}
// --- delete
/**

Loading…
Cancel
Save