Use new UUID field instead of REMOTE_ID in a few more places

pull/14/head
Sam Bosley 12 years ago
parent 48d9c46d72
commit c771987cdc

@ -137,12 +137,14 @@ public class Astrid44SyncMigrator {
for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
instance.readPropertiesFromCursor(cursor); instance.readPropertiesFromCursor(cursor);
if (!instance.containsNonNullValue(RemoteModel.REMOTE_ID_PROPERTY)) { if (!instance.containsNonNullValue(RemoteModel.REMOTE_ID_PROPERTY)) {
Pair<Long, String> uuidPair = UUIDHelper.newUUID(); // No remote id exists, just create a UUID
instance.setValue(RemoteModel.REMOTE_ID_PROPERTY, uuidPair.getLeft()); Pair<BigInteger, String> uuidPair = UUIDHelper.newUUID();
instance.setValue(RemoteModel.UUID_PROPERTY, uuidPair.getLeft());
instance.setValue(RemoteModel.PROOF_TEXT_PROPERTY, uuidPair.getRight()); instance.setValue(RemoteModel.PROOF_TEXT_PROPERTY, uuidPair.getRight());
} } else {
// Migrate remote id to uuid field // Migrate remote id to uuid field
instance.setValue(RemoteModel.UUID_PROPERTY, BigInteger.valueOf(instance.getValue(RemoteModel.REMOTE_ID_PROPERTY))); instance.setValue(RemoteModel.UUID_PROPERTY, BigInteger.valueOf(instance.getValue(RemoteModel.REMOTE_ID_PROPERTY)));
}
dao.saveExisting(instance); dao.saveExisting(instance);
} }
} finally { } finally {

@ -1,5 +1,7 @@
package com.todoroo.astrid.dao; package com.todoroo.astrid.dao;
import java.math.BigInteger;
import com.todoroo.andlib.data.DatabaseDao; import com.todoroo.andlib.data.DatabaseDao;
import com.todoroo.andlib.utility.Pair; import com.todoroo.andlib.utility.Pair;
import com.todoroo.astrid.data.RemoteModel; import com.todoroo.astrid.data.RemoteModel;
@ -22,9 +24,9 @@ public class RemoteModelDao<RTYPE extends RemoteModel> extends DatabaseDao<RTYPE
@Override @Override
public boolean createNew(RTYPE item) { public boolean createNew(RTYPE item) {
if (!item.containsValue(RemoteModel.REMOTE_ID_PROPERTY)) { if (!item.containsValue(RemoteModel.UUID_PROPERTY)) {
Pair<Long, String> uuidPair = UUIDHelper.newUUID(); Pair<BigInteger, String> uuidPair = UUIDHelper.newUUID();
item.setValue(RemoteModel.REMOTE_ID_PROPERTY, uuidPair.getLeft()); item.setValue(RemoteModel.UUID_PROPERTY, uuidPair.getLeft());
item.setValue(RemoteModel.PROOF_TEXT_PROPERTY, uuidPair.getRight()); item.setValue(RemoteModel.PROOF_TEXT_PROPERTY, uuidPair.getRight());
} }
return super.createNew(item); return super.createNew(item);

@ -30,7 +30,7 @@ public class TagDataDao extends RemoteModelDao<TagData> {
private static final String[] IGNORE_OUTSTANDING_COLUMNS = new String[] { private static final String[] IGNORE_OUTSTANDING_COLUMNS = new String[] {
TagData.MODIFICATION_DATE.name, TagData.MODIFICATION_DATE.name,
TagData.REMOTE_ID.name, TagData.UUID.name,
}; };
@Override @Override

@ -320,7 +320,7 @@ public class TaskDao extends RemoteModelDao<Task> {
Task.DETAILS.name, Task.DETAILS.name,
Task.DETAILS_DATE.name, Task.DETAILS_DATE.name,
Task.CALENDAR_URI.name, Task.CALENDAR_URI.name,
Task.REMOTE_ID.name, Task.UUID.name,
Task.PUSHED_AT.name, Task.PUSHED_AT.name,
Task.LAST_SYNC.name, Task.LAST_SYNC.name,
Task.ESTIMATED_SECONDS.name, Task.ESTIMATED_SECONDS.name,

@ -1,5 +1,6 @@
package com.todoroo.astrid.helper; package com.todoroo.astrid.helper;
import java.math.BigInteger;
import java.security.SecureRandom; import java.security.SecureRandom;
import java.util.UUID; import java.util.UUID;
@ -39,7 +40,7 @@ public class UUIDHelper {
* @return a pair consisting of the newly * @return a pair consisting of the newly
* generated uuid and the corresponding proof text * generated uuid and the corresponding proof text
*/ */
public static Pair<Long, String> newUUID() { public static Pair<BigInteger, String> newUUID() {
long uuid = 0; long uuid = 0;
String proofText = ""; //$NON-NLS-1$ String proofText = ""; //$NON-NLS-1$
do { do {
@ -54,7 +55,7 @@ public class UUIDHelper {
proofText = d + "," + s; //$NON-NLS-1$ proofText = d + "," + s; //$NON-NLS-1$
uuid = bcryptToLong(proofText); uuid = bcryptToLong(proofText);
} while (uuid < MIN_UUID); } while (uuid < MIN_UUID);
return Pair.create(uuid, proofText); return Pair.create(BigInteger.valueOf(uuid), proofText);
} }
private static final String SALT = "$2a$10$2RHhxhKaPb4VXlQUJyBU/O"; //$NON-NLS-1$ private static final String SALT = "$2a$10$2RHhxhKaPb4VXlQUJyBU/O"; //$NON-NLS-1$

Loading…
Cancel
Save