Convert TaskListMetadataDao to Room

pull/618/head
Alex Baker 6 years ago
parent 2789ccc239
commit c499064e3e

@ -0,0 +1,272 @@
{
"formatVersion": 1,
"database": {
"version": 43,
"identityHash": "0f95ff251eaec3b1e0ddf0924a70cabf",
"entities": [
{
"tableName": "notification",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`uid` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `task` INTEGER NOT NULL, `timestamp` INTEGER NOT NULL, `type` INTEGER NOT NULL)",
"fields": [
{
"fieldPath": "uid",
"columnName": "uid",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "taskId",
"columnName": "task",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "timestamp",
"columnName": "timestamp",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "type",
"columnName": "type",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"columnNames": [
"uid"
],
"autoGenerate": true
},
"indices": [
{
"name": "index_notification_task",
"unique": true,
"columnNames": [
"task"
],
"createSql": "CREATE UNIQUE INDEX `index_notification_task` ON `${TABLE_NAME}` (`task`)"
}
],
"foreignKeys": []
},
{
"tableName": "tagdata",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`_id` INTEGER PRIMARY KEY AUTOINCREMENT, `remoteId` TEXT, `name` TEXT, `color` INTEGER, `tagOrdering` TEXT, `deleted` INTEGER)",
"fields": [
{
"fieldPath": "id",
"columnName": "_id",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "remoteId",
"columnName": "remoteId",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "name",
"columnName": "name",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "color",
"columnName": "color",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "tagOrdering",
"columnName": "tagOrdering",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "deleted",
"columnName": "deleted",
"affinity": "INTEGER",
"notNull": false
}
],
"primaryKey": {
"columnNames": [
"_id"
],
"autoGenerate": true
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "userActivity",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`_id` INTEGER PRIMARY KEY AUTOINCREMENT, `remoteId` TEXT, `action` TEXT, `message` TEXT, `picture` TEXT, `target_id` TEXT, `created_at` INTEGER, `deleted_at` INTEGER)",
"fields": [
{
"fieldPath": "id",
"columnName": "_id",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "remoteId",
"columnName": "remoteId",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "action",
"columnName": "action",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "message",
"columnName": "message",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "picture",
"columnName": "picture",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "targetId",
"columnName": "target_id",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "created",
"columnName": "created_at",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "deleted",
"columnName": "deleted_at",
"affinity": "INTEGER",
"notNull": false
}
],
"primaryKey": {
"columnNames": [
"_id"
],
"autoGenerate": true
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "task_attachments",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`_id` INTEGER PRIMARY KEY AUTOINCREMENT, `remoteId` TEXT, `task_id` TEXT, `name` TEXT, `path` TEXT, `content_type` TEXT, `deleted_at` INTEGER)",
"fields": [
{
"fieldPath": "id",
"columnName": "_id",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "remoteId",
"columnName": "remoteId",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "taskId",
"columnName": "task_id",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "name",
"columnName": "name",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "path",
"columnName": "path",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "contentType",
"columnName": "content_type",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "deleted",
"columnName": "deleted_at",
"affinity": "INTEGER",
"notNull": false
}
],
"primaryKey": {
"columnNames": [
"_id"
],
"autoGenerate": true
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "task_list_metadata",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`_id` INTEGER PRIMARY KEY AUTOINCREMENT, `remoteId` TEXT, `tag_uuid` TEXT, `filter` TEXT, `task_ids` TEXT)",
"fields": [
{
"fieldPath": "id",
"columnName": "_id",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "remoteId",
"columnName": "remoteId",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "tagUuid",
"columnName": "tag_uuid",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "filter",
"columnName": "filter",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "taskIds",
"columnName": "task_ids",
"affinity": "TEXT",
"notNull": false
}
],
"primaryKey": {
"columnNames": [
"_id"
],
"autoGenerate": true
},
"indices": [],
"foreignKeys": []
}
],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, \"0f95ff251eaec3b1e0ddf0924a70cabf\")"
]
}
}

