Removed task to tags table and started refactor to use metadata table (compilation errors)

pull/14/head
Sam Bosley 12 years ago
parent 7b244da3b9
commit 58e1bdc455

@ -1,76 +0,0 @@
package com.todoroo.astrid.data;
import android.content.ContentValues;
import android.net.Uri;
import com.todoroo.andlib.data.AbstractModel;
import com.todoroo.andlib.data.Property;
import com.todoroo.andlib.data.Property.LongProperty;
import com.todoroo.andlib.data.Table;
import com.todoroo.astrid.api.AstridApiConstants;
@SuppressWarnings("nls")
public class TaskToTag extends AbstractModel {
/** table for this model */
public static final Table TABLE = new Table("tasks_to_tags", TaskToTag.class);
/** content uri for this model */
public static final Uri CONTENT_URI = Uri.parse("content://" + AstridApiConstants.PACKAGE + "/" +
TABLE.name);
// --- properties
/** ID */
public static final LongProperty ID = new LongProperty(
TABLE, ID_PROPERTY_NAME);
public static final LongProperty TASK_ID = new LongProperty(
TABLE, "taskId");
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_REMOTEID = new LongProperty(
TABLE, "tagUuid");
public static final LongProperty DELETED_AT = new LongProperty(
TABLE, "deletedAt");
public static final LongProperty PUSHED_AT = new LongProperty(
TABLE, "pushedAt");
/** List of all properties for this model */
public static final Property<?>[] PROPERTIES = generateProperties(TaskToTag.class);
/** Default values container */
private static final ContentValues defaultValues = new ContentValues();
static {
defaultValues.put(DELETED_AT.name, 0L);
defaultValues.put(PUSHED_AT.name, 0L);
}
@Override
public ContentValues getDefaultValues() {
return defaultValues;
}
@Override
public long getId() {
return getIdHelper(ID);
};
// --- parcelable helpers
private static final Creator<TaskToTag> CREATOR = new ModelCreator<TaskToTag>(TaskToTag.class);
@Override
protected Creator<? extends AbstractModel> getCreator() {
return CREATOR;
}
}

