Skip to content

Commit

Permalink
feat: support JPA annotation mapping for object model (#14626)
Browse files Browse the repository at this point in the history
* feat: support jpa annotation mapping#

* code style

* feat: support jpa annotation mapping#

* code style

* code style

* fix merge conflicts

* fix merge conflicts

* fix merge conflicts

* fix merge conflicts

* fix maven dependencies

* fix maven dependencies

* turn off debug logs

* fix merge conflicts

* code styles

* fix merge conflicts

* fix merge conflicts

* remove dbms.clearSession() in metadata import service

* code styles

* support constructor injection for EntityManager

* code styles

* remove unused codes

* code styles

* merge from master

* merge from master

* merge from master

* merge from master

* merge from master

* code styles

* feat: replace SessionFactory with EntityManager in all stores

* git cache cleared

* merge from master

* remove unused EntityManager

* merge from master

* add back build.sh

* fix dependencies

* replace SessionFactory with EntityManager

* replace sessionFactory with EntityManager

* code styles

* fix javax.persistence-api dependency

* remove unused OAuth2Client.hbm.xml

* merge from master

* merge from master

* merge from master

* getPropertyValue() use methods instead of properties

* Period.getCode should return IsoDate

* remove session.flush in integrationTest

* remove hibernate flush in DhisConvenienceTest

* enable session flush for integration test

* remove session.update() calls

* use EntityManager in unit tests

* fix dataApproval test

* use entityManager in object bundle hooks

* fix ProgramRuleVariableObjectBundleHookTest

* use entityManager in HibernateGenericStore

* add back dbmsManager.clearSession() for DataApprovalStoreIntegrationTest

* replace SessionFactory with EntityManager in unit tests

* fix ObjectBundleServiceTest

* use save instead of persist

* fix tracker aclStore bean name

* fix AclStore bean name

* fix AclStore bean autowire

* use hibernate session to save objects

* fix transactionTemplate config

* use EntityManager in BaseSpringTest

* fix maven deps

* replace SessionFactory with EntityManager

* fix maven dependency issue

* use hibernate session.update()

* use entityManager in HibernateDbmsManager

* remove redundant translation test

* set hibernate ddl property for h2 test

* fix maven deps

* remove refresh and flush calls in CollectionService

* use EM in FollowupValueManager

* fix collectionService

* use EntityManager in new TrackerImport services

* fix TrackerOrgUnitMergeHandlerTest

* replace sessionFactory with EntityManager

* add missing methods in Legend class

* fix PeriodServiceTest

* clean: reserved values

* fix: error in ProgramStageSectionIntegrationTest

* fix: delete-orphan not work for programStage.programStageSection

* fix: maven dependency

* fix: merge before remove attributeValue in TrackerPersister

* fix: code styles

* fix code styles

* fix maven dependency

* fix: ContextInterceptor refer to DatabaseInfoProvider

* fix: ContextInterceptor missing constructor

* fix: add back Legend.hbm.xml

* clean up codes

* fix maven dependency

* codes clean up

* codes clean up

* code clean up

* code clean up

* TECH-1517-41

* rever unrelated fix in BaseIdentifiableObject

* rever unrelated fix

* fix circular dependency in HibernateEncryptionConfig

* use constructor for EM injection in DefaultObjectBundleService

* remove sessionFactory bean in HibernateConfig

* remove uses of SessionFactory bean

* remove uses of SessionFactory bean

---------

Co-authored-by: luca <[email protected]>
  • Loading branch information
vietnguyen and lucaCambi77 authored Nov 16, 2023
1 parent 5b0cc8e commit 6eb421d
Show file tree
Hide file tree
Showing 231 changed files with 1,229 additions and 1,291 deletions.
Empty file modified dhis-2/build.sh
100755 → 100644
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
*/
package org.hisp.dhis.dbms;

import java.io.Serializable;
import java.util.List;

/**
Expand All @@ -47,10 +46,4 @@ public interface DbmsManager {
boolean tableExists(String tableName);

List<List<Object>> getTableContent(String table);

void evictObject(Object object);

boolean contains(Object object);

Serializable getIdentifier(Object object);
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ public interface ReservedValueStore extends GenericStore<ReservedValue> {
List<ReservedValue> getAvailableValues(
ReservedValue reservedValue, List<String> values, String ownerObject);

List<ReservedValue> reserveValuesJpa(ReservedValue reservedValue, List<String> values);

int getNumberOfUsedValues(ReservedValue reservedValue);

boolean useReservedValue(String ownerUID, String value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public String getCurrentUsername() {
return CurrentUserUtil.getCurrentUsername();
}

@Transactional(readOnly = true)
public User getCurrentUser() {
String username = CurrentUserUtil.getCurrentUsername();

Expand Down
4 changes: 2 additions & 2 deletions dhis-2/dhis-services/dhis-service-administration/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<groupId>javax.persistence</groupId>
<artifactId>javax.persistence-api</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@

import java.util.Date;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import lombok.RequiredArgsConstructor;
import org.hibernate.SessionFactory;
import org.hisp.dhis.dataintegrity.DataIntegrityCheck;
import org.hisp.dhis.dataintegrity.DataIntegrityDetails;
import org.hisp.dhis.dataintegrity.DataIntegrityDetails.DataIntegrityIssue;
Expand All @@ -50,13 +51,13 @@
@Repository
@RequiredArgsConstructor
public class HibernateDataIntegrityStore implements DataIntegrityStore {
private final SessionFactory sessionFactory;
@PersistenceContext private final EntityManager entityManager;

@Override
@Transactional(readOnly = true)
public DataIntegritySummary querySummary(DataIntegrityCheck check, String sql) {
Date startTime = new Date();
Object summary = sessionFactory.getCurrentSession().createNativeQuery(sql).getSingleResult();
Object summary = entityManager.createNativeQuery(sql).getSingleResult();
return new DataIntegritySummary(
check, startTime, new Date(), null, parseCount(summary), parsePercentage(summary));
}
Expand All @@ -66,7 +67,7 @@ public DataIntegritySummary querySummary(DataIntegrityCheck check, String sql) {
public DataIntegrityDetails queryDetails(DataIntegrityCheck check, String sql) {
Date startTime = new Date();
@SuppressWarnings("unchecked")
List<Object[]> rows = sessionFactory.getCurrentSession().createNativeQuery(sql).getResultList();
List<Object[]> rows = entityManager.createNativeQuery(sql).getResultList();
return new DataIntegrityDetails(
check,
startTime,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@

import static org.hisp.dhis.common.IdentifiableObjectUtils.getIdentifiers;

import javax.persistence.EntityManager;
import lombok.RequiredArgsConstructor;
import org.hibernate.SessionFactory;
import org.hisp.dhis.common.IdentifiableObjectUtils;
import org.hisp.dhis.dataapproval.DataApprovalAuditService;
import org.hisp.dhis.dataset.DataSetService;
Expand All @@ -55,7 +55,7 @@
@Transactional
@RequiredArgsConstructor
public class DataOrgUnitMergeHandler {
private final SessionFactory sessionFactory;
private final EntityManager entityManager;

private final NamedParameterJdbcTemplate jdbcTemplate;

Expand Down Expand Up @@ -201,11 +201,10 @@ public void mergeInterpretations(OrgUnitMergeRequest request) {
}

private void migrate(String hql, OrgUnitMergeRequest request) {
sessionFactory
.getCurrentSession()
entityManager
.createQuery(hql)
.setParameter("target", request.getTarget())
.setParameterList("sources", IdentifiableObjectUtils.getIdentifiers(request.getSources()))
.setParameter("sources", IdentifiableObjectUtils.getIdentifiers(request.getSources()))
.executeUpdate();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
*/
package org.hisp.dhis.merge.orgunit.handler;

import javax.persistence.EntityManager;
import lombok.RequiredArgsConstructor;
import org.hibernate.SessionFactory;
import org.hisp.dhis.common.IdentifiableObjectUtils;
import org.hisp.dhis.merge.orgunit.OrgUnitMergeRequest;
import org.springframework.stereotype.Service;
Expand All @@ -42,7 +42,7 @@
@Service
@RequiredArgsConstructor
public class TrackerOrgUnitMergeHandler {
private final SessionFactory sessionFactory;
private final EntityManager entityManager;

@Transactional
public void mergeProgramMessages(OrgUnitMergeRequest request) {
Expand Down Expand Up @@ -90,11 +90,10 @@ public void mergeTrackedEntities(OrgUnitMergeRequest request) {
}

private void migrate(String hql, OrgUnitMergeRequest request) {
sessionFactory
.getCurrentSession()
entityManager
.createQuery(hql)
.setParameter("target", request.getTarget())
.setParameterList("sources", IdentifiableObjectUtils.getIdentifiers(request.getSources()))
.setParameter("sources", IdentifiableObjectUtils.getIdentifiers(request.getSources()))
.executeUpdate();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
*/
package org.hisp.dhis.split.orgunit.handler;

import javax.persistence.EntityManager;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.SessionFactory;
import org.hisp.dhis.split.orgunit.OrgUnitSplitRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -46,7 +46,7 @@ public class DataOrgUnitSplitHandler {

private static final String PARAM_SOURCE = "source";

private final SessionFactory sessionFactory;
private final EntityManager entityManager;

@Transactional
public void splitData(OrgUnitSplitRequest request) {
Expand Down Expand Up @@ -74,8 +74,7 @@ private void migrate(OrgUnitSplitRequest request, String entity, String property

log.debug("Update data HQL: '{}'", hql);

sessionFactory
.getCurrentSession()
entityManager
.createQuery(hql)
.setParameter("source", request.getSource())
.setParameter("target", request.getPrimaryTarget())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
package org.hisp.dhis.analytics.hibernate;

import java.util.List;
import javax.persistence.EntityManager;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.SessionFactory;
import org.hisp.dhis.analytics.AnalyticsTableHook;
import org.hisp.dhis.analytics.AnalyticsTableHookStore;
import org.hisp.dhis.analytics.AnalyticsTablePhase;
Expand All @@ -51,13 +51,13 @@ public class HibernateAnalyticsTableHookStore
extends HibernateIdentifiableObjectStore<AnalyticsTableHook>
implements AnalyticsTableHookStore {
public HibernateAnalyticsTableHookStore(
SessionFactory sessionFactory,
EntityManager entityManager,
JdbcTemplate jdbcTemplate,
ApplicationEventPublisher publisher,
CurrentUserService currentUserService,
AclService aclService) {
super(
sessionFactory,
entityManager,
jdbcTemplate,
publisher,
AnalyticsTableHook.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*/
package org.hisp.dhis.attribute.hibernate;

import org.hibernate.SessionFactory;
import javax.persistence.EntityManager;
import org.hisp.dhis.attribute.Attribute;
import org.hisp.dhis.attribute.AttributeStore;
import org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore;
Expand All @@ -46,13 +46,13 @@ public class HibernateAttributeStore extends HibernateIdentifiableObjectStore<At
implements AttributeStore {
@Autowired
public HibernateAttributeStore(
SessionFactory sessionFactory,
EntityManager entityManager,
JdbcTemplate jdbcTemplate,
ApplicationEventPublisher publisher,
CurrentUserService currentUserService,
AclService aclService) {
super(
sessionFactory,
entityManager,
jdbcTemplate,
publisher,
Attribute.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
package org.hisp.dhis.category.hibernate;

import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import org.hibernate.SessionFactory;
import org.hisp.dhis.category.CategoryCombo;
import org.hisp.dhis.category.CategoryComboStore;
import org.hisp.dhis.common.DataDimensionType;
Expand All @@ -47,13 +47,13 @@
public class HibernateCategoryComboStore extends HibernateIdentifiableObjectStore<CategoryCombo>
implements CategoryComboStore {
public HibernateCategoryComboStore(
SessionFactory sessionFactory,
EntityManager entityManager,
JdbcTemplate jdbcTemplate,
ApplicationEventPublisher publisher,
CurrentUserService currentUserService,
AclService aclService) {
super(
sessionFactory,
entityManager,
jdbcTemplate,
publisher,
CategoryCombo.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@

import java.util.List;
import java.util.Set;
import javax.persistence.EntityManager;
import org.hibernate.NonUniqueResultException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.query.Query;
import org.hisp.dhis.category.CategoryCombo;
import org.hisp.dhis.category.CategoryOption;
Expand All @@ -56,14 +56,14 @@ public class HibernateCategoryOptionComboStore
private final DbmsManager dbmsManager;

public HibernateCategoryOptionComboStore(
SessionFactory sessionFactory,
EntityManager entityManager,
JdbcTemplate jdbcTemplate,
ApplicationEventPublisher publisher,
CurrentUserService currentUserService,
AclService aclService,
DbmsManager dbmsManager) {
super(
sessionFactory,
entityManager,
jdbcTemplate,
publisher,
CategoryOptionCombo.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
package org.hisp.dhis.category.hibernate;

import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import org.hibernate.SessionFactory;
import org.hisp.dhis.category.CategoryOptionGroupSet;
import org.hisp.dhis.category.CategoryOptionGroupSetStore;
import org.hisp.dhis.common.DataDimensionType;
Expand All @@ -48,13 +48,13 @@ public class HibernateCategoryOptionGroupSetStore
extends HibernateIdentifiableObjectStore<CategoryOptionGroupSet>
implements CategoryOptionGroupSetStore {
public HibernateCategoryOptionGroupSetStore(
SessionFactory sessionFactory,
EntityManager entityManager,
JdbcTemplate jdbcTemplate,
ApplicationEventPublisher publisher,
CurrentUserService currentUserService,
AclService aclService) {
super(
sessionFactory,
entityManager,
jdbcTemplate,
publisher,
CategoryOptionGroupSet.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
package org.hisp.dhis.category.hibernate;

import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.Join;
import org.hibernate.SessionFactory;
import org.hisp.dhis.category.CategoryOptionGroup;
import org.hisp.dhis.category.CategoryOptionGroupSet;
import org.hisp.dhis.category.CategoryOptionGroupStore;
Expand All @@ -50,13 +50,13 @@ public class HibernateCategoryOptionGroupStore
extends HibernateIdentifiableObjectStore<CategoryOptionGroup>
implements CategoryOptionGroupStore {
public HibernateCategoryOptionGroupStore(
SessionFactory sessionFactory,
EntityManager entityManager,
JdbcTemplate jdbcTemplate,
ApplicationEventPublisher publisher,
CurrentUserService currentUserService,
AclService aclService) {
super(
sessionFactory,
entityManager,
jdbcTemplate,
publisher,
CategoryOptionGroup.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
package org.hisp.dhis.category.hibernate;

import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import org.hibernate.SessionFactory;
import org.hisp.dhis.category.Category;
import org.hisp.dhis.category.CategoryOption;
import org.hisp.dhis.category.CategoryOptionStore;
Expand All @@ -48,13 +48,13 @@
public class HibernateCategoryOptionStore extends HibernateIdentifiableObjectStore<CategoryOption>
implements CategoryOptionStore {
public HibernateCategoryOptionStore(
SessionFactory sessionFactory,
EntityManager entityManager,
JdbcTemplate jdbcTemplate,
ApplicationEventPublisher publisher,
CurrentUserService currentUserService,
AclService aclService) {
super(
sessionFactory,
entityManager,
jdbcTemplate,
publisher,
CategoryOption.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
package org.hisp.dhis.category.hibernate;

import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import org.hibernate.SessionFactory;
import org.hisp.dhis.category.Category;
import org.hisp.dhis.category.CategoryStore;
import org.hisp.dhis.common.DataDimensionType;
Expand All @@ -47,13 +47,13 @@
public class HibernateCategoryStore extends HibernateIdentifiableObjectStore<Category>
implements CategoryStore {
public HibernateCategoryStore(
SessionFactory sessionFactory,
EntityManager entityManager,
JdbcTemplate jdbcTemplate,
ApplicationEventPublisher publisher,
CurrentUserService currentUserService,
AclService aclService) {
super(
sessionFactory,
entityManager,
jdbcTemplate,
publisher,
Category.class,
Expand Down
Loading

0 comments on commit 6eb421d

Please sign in to comment.