ReplayOutstandingEntries should add a ChangesHappened message to the queue if no errors occurred

pull/14/head
Sam Bosley 13 years ago
parent 1f7a937a98
commit ca591d73e4

@ -217,8 +217,8 @@ public class ActFmSyncThread {
// Reapplies changes still in the outstanding tables to the local database // Reapplies changes still in the outstanding tables to the local database
// Called after a batch has finished processing // Called after a batch has finished processing
private void replayOutstandingChanges(boolean afterErrors) { private void replayOutstandingChanges(boolean afterErrors) {
new ReplayOutstandingEntries<Task, TaskOutstanding>(Task.class, NameMaps.TABLE_ID_TASKS, taskDao, taskOutstandingDao, afterErrors).execute(); new ReplayOutstandingEntries<Task, TaskOutstanding>(Task.class, NameMaps.TABLE_ID_TASKS, taskDao, taskOutstandingDao, pendingMessages, monitor, afterErrors).execute();
new ReplayOutstandingEntries<TagData, TagOutstanding>(TagData.class, NameMaps.TABLE_ID_TAGS, tagDataDao, tagOutstandingDao, afterErrors).execute(); new ReplayOutstandingEntries<TagData, TagOutstanding>(TagData.class, NameMaps.TABLE_ID_TAGS, tagDataDao, tagOutstandingDao, pendingMessages, monitor, afterErrors).execute();
} }
private boolean timeForBackgroundSync() { private boolean timeForBackgroundSync() {

@ -52,7 +52,7 @@ public class ChangesHappened<TYPE extends RemoteModel, OE extends OutstandingEnt
} }
} }
private ChangesHappened(long id, Class<TYPE> modelClass, RemoteModelDao<TYPE> modelDao, public ChangesHappened(long id, Class<TYPE> modelClass, RemoteModelDao<TYPE> modelDao,
OutstandingEntryDao<OE> outstandingDao) { OutstandingEntryDao<OE> outstandingDao) {
super(id, modelClass, modelDao); super(id, modelClass, modelDao);

@ -1,5 +1,7 @@
package com.todoroo.astrid.actfm.sync.messages; package com.todoroo.astrid.actfm.sync.messages;
import java.util.List;
import android.util.Log; import android.util.Log;
import com.todoroo.andlib.data.Property; import com.todoroo.andlib.data.Property;
@ -24,14 +26,19 @@ public class ReplayOutstandingEntries<T extends RemoteModel, OE extends Outstand
private final String table; private final String table;
private final RemoteModelDao<T> dao; private final RemoteModelDao<T> dao;
private final OutstandingEntryDao<OE> outstandingDao; private final OutstandingEntryDao<OE> outstandingDao;
private final List<ClientToServerMessage<?>> queue;
private final Object monitor;
private final boolean afterErrors; private final boolean afterErrors;
public ReplayOutstandingEntries(Class<T> modelClass, String table, RemoteModelDao<T> dao, OutstandingEntryDao<OE> outstandingDao, boolean afterErrors) { public ReplayOutstandingEntries(Class<T> modelClass, String table, RemoteModelDao<T> dao, OutstandingEntryDao<OE> outstandingDao,
List<ClientToServerMessage<?>> queue, Object monitor, boolean afterErrors) {
this.modelClass = modelClass; this.modelClass = modelClass;
this.outstandingClass = DaoReflectionHelpers.getOutstandingClass(modelClass); this.outstandingClass = DaoReflectionHelpers.getOutstandingClass(modelClass);
this.table = table; this.table = table;
this.dao = dao; this.dao = dao;
this.outstandingDao = outstandingDao; this.outstandingDao = outstandingDao;
this.queue = queue;
this.monitor = monitor;
this.afterErrors = afterErrors; this.afterErrors = afterErrors;
} }
@ -59,12 +66,13 @@ public class ReplayOutstandingEntries<T extends RemoteModel, OE extends Outstand
T model = modelClass.newInstance(); T model = modelClass.newInstance();
model.setId(id); model.setId(id);
OutstandingToModelVisitor<T> visitor = new OutstandingToModelVisitor<T>(model); OutstandingToModelVisitor<T> visitor = new OutstandingToModelVisitor<T>(model);
int count = 0;
for (; !outstanding.isAfterLast(); outstanding.moveToNext()) { for (; !outstanding.isAfterLast(); outstanding.moveToNext()) {
instance.clear(); instance.clear();
instance.readPropertiesFromCursor(outstanding); instance.readPropertiesFromCursor(outstanding);
if (instance.getValue(OutstandingEntry.ENTITY_ID_PROPERTY) != id) if (instance.getValue(OutstandingEntry.ENTITY_ID_PROPERTY) != id)
break; break;
count ++;
String column = instance.getValue(OutstandingEntry.COLUMN_STRING_PROPERTY); String column = instance.getValue(OutstandingEntry.COLUMN_STRING_PROPERTY);
Property<?> property = NameMaps.localColumnNameToProperty(table, column); Property<?> property = NameMaps.localColumnNameToProperty(table, column);
// set values to model // set values to model
@ -72,10 +80,19 @@ public class ReplayOutstandingEntries<T extends RemoteModel, OE extends Outstand
property.accept(visitor, instance); property.accept(visitor, instance);
} }
if (afterErrors)
model.putTransitory(SyncFlags.ACTFM_SUPPRESS_OUTSTANDING_ENTRIES, true); model.putTransitory(SyncFlags.ACTFM_SUPPRESS_OUTSTANDING_ENTRIES, true);
dao.saveExisting(model); dao.saveExisting(model);
if (count > 0 && !afterErrors) {
ChangesHappened<T, OE> ch = new ChangesHappened<T, OE>(id, modelClass, dao, outstandingDao);
if (!queue.contains(ch)) {
queue.add(ch);
synchronized(monitor) {
monitor.notifyAll();
}
}
}
outstanding.moveToPrevious(); // Move back one to undo the last iteration of the for loop outstanding.moveToPrevious(); // Move back one to undo the last iteration of the for loop
} catch (InstantiationException e) { } catch (InstantiationException e) {
Log.e(ERROR_TAG, "Error instantiating model", e); Log.e(ERROR_TAG, "Error instantiating model", e);

Loading…
Cancel
Save