Remove UUIDs (new scheme), bring some changes from an experimental branch

pull/14/head
Sam Bosley 12 years ago
parent e7610650c1
commit 8dd89107a7

@ -35,11 +35,4 @@ abstract public class RemoteModel extends AbstractModel {
/** user json property */ /** user json property */
public static final StringProperty USER_JSON_PROPERTY = new StringProperty(null, USER_JSON_PROPERTY_NAME); 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);
} }

@ -117,10 +117,6 @@ public final class TagData extends RemoteModel {
public static final StringProperty TAG_DESCRIPTION = new StringProperty( public static final StringProperty TAG_DESCRIPTION = new StringProperty(
TABLE, "tagDescription"); TABLE, "tagDescription");
/** uuid */
public static final StringProperty UUID = new StringProperty(
TABLE, UUID_PROPERTY_NAME);
/** List of all properties for this model */ /** List of all properties for this model */
public static final Property<?>[] PROPERTIES = generateProperties(TagData.class); public static final Property<?>[] PROPERTIES = generateProperties(TagData.class);

@ -137,10 +137,6 @@ public final class Task extends RemoteModel {
public static final StringProperty CALENDAR_URI = new StringProperty( public static final StringProperty CALENDAR_URI = new StringProperty(
TABLE, "calendarUri"); TABLE, "calendarUri");
/** uuid */
public static final StringProperty UUID = new StringProperty(
TABLE, UUID_PROPERTY_NAME);
// --- for astrid.com // --- for astrid.com
/** Remote id */ /** Remote id */

@ -28,13 +28,13 @@ public class TaskToTag extends AbstractModel {
public static final LongProperty TASK_ID = new LongProperty( public static final LongProperty TASK_ID = new LongProperty(
TABLE, "taskId"); TABLE, "taskId");
public static final LongProperty TASK_UUID = new LongProperty( public static final LongProperty TASK_REMOTEID= new LongProperty(
TABLE, "taskUuid"); TABLE, "taskUuid");
public static final LongProperty TAG_ID = new LongProperty( public static final LongProperty TAG_ID = new LongProperty(
TABLE, "tagId"); TABLE, "tagId");
public static final LongProperty TAG_UUID = new LongProperty( public static final LongProperty TAG_REMOTEID = new LongProperty(
TABLE, "tagUuid"); TABLE, "tagUuid");
public static final LongProperty DELETED_AT = new LongProperty( public static final LongProperty DELETED_AT = new LongProperty(

@ -101,10 +101,6 @@ public class Update extends RemoteModel {
public static final LongProperty CREATION_DATE = new LongProperty( public static final LongProperty CREATION_DATE = new LongProperty(
TABLE, "created"); TABLE, "created");
/** uuid */
public static final StringProperty UUID = new StringProperty(
TABLE, UUID_PROPERTY_NAME);
/** List of all properties for this model */ /** List of all properties for this model */
public static final Property<?>[] PROPERTIES = generateProperties(Update.class); public static final Property<?>[] PROPERTIES = generateProperties(Update.class);

@ -58,10 +58,6 @@ public final class User extends RemoteModel {
public static final LongProperty REMOTE_ID = new LongProperty( public static final LongProperty REMOTE_ID = new LongProperty(
TABLE, REMOTE_ID_PROPERTY_NAME); TABLE, REMOTE_ID_PROPERTY_NAME);
/** uuid */
public static final StringProperty UUID = new StringProperty(
TABLE, UUID_PROPERTY_NAME);
/** List of all properties for this model */ /** List of all properties for this model */
public static final Property<?>[] PROPERTIES = generateProperties(User.class); public static final Property<?>[] PROPERTIES = generateProperties(User.class);

@ -42,6 +42,7 @@ import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.data.TagData; import com.todoroo.astrid.data.TagData;
import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.data.TaskApiDao; import com.todoroo.astrid.data.TaskApiDao;
import com.todoroo.astrid.data.TaskToTag;
import com.todoroo.astrid.service.MetadataService; import com.todoroo.astrid.service.MetadataService;
import com.todoroo.astrid.service.TagDataService; import com.todoroo.astrid.service.TagDataService;
import com.todoroo.astrid.service.TaskService; import com.todoroo.astrid.service.TaskService;
@ -115,18 +116,14 @@ public final class TagService {
public static final class Tag { public static final class Tag {
public String tag; public String tag;
public int count; public int count;
public long id;
public long remoteId; public long remoteId;
public String image; public String image;
public long userId; public long userId;
public long memberCount; public long memberCount;
public Tag(String tag, int count, long remoteId) {
this.tag = tag;
this.count = count;
this.remoteId = remoteId;
}
public Tag(TagData tagData) { public Tag(TagData tagData) {
id = tagData.getId();
tag = tagData.getValue(TagData.NAME); tag = tagData.getValue(TagData.NAME);
count = tagData.getValue(TagData.TASK_COUNT); count = tagData.getValue(TagData.TASK_COUNT);
remoteId = tagData.getValue(TagData.REMOTE_ID); remoteId = tagData.getValue(TagData.REMOTE_ID);
@ -140,19 +137,7 @@ public final class TagService {
return tag; return tag;
} }
/** private static final String TABLE_ALIAS = "taglinks";
* 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);
}
/** /**
* Return SQL selector query for getting tasks with a given tagData * Return SQL selector query for getting tasks with a given tagData
@ -160,9 +145,13 @@ public final class TagService {
* @param tagData * @param tagData
* @return * @return
*/ */
public static QueryTemplate queryTemplate(Criterion criterion, TagData tagData) { public QueryTemplate queryTemplate(Criterion criterion) {
return new QueryTemplate().join(Join.inner(Metadata.TABLE, String prefix = TABLE_ALIAS + ".";
Task.ID.eq(Metadata.TASK))).where(tagEqIgnoreCase(tagData.getValue(TagData.NAME), criterion)); 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 * @param activeStatus criterion for specifying completed or uncompleted
* @return empty array if no tags, otherwise array * @return empty array if no tags, otherwise array
*/ */
@Deprecated
public Tag[] getGroupedTags(Order order, Criterion activeStatus, boolean includeEmergent) { public Tag[] getGroupedTags(Order order, Criterion activeStatus, boolean includeEmergent) {
Criterion criterion; Criterion criterion;
if (includeEmergent) if (includeEmergent)
@ -318,40 +308,23 @@ public final class TagService {
* @return * @return
*/ */
public ArrayList<Tag> getTagList() { public ArrayList<Tag> getTagList() {
HashMap<String, Tag> tags = new HashMap<String, Tag>(); ArrayList<Tag> tagList = new ArrayList<Tag>();
TodorooCursor<TagData> cursor = tagDataService.query(Query.select(TagData.PROPERTIES).orderBy(Order.asc(TagData.NAME)));
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<TagData> cursor = tagDataService.query(Query.select(TagData.PROPERTIES));
try { try {
TagData tagData = new TagData(); TagData tagData = new TagData();
for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
tagData.readFromCursor(cursor); tagData.readFromCursor(cursor);
String tagName = tagData.getValue(TagData.NAME).trim();
Tag tag = new Tag(tagData); 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)) { 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; continue;
} }
if(TextUtils.isEmpty(tag.tag)) if(TextUtils.isEmpty(tag.tag))
continue; continue;
tags.put(tagName, tag); tagList.add(tag);
} }
} finally { } finally {
cursor.close(); cursor.close();
} }
ArrayList<Tag> tagList = new ArrayList<Tag>(tags.values());
Collections.sort(tagList,
new Comparator<Tag>() {
@Override
public int compare(Tag object1, Tag object2) {
return object1.tag.compareToIgnoreCase(object2.tag);
}
});
return tagList; return tagList;
} }

@ -340,11 +340,6 @@ public class Database extends AbstractDatabase {
database.execSQL(createTableSql(visitor, TaskOutstanding.TABLE.name, TaskOutstanding.PROPERTIES)); database.execSQL(createTableSql(visitor, TaskOutstanding.TABLE.name, TaskOutstanding.PROPERTIES));
database.execSQL(createTableSql(visitor, TagOutstanding.TABLE.name, TagOutstanding.PROPERTIES)); database.execSQL(createTableSql(visitor, TagOutstanding.TABLE.name, TagOutstanding.PROPERTIES));
database.execSQL(createTableSql(visitor, TaskToTag.TABLE.name, TaskToTag.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) { } catch (SQLiteException e) {
Log.e("astrid", "db-upgrade-" + oldVersion + "-" + newVersion, e); Log.e("astrid", "db-upgrade-" + oldVersion + "-" + newVersion, e);
} }
@ -355,10 +350,6 @@ public class Database extends AbstractDatabase {
return false; 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 * Create table generation SQL
* @param sql * @param sql

@ -31,7 +31,7 @@ public class TagDataDao extends DatabaseDao<TagData> {
private static final String[] IGNORE_OUTSTANDING_COLUMNS = new String[] { private static final String[] IGNORE_OUTSTANDING_COLUMNS = new String[] {
TagData.MODIFICATION_DATE.name, TagData.MODIFICATION_DATE.name,
TagData.UUID.name TagData.REMOTE_ID.name
}; };
@Override @Override

@ -321,7 +321,7 @@ public class TaskDao extends DatabaseDao<Task> {
Task.DETAILS.name, Task.DETAILS.name,
Task.DETAILS_DATE.name, Task.DETAILS_DATE.name,
Task.CALENDAR_URI.name, Task.CALENDAR_URI.name,
Task.UUID.name Task.REMOTE_ID.name
}; };
@Override @Override

Loading…
Cancel
Save