@ -42,7 +42,6 @@ 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;
@ -122,11 +121,19 @@ public final class TagService {
public long userId;
public long memberCount;
@Deprecated
private Tag(String tag, int count, long remoteId) {
this.tag = tag;
this.count = count;
this.remoteId = remoteId;
public static Tag tagFromRemoteId(long remoteId) {
TodorooCursor<TagData> tagData = PluginServices.getTagDataService().query(Query.select(TagData.PROPERTIES).where(TagData.REMOTE_ID.eq(remoteId)));
try {
if (tagData.getCount() > 0) {
tagData.moveToFirst();
return new Tag(new TagData(tagData));
} else {
return null;
}
} finally {
tagData.close();
}
}
public Tag(TagData tagData) {
@ -153,12 +160,12 @@ public final class TagService {
* @return
*/
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);
// 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);
}
}
@ -210,12 +217,14 @@ public final class TagService {
orderBy(order).groupBy(TAG);
TodorooCursor<Metadata> cursor = metadataDao.query(query);
try {
Tag[] array = new Tag[cursor.getCount()];
for (int i = 0; i < array.length; i++) {
ArrayList<Tag> array = new ArrayList<Tag>();
for (int i = 0; i < cursor.getCount(); i++) {
cursor.moveToNext();
array[i] = new Tag(cursor.get(TAG), cursor.get(COUNT), cursor.get(REMOTE_ID));
Tag tag = Tag.tagFromRemoteId(cursor.get(REMOTE_ID));
if (tag != null)
array.add(tag);
}
return array;
return array.toArray(new Tag[array.size()]);
} finally {
cursor.close();
}

@ -6,14 +6,11 @@ import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.sql.Criterion;
import com.todoroo.andlib.sql.Join;
import com.todoroo.andlib.sql.Query;
import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.dao.MetadataDao.MetadataCriteria;
import com.todoroo.astrid.dao.TaskToTagDao;
import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.data.TagData;
import com.todoroo.astrid.data.TaskToTag;
import com.todoroo.astrid.service.MetadataService;
import com.todoroo.astrid.service.TagDataService;
import com.todoroo.astrid.utility.Constants;
@ -22,7 +19,6 @@ public class TagsTableMigrator {
@Autowired private MetadataService metadataService;
@Autowired private TagDataService tagDataService;
@Autowired private TaskToTagDao taskToTagDao;
private static final String PREF_MIGRATED_TASKS_TO_TAGS = "tasks_to_tags_migration"; //$NON-NLS-1$
@ -57,32 +53,6 @@ public class TagsTableMigrator {
noTagData.close();
}
// Then move all tag metadata to the new table
Query joinedTagData = Query.select(Metadata.TASK, TagService.TAG, TagData.ID)
.join(Join.left(TagData.TABLE,
Criterion.and(MetadataCriteria.withKey(TagService.KEY), TagService.TAG.eq(TagData.NAME))));
TodorooCursor<Metadata> allTagLinks = metadataService.query(joinedTagData);
try {
Metadata tag = new Metadata();
for (allTagLinks.moveToFirst(); !allTagLinks.isAfterLast(); allTagLinks.moveToNext()) {
tag.readFromCursor(allTagLinks);
// Create new tag links
TaskToTag link = new TaskToTag();
if (Constants.DEBUG)
Log.w("tag-link-migrate", "LINK FROM TASK " + tag.getValue(Metadata.TASK) + " TO TAG " + tag.getValue(TagService.TAG));
link.setValue(TaskToTag.TASK_ID, tag.getValue(Metadata.TASK));
link.setValue(TaskToTag.TAG_ID, tag.getValue(TagData.ID));
taskToTagDao.createNew(link);
}
} finally {
allTagLinks.close();
}
Preferences.setBoolean(PREF_MIGRATED_TASKS_TO_TAGS, true);
}

@ -20,7 +20,6 @@ import com.todoroo.astrid.data.TagData;
import com.todoroo.astrid.data.TagOutstanding;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.data.TaskOutstanding;
import com.todoroo.astrid.data.TaskToTag;
import com.todoroo.astrid.data.Update;
import com.todoroo.astrid.data.User;
import com.todoroo.astrid.provider.Astrid2TaskProvider;
@ -64,7 +63,6 @@ public class Database extends AbstractDatabase {
TaskOutstanding.TABLE,
TagOutstanding.TABLE,
TaskToTag.TABLE
};
// --- listeners
@ -339,7 +337,6 @@ public class Database extends AbstractDatabase {
case 25: try {
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));
} catch (SQLiteException e) {
Log.e("astrid", "db-upgrade-" + oldVersion + "-" + newVersion, e);
}

@ -1,19 +0,0 @@
package com.todoroo.astrid.dao;
import com.todoroo.andlib.data.DatabaseDao;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.astrid.data.TaskToTag;
public class TaskToTagDao extends DatabaseDao<TaskToTag> {
@Autowired
private Database database;
public TaskToTagDao() {
super(TaskToTag.class);
DependencyInjectionService.getInstance().inject(this);
setDatabase(database);
}
}

@ -20,7 +20,6 @@ import com.todoroo.astrid.dao.MetadataDao;
import com.todoroo.astrid.dao.StoreObjectDao;
import com.todoroo.astrid.dao.TagDataDao;
import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.dao.TaskToTagDao;
import com.todoroo.astrid.dao.UpdateDao;
import com.todoroo.astrid.dao.UserDao;
import com.todoroo.astrid.gtasks.GtasksListService;
@ -73,7 +72,6 @@ public class AstridDependencyInjector extends AbstractDependencyInjector {
injectables.put("storeObjectDao", StoreObjectDao.class);
injectables.put("updateDao", UpdateDao.class);
injectables.put("userDao", UserDao.class);
injectables.put("taskToTagDao", TaskToTagDao.class);
// com.todoroo.astrid.service
injectables.put("taskService", TaskService.class);

@ -31,11 +31,9 @@ import com.todoroo.astrid.dao.MetadataDao;
import com.todoroo.astrid.dao.MetadataDao.MetadataCriteria;
import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.dao.TaskDao.TaskCriteria;
import com.todoroo.astrid.dao.TaskToTagDao;
import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.data.SyncFlags;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.data.TaskToTag;
import com.todoroo.astrid.gcal.GCalHelper;
import com.todoroo.astrid.gtasks.GtasksMetadata;
import com.todoroo.astrid.opencrx.OpencrxCoreUtils;
@ -67,14 +65,15 @@ public class TaskService {
private static final int TOTAL_TASKS_FOR_ACTIVATION = 3;
private static final int COMPLETED_TASKS_FOR_ACTIVATION = 1;
private static final String PREF_USER_ACTVATED = "user-activated"; //$NON-NLS-1$
@Autowired
private TaskDao taskDao;
private TagService tagService;
@Autowired
private MetadataDao metadataDao;
private TaskDao taskDao;
@Autowired
private TaskToTagDao taskToTagDao;
private MetadataDao metadataDao;
public TaskService() {
DependencyInjectionService.getInstance().inject(this);
@ -206,10 +205,7 @@ public class TaskService {
taskDao.save(newTask);
if (tagId > 0) {
TaskToTag link = new TaskToTag();
link.setValue(TaskToTag.ID, newTask.getId());
link.setValue(TaskToTag.TAG_ID, tagId);
taskToTagDao.createNew(link);
tagService.createLink(task, tagId);
}
return newTask;
}

Loading…
Cancel
Save