Some changes to make it easier to control which properties should have outstanding entries recorded

pull/14/head
Sam Bosley 12 years ago
parent b148966d7c
commit 1be7b9e449

@ -388,7 +388,7 @@ public class DatabaseDao<TYPE extends AbstractModel> {
long now = DateUtilities.now(); long now = DateUtilities.now();
int count = 0; int count = 0;
for (Entry<String, Object> entry : entries) { for (Entry<String, Object> entry : entries) {
if (entry.getValue() != null && shouldRecordOutstandingEntry(entry.getKey())) { if (entry.getValue() != null && shouldRecordOutstandingEntry(entry.getKey(), entry.getValue())) {
AbstractModel m; AbstractModel m;
try { try {
m = outstandingTable.modelClass.newInstance(); m = outstandingTable.modelClass.newInstance();
@ -415,7 +415,7 @@ public class DatabaseDao<TYPE extends AbstractModel> {
* @param columnName * @param columnName
* @return * @return
*/ */
protected boolean shouldRecordOutstandingEntry(String columnName) { protected boolean shouldRecordOutstandingEntry(String columnName, Object value) {
return true; return true;
} }

@ -194,16 +194,18 @@ public class NameMaps {
private static final Map<String, Property<?>> USER_COLUMN_NAMES_TO_PROPERTIES; private static final Map<String, Property<?>> USER_COLUMN_NAMES_TO_PROPERTIES;
private static final Map<String, String> USER_COLUMNS_LOCAL_TO_SERVER; private static final Map<String, String> USER_COLUMNS_LOCAL_TO_SERVER;
private static final Map<String, Property<?>> USER_PROPERTIES_SERVER_TO_LOCAL; private static final Map<String, Property<?>> USER_PROPERTIES_SERVER_TO_LOCAL;
private static final Set<String> USER_PROPERTIES_EXCLUDED;
private static void putUserPropertyToServerName(Property<?> property, String serverName, boolean writeable) { private static void putUserPropertyToServerName(Property<?> property, String serverName, boolean writeable) {
putPropertyToServerName(property, serverName, USER_PROPERTIES_LOCAL_TO_SERVER, USER_COLUMN_NAMES_TO_PROPERTIES, putPropertyToServerName(property, serverName, USER_PROPERTIES_LOCAL_TO_SERVER, USER_COLUMN_NAMES_TO_PROPERTIES,
USER_COLUMNS_LOCAL_TO_SERVER, null, writeable); USER_COLUMNS_LOCAL_TO_SERVER, USER_PROPERTIES_EXCLUDED, writeable);
} }
static { static {
USER_PROPERTIES_LOCAL_TO_SERVER = new HashMap<Property<?>, String>(); USER_PROPERTIES_LOCAL_TO_SERVER = new HashMap<Property<?>, String>();
USER_COLUMN_NAMES_TO_PROPERTIES = new HashMap<String, Property<?>>(); USER_COLUMN_NAMES_TO_PROPERTIES = new HashMap<String, Property<?>>();
USER_COLUMNS_LOCAL_TO_SERVER = new HashMap<String, String>(); USER_COLUMNS_LOCAL_TO_SERVER = new HashMap<String, String>();
USER_PROPERTIES_EXCLUDED = new HashSet<String>();
putUserPropertyToServerName(User.UUID, "uuid", false); putUserPropertyToServerName(User.UUID, "uuid", false);
putUserPropertyToServerName(User.PICTURE, "picture", false); putUserPropertyToServerName(User.PICTURE, "picture", false);
@ -358,6 +360,9 @@ public class NameMaps {
} else if (TABLE_ID_USER_ACTIVITY.equals(table)) { } else if (TABLE_ID_USER_ACTIVITY.equals(table)) {
if (USER_ACTIVITY_COLUMN_NAMES_TO_PROPERTIES.containsKey(column)) if (USER_ACTIVITY_COLUMN_NAMES_TO_PROPERTIES.containsKey(column))
return !USER_ACTIVITY_PROPERTIES_EXCLUDED.contains(column); return !USER_ACTIVITY_PROPERTIES_EXCLUDED.contains(column);
} else if (TABLE_ID_USERS.equals(table)) {
if (USER_COLUMN_NAMES_TO_PROPERTIES.containsKey(column))
return !USER_PROPERTIES_EXCLUDED.contains(column);
} else if (TABLE_ID_ATTACHMENTS.equals(table)) { } else if (TABLE_ID_ATTACHMENTS.equals(table)) {
if (TASK_ATTACHMENT_COLUMN_NAMES_TO_PROPERTIES.containsKey(column)) if (TASK_ATTACHMENT_COLUMN_NAMES_TO_PROPERTIES.containsKey(column))
return !TASK_ATTACHMENT_PROPERTIES_EXCLUDED.contains(column); return !TASK_ATTACHMENT_PROPERTIES_EXCLUDED.contains(column);

@ -29,7 +29,7 @@ public class TagDataDao extends RemoteModelDao<TagData> {
} }
@Override @Override
protected boolean shouldRecordOutstandingEntry(String columnName) { protected boolean shouldRecordOutstandingEntry(String columnName, Object value) {
return NameMaps.shouldRecordOutstandingColumnForTable(NameMaps.TABLE_ID_TAGS, columnName); return NameMaps.shouldRecordOutstandingColumnForTable(NameMaps.TABLE_ID_TAGS, columnName);
} }

@ -41,7 +41,7 @@ public class TaskAttachmentDao extends RemoteModelDao<TaskAttachment> {
} }
@Override @Override
protected boolean shouldRecordOutstandingEntry(String columnName) { protected boolean shouldRecordOutstandingEntry(String columnName, Object value) {
return NameMaps.shouldRecordOutstandingColumnForTable(NameMaps.TABLE_ID_ATTACHMENTS, columnName); return NameMaps.shouldRecordOutstandingColumnForTable(NameMaps.TABLE_ID_ATTACHMENTS, columnName);
} }

@ -287,7 +287,7 @@ public class TaskDao extends RemoteModelDao<Task> {
}; };
@Override @Override
protected boolean shouldRecordOutstandingEntry(String columnName) { protected boolean shouldRecordOutstandingEntry(String columnName, Object value) {
return NameMaps.shouldRecordOutstandingColumnForTable(NameMaps.TABLE_ID_TASKS, columnName); return NameMaps.shouldRecordOutstandingColumnForTable(NameMaps.TABLE_ID_TASKS, columnName);
} }

@ -12,6 +12,7 @@ import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.sql.Criterion; import com.todoroo.andlib.sql.Criterion;
import com.todoroo.andlib.sql.Query; import com.todoroo.andlib.sql.Query;
import com.todoroo.astrid.actfm.sync.messages.NameMaps; import com.todoroo.astrid.actfm.sync.messages.NameMaps;
import com.todoroo.astrid.data.RemoteModel;
import com.todoroo.astrid.data.TagData; import com.todoroo.astrid.data.TagData;
import com.todoroo.astrid.data.TaskListMetadata; import com.todoroo.astrid.data.TaskListMetadata;
@ -33,7 +34,10 @@ public class TaskListMetadataDao extends RemoteModelDao<TaskListMetadata> {
} }
@Override @Override
protected boolean shouldRecordOutstandingEntry(String columnName) { protected boolean shouldRecordOutstandingEntry(String columnName, Object value) {
if (TaskListMetadata.FILTER.name.equals(columnName) || TaskListMetadata.TAG_UUID.name.equals(columnName))
return !RemoteModel.isUuidEmpty(value.toString());
return NameMaps.shouldRecordOutstandingColumnForTable(NameMaps.TABLE_ID_TASK_LIST_METADATA, columnName); return NameMaps.shouldRecordOutstandingColumnForTable(NameMaps.TABLE_ID_TASK_LIST_METADATA, columnName);
} }

@ -35,7 +35,7 @@ public class UserActivityDao extends RemoteModelDao<UserActivity> {
} }
@Override @Override
protected boolean shouldRecordOutstandingEntry(String columnName) { protected boolean shouldRecordOutstandingEntry(String columnName, Object value) {
return NameMaps.shouldRecordOutstandingColumnForTable(NameMaps.TABLE_ID_USER_ACTIVITY, columnName); return NameMaps.shouldRecordOutstandingColumnForTable(NameMaps.TABLE_ID_USER_ACTIVITY, columnName);
} }
} }

@ -7,6 +7,7 @@ package com.todoroo.astrid.dao;
import com.todoroo.andlib.service.Autowired; import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.DependencyInjectionService; import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.astrid.actfm.sync.messages.NameMaps;
import com.todoroo.astrid.data.User; import com.todoroo.astrid.data.User;
public class UserDao extends RemoteModelDao<User> { public class UserDao extends RemoteModelDao<User> {
@ -18,4 +19,9 @@ public class UserDao extends RemoteModelDao<User> {
DependencyInjectionService.getInstance().inject(this); DependencyInjectionService.getInstance().inject(this);
setDatabase(database); setDatabase(database);
} }
@Override
protected boolean shouldRecordOutstandingEntry(String columnName, Object value) {
return NameMaps.shouldRecordOutstandingColumnForTable(NameMaps.TABLE_ID_USERS, columnName);
}
} }

Loading…
Cancel
Save