Search in sources :

Example 16 with Transaction

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();
    }
}
Also used : Transaction(org.hisp.dhis.android.core.data.database.Transaction) ResourceHandler(org.hisp.dhis.android.core.resource.ResourceHandler)

Example 17 with Transaction

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();
    }
}
Also used : Transaction(org.hisp.dhis.android.core.data.database.Transaction)

Example 18 with Transaction

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;
}
Also used : Transaction(org.hisp.dhis.android.core.data.database.Transaction) SQLiteConstraintException(android.database.sqlite.SQLiteConstraintException) ResourceHandler(org.hisp.dhis.android.core.resource.ResourceHandler)

Aggregations

Transaction (org.hisp.dhis.android.core.data.database.Transaction)18 Payload (org.hisp.dhis.android.core.common.Payload)6 ResourceHandler (org.hisp.dhis.android.core.resource.ResourceHandler)5 Response (retrofit2.Response)5 SQLiteConstraintException (android.database.sqlite.SQLiteConstraintException)4 SystemInfoCall (org.hisp.dhis.android.core.systeminfo.SystemInfoCall)4 Date (java.util.Date)3 SystemInfo (org.hisp.dhis.android.core.systeminfo.SystemInfo)3 Cursor (android.database.Cursor)1 CategoryCombo (org.hisp.dhis.android.core.category.CategoryCombo)1 CategoryOption (org.hisp.dhis.android.core.category.CategoryOption)1 GenericCallData (org.hisp.dhis.android.core.common.GenericCallData)1 CursorAssert.assertThatCursor (org.hisp.dhis.android.core.data.database.CursorAssert.assertThatCursor)1 OptionSetCall (org.hisp.dhis.android.core.option.OptionSetCall)1 OrganisationUnit (org.hisp.dhis.android.core.organisationunit.OrganisationUnit)1 Program (org.hisp.dhis.android.core.program.Program)1 ProgramCall (org.hisp.dhis.android.core.program.ProgramCall)1 ProgramStage (org.hisp.dhis.android.core.program.ProgramStage)1 TrackedEntityCall (org.hisp.dhis.android.core.trackedentity.TrackedEntityCall)1 TrackedEntityInstance (org.hisp.dhis.android.core.trackedentity.TrackedEntityInstance)1