Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@
import org.javarosa.core.services.Logger;

public class ConnectUserDatabaseUtil {
private static final Object LOCK = new Object();

public static ConnectUserRecord getUser(Context context) {
if (context == null) {
throw new IllegalArgumentException("Context must not be null");
}
synchronized (LOCK) {
if (!ConnectDatabaseHelper.dbExists(context)) {
return null;
}
Expand All @@ -31,7 +29,6 @@ public static ConnectUserRecord getUser(Context context) {
ConnectDatabaseHelper.dbBroken = true;
throw new RuntimeException("Failed to access Connect database", e);
}
}
}

public static void storeUser(Context context, ConnectUserRecord user) {
Expand All @@ -41,25 +38,23 @@ public static void storeUser(Context context, ConnectUserRecord user) {
if (user == null) {
throw new IllegalArgumentException("User must not be null");
}
synchronized (LOCK) {
try {
ConnectDatabaseHelper.getConnectStorage(context, ConnectUserRecord.class).write(user);
} catch (Exception e) {
Logger.exception("Failed to store user", e);
throw new RuntimeException("Failed to store user in Connect database", e);
}
}
}

public static void forgetUser(Context context) {
if (context == null) {
throw new IllegalArgumentException("Context must not be null");
}
synchronized (LOCK) {
try {
DatabaseConnectOpenHelper.deleteDb(context);
CommCareApplication.instance().getGlobalStorage(ConnectKeyRecord.class).removeAll();
ConnectDatabaseHelper.dbBroken = false;
ConnectDatabaseHelper.teardown();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this the primary fix here or removal of synchronized blocks ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the primary fix is this one lock dosent help because connectdatabse is not getting null

} catch (IllegalStateException e) {
Logger.exception("Database access error while forgetting user", e);
throw new RuntimeException("Failed to access database while cleaning up", e);
Expand All @@ -70,6 +65,5 @@ public static void forgetUser(Context context) {
Logger.exception("Failed to forget user", e);
throw new RuntimeException("Failed to clean up Connect database", e);
}
}
}
}