use of org.hisp.dhis.android.core.data.database.Transaction in project dhis2-android-sdk by dhis2.
the class CategoryEndpointCall method handle.
private void handle(List<Category> categories) {
Transaction transaction = databaseAdapter.beginNewTransaction();
try {
for (Category category : categories) {
handler.handle(category);
}
resourceHandler.handleResource(ResourceModel.Type.CATEGORY, 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 CategoryComboEndpointCall method handle.
private void handle(List<CategoryCombo> categoryCombos) {
Transaction transaction = databaseAdapter.beginNewTransaction();
try {
for (CategoryCombo categoryCombo : categoryCombos) {
handler.handle(categoryCombo);
}
resourceHandler.handleResource(ResourceModel.Type.CATEGORY_COMBO, 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 TrackedEntityCall method call.
@Override
public Response<Payload<TrackedEntity>> call() throws Exception {
synchronized (this) {
if (isExecuted) {
throw new IllegalStateException("Already executed");
}
isExecuted = true;
}
if (uidSet.size() > MAX_UIDS) {
throw new IllegalArgumentException("Can't handle the amount of tracked entities: " + uidSet.size() + ". " + "Max size is: " + MAX_UIDS);
}
ResourceHandler resourceHandler = new ResourceHandler(resourceStore);
String lastUpdated = resourceHandler.getLastUpdated(resourceType);
Response<Payload<TrackedEntity>> response = getTrackedEntities(lastUpdated);
TrackedEntityHandler trackedEntityHandler = new TrackedEntityHandler(trackedEntityStore);
Transaction transaction = databaseAdapter.beginNewTransaction();
try {
if (response != null && response.isSuccessful()) {
List<TrackedEntity> trackedEntities = response.body().items();
int size = trackedEntities.size();
for (int i = 0; i < size; i++) {
TrackedEntity trackedEntity = trackedEntities.get(i);
trackedEntityHandler.handleTrackedEntity(trackedEntity);
}
resourceHandler.handleResource(resourceType, serverDate);
transaction.setSuccessful();
}
} finally {
transaction.end();
}
return response;
}
use of org.hisp.dhis.android.core.data.database.Transaction in project dhis2-android-sdk by dhis2.
the class OrganisationUnitCall method call.
@Override
public Response<Payload<OrganisationUnit>> call() throws Exception {
synchronized (this) {
if (isExecuted) {
throw new IllegalArgumentException("AlreadyExecuted");
}
isExecuted = true;
}
Response<Payload<OrganisationUnit>> response = null;
Response<Payload<OrganisationUnit>> totalResponse = null;
Transaction transaction = genericCallData.databaseAdapter().beginNewTransaction();
OrganisationUnitModelBuilder modelBuilder = new OrganisationUnitModelBuilder();
try {
Set<String> rootOrgUnitUids = findRoots(user.organisationUnits());
Filter<OrganisationUnit, String> lastUpdatedFilter = OrganisationUnit.lastUpdated.gt(genericCallData.resourceHandler().getLastUpdated(ResourceModel.Type.ORGANISATION_UNIT));
// Call OrganisationUnitService for each tree root & try to handleTrackedEntity sub-tree:
for (String uid : rootOrgUnitUids) {
response = getOrganisationUnit(uid, lastUpdatedFilter);
if (response.isSuccessful()) {
if (totalResponse == null) {
totalResponse = response;
} else {
totalResponse.body().items().addAll(response.body().items());
}
organisationUnitHandler.handleMany(response.body().items(), modelBuilder);
} else {
totalResponse = response;
// stop early unsuccessful:
break;
}
}
if (response != null && response.isSuccessful()) {
genericCallData.resourceHandler().handleResource(ResourceModel.Type.ORGANISATION_UNIT, genericCallData.serverDate());
transaction.setSuccessful();
}
} finally {
transaction.end();
}
return totalResponse;
}
use of org.hisp.dhis.android.core.data.database.Transaction in project dhis2-android-sdk by dhis2.
the class ProgramCall method call.
@Override
public Response<Payload<Program>> call() throws Exception {
synchronized (this) {
if (isExecuted) {
throw new IllegalStateException("Already executed");
}
isExecuted = true;
}
if (uids.size() > MAX_UIDS) {
throw new IllegalArgumentException("Can't handle the amount of programs: " + uids.size() + ". " + "Max size is: " + MAX_UIDS);
}
ResourceHandler resourceHandler = new ResourceHandler(resourceStore);
String lastSyncedPrograms = resourceHandler.getLastUpdated(ResourceModel.Type.PROGRAM);
Response<Payload<Program>> programsByLastUpdated = programService.getPrograms(getFields(), Program.lastUpdated.gt(lastSyncedPrograms), Program.uid.in(uids), Boolean.FALSE).execute();
if (programsByLastUpdated.isSuccessful()) {
Transaction transaction = databaseAdapter.beginNewTransaction();
try {
List<Program> programs = programsByLastUpdated.body().items();
int size = programs.size();
for (int i = 0; i < size; i++) {
Program program = programs.get(i);
programHandler.handleProgram(program);
}
resourceHandler.handleResource(ResourceModel.Type.PROGRAM, serverDate);
transaction.setSuccessful();
} finally {
transaction.end();
}
}
return programsByLastUpdated;
}
Aggregations