Skip to content

Commit

Permalink
Upgrade from javax to jakarta and Hibernate 6
Browse files Browse the repository at this point in the history
  • Loading branch information
ar committed Feb 26, 2024
1 parent fe18309 commit 8d105c0
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 62 deletions.
12 changes: 5 additions & 7 deletions modules/dbsupport/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ description = 'jPOS-EE :: Database Support Module'

dependencies {
api project(':modules:core')
api libraries.hibernate_core
api libraries.hibernate_envers
api libraries.hibernate_c3p0
api libraries.c3p0 // force c3p0 version (temporary fix un Hibernate bumps up version)
api libraries.hibernate_ehcache
api libraries.jta
api libraries.jacksonDatabind
api libs.hibernate
api libs.jacksonDatabind
implementation libs.dom4j
implementation libs.hibernateToolsOrm
implementation libs.agroal
}

49 changes: 19 additions & 30 deletions modules/dbsupport/src/main/java/org/jpos/ee/DB.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public static synchronized void invalidateSessionFactories() {
sessionFactories.clear();
}

private SessionFactory newSessionFactory() throws IOException, ConfigurationException, DocumentException, InterruptedException {
private SessionFactory newSessionFactory() throws IOException, ConfigurationException, InterruptedException, DocumentException {
Metadata md = getMetadata();
try {
newSessionSem.acquireUninterruptibly();
Expand All @@ -198,19 +198,14 @@ private void configureProperties(Configuration cfg) throws IOException
}
}

private void configureMappings(Configuration cfg) throws ConfigurationException, IOException {
try {
List<String> moduleConfigs = ModuleUtils.getModuleEntries("META-INF/org/jpos/ee/modules/");
for (String moduleConfig : moduleConfigs) {
addMappings(cfg, moduleConfig);
}
} catch (DocumentException e) {
throw new ConfigurationException("Could not parse mappings document", e);
private void configureMappings(Configuration cfg) throws ConfigurationException, IOException, DocumentException {
List<String> moduleConfigs = ModuleUtils.getModuleEntries("META-INF/org/jpos/ee/modules/");
for (String moduleConfig : moduleConfigs) {
addMappings(cfg, moduleConfig);
}
}

private void addMappings(Configuration cfg, String moduleConfig) throws ConfigurationException, DocumentException
{
private void addMappings(Configuration cfg, String moduleConfig) throws ConfigurationException, DocumentException {
Element module = readMappingElements(moduleConfig);
if (module != null)
{
Expand Down Expand Up @@ -488,45 +483,39 @@ public static <T> T unwrap (T proxy) {
}

@SuppressWarnings({"unchecked"})
public void printStats()
{
if (getLog() != null)
{
public void printStats() {
if (getLog() != null) {
LogEvent info = getLog().createInfo();

if (session != null)
{
if (session != null) {
info.addMessage("==== STATISTICS ====");
SessionStatistics statistics = session().getStatistics();

info.addMessage("==== ENTITIES ====");
Set<EntityKey> entityKeys = statistics.getEntityKeys();
for (EntityKey ek : entityKeys)
{
info.addMessage(String.format("[%s] %s", ek.getIdentifier(), ek.getEntityName()));
for (Object o : statistics.getEntityKeys()) {
if (o instanceof EntityKey ek)
info.addMessage(String.format("[%s] %s", ek.getIdentifier(), ek.getEntityName()));
}
info.addMessage("==== COLLECTIONS ====");
Set<CollectionKey> collectionKeys = statistics.getCollectionKeys();
for (CollectionKey ck : collectionKeys)
{
info.addMessage(String.format("[%s] %s", ck.getKey(), ck.getRole()));
for (Object o : statistics.getCollectionKeys()) {
if (o instanceof CollectionKey ck)
info.addMessage(String.format("[%s] %s", ck.getKey(), ck.getRole()));
}
info.addMessage("=====================");
}
else
{
else {
info.addMessage("Session is not open");
}
Logger.log(info);
}
}



@Override
public String toString() {
return "DB{" + (configModifier != null ? configModifier : "") + '}';
}

private Metadata getMetadata() throws IOException, ConfigurationException, DocumentException, InterruptedException {
private Metadata getMetadata() throws IOException, ConfigurationException, InterruptedException, DocumentException {
Semaphore mdSem = mdSems.get(configModifier);
if (!mdSem.tryAcquire(60, TimeUnit.SECONDS))
throw new RuntimeException ("Unable to acquire lock");
Expand Down
7 changes: 3 additions & 4 deletions modules/dbsupport/src/main/java/org/jpos/ee/DBFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@

package org.jpos.ee;


import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.Predicate;
import jakarta.persistence.criteria.Root;

/**
* Functional interface to create predicates for querying {@link DBManager}
Expand Down
14 changes: 6 additions & 8 deletions modules/dbsupport/src/main/java/org/jpos/ee/DBManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,15 @@

package org.jpos.ee;

import org.hibernate.query.criteria.internal.OrderImpl;
// import org.hibernate.query.criteria.internal.OrderImpl;

import javax.persistence.NoResultException;
import javax.persistence.criteria.*;
import jakarta.persistence.NoResultException;
import jakarta.persistence.criteria.*;
import org.hibernate.query.Query;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;

public class DBManager<T> {

Expand Down Expand Up @@ -91,10 +90,9 @@ public List<T> getAll(int offset, int limit, Map<String,Boolean> orders, DBFilte
List<Order> orderList = new ArrayList<>();
//ORDERS
if (orders != null) {
for (Map.Entry<String, Boolean> entry : orders.entrySet()) {
OrderImpl order = new OrderImpl(root.get(entry.getKey()), entry.getValue());
orderList.add(order);
}
orders.forEach((key, value) ->
orderList.add(value ? criteriaBuilder.asc(root.get(key)) : criteriaBuilder.desc(root.get(key)))
);
}
Predicate combinedPredicate = null;
if (filters != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import javax.persistence.AttributeConverter;
import javax.persistence.Converter;
import jakarta.persistence.AttributeConverter;
import jakarta.persistence.Converter;
import java.io.IOException;

@Converter(autoApply = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
package org.jpos.ee.converter;

import org.jpos.util.Tags;
import javax.persistence.AttributeConverter;
import javax.persistence.Converter;
import jakarta.persistence.AttributeConverter;
import jakarta.persistence.Converter;

@Converter(autoApply = true)
public class TagsConverter implements AttributeConverter<Tags,String> {
Expand Down
10 changes: 1 addition & 9 deletions modules/dbsupport/src/main/resources/hibernate.cfg.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,6 @@
<property name="connection.isolation">2</property>
<property name="hibernate.transaction.flush_before_completion">true</property>
<property name="current_session_context_class">managed</property>
<property name="hibernate.c3p0.min_size">2</property>
<property name="hibernate.c3p0.max_size">100</property>
<property name="hibernate.c3p0.timeout">300</property>
<property name="hibernate.c3p0.max_statements">300</property>
<property name="hibernate.c3p0.idle_test_period">3000</property>
<property name="hibernate.cache.use_structured_entries">true</property>
<property name="hibernate.cache.use_query_cache">true</property>
<property name="hibernate.cache.use_second_level_cache">true</property>
<property name="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory</property>
</session-factory>
</hibernate-configuration>

0 comments on commit 8d105c0

Please sign in to comment.