@ -41,15 +41,17 @@ import timber.log.Timber;
Notification.class,
TagData.class,
UserActivity.class,
TaskAttachment.class
TaskAttachment.class,
TaskListMetadata.class
},
version = 42)
version = 43)
public abstract class Database extends RoomDatabase {
public abstract NotificationDao notificationDao();
public abstract TagDataDao getTagDataDao();
public abstract UserActivityDao getUserActivityDao();
public abstract TaskAttachmentDao getTaskAttachmentDao();
public abstract TaskListMetadataDao getTaskListMetadataDao();
public static final String NAME = "database";
@ -57,7 +59,6 @@ public abstract class Database extends RoomDatabase {
Task.TABLE,
Metadata.TABLE,
StoreObject.TABLE,
TaskListMetadata.TABLE,
};
private SupportSQLiteDatabase database;
@ -188,7 +189,7 @@ public abstract class Database extends RoomDatabase {
return result;
}
public int update(String table, ContentValues values, String whereClause) {
public int update(String table, ContentValues values, String whereClause) {
int result = getDatabase().update(table, SQLiteDatabase.CONFLICT_REPLACE, values, whereClause, null);
onDatabaseUpdated();
return result;

@ -5,38 +5,33 @@
*/
package com.todoroo.astrid.dao;
import com.todoroo.andlib.sql.Criterion;
import com.todoroo.andlib.sql.Query;
import com.todoroo.astrid.data.TagData;
import android.arch.persistence.room.Dao;
import android.arch.persistence.room.Insert;
import android.arch.persistence.room.OnConflictStrategy;
import android.arch.persistence.room.Query;
import android.arch.persistence.room.Update;
import com.todoroo.astrid.data.RemoteModel;
import com.todoroo.astrid.data.TaskListMetadata;
import com.todoroo.astrid.helper.UUIDHelper;
import javax.inject.Inject;
@Dao
public abstract class TaskListMetadataDao {
/**
* Data Access layer for {@link TagData}-related operations.
*
* @author Tim Su <tim@todoroo.com>
*/
public class TaskListMetadataDao {
@Query("SELECT * from task_list_metadata where tag_uuid = :tagUuid OR filter = :tagUuid LIMIT 1")
public abstract TaskListMetadata fetchByTagId(String tagUuid);
private final RemoteModelDao<TaskListMetadata> dao;
@Update
public abstract void update(TaskListMetadata taskListMetadata);
@Inject
public TaskListMetadataDao(Database database) {
dao = new RemoteModelDao<>(database, TaskListMetadata.class);
}
public TaskListMetadata fetchByTagId(String tagUuid) {
return dao.getFirst(Query.select(TaskListMetadata.PROPERTIES).where(Criterion.or(TaskListMetadata.TAG_UUID.eq(tagUuid),
TaskListMetadata.FILTER.eq(tagUuid))));
}
@Insert(onConflict = OnConflictStrategy.REPLACE)
public abstract void insert(TaskListMetadata taskListMetadata);
public void createNew(TaskListMetadata taskListMetadata) {
dao.createNew(taskListMetadata);
}
public void saveExisting(TaskListMetadata list) {
dao.saveExisting(list);
if (RemoteModel.isUuidEmpty(taskListMetadata.getRemoteId())) {
taskListMetadata.setRemoteId(UUIDHelper.newUUID());
}
insert(taskListMetadata);
}
}

@ -11,6 +11,4 @@ public class SyncFlags {
public static final String FORCE_SYNC = "force_sync";
public static final String ACTFM_SUPPRESS_OUTSTANDING_ENTRIES = "actfm-suppress-outstanding";
}

@ -6,6 +6,9 @@
package com.todoroo.astrid.data;
import android.arch.persistence.room.ColumnInfo;
import android.arch.persistence.room.Entity;
import android.arch.persistence.room.PrimaryKey;
import android.content.ContentValues;
import com.todoroo.andlib.data.Property;
@ -19,82 +22,65 @@ import com.todoroo.andlib.data.Table;
* @author Tim Su <tim@todoroo.com>
*
*/
public final class TaskListMetadata extends RemoteModel {
@Entity(tableName = "task_list_metadata")
public class TaskListMetadata {
// --- table and uri
/** table for this model */
public static final Table TABLE = new Table("task_list_metadata", TaskListMetadata.class);
// --- properties
/** ID */
@SuppressWarnings("WeakerAccess")
public static final LongProperty ID = new LongProperty(
TABLE, ID_PROPERTY_NAME);
/** Remote id */
@SuppressWarnings("WeakerAccess")
public static final StringProperty UUID = new StringProperty(
TABLE, UUID_PROPERTY_NAME);
/** Tag UUID */
public static final StringProperty TAG_UUID = new StringProperty(
TABLE, "tag_uuid");
public static final String FILTER_ID_ALL = "all";
public static final String FILTER_ID_TODAY = "today";
/** Filter id (one of below) */
public static final StringProperty FILTER = new StringProperty(
TABLE, "filter");
@PrimaryKey(autoGenerate = true)
@ColumnInfo(name = "_id")
private Long id;
/** Tree of task ids (serialized to json array) */
public static final StringProperty TASK_IDS = new StringProperty(
TABLE, "task_ids", Property.PROP_FLAG_JSON);
@ColumnInfo(name = "remoteId")
private String remoteId = RemoteModel.NO_UUID;
/** List of all properties for this model */
public static final Property<?>[] PROPERTIES = generateProperties(TaskListMetadata.class);
@ColumnInfo(name = "tag_uuid")
private String tagUuid = RemoteModel.NO_UUID;
public static final String FILTER_ID_ALL = "all";
public static final String FILTER_ID_TODAY = "today";
@ColumnInfo(name = "filter")
private String filter = "";
// --- defaults
@ColumnInfo(name = "task_ids")
private String taskIds = "[]";
/** Default values container */
private static final ContentValues defaultValues = new ContentValues();
public Long getId() {
return id;
}
static {
defaultValues.put(UUID.name, NO_UUID);
defaultValues.put(TAG_UUID.name, NO_UUID);
defaultValues.put(FILTER.name, "");
defaultValues.put(TASK_IDS.name, "[]");
public void setId(Long id) {
this.id = id;
}
@Override
public ContentValues getDefaultValues() {
return defaultValues;
public String getRemoteId() {
return remoteId;
}
@Override
public long getId() {
return getIdHelper(ID);
public void setRemoteId(String remoteId) {
this.remoteId = remoteId;
}
// --- parcelable helpers
public String getTagUuid() {
return tagUuid;
}
public static final Creator<TaskListMetadata> CREATOR = new ModelCreator<>(TaskListMetadata.class);
public void setTagUuid(String tagUuid) {
this.tagUuid = tagUuid;
}
public String getTaskIDs() {
return getValue(TASK_IDS);
public String getFilter() {
return filter;
}
public void setTaskIDs(String taskIds) {
setValue(TASK_IDS, taskIds);
public void setFilter(String filter) {
this.filter = filter;
}
public void setTagUUID(String tagUuid) {
setValue(TAG_UUID, tagUuid);
public String getTaskIds() {
return taskIds;
}
public void setFilter(String filter) {
setValue(FILTER, filter);
public void setTaskIds(String taskIds) {
this.taskIds = taskIds;
}
}

@ -166,7 +166,7 @@ class AstridOrderedListFragmentHelper {
}
if (madeChanges) {
updater.writeSerialization(list, updater.serializeTree(), true);
updater.writeSerialization(list, updater.serializeTree());
}
} finally {
recurring.close();

@ -7,7 +7,6 @@ import com.todoroo.astrid.api.Filter;
import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.dao.TaskListMetadataDao;
import com.todoroo.astrid.data.RemoteModel;
import com.todoroo.astrid.data.SyncFlags;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.data.TaskListMetadata;
@ -44,7 +43,7 @@ public class SubtasksFilterUpdater {
if (list == null) {
return "[]"; //$NON-NLS-1$
}
String order = list.getTaskIDs();
String order = list.getTaskIds();
if (TextUtils.isEmpty(order) || "null".equals(order)) //$NON-NLS-1$
{
order = "[]"; //$NON-NLS-1$
@ -53,13 +52,10 @@ public class SubtasksFilterUpdater {
return order;
}
void writeSerialization(TaskListMetadata list, String serialized, boolean shouldQueueSync) {
void writeSerialization(TaskListMetadata list, String serialized) {
if (list != null) {
list.setTaskIDs(serialized);
if (!shouldQueueSync) {
list.putTransitory(SyncFlags.ACTFM_SUPPRESS_OUTSTANDING_ENTRIES, true);
}
taskListMetadataDao.saveExisting(list);
list.setTaskIds(serialized);
taskListMetadataDao.update(list);
}
}
@ -148,7 +144,7 @@ public class SubtasksFilterUpdater {
tasks.close();
}
if (changedThings) {
writeSerialization(list, serializeTree(), false);
writeSerialization(list, serializeTree());
}
}
@ -275,7 +271,7 @@ public class SubtasksFilterUpdater {
newSiblings.add(insertAfter + 1, node);
}
writeSerialization(list, serializeTree(), true);
writeSerialization(list, serializeTree());
applyToFilter(filter);
}
@ -360,7 +356,7 @@ public class SubtasksFilterUpdater {
beforeIndex--;
}
newSiblings.add(beforeIndex, moveThis);
writeSerialization(list, serializeTree(), true);
writeSerialization(list, serializeTree());
applyToFilter(filter);
}
@ -382,7 +378,7 @@ public class SubtasksFilterUpdater {
treeRoot.children.add(moveThis);
moveThis.parent = treeRoot;
setNodeIndent(moveThis, 0);
writeSerialization(list, serializeTree(), true);
writeSerialization(list, serializeTree());
applyToFilter(filter);
}
@ -394,7 +390,7 @@ public class SubtasksFilterUpdater {
Node newNode = new Node(uuid, treeRoot, 0);
treeRoot.children.add(0, newNode);
idToNode.put(uuid, newNode);
writeSerialization(list, serializeTree(), true);
writeSerialization(list, serializeTree());
applyToFilter(filter);
}
@ -419,7 +415,7 @@ public class SubtasksFilterUpdater {
}
idToNode.remove(taskId);
writeSerialization(list, serializeTree(), true);
writeSerialization(list, serializeTree());
applyToFilter(filter);
}

@ -86,7 +86,7 @@ public class SubtasksHelper {
private String getOrderString(TagData tagData, TaskListMetadata tlm) {
String serialized;
if (tlm != null) {
serialized = tlm.getTaskIDs();
serialized = tlm.getTaskIds();
} else if (tagData != null) {
serialized = convertTreeToRemoteIds(taskDao, tagData.getTagOrdering());
} else {

@ -84,7 +84,7 @@ public class SubtasksListFragment extends TaskListFragment {
defaultOrder = SubtasksHelper.convertTreeToRemoteIds(taskDao, defaultOrder);
taskListMetadata = new TaskListMetadata();
taskListMetadata.setFilter(filterId);
taskListMetadata.setTaskIDs(defaultOrder);
taskListMetadata.setTaskIds(defaultOrder);
taskListMetadataDao.createNew(taskListMetadata);
}
return taskListMetadata;

@ -52,7 +52,7 @@ public class SubtasksTagListFragment extends TagListFragment {
TaskListMetadata taskListMetadata = taskListMetadataDao.fetchByTagId(tagData.getRemoteId());
if (taskListMetadata == null && !RemoteModel.isUuidEmpty(tdId)) {
taskListMetadata = new TaskListMetadata();
taskListMetadata.setTagUUID(tdId);
taskListMetadata.setTagUuid(tdId);
taskListMetadataDao.createNew(taskListMetadata);
}
helper.setList(taskListMetadata);

@ -60,7 +60,8 @@ public class Migrations {
MIGRATION_38_39,
NOOP(39, 40),
NOOP(40, 41),
NOOP(41, 42)
NOOP(41, 42),
NOOP(42, 43)
};
public static RoomDatabase.Callback ON_CREATE = new RoomDatabase.Callback() {

@ -6,6 +6,7 @@ import android.content.Context;
import com.todoroo.astrid.dao.Database;
import com.todoroo.astrid.dao.TagDataDao;
import com.todoroo.astrid.dao.TaskAttachmentDao;
import com.todoroo.astrid.dao.TaskListMetadataDao;
import com.todoroo.astrid.dao.UserActivityDao;
import com.todoroo.astrid.provider.Astrid2TaskProvider;
@ -79,4 +80,9 @@ public class ApplicationModule {
public TaskAttachmentDao getTaskAttachmentDao(Database database) {
return database.getTaskAttachmentDao();
}
@Provides
public TaskListMetadataDao getTaskListMetadataDao(Database database) {
return database.getTaskListMetadataDao();
}
}

Loading…
Cancel
Save