Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/2.41-DHIS2-16240' into 2.41-DHIS…
Browse files Browse the repository at this point in the history
…2-16240
  • Loading branch information
d-bernat committed Jan 4, 2024
2 parents 6b13a7d + 2ef0fee commit eca7a0e
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (c) 2004-2024, University of Oslo
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* Neither the name of the HISP project nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.hisp.dhis.common;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* A marker annotation to indicate that the annotated method (although it being a service method)
* should not be annotated with spring's {@code @Transactional} annotation as it uses a different
* transaction management.
*
* @see NonTransactional
* @author Jan Bernitt
*/
@Retention(RetentionPolicy.SOURCE)
@Target(ElementType.METHOD)
public @interface IndirectTransactional {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (c) 2004-2024, University of Oslo
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* Neither the name of the HISP project nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.hisp.dhis.common;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* An annotation to indicate that a service method does not need transactions at all. Such a method
* should not be annotated with spring's {@code @Transactional}.
*
* @see IndirectTransactional
* @author Jan Bernitt
*/
@Retention(RetentionPolicy.SOURCE)
@Target(ElementType.METHOD)
public @interface NonTransactional {}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import javax.annotation.PostConstruct;
import lombok.RequiredArgsConstructor;
import org.hisp.dhis.calendar.impl.Iso8601Calendar;
import org.hisp.dhis.common.IndirectTransactional;
import org.hisp.dhis.common.NonTransactional;
import org.hisp.dhis.period.Cal;
import org.hisp.dhis.period.PeriodType;
import org.hisp.dhis.setting.SettingKey;
Expand Down Expand Up @@ -75,6 +77,7 @@ public void init() {
}

@Override
@NonTransactional
public List<Calendar> getAllCalendars() {
List<Calendar> sortedCalendars = Lists.newArrayList(calendarMap.values());
Collections.sort(sortedCalendars, CalendarComparator.INSTANCE);
Expand All @@ -87,6 +90,7 @@ public List<DateFormat> getAllDateFormats() {
}

@Override
@IndirectTransactional
public Calendar getSystemCalendar() {
String calendarKey = settingManager.getStringSetting(SettingKey.CALENDAR);
String dateFormat = settingManager.getStringSetting(SettingKey.DATE_FORMAT);
Expand All @@ -105,6 +109,7 @@ public Calendar getSystemCalendar() {
}

@Override
@IndirectTransactional
public DateFormat getSystemDateFormat() {
String dateFormatKey = settingManager.getStringSetting(SettingKey.DATE_FORMAT);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import lombok.extern.slf4j.Slf4j;
import org.hisp.dhis.cache.Cache;
import org.hisp.dhis.cache.CacheProvider;
import org.hisp.dhis.common.IndirectTransactional;
import org.hisp.dhis.system.util.SerializableOptional;
import org.jasypt.encryption.pbe.PBEStringEncryptor;
import org.jasypt.exceptions.EncryptionOperationNotPossibleException;
Expand Down Expand Up @@ -163,6 +164,7 @@ public void deleteSystemSetting(SettingKey key) {
* behind the cache to avoid the transaction overhead for cache hits.
*/
@Override
@IndirectTransactional
@SuppressWarnings("unchecked")
public <T extends Serializable> T getSystemSetting(SettingKey key, T defaultValue) {
SerializableOptional value =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.util.stream.Stream;
import javax.annotation.Nonnull;
import lombok.RequiredArgsConstructor;
import org.hisp.dhis.common.IndirectTransactional;
import org.hisp.dhis.scheduling.JobProgress;
import org.hisp.dhis.tracker.TrackerType;
import org.hisp.dhis.tracker.imports.bundle.TrackerBundle;
Expand Down Expand Up @@ -66,10 +67,16 @@ public class DefaultTrackerImportService implements TrackerImportService {

@Nonnull private final TrackerUserService trackerUserService;

/* Import is not meant to be annotated with @Transactional.
* PreHeat and Commit phases are separated transactions, other
* phases do not need to be in a transaction. */
private PersistenceReport commit(TrackerImportParams params, TrackerBundle trackerBundle) {
if (TrackerImportStrategy.DELETE == params.getImportStrategy()) {
return deleteBundle(trackerBundle);
} else {
return commitBundle(trackerBundle);
}
}

@Override
@IndirectTransactional
public ImportReport importTracker(
TrackerImportParams params, TrackerObjects trackerObjects, JobProgress jobProgress) {
User user = trackerUserService.getUser(params.getUserId());
Expand Down Expand Up @@ -120,14 +127,6 @@ public ImportReport importTracker(
Status.OK, persistenceReport, validationReport, bundleSize);
}

private PersistenceReport commit(TrackerImportParams params, TrackerBundle trackerBundle) {
if (TrackerImportStrategy.DELETE == params.getImportStrategy()) {
return deleteBundle(trackerBundle);
} else {
return commitBundle(trackerBundle);
}
}

protected ValidationResult validateBundle(TrackerBundle bundle) {
ValidationResult result = validationService.validate(bundle);
bundle.setTrackedEntities(result.getTrackedEntities());
Expand Down

0 comments on commit eca7a0e

Please sign in to comment.