TODOs: Update HLAPI to 2.1.6
In this change, userdata works well, and SyncbaseException is used now.
Change-Id: I5c65abbf1bf0a95128a518f5a31f0a14bdb0bde7
diff --git a/app/build.gradle b/app/build.gradle
index 85e4d95..5e9e0a6 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -83,5 +83,5 @@
)
firebaseCompile 'com.firebase:firebase-client-android:2.5.2'
syncbaseCompile 'io.v:vanadium-android:2.2.+'
- syncbase2Compile 'io.v:syncbase:0.1.5'
+ syncbase2Compile 'io.v:syncbase:0.1.6'
}
diff --git a/app/src/syncbase2/java/io/v/todos/persistence/syncbase/SyncbaseMain.java b/app/src/syncbase2/java/io/v/todos/persistence/syncbase/SyncbaseMain.java
index 5359f7e..2c39fb0 100644
--- a/app/src/syncbase2/java/io/v/todos/persistence/syncbase/SyncbaseMain.java
+++ b/app/src/syncbase2/java/io/v/todos/persistence/syncbase/SyncbaseMain.java
@@ -14,7 +14,7 @@
import io.v.syncbase.DatabaseHandle;
import io.v.syncbase.Id;
import io.v.syncbase.Syncbase;
-import io.v.syncbase.core.VError;
+import io.v.syncbase.exception.SyncbaseException;
import io.v.todos.model.ListMetadata;
import io.v.todos.model.ListSpec;
import io.v.todos.persistence.ListEventListener;
@@ -40,14 +40,12 @@
public String addTodoList(ListSpec listSpec) {
DatabaseHandle.CollectionOptions opts = new DatabaseHandle.CollectionOptions();
try {
- // TODO(alexfandrianto): We're not allowed to have dashes in our collection names still!
- // You also must start with a letter, not a number.
- Collection c = sDb.collection("list_" + UUID.randomUUID().toString().replaceAll("-", ""), opts);
+ Collection c = sDb.createCollection(opts.setPrefix(TODO_LIST_COLLECTION_PREFIX));
c.put(TODO_LIST_KEY, listSpec);
return c.getId().encode();
- } catch (VError vError) {
- Log.e(TAG, "Failed to create todo list collection", vError);
- throw new RuntimeException(vError);
+ } catch (SyncbaseException e) {
+ Log.e(TAG, "Failed to create todo list collection", e);
+ throw new RuntimeException(e);
}
}
@@ -57,8 +55,8 @@
Collection c = sDb.getCollection(listId);
try {
c.delete(TODO_LIST_KEY);
- } catch (VError vError) {
- Log.e(TAG, "Failed to delete todo list key", vError);
+ } catch (SyncbaseException e) {
+ Log.e(TAG, "Failed to delete todo list key", e);
}
// TODO(alexfandrianto): Instead of deleting the key, we should destroy the collection.
// Unfortunately, I can't yet: https://v.io/i/1374
diff --git a/app/src/syncbase2/java/io/v/todos/persistence/syncbase/SyncbasePersistence.java b/app/src/syncbase2/java/io/v/todos/persistence/syncbase/SyncbasePersistence.java
index 72affe4..e5d4ef8 100644
--- a/app/src/syncbase2/java/io/v/todos/persistence/syncbase/SyncbasePersistence.java
+++ b/app/src/syncbase2/java/io/v/todos/persistence/syncbase/SyncbasePersistence.java
@@ -25,7 +25,7 @@
import io.v.syncbase.Syncgroup;
import io.v.syncbase.SyncgroupInvite;
import io.v.syncbase.WatchChange;
-import io.v.syncbase.core.VError;
+import io.v.syncbase.exception.SyncbaseException;
import io.v.todos.model.ListMetadata;
import io.v.todos.model.ListSpec;
import io.v.todos.model.Task;
@@ -37,9 +37,9 @@
import io.v.todos.sharing.ShareListDialogFragment;
public abstract class SyncbasePersistence implements Persistence {
- protected static final String SETTINGS_COLLECTION = "settings";
protected static final String SHOW_DONE_KEY = "showDoneKey";
protected static final String TODO_LIST_KEY = "todoListKey";
+ protected static final String TODO_LIST_COLLECTION_PREFIX = "list";
protected static final String TAG = "High-Level Syncbase";
protected static boolean sInitialized = false;
@@ -50,7 +50,6 @@
protected static boolean sShowDone = true;
protected static Database sDb;
- protected static Collection sSettings;
private static final Object sSyncbaseMutex = new Object();
private static TodoListListener sTodoListListener;
@@ -72,12 +71,10 @@
Syncbase.Options opts = new Syncbase.Options();
opts.rootDir = activity.getFilesDir().getAbsolutePath();
opts.disableSyncgroupPublishing = true;
- // TODO(alexfandrianto): https://v.io/i/1375
- opts.disableUserdataSyncgroup = true;
try {
Syncbase.init(opts);
- } catch (VError vError) {
- Log.e(TAG, "Failed to initialize", vError);
+ } catch (SyncbaseException e) {
+ Log.e(TAG, "Failed to initialize", e);
return;
}
@@ -91,8 +88,8 @@
Log.d(TAG, "Successfully logged in!");
try {
sDb = Syncbase.database();
- } catch (VError vError) {
- Log.e(TAG, "Failed to create database", vError);
+ } catch (SyncbaseException e) {
+ Log.e(TAG, "Failed to create database", e);
callNotify();
return;
}
@@ -163,14 +160,6 @@
}
private void continueSetup() {
- Log.d(TAG, "Creating settings collection");
- // Create a settings collection.
- try {
- sSettings = sDb.collection(SETTINGS_COLLECTION);
- } catch (VError vError) {
- Log.e(TAG, "couldn't create settings collection", vError);
- }
-
Log.d(TAG, "Watching everything");
// Watch everything.
// TODO(alexfandrianto): This can be simplified if we watch specific collections and the
@@ -202,16 +191,14 @@
Log.d(TAG, "Handling put change " + value.getRowKey());
Log.d(TAG, "From collection: " + value.getCollectionId());
Log.d(TAG, "With entity type: " + value.getEntityType());
- if (value.getEntityType() != WatchChange.EntityType.ROW ||
- value.getCollectionId().getName().equals("userdata__")) {
- // TODO(alexfandrianto): I can't deal with these yet. Please skip to avoid crashing.
- // TODO(alexfandrianto): export/hide userdata__ https://v.io/i/1372
+ if (value.getEntityType() != WatchChange.EntityType.ROW) {
+ // TODO(alexfandrianto): I can't deal with non-row entities yet. Skip.
return;
}
Log.d(TAG, "With row...: " + value.getRowKey());
final Id collectionId = value.getCollectionId();
- if (collectionId.getName().equals(SETTINGS_COLLECTION)) {
+ if (collectionId.getName().equals(Syncbase.USERDATA_NAME)) {
if (value.getRowKey().equals(SHOW_DONE_KEY)) {
try {
sShowDone = value.getValue(Boolean.class);
@@ -221,8 +208,8 @@
if (sTodoListListener != null) {
sTodoListListener.onUpdateShowDone(sShowDone);
}
- } catch (VError vError) {
- Log.e(TAG, "Failed to decode watch change as Boolean", vError);
+ } catch (SyncbaseException e) {
+ Log.e(TAG, "Failed to decode watch change as Boolean", e);
}
}
return; // Show done updated. Nothing left to do.
@@ -250,8 +237,8 @@
if (sTodoListListener != null && sTodoListExpectedId.equals(collectionId)) {
sTodoListListener.onUpdate(listSpec);
}
- } catch (VError vError) {
- Log.e(TAG, "Failed to decode watch change value as ListSpec", vError);
+ } catch (SyncbaseException e) {
+ Log.e(TAG, "Failed to decode watch change value as ListSpec", e);
}
} else {
Map<String, TaskSpec> taskData = sTasksByListMap.get(collectionId);
@@ -275,8 +262,8 @@
sTodoListListener.onItemUpdate(new Task(rowKey, newSpec));
}
}
- } catch (VError vError) {
- Log.e(TAG, "Failed to decode watch change value as TaskSpec", vError);
+ } catch (SyncbaseException e) {
+ Log.e(TAG, "Failed to decode watch change value as TaskSpec", e);
}
}
}
@@ -288,9 +275,10 @@
Log.d(TAG, "Handling delete change " + value.getRowKey());
Log.d(TAG, "From collection: " + value.getCollectionId());
Log.d(TAG, "With entity type: " + value.getEntityType());
- if (value.getEntityType() != WatchChange.EntityType.ROW || value.getCollectionId().getName().equals("userdata__")) {
- // TODO(alexfandrianto): I can't deal with these yet. Please skip to avoid crashing.
- // TODO(alexfandrianto): export/hide userdata__ https://v.io/i/1372
+ if (value.getEntityType() != WatchChange.EntityType.ROW ||
+ value.getCollectionId().getName().equals(Syncbase.USERDATA_NAME)) {
+ // TODO(alexfandrianto): I can't deal with non-row entities, and we don't need
+ // to watch deletes from userdata.
return;
}
Log.d(TAG, "With row...: " + value.getRowKey());
diff --git a/app/src/syncbase2/java/io/v/todos/persistence/syncbase/SyncbaseTodoList.java b/app/src/syncbase2/java/io/v/todos/persistence/syncbase/SyncbaseTodoList.java
index 556ecda..c30ec72 100644
--- a/app/src/syncbase2/java/io/v/todos/persistence/syncbase/SyncbaseTodoList.java
+++ b/app/src/syncbase2/java/io/v/todos/persistence/syncbase/SyncbaseTodoList.java
@@ -23,7 +23,7 @@
import io.v.syncbase.Database;
import io.v.syncbase.Id;
import io.v.syncbase.User;
-import io.v.syncbase.core.VError;
+import io.v.syncbase.exception.SyncbaseException;
import io.v.todos.model.ListSpec;
import io.v.todos.model.Task;
import io.v.todos.model.TaskSpec;
@@ -86,8 +86,8 @@
public void updateTodoList(ListSpec listSpec) {
try {
mCollection.put(TODO_LIST_KEY, listSpec);
- } catch (VError vError) {
- Log.w(TAG, vError);
+ } catch (SyncbaseException e) {
+ Log.w(TAG, e);
}
}
@@ -95,8 +95,8 @@
public void deleteTodoList() {
try {
mCollection.delete(TODO_LIST_KEY);
- } catch (VError vError) {
- Log.w(TAG, vError);
+ } catch (SyncbaseException e) {
+ Log.w(TAG, e);
}
}
@@ -118,14 +118,14 @@
// TODO(alexfandrianto): If we're in a batch, it's okay to error, isn't it?
try {
bCollection.put(rowKey, newSpec);
- } catch (VError vError) {
- Log.w(TAG, vError);
+ } catch (SyncbaseException e) {
+ Log.w(TAG, e);
}
}
}
}, new Database.BatchOptions());
- } catch (VError vError) {
- Log.w(TAG, vError);
+ } catch (SyncbaseException e) {
+ Log.w(TAG, e);
}
}
@@ -133,8 +133,8 @@
public void addTask(TaskSpec task) {
try {
mCollection.put(UUID.randomUUID().toString(), task);
- } catch (VError vError) {
- Log.w(TAG, vError);
+ } catch (SyncbaseException e) {
+ Log.w(TAG, e);
}
}
@@ -142,8 +142,8 @@
public void updateTask(Task task) {
try {
mCollection.put(task.key, task.toSpec());
- } catch (VError vError) {
- Log.w(TAG, vError);
+ } catch (SyncbaseException e) {
+ Log.w(TAG, e);
}
}
@@ -151,17 +151,17 @@
public void deleteTask(String key) {
try {
mCollection.delete(key);
- } catch (VError vError) {
- Log.w(TAG, vError);
+ } catch (SyncbaseException e) {
+ Log.w(TAG, e);
}
}
@Override
public void setShowDone(boolean showDone) {
try {
- sSettings.put(SHOW_DONE_KEY, showDone);
- } catch (VError vError) {
- Log.w(TAG, vError);
+ sDb.getUserdataCollection().put(SHOW_DONE_KEY, showDone);
+ } catch (SyncbaseException e) {
+ Log.w(TAG, e);
}
}
@@ -177,8 +177,8 @@
}
try {
mCollection.getSyncgroup().inviteUsers(users, AccessList.AccessLevel.READ_WRITE);
- } catch (VError vError) {
- Log.w(TAG, "Could not share to: " + users.toString(), vError);
+ } catch (SyncbaseException e) {
+ Log.w(TAG, "Could not share to: " + users.toString(), e);
}
}
}