From 8dd89107a799a351c1e964f14dd37b9aa8eade0f Mon Sep 17 00:00:00 2001 From: Sam Bosley Date: Fri, 14 Sep 2012 11:03:42 -0700 Subject: [PATCH] Remove UUIDs (new scheme), bring some changes from an experimental branch --- .../com/todoroo/astrid/data/RemoteModel.java | 7 --- api/src/com/todoroo/astrid/data/TagData.java | 4 -- api/src/com/todoroo/astrid/data/Task.java | 4 -- .../com/todoroo/astrid/data/TaskToTag.java | 4 +- api/src/com/todoroo/astrid/data/Update.java | 4 -- api/src/com/todoroo/astrid/data/User.java | 4 -- .../com/todoroo/astrid/tags/TagService.java | 57 +++++-------------- .../src/com/todoroo/astrid/dao/Database.java | 9 --- .../com/todoroo/astrid/dao/TagDataDao.java | 2 +- .../src/com/todoroo/astrid/dao/TaskDao.java | 2 +- 10 files changed, 19 insertions(+), 78 deletions(-) diff --git a/api/src/com/todoroo/astrid/data/RemoteModel.java b/api/src/com/todoroo/astrid/data/RemoteModel.java index efafb0d54..b2d039dc7 100644 --- a/api/src/com/todoroo/astrid/data/RemoteModel.java +++ b/api/src/com/todoroo/astrid/data/RemoteModel.java @@ -35,11 +35,4 @@ abstract public class RemoteModel extends AbstractModel { /** user json property */ public static final StringProperty USER_JSON_PROPERTY = new StringProperty(null, USER_JSON_PROPERTY_NAME); - /** uuid property name */ - public static final String UUID_PROPERTY_NAME = "uuid"; //$NON-NLS-1$ - - /** uuid property */ - public static final StringProperty UUID_PROPERTY = new StringProperty(null, UUID_PROPERTY_NAME); - - } diff --git a/api/src/com/todoroo/astrid/data/TagData.java b/api/src/com/todoroo/astrid/data/TagData.java index e577300e6..9aa7b422f 100644 --- a/api/src/com/todoroo/astrid/data/TagData.java +++ b/api/src/com/todoroo/astrid/data/TagData.java @@ -117,10 +117,6 @@ public final class TagData extends RemoteModel { public static final StringProperty TAG_DESCRIPTION = new StringProperty( TABLE, "tagDescription"); - /** uuid */ - public static final StringProperty UUID = new StringProperty( - TABLE, UUID_PROPERTY_NAME); - /** List of all properties for this model */ public static final Property[] PROPERTIES = generateProperties(TagData.class); diff --git a/api/src/com/todoroo/astrid/data/Task.java b/api/src/com/todoroo/astrid/data/Task.java index 4cc7c9efd..80f95324c 100644 --- a/api/src/com/todoroo/astrid/data/Task.java +++ b/api/src/com/todoroo/astrid/data/Task.java @@ -137,10 +137,6 @@ public final class Task extends RemoteModel { public static final StringProperty CALENDAR_URI = new StringProperty( TABLE, "calendarUri"); - /** uuid */ - public static final StringProperty UUID = new StringProperty( - TABLE, UUID_PROPERTY_NAME); - // --- for astrid.com /** Remote id */ diff --git a/api/src/com/todoroo/astrid/data/TaskToTag.java b/api/src/com/todoroo/astrid/data/TaskToTag.java index f7a4b57d5..dd9d50f0c 100644 --- a/api/src/com/todoroo/astrid/data/TaskToTag.java +++ b/api/src/com/todoroo/astrid/data/TaskToTag.java @@ -28,13 +28,13 @@ public class TaskToTag extends AbstractModel { public static final LongProperty TASK_ID = new LongProperty( TABLE, "taskId"); - public static final LongProperty TASK_UUID = new LongProperty( + public static final LongProperty TASK_REMOTEID= new LongProperty( TABLE, "taskUuid"); public static final LongProperty TAG_ID = new LongProperty( TABLE, "tagId"); - public static final LongProperty TAG_UUID = new LongProperty( + public static final LongProperty TAG_REMOTEID = new LongProperty( TABLE, "tagUuid"); public static final LongProperty DELETED_AT = new LongProperty( diff --git a/api/src/com/todoroo/astrid/data/Update.java b/api/src/com/todoroo/astrid/data/Update.java index ada77579e..9a13fbfe0 100644 --- a/api/src/com/todoroo/astrid/data/Update.java +++ b/api/src/com/todoroo/astrid/data/Update.java @@ -101,10 +101,6 @@ public class Update extends RemoteModel { public static final LongProperty CREATION_DATE = new LongProperty( TABLE, "created"); - /** uuid */ - public static final StringProperty UUID = new StringProperty( - TABLE, UUID_PROPERTY_NAME); - /** List of all properties for this model */ public static final Property[] PROPERTIES = generateProperties(Update.class); diff --git a/api/src/com/todoroo/astrid/data/User.java b/api/src/com/todoroo/astrid/data/User.java index bcf31797c..f5641badf 100644 --- a/api/src/com/todoroo/astrid/data/User.java +++ b/api/src/com/todoroo/astrid/data/User.java @@ -58,10 +58,6 @@ public final class User extends RemoteModel { public static final LongProperty REMOTE_ID = new LongProperty( TABLE, REMOTE_ID_PROPERTY_NAME); - /** uuid */ - public static final StringProperty UUID = new StringProperty( - TABLE, UUID_PROPERTY_NAME); - /** List of all properties for this model */ public static final Property[] PROPERTIES = generateProperties(User.class); diff --git a/astrid/plugin-src/com/todoroo/astrid/tags/TagService.java b/astrid/plugin-src/com/todoroo/astrid/tags/TagService.java index c573aaf79..089f66983 100644 --- a/astrid/plugin-src/com/todoroo/astrid/tags/TagService.java +++ b/astrid/plugin-src/com/todoroo/astrid/tags/TagService.java @@ -42,6 +42,7 @@ import com.todoroo.astrid.data.Metadata; import com.todoroo.astrid.data.TagData; import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.TaskApiDao; +import com.todoroo.astrid.data.TaskToTag; import com.todoroo.astrid.service.MetadataService; import com.todoroo.astrid.service.TagDataService; import com.todoroo.astrid.service.TaskService; @@ -115,18 +116,14 @@ public final class TagService { public static final class Tag { public String tag; public int count; + public long id; public long remoteId; public String image; public long userId; public long memberCount; - public Tag(String tag, int count, long remoteId) { - this.tag = tag; - this.count = count; - this.remoteId = remoteId; - } - public Tag(TagData tagData) { + id = tagData.getId(); tag = tagData.getValue(TagData.NAME); count = tagData.getValue(TagData.TASK_COUNT); remoteId = tagData.getValue(TagData.REMOTE_ID); @@ -140,19 +137,7 @@ public final class TagService { return tag; } - /** - * Return SQL selector query for getting tasks with a given tag - * - * @param tag - * @return - */ - public QueryTemplate queryTemplate(Criterion criterion) { - return new QueryTemplate().join(Join.inner(Metadata.TABLE.as("mtags"), - Criterion.and(Task.ID.eq(Field.field("mtags." + Metadata.TASK.name)), - Field.field("mtags." + Metadata.KEY.name).eq(KEY), - Field.field("mtags." + TAG.name).eqCaseInsensitive(tag)))).where(criterion); - } - + private static final String TABLE_ALIAS = "taglinks"; /** * Return SQL selector query for getting tasks with a given tagData @@ -160,9 +145,13 @@ public final class TagService { * @param tagData * @return */ - public static QueryTemplate queryTemplate(Criterion criterion, TagData tagData) { - return new QueryTemplate().join(Join.inner(Metadata.TABLE, - Task.ID.eq(Metadata.TASK))).where(tagEqIgnoreCase(tagData.getValue(TagData.NAME), criterion)); + public QueryTemplate queryTemplate(Criterion criterion) { + String prefix = TABLE_ALIAS + "."; + return new QueryTemplate().join(Join.inner(TaskToTag.TABLE.as(TABLE_ALIAS), + Criterion.and( + Criterion.or(Task.ID.eq(Field.field(prefix + TaskToTag.TASK_ID.name)), Task.REMOTE_ID.eq(Field.field(prefix + TaskToTag.TASK_REMOTEID.name))), + Criterion.or(Field.field(prefix + TaskToTag.TAG_ID.name).eq(id), Field.field(prefix + TaskToTag.TAG_REMOTEID.name).eq(remoteId))))) + .where(criterion); } } @@ -201,6 +190,7 @@ public final class TagService { * @param activeStatus criterion for specifying completed or uncompleted * @return empty array if no tags, otherwise array */ + @Deprecated public Tag[] getGroupedTags(Order order, Criterion activeStatus, boolean includeEmergent) { Criterion criterion; if (includeEmergent) @@ -318,40 +308,23 @@ public final class TagService { * @return */ public ArrayList getTagList() { - HashMap tags = new HashMap(); - - Tag[] tagsByAlpha = getGroupedTags(TagService.GROUPED_TAGS_BY_ALPHA, - TaskCriteria.activeAndVisible(), false); - for(Tag tag : tagsByAlpha) - if(!TextUtils.isEmpty(tag.tag)) - tags.put(tag.tag, tag); - - TodorooCursor cursor = tagDataService.query(Query.select(TagData.PROPERTIES)); + ArrayList tagList = new ArrayList(); + TodorooCursor cursor = tagDataService.query(Query.select(TagData.PROPERTIES).orderBy(Order.asc(TagData.NAME))); try { TagData tagData = new TagData(); for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { tagData.readFromCursor(cursor); - String tagName = tagData.getValue(TagData.NAME).trim(); Tag tag = new Tag(tagData); if(tagData.getValue(TagData.DELETION_DATE) > 0 || tagData.getFlag(TagData.FLAGS, TagData.FLAG_EMERGENT) || tagData.getFlag(TagData.FLAGS, TagData.FLAG_FEATURED)) { - tags.remove(tagName); continue; } if(TextUtils.isEmpty(tag.tag)) continue; - tags.put(tagName, tag); + tagList.add(tag); } } finally { cursor.close(); } - ArrayList tagList = new ArrayList(tags.values()); - Collections.sort(tagList, - new Comparator() { - @Override - public int compare(Tag object1, Tag object2) { - return object1.tag.compareToIgnoreCase(object2.tag); - } - }); return tagList; } diff --git a/astrid/src/com/todoroo/astrid/dao/Database.java b/astrid/src/com/todoroo/astrid/dao/Database.java index 194488bcb..905d3d379 100644 --- a/astrid/src/com/todoroo/astrid/dao/Database.java +++ b/astrid/src/com/todoroo/astrid/dao/Database.java @@ -340,11 +340,6 @@ public class Database extends AbstractDatabase { database.execSQL(createTableSql(visitor, TaskOutstanding.TABLE.name, TaskOutstanding.PROPERTIES)); database.execSQL(createTableSql(visitor, TagOutstanding.TABLE.name, TagOutstanding.PROPERTIES)); database.execSQL(createTableSql(visitor, TaskToTag.TABLE.name, TaskToTag.PROPERTIES)); - - database.execSQL(addColumnSql(TagData.TABLE, TagData.UUID, visitor)); - database.execSQL(addColumnSql(Task.TABLE, Task.UUID, visitor)); - database.execSQL(addColumnSql(Update.TABLE, Update.UUID, visitor)); - database.execSQL(addColumnSql(User.TABLE, User.UUID, visitor)); } catch (SQLiteException e) { Log.e("astrid", "db-upgrade-" + oldVersion + "-" + newVersion, e); } @@ -355,10 +350,6 @@ public class Database extends AbstractDatabase { return false; } - private String addColumnSql(Table table, Property column, SqlConstructorVisitor visitor) { - return "ALTER TABLE " + table.name + " ADD " + column.accept(visitor, null); - } - /** * Create table generation SQL * @param sql diff --git a/astrid/src/com/todoroo/astrid/dao/TagDataDao.java b/astrid/src/com/todoroo/astrid/dao/TagDataDao.java index 89de28b67..963dcfa28 100644 --- a/astrid/src/com/todoroo/astrid/dao/TagDataDao.java +++ b/astrid/src/com/todoroo/astrid/dao/TagDataDao.java @@ -31,7 +31,7 @@ public class TagDataDao extends DatabaseDao { private static final String[] IGNORE_OUTSTANDING_COLUMNS = new String[] { TagData.MODIFICATION_DATE.name, - TagData.UUID.name + TagData.REMOTE_ID.name }; @Override diff --git a/astrid/src/com/todoroo/astrid/dao/TaskDao.java b/astrid/src/com/todoroo/astrid/dao/TaskDao.java index 3c7faa945..f82554e22 100644 --- a/astrid/src/com/todoroo/astrid/dao/TaskDao.java +++ b/astrid/src/com/todoroo/astrid/dao/TaskDao.java @@ -321,7 +321,7 @@ public class TaskDao extends DatabaseDao { Task.DETAILS.name, Task.DETAILS_DATE.name, Task.CALENDAR_URI.name, - Task.UUID.name + Task.REMOTE_ID.name }; @Override