Skip to content

Commit

Permalink
#813 - more javax => jakarta. hibernate/postgres related changes
Browse files Browse the repository at this point in the history
  • Loading branch information
petmongrels committed Nov 1, 2024
1 parent 3b907db commit 2730449
Show file tree
Hide file tree
Showing 210 changed files with 297 additions and 326 deletions.
39 changes: 24 additions & 15 deletions avni-server-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,31 +41,38 @@ repositories { mavenCentral() }

configurations {
dev
all*.exclude group: 'org.slf4j', module: 'slf4j-reload4j'
all*.exclude group: 'org.slf4j', module: 'slf4j-simple'
}

dependencies {
implementation group: 'org.apache.tomcat', name: 'tomcat-jdbc', version: '8.5.46'
implementation group: 'org.apache.tomcat', name: 'tomcat-jdbc'
implementation("org.springframework.boot:spring-boot-starter-web:${springBootVersion}")
implementation "org.springframework.boot:spring-boot-starter-data-jpa:${springBootVersion}"
testImplementation "org.springframework.boot:spring-boot-starter-test:${springBootVersion}"
implementation "org.springframework.boot:spring-boot-starter-data-rest:${springBootVersion}"
implementation("org.springframework.boot:spring-boot-starter-security:${springBootVersion}")
testImplementation "com.github.tomakehurst:wiremock-jre8-standalone:2.34.0"
implementation "org.postgresql:postgresql:9.4-1200-jdbc41"
implementation "org.postgresql:postgresql"
implementation 'org.springframework.boot:spring-boot-starter-batch'
testImplementation 'org.springframework.batch:spring-batch-test'
implementation "joda-time:joda-time:2.9.4"
implementation group: 'org.jadira.usertype', name: 'usertype.core', version: '6.0.1.GA'
implementation "org.flywaydb:flyway-core:4.0.3"
implementation "org.flywaydb.flyway-test-extensions:flyway-spring-test:4.0"
implementation "com.zaxxer:HikariCP:2.5.1"
implementation "joda-time:joda-time"
runtimeOnly("javax.transaction:jta:1.1")
// implementation(group: 'org.jadira.usertype', name: 'usertype.core', version: '7.0.0.CR1') {
// exclude(group: 'org.hibernate', module: 'hibernate-core')
// }
implementation "org.flywaydb:flyway-core:10.20.1"
runtimeOnly("org.flywaydb:flyway-database-postgresql:10.20.1")
implementation "org.flywaydb.flyway-test-extensions:flyway-spring6-test:10.0.0"
implementation "com.zaxxer:HikariCP"
implementation "org.apache.poi:poi:3.16-beta2"
implementation "org.apache.poi:poi-ooxml:3.16-beta2"
implementation 'org.apache.httpcomponents:httpclient:4.5.9'
implementation 'org.apache.httpcomponents:httpclient'
implementation 'com.auth0:jwks-rsa:0.3.0'
implementation 'com.auth0:java-jwt:3.3.0'
implementation group: 'org.hibernate', name: 'hibernate-search-orm', version: '5.9.2.Final'
implementation(group: 'org.hibernate', name: 'hibernate-search-orm', version: '5.9.2.Final') {
exclude(group: 'org.hibernate', module: 'hibernate-core')
}
implementation 'com.bugsnag:bugsnag:3.+'
implementation 'com.amazonaws:aws-java-sdk-s3'
implementation 'com.amazonaws:aws-java-sdk-cognitoidp'
Expand All @@ -74,12 +81,14 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-cache'
implementation 'org.keycloak:keycloak-spring-boot-starter:21.0.2'
implementation 'org.keycloak:keycloak-admin-client:21.0.2'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.12.6'
implementation 'com.fasterxml.jackson.core:jackson-core:2.12.6'
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.12.6'
implementation 'com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:2.12.6'
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-joda:2.12.6'
implementation 'org.hibernate:hibernate-ehcache:5.6.15.Final'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.15.4'
implementation 'com.fasterxml.jackson.core:jackson-core:2.15.4'
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.15.4'
implementation 'com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:2.15.2'
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-joda:2.15.4'
implementation('org.hibernate:hibernate-ehcache:5.6.15.Final') {
exclude(group: 'org.hibernate', module: 'hibernate-core')
}
implementation 'javax.cache:cache-api:1.1.1'
dev "org.springframework.boot:spring-boot-devtools:${springBootVersion}"
testImplementation "org.mockito:mockito-core:2.23.4"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
import org.avni.server.framework.hibernate.NextTriggerDetailsUserType;
import org.hibernate.annotations.Type;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import jakarta.persistence.*;

@Entity
@Table(name = "manual_message")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import org.avni.server.domain.OrganisationAwareEntity;

import javax.persistence.*;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;

@Entity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import org.avni.server.domain.OrganisationAwareEntity;
import org.joda.time.DateTime;

import javax.persistence.*;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;

@Entity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import org.avni.server.domain.OrganisationAwareEntity;

import javax.persistence.*;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;

@Entity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import org.avni.server.domain.Concept;

import javax.persistence.*;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;

@Entity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.avni.server.framework.hibernate.DeclarativeRuleUserType;
import org.hibernate.annotations.Type;

import javax.persistence.*;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import java.util.*;
import java.util.stream.Collectors;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.avni.server.web.validation.ValidationException;
import org.springframework.util.StringUtils;

import javax.persistence.*;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.HashSet;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.hibernate.annotations.BatchSize;
import org.hibernate.annotations.Type;

import javax.persistence.*;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import java.util.HashSet;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.rest.core.config.Projection;

import javax.persistence.*;
import jakarta.persistence.*;

@Entity
@Table(name = "form_mapping")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.avni.server.application;

import javax.persistence.Column;
import javax.persistence.Embeddable;
import jakarta.persistence.*;

@Embeddable
public class Format {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import org.avni.server.domain.OrganisationAwareEntity;
import org.hibernate.annotations.BatchSize;

import javax.persistence.*;
import jakarta.persistence.*;

@Entity
@Table(name = "non_applicable_form_element")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import org.avni.server.domain.OrganisationAwareEntity;

import javax.persistence.*;
import jakarta.persistence.*;

@Entity
@Table(name = "menu_item")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import jakarta.persistence.EntityManager;
import jakarta.persistence.Query;
import javax.transaction.Transactional;
import jakarta.transaction.Transactional;
import java.math.BigInteger;
import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package org.avni.server.dao;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import jakarta.persistence.*;
import java.util.Date;

@Entity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.springframework.stereotype.Repository;

import jakarta.persistence.EntityManager;
import javax.transaction.Transactional;
import jakarta.transaction.Transactional;

/**
* LocationSyncRepository uses the postgres @> keyword for sync, which does not index well and creates poor plans.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.springframework.stereotype.Repository;

import jakarta.persistence.EntityManager;
import javax.transaction.Transactional;
import jakarta.transaction.Transactional;

@Repository
public class LocationSyncRepository extends RoleSwitchableRepository implements SyncableRepository<AddressLevel> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import org.avni.server.framework.security.UserContextHolder;

import jakarta.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import jakarta.persistence.Query;
import jakarta.persistence.*;

public abstract class RoleSwitchableRepository {
@PersistenceContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@
import org.avni.server.dao.search.SqlQuery;
import org.avni.server.domain.SubjectType;
import org.avni.server.web.request.webapp.search.SubjectSearchRequest;
import org.hibernate.query.internal.NativeQueryImpl;
import org.hibernate.transform.AliasToEntityMapResultTransformer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;
import org.springframework.util.StringUtils;

import jakarta.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import jakarta.persistence.*;

import jakarta.persistence.Query;
import javax.transaction.Transactional;
import jakarta.transaction.Transactional;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

Expand All @@ -32,6 +35,24 @@ public SubjectSearchRepository(EntityManager entityManager, SubjectTypeRepositor
this.subjectTypeRepository = subjectTypeRepository;
}

private List<Map<String, Object>> convertTuplesToMap(List<?> tuples) {
List<Map<String, Object>> result = new ArrayList<>();

tuples.forEach(object -> {
if (object instanceof Tuple single) {
Map<String, Object> tempMap = new HashMap<>();
for (TupleElement<?> key : single.getElements()) {
tempMap.put(key.getAlias(), single.get(key));
}
result.add(tempMap);
} else {
throw new RuntimeException("Query should return instance of Tuple");
}
});

return result;
}

@Transactional
public List<Map<String, Object>> search(SubjectSearchRequest searchRequest, SearchBuilder searchBuilder) {
SubjectType subjectType = StringUtils.isEmpty(searchRequest.getSubjectType()) ? null : subjectTypeRepository.findByUuid(searchRequest.getSubjectType());
Expand All @@ -41,12 +62,11 @@ public List<Map<String, Object>> search(SubjectSearchRequest searchRequest, Sear
logger.debug("Executing query: " + query.getSql());
logger.debug("Parameters: " + query.getParameters());
Query sql = entityManager.createNativeQuery(query.getSql());
NativeQueryImpl nativeQuery = (NativeQueryImpl) sql;
nativeQuery.setResultTransformer(AliasToEntityMapResultTransformer.INSTANCE);
query.getParameters().forEach((name, value) -> {
sql.setParameter(name, value);
});
return sql.getResultList();
List resultList = sql.getResultList();
return convertTuplesToMap(resultList);
} finally {
setRoleBackToUser();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
import org.springframework.data.rest.core.annotation.RestResource;
import org.springframework.stereotype.Repository;

import javax.persistence.EntityNotFoundException;
import jakarta.persistence.QueryHint;
import jakarta.persistence.*;
import java.util.List;
import java.util.Optional;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.hibernate.annotations.Type;
import org.joda.time.DateTime;

import javax.persistence.*;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import java.util.Objects;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.hibernate.annotations.BatchSize;

import javax.persistence.*;
import jakarta.persistence.*;
import java.util.HashSet;
import java.util.Set;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import org.hibernate.annotations.BatchSize;

import javax.persistence.*;
import jakarta.persistence.*;

@Entity
@Table(name = "account_admin")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import org.avni.server.geo.Point;
import org.springframework.data.rest.core.config.Projection;

import javax.persistence.*;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import java.util.*;
import java.util.stream.Collectors;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.avni.server.application.projections.BaseProjection;
import org.springframework.data.rest.core.config.Projection;

import javax.persistence.*;
import jakarta.persistence.*;
import jakarta.validation.constraints.*;
import jakarta.validation.constraints.NotNull;
import java.util.HashSet;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.hibernate.annotations.BatchSize;

import javax.persistence.*;
import jakarta.persistence.*;

@Entity
@Table(name = "answer_concept_migration")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import org.hibernate.annotations.BatchSize;

import javax.persistence.*;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import org.joda.time.DateTime;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package org.avni.server.domain;

import jakarta.validation.constraints.NotNull;
import org.hibernate.proxy.HibernateProxyHelper;
import org.hibernate.proxy.HibernateProxy;
import org.hibernate.proxy.LazyInitializer;

import javax.persistence.*;
import jakarta.persistence.*;
import java.util.UUID;

@MappedSuperclass
Expand Down Expand Up @@ -59,7 +60,10 @@ public void assignUUIDIfRequired() {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || HibernateProxyHelper.getClassWithoutInitializingProxy(this) != HibernateProxyHelper.getClassWithoutInitializingProxy(o)) return false;

LazyInitializer lazyInitializer1 = HibernateProxy.extractLazyInitializer(this);
LazyInitializer lazyInitializer2 = HibernateProxy.extractLazyInitializer(o);
if (o == null || lazyInitializer2 == null || lazyInitializer1 == null || lazyInitializer1.getImplementationClass() != lazyInitializer2.getImplementationClass()) return false;

CHSBaseEntity that = (CHSBaseEntity) o;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import jakarta.persistence.*;
import java.util.Date;

@MappedSuperclass
Expand Down
Loading

0 comments on commit 2730449

Please sign in to comment.