Hide readPropertiesFromCursor

pull/189/head
Alex Baker 11 years ago
parent 1274f69d38
commit 34511b83ff

@ -76,6 +76,13 @@ public abstract class AbstractModel implements Parcelable, Cloneable {
/** Transitory Metadata (not saved in database) */
protected HashMap<String, Object> transitoryData = null;
public AbstractModel() {
}
public AbstractModel(TodorooCursor<? extends AbstractModel> cursor) {
readPropertiesFromCursor(cursor);
}
/** Get database-read values for this object */
public ContentValues getDatabaseValues() {
return values;
@ -165,12 +172,10 @@ public abstract class AbstractModel implements Parcelable, Cloneable {
return clone;
}
// --- data retrieval
/**
* Reads all properties from the supplied cursor and store
*/
public synchronized void readPropertiesFromCursor(TodorooCursor<? extends AbstractModel> cursor) {
private void readPropertiesFromCursor(TodorooCursor<? extends AbstractModel> cursor) {
if (values == null) {
values = new ContentValues();
}

@ -106,12 +106,7 @@ public class Metadata extends AbstractModel {
}
public Metadata(TodorooCursor<Metadata> cursor) {
this();
readPropertiesFromCursor(cursor);
}
public void readFromCursor(TodorooCursor<Metadata> cursor) {
super.readPropertiesFromCursor(cursor);
super(cursor);
}
@Override

@ -11,6 +11,7 @@ import android.text.TextUtils;
import com.todoroo.andlib.data.AbstractModel;
import com.todoroo.andlib.data.Property.StringProperty;
import com.todoroo.andlib.data.TodorooCursor;
import org.json.JSONException;
import org.json.JSONObject;
@ -27,6 +28,14 @@ import java.io.File;
*/
abstract public class RemoteModel extends AbstractModel {
public RemoteModel() {
super();
}
public RemoteModel(TodorooCursor<? extends AbstractModel> cursor) {
super(cursor);
}
private static final Logger log = LoggerFactory.getLogger(RemoteModel.class);
/** remote id property common to all remote models */

@ -80,12 +80,7 @@ public class StoreObject extends AbstractModel {
}
public StoreObject(TodorooCursor<StoreObject> cursor) {
this();
readPropertiesFromCursor(cursor);
}
public void readFromCursor(TodorooCursor<StoreObject> cursor) {
super.readPropertiesFromCursor(cursor);
super(cursor);
}
@Override

@ -83,12 +83,7 @@ public final class TagData extends RemoteModel {
}
public TagData(TodorooCursor<TagData> cursor) {
this();
readPropertiesFromCursor(cursor);
}
public void readFromCursor(TodorooCursor<TagData> cursor) {
super.readPropertiesFromCursor(cursor);
super(cursor);
}
@Override

@ -219,12 +219,7 @@ public class Task extends RemoteModel {
}
public Task(TodorooCursor<Task> cursor) {
this();
readPropertiesFromCursor(cursor);
}
public void readFromCursor(TodorooCursor<Task> cursor) {
super.readPropertiesFromCursor(cursor);
super(cursor);
}
@Override

@ -123,12 +123,7 @@ public final class TaskAttachment extends RemoteModel {
}
public TaskAttachment(TodorooCursor<TaskAttachment> cursor) {
this();
readPropertiesFromCursor(cursor);
}
public void readFromCursor(TodorooCursor<TaskAttachment> cursor) {
super.readPropertiesFromCursor(cursor);
super(cursor);
}
@Override

@ -79,8 +79,7 @@ public final class TaskListMetadata extends RemoteModel {
}
public TaskListMetadata(TodorooCursor<TaskListMetadata> cursor) {
this();
readPropertiesFromCursor(cursor);
super(cursor);
}
@Override

@ -63,8 +63,7 @@ public class UserActivity extends RemoteModel {
public static final String ACTION_TASK_COMMENT = "task_comment";
public UserActivity(TodorooCursor<UserActivity> cursor) {
this();
readPropertiesFromCursor(cursor);
super(cursor);
}
// --- helpers

@ -75,7 +75,7 @@ public class MetadataDaoTests extends DatabaseTestCase {
Query.select(KEYS));
assertEquals(1, cursor.getCount());
cursor.moveToFirst();
metadata.readFromCursor(cursor);
metadata = new Metadata(cursor);
assertEquals("happy", metadata.getKey());
cursor.close();
}
@ -105,10 +105,10 @@ public class MetadataDaoTests extends DatabaseTestCase {
Query.select(KEYS).where(MetadataCriteria.byTask(1)));
assertEquals(2, cursor.getCount());
cursor.moveToFirst();
metadata.readFromCursor(cursor);
metadata = new Metadata(cursor);
assertEquals("with1", metadata.getKey());
cursor.moveToNext();
metadata.readFromCursor(cursor);
metadata = new Metadata(cursor);
assertEquals("with1", metadata.getKey());
cursor.close();
@ -185,7 +185,7 @@ public class MetadataDaoTests extends DatabaseTestCase {
cursor = metadataDao.fetchDangling(KEYS);
assertEquals(1, cursor.getCount());
cursor.moveToFirst();
metadata.readFromCursor(cursor);
metadata = new Metadata(cursor);
assertEquals("with2", metadata.getKey());
cursor.close();
}

@ -144,7 +144,7 @@ public class NewRepeatTests extends DatabaseTestCase {
}
assertEquals(1, cursor.getCount());
cursor.moveToFirst();
t.readFromCursor(cursor);
t = new Task(cursor);
assertEquals(title, t.getTitle());
assertFalse(t.isCompleted());

@ -125,14 +125,14 @@ public class TagViewFragment extends TaskListFragment {
}
try {
tagData = new TagData();
if(cursor.getCount() == 0) {
tagData = new TagData();
tagData.setName(tag);
tagData.setUUID(uuid);
tagDataService.save(tagData);
} else {
cursor.moveToFirst();
tagData.readFromCursor(cursor);
tagData = new TagData(cursor);
}
} finally {
cursor.close();

@ -360,12 +360,11 @@ public class TaskAdapter extends CursorAdapter implements Filterable {
viewHolder.hasNotes = cursor.get(HAS_NOTES_PROPERTY) > 0;
}
Task task = viewHolder.task;
task.clear();
task.readFromCursor(cursor);
// TODO: see if this is a performance issue
viewHolder.task = new Task(cursor);
setFieldContentsAndVisibility(view);
setTaskAppearance(viewHolder, task);
setTaskAppearance(viewHolder, viewHolder.task);
}
public String getItemUuid(int position) {
@ -686,11 +685,8 @@ public class TaskAdapter extends CursorAdapter implements Filterable {
try {
Random random = new Random();
Task task = new Task();
for(fetchCursor.moveToFirst(); !fetchCursor.isAfterLast(); fetchCursor.moveToNext()) {
task.clear();
task.readFromCursor(fetchCursor);
Task task = new Task(fetchCursor);
if(task.isCompleted()) {
continue;
}

@ -128,9 +128,8 @@ public class AlarmService {
public void scheduleAllAlarms() {
TodorooCursor<Metadata> cursor = getActiveAlarms();
try {
Metadata alarm = new Metadata();
for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
alarm.readFromCursor(cursor);
Metadata alarm = new Metadata(cursor);
scheduleAlarm(alarm);
}
} catch (Exception e) {
@ -149,9 +148,8 @@ public class AlarmService {
public void scheduleAlarms(long taskId) {
TodorooCursor<Metadata> cursor = getActiveAlarmsForTask(taskId);
try {
Metadata alarm = new Metadata();
for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
alarm.readFromCursor(cursor);
Metadata alarm = new Metadata(cursor);
scheduleAlarm(alarm);
}
} catch (Exception e) {

@ -49,10 +49,9 @@ public class AlarmTaskRepeatListener extends InjectingBroadcastReceiver {
return;
}
Metadata metadata = new Metadata();
LinkedHashSet<Long> alarms = new LinkedHashSet<>(cursor.getCount());
for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
metadata.readFromCursor(cursor);
Metadata metadata = new Metadata(cursor);
alarms.add(metadata.getValue(AlarmFields.TIME) + (newDueDate - oldDueDate));
}
alarmService.synchronizeAlarms(taskId, alarms);

@ -176,11 +176,10 @@ public class TasksXmlExporter {
TagData.PROPERTIES).orderBy(Order.asc(TagData.ID)));
try {
TagData tag = new TagData();
int length = cursor.getCount();
for(int i = 0; i < length; i++) {
cursor.moveToNext();
tag.readFromCursor(cursor);
TagData tag = new TagData(cursor);
//TODO setProgress(i, length);
@ -199,11 +198,10 @@ public class TasksXmlExporter {
cursor = taskService.query(Query.select(
Task.PROPERTIES).orderBy(Order.asc(Task.ID)));
try {
Task task = new Task();
int length = cursor.getCount();
for(int i = 0; i < length; i++) {
cursor.moveToNext();
task.readFromCursor(cursor);
Task task = new Task(cursor);
setProgress(i, length);
@ -222,9 +220,8 @@ public class TasksXmlExporter {
TodorooCursor<Metadata> cursor = metadataService.query(Query.select(
Metadata.PROPERTIES).where(MetadataCriteria.byTask(task.getId())));
try {
Metadata metadata = new Metadata();
for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
metadata.readFromCursor(cursor);
Metadata metadata = new Metadata(cursor);
xml.startTag(null, BackupConstants.METADATA_TAG);
serializeModel(metadata, Metadata.PROPERTIES, Metadata.ID, Metadata.TASK);

@ -88,9 +88,8 @@ public final class CustomFilterExposer extends InjectingBroadcastReceiver implem
}
if (cursor != null) {
StoreObject savedFilter = new StoreObject();
for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
savedFilter.readFromCursor(cursor);
StoreObject savedFilter = new StoreObject(cursor);
Filter f = SavedFilter.load(savedFilter);
Intent deleteIntent = new Intent(context, DeleteActivity.class);

@ -147,11 +147,10 @@ public class OldTaskPreferences extends TodorooPreferenceActivity {
TodorooCursor<Task> cursor = taskService.query(Query.select(Task.ID, Task.CALENDAR_URI).where(
Criterion.and(Task.COMPLETION_DATE.gt(0), Task.CALENDAR_URI.isNotNull())));
try {
Task task = new Task();
int length = cursor.getCount();
for(int i = 0; i < length; i++) {
cursor.moveToNext();
task.readFromCursor(cursor);
Task task = new Task(cursor);
gcalHelper.deleteTaskEvent(task);
}
} finally {
@ -186,11 +185,10 @@ public class OldTaskPreferences extends TodorooPreferenceActivity {
TodorooCursor<Task> cursor = taskService.query(Query.select(Task.ID, Task.TITLE, Task.CALENDAR_URI).where(
Criterion.and(Task.DELETION_DATE.gt(0), Task.CALENDAR_URI.isNotNull())));
try {
Task task = new Task();
int length = cursor.getCount();
for(int i = 0; i < length; i++) {
cursor.moveToNext();
task.readFromCursor(cursor);
Task task = new Task(cursor);
gcalHelper.deleteTaskEvent(task);
}
} finally {
@ -221,11 +219,10 @@ public class OldTaskPreferences extends TodorooPreferenceActivity {
TodorooCursor<Task> cursor = taskService.query(Query.select(Task.ID, Task.CALENDAR_URI).where(
Criterion.and(Task.COMPLETION_DATE.gt(0), Task.CALENDAR_URI.isNotNull())));
try {
Task task = new Task();
int length = cursor.getCount();
for(int i = 0; i < length; i++) {
cursor.moveToNext();
task.readFromCursor(cursor);
Task task = new Task(cursor);
if (gcalHelper.deleteTaskEvent(task)) {
deletedEventCount++;
}
@ -263,11 +260,10 @@ public class OldTaskPreferences extends TodorooPreferenceActivity {
TodorooCursor<Task> cursor = taskService.query(Query.select(Task.ID, Task.CALENDAR_URI).where(
Task.CALENDAR_URI.isNotNull()));
try {
Task task = new Task();
int length = cursor.getCount();
for(int i = 0; i < length; i++) {
cursor.moveToNext();
task.readFromCursor(cursor);
Task task = new Task(cursor);
if (gcalHelper.deleteTaskEvent(task)) {
deletedEventCount++;
}

@ -57,12 +57,14 @@ public class SavedFilter {
}
// if filter of this name exists, edit it
StoreObject storeObject = new StoreObject();
StoreObject storeObject;
TodorooCursor<StoreObject> cursor = dao.query(Query.select(StoreObject.ID).where(NAME.eq(title)));
try {
if(!cursor.isAfterLast()) {
if (cursor.isAfterLast()) {
storeObject = new StoreObject();
} else {
cursor.moveToNext();
storeObject.readFromCursor(cursor);
storeObject = new StoreObject(cursor);
}
} finally {
cursor.close();

@ -84,13 +84,12 @@ public class MetadataDao extends DatabaseDao<Metadata> {
newMetadataValues.add(metadatum.getMergedValues());
}
Metadata item = new Metadata();
TodorooCursor<Metadata> cursor = query(Query.select(Metadata.PROPERTIES).where(Criterion.and(MetadataCriteria.byTask(taskId),
metadataCriteria)));
try {
// try to find matches within our metadata list
for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
item.readFromCursor(cursor);
Metadata item = new Metadata(cursor);
long id = item.getId();
// clear item id when matching with incoming values
@ -110,7 +109,7 @@ public class MetadataDao extends DatabaseDao<Metadata> {
// everything that remains shall be written
for(ContentValues values : newMetadataValues) {
item.clear();
Metadata item = new Metadata();
item.mergeWith(values);
persist(item);
}

@ -258,10 +258,8 @@ public class TaskDao extends RemoteModelDao<Task> {
Task.UUID.eq(uuid)));
try {
if (tasksWithUUID.getCount() > 0) {
Task curr = new Task();
for (tasksWithUUID.moveToFirst();
!tasksWithUUID.isAfterLast(); tasksWithUUID.moveToNext()) {
curr.readFromCursor(tasksWithUUID);
for (tasksWithUUID.moveToFirst(); !tasksWithUUID.isAfterLast(); tasksWithUUID.moveToNext()) {
Task curr = new Task(tasksWithUUID);
if (curr.getId() == item.getId()) {
continue;
}

@ -96,8 +96,7 @@ public class FilesControlSet extends PopupControlSet {
try {
files.clear();
for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
TaskAttachment attachment = new TaskAttachment();
attachment.readFromCursor(cursor);
TaskAttachment attachment = new TaskAttachment(cursor);
files.add(attachment);
}
} finally {

@ -161,9 +161,8 @@ public class GtasksTaskListUpdater extends OrderedMetadataListUpdater<StoreObjec
.orderBy(Order.asc(Functions.cast(GtasksMetadata.GTASKS_ORDER, "INTEGER")))); //$NON-NLS-1$
try {
if (metadata.getCount() > 0) {
Metadata curr = new Metadata();
for (metadata.moveToFirst(); !metadata.isAfterLast(); metadata.moveToNext()) {
curr.readFromCursor(metadata);
Metadata curr = new Metadata(metadata);
if(alreadyChecked.contains(curr.getTask())) {
continue;
}

@ -161,9 +161,8 @@ public class GtasksSyncV2Provider extends SyncV2Provider {
private synchronized void pushTasks(TodorooCursor<Task> queued, GtasksInvoker invoker) {
try {
Task task = new Task();
for (queued.moveToFirst(); !queued.isAfterLast(); queued.moveToNext()) {
task.readFromCursor(queued);
Task task = new Task(queued);
try {
gtasksSyncService.pushTaskOnSave(task, task.getMergedValues(), invoker);
} catch (IOException e) {

@ -283,9 +283,8 @@ public class EditNoteActivity extends LinearLayout implements TimerActionListene
MetadataCriteria.byTaskAndwithKey(task.getId(),
NoteMetadata.METADATA_KEY)));
try {
Metadata metadata = new Metadata();
for(notes.moveToFirst(); !notes.isAfterLast(); notes.moveToNext()) {
metadata.readFromCursor(notes);
Metadata metadata = new Metadata(notes);
items.add(NoteOrUpdate.fromMetadata(metadata));
}
} finally {

@ -88,10 +88,9 @@ public class NotesDetailExposer extends InjectingBroadcastReceiver {
Query.select(Metadata.PROPERTIES).where(
MetadataCriteria.byTaskAndwithKey(task.getId(),
NoteMetadata.METADATA_KEY)).orderBy(Order.asc(Metadata.CREATION_DATE)));
Metadata metadata = new Metadata();
try {
for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
metadata.readFromCursor(cursor);
Metadata metadata = new Metadata(cursor);
if(notesBuilder.length() > 0) {
notesBuilder.append("\n");

@ -123,10 +123,9 @@ public final class ReminderService {
public void scheduleAllAlarms(TaskDao taskDao) {
TodorooCursor<Task> cursor = getTasksWithReminders(taskDao, NOTIFICATION_PROPERTIES);
try {
Task task = new Task();
now = DateUtilities.now(); // Before mass scheduling, initialize now variable
for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
task.readFromCursor(cursor);
Task task = new Task(cursor);
scheduleAlarm(task, null);
}
} catch (Exception e) {

@ -113,13 +113,12 @@ public class MetadataService {
newMetadataValues.add(values);
}
Metadata item = new Metadata();
TodorooCursor<Metadata> cursor = metadataDao.query(Query.select(Metadata.PROPERTIES).where(Criterion.and(MetadataCriteria.byTask(taskId),
metadataCriterion)));
try {
// try to find matches within our metadata list
for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
item.readFromCursor(cursor);
Metadata item = new Metadata(cursor);
long id = item.getId();
// clear item id when matching with incoming values
@ -146,7 +145,7 @@ public class MetadataService {
// everything that remains shall be written
for(ContentValues values : newMetadataValues) {
item.clear();
Metadata item = new Metadata();
item.setCreationDate(DateUtilities.now());
item.mergeWith(values);
metadataDao.persist(item);

@ -54,12 +54,11 @@ public class TaskDuplicator {
Query.select(Metadata.PROPERTIES).where(MetadataDao.MetadataCriteria.byTask(task.getId())));
try {
if(cursor.getCount() > 0) {
Metadata metadata = new Metadata();
newTask.putTransitory(SyncFlags.GTASKS_SUPPRESS_SYNC, true);
taskService.save(newTask);
long newId = newTask.getId();
for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
metadata.readFromCursor(cursor);
Metadata metadata = new Metadata(cursor);
if(!metadata.containsNonNullValue(Metadata.KEY)) {
continue;

@ -247,11 +247,9 @@ public class AstridOrderedListFragmentHelper<LIST> implements OrderedListFragmen
Criterion.and(Task.UUID.in(chained.toArray(new String[chained.size()])),
Task.RECURRENCE.isNotNull(), Functions.length(Task.RECURRENCE).gt(0))));
try {
Task t = new Task();
boolean madeChanges = false;
for (recurring.moveToFirst(); !recurring.isAfterLast(); recurring.moveToNext()) {
t.clear();
t.readFromCursor(recurring);
Task t = new Task(recurring);
if (!TextUtils.isEmpty(t.getRecurrence())) {
updater.moveToParentOf(t.getUuid(), itemId);
madeChanges = true;

@ -240,10 +240,9 @@ public final class TagService {
TodorooCursor<Metadata> tags = getTags(taskId);
try {
int length = tags.getCount();
Metadata metadata = new Metadata();
for (int i = 0; i < length; i++) {
tags.moveToNext();
metadata.readFromCursor(tags);
Metadata metadata = new Metadata(tags);
tagBuilder.append(metadata.getValue(TaskToTagMetadata.TAG_NAME));
if (i < length - 1) {
tagBuilder.append(separator);
@ -264,9 +263,8 @@ public final class TagService {
TagData.DELETION_DATE.eq(0),
TagData.NAME.isNotNull())).orderBy(Order.asc(Functions.upper(TagData.NAME))));
try {
TagData tagData = new TagData();
for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
tagData.readFromCursor(cursor);
TagData tagData = new TagData(cursor);
Tag tag = new Tag(tagData);
if(TextUtils.isEmpty(tag.tag)) {
continue;

@ -118,11 +118,10 @@ public class WidgetUpdateService extends InjectingService {
database.openForReading();
cursor = taskService.fetchFiltered(query, null, Task.ID, Task.TITLE, Task.DUE_DATE, Task.COMPLETION_DATE);
Task task = new Task();
int i;
for (i = 0; i < cursor.getCount() && i < numberOfTasks; i++) {
cursor.moveToPosition(i);
task.readFromCursor(cursor);
Task task = new Task(cursor);
String textContent;
Resources r = context.getResources();

@ -41,9 +41,8 @@ public class RefreshScheduler {
public void scheduleAllAlarms() {
TodorooCursor<Task> cursor = getTasks();
try {
Task task = new Task();
for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
task.readFromCursor(cursor);
Task task = new Task(cursor);
scheduleRefresh(task);
}
} finally {

Loading…
Cancel
Save