use of org.hisp.dhis.android.core.data.database.Transaction in project dhis2-android-sdk by dhis2.
the class SystemInfoCall method insertOrUpdateSystemInfo.
private void insertOrUpdateSystemInfo(Response<SystemInfo> response) {
SystemInfoHandler systemInfoHandler = new SystemInfoHandler(systemInfoStore);
ResourceHandler resourceHandler = new ResourceHandler(resourceStore);
Transaction transaction = databaseAdapter.beginNewTransaction();
try {
if (response.body() != null) {
SystemInfo systemInfo = response.body();
systemInfoHandler.handleSystemInfo(systemInfo);
resourceHandler.handleResource(ResourceModel.Type.SYSTEM_INFO, systemInfo.serverDate());
}
transaction.setSuccessful();
} finally {
transaction.end();
}
}
use of org.hisp.dhis.android.core.data.database.Transaction in project dhis2-android-sdk by dhis2.
the class UserAuthenticateCall method saveUser.
private void saveUser(Response<User> response) throws Exception {
Transaction transaction = databaseAdapter.beginNewTransaction();
// order to make sure that databaseAdapter transaction won't be leaked
try {
User user = response.body();
handleUser(user, serverDate);
transaction.setSuccessful();
} finally {
transaction.end();
}
}
use of org.hisp.dhis.android.core.data.database.Transaction in project dhis2-android-sdk by dhis2.
the class UserCall method call.
@Override
public Response<User> call() throws Exception {
synchronized (this) {
if (isExecuted) {
throw new IllegalStateException("Already executed");
}
isExecuted = true;
}
Response<User> response = getUser();
if (response.isSuccessful()) {
UserHandler userHandler = new UserHandler(userStore);
UserCredentialsHandler userCredentialsHandler = new UserCredentialsHandler(userCredentialsStore);
UserRoleHandler userRoleHandler = new UserRoleHandler(userRoleStore);
ResourceHandler resourceHandler = new ResourceHandler(resourceStore);
Transaction transaction = databaseAdapter.beginNewTransaction();
try {
User user = response.body();
// TODO: check that this is user is authenticated and is persisted in db
userHandler.handleUser(user);
UserCredentials userCredentials = user.userCredentials();
userCredentialsHandler.handleUserCredentials(userCredentials, user);
List<UserRole> userRoles = userCredentials.userRoles();
userRoleHandler.handleUserRoles(userRoles);
resourceHandler.handleResource(ResourceModel.Type.USER, serverDate);
transaction.setSuccessful();
} catch (SQLiteConstraintException constraintException) {
// constraintException.printStackTrace();
Log.d("CAll", "call: constraintException");
} finally {
transaction.end();
}
}
return response;
}
Aggregations