Skip to content

Commit

Permalink
Bump versions to at least Java 17, JEE 10, Hibernate 6; fixed failing
Browse files Browse the repository at this point in the history
logic and tests caused by changes in Hibernate 6; catch up Java 17
features such as var and instanceof var
  • Loading branch information
BalusC committed Sep 4, 2024
1 parent 7a8549f commit c6e2b2e
Show file tree
Hide file tree
Showing 5 changed files with 302 additions and 334 deletions.
90 changes: 34 additions & 56 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<groupId>org.omnifaces</groupId>
<artifactId>omnipersistence</artifactId>
<version>0.20.J2</version>
<version>0.21.J1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>OmniPersistence</name>
Expand Down Expand Up @@ -62,21 +62,20 @@
<properties>

<!-- Minimum required Java versions. -->
<javase.version>11</javase.version>
<jakartaee.version>9</jakartaee.version>
<javase.version>17</javase.version>
<jakartaee.version>10</jakartaee.version>

<!-- Essential Maven defaults. -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>${javase.version}</maven.compiler.source>
<maven.compiler.target>${javase.version}</maven.compiler.target>
<maven.compiler.release>${javase.version}</maven.compiler.release>
<maven.source.excludeResources>true</maven.source.excludeResources>

<!-- Test versions. -->
<test.wildfly.version>26.1.1.Final</test.wildfly.version> <!-- https://search.maven.org/artifact/org.wildfly.bom/wildfly -->
<test.payara.version>6.2022.1.Alpha2</test.payara.version> <!-- https://search.maven.org/artifact/fish.payara.distributions/payara-web -->
<test.glassfish.version>6.2.5</test.glassfish.version> <!-- https://search.maven.org/artifact/org.glassfish.main.distributions/glassfish -->
<test.h2.version>1.4.200</test.h2.version>
<test.wildfly.version>33.0.1.Final</test.wildfly.version> <!-- https://mvnrepository.com/artifact/org.wildfly.bom/wildfly -->
<test.payara.version>6.2024.8</test.payara.version> <!-- https://mvnrepository.com/artifact/fish.payara.distributions/payara-web -->
<test.glassfish.version>7.0.17</test.glassfish.version> <!-- https://mvnrepository.com/artifact/org.glassfish.main.distributions/glassfish -->
<test.h2.version>2.3.232</test.h2.version> <!-- https://mvnrepository.com/artifact/com.h2database/h2 -->
</properties>

<dependencies>
Expand All @@ -100,59 +99,39 @@
<dependency>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>6.0.2.Final</version>
<version>6.6.0.Final</version>
<scope>provided</scope>
</dependency>

<!-- Test dependencies. -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.junit5</groupId>
<artifactId>arquillian-junit5-container</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-depchain</artifactId>
<type>pom</type>
<version>5.11.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.junit5</groupId>
<artifactId>arquillian-junit5-container</artifactId>
<version>1.9.1.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-impl-maven-archive</artifactId>
<version>3.3.1</version>
<scope>test</scope>
</dependency>
</dependencies>

<dependencyManagement>
<dependencies>

<!-- Test dependencies. -->
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-bom</artifactId>
<version>1.7.0.Alpha10</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-bom</artifactId>
<version>3.1.4</version>
<type>pom</type>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>

<build>
<plugins>

<!-- Add missing license headers to source files. -->
<plugin>
<groupId>com.mycila</groupId>
<artifactId>license-maven-plugin</artifactId>
<version>4.1</version>
<version>4.5</version>
<configuration>
<header>license.txt</header>
<excludes>
Expand All @@ -176,7 +155,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.2</version>
<version>3.4.2</version>
<executions>
<execution>
<goals>
Expand All @@ -202,7 +181,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.1</version>
<version>3.3.1</version>
<executions>
<execution>
<id>attach-sources</id>
Expand All @@ -217,7 +196,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.4.0</version>
<version>3.10.0</version>
<configuration>
<javadocExecutable>${java.home}/bin/javadoc</javadocExecutable>
<javadocVersion>${javase.version}</javadocVersion>
Expand All @@ -242,7 +221,7 @@
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.13</version>
<version>1.7.0</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
Expand All @@ -267,7 +246,7 @@
<pluginExecutionFilter>
<groupId>com.mycila</groupId>
<artifactId>license-maven-plugin</artifactId>
<versionRange>[4.1,)</versionRange>
<versionRange>[4.4,)</versionRange>
<goals>
<goal>format</goal>
</goals>
Expand All @@ -287,7 +266,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.3.0</version>
<version>3.8.0</version>
<executions>
<execution>
<phase>process-test-classes</phase>
Expand All @@ -303,7 +282,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<version>3.5.0</version>
<configuration>
<trimStackTrace>false</trimStackTrace>
<systemPropertyVariables>
Expand Down Expand Up @@ -331,7 +310,7 @@
<dependency>
<groupId>org.wildfly.arquillian</groupId>
<artifactId>wildfly-arquillian-container-managed</artifactId>
<version>3.0.1.Final</version>
<version>5.0.1.Final</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down Expand Up @@ -361,7 +340,6 @@
<configuration>
<systemPropertyVariables>
<jboss.home>${project.build.directory}/wildfly-preview-${test.wildfly.version}</jboss.home>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
</systemPropertyVariables>
</configuration>
</plugin>
Expand All @@ -376,7 +354,7 @@
<dependency>
<groupId>org.omnifaces.arquillian</groupId>
<artifactId>arquillian-glassfish-server-managed</artifactId>
<version>1.1</version>
<version>1.6</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down Expand Up @@ -438,7 +416,7 @@
<dependency>
<groupId>org.omnifaces.arquillian</groupId>
<artifactId>arquillian-glassfish-server-managed</artifactId>
<version>1.1</version>
<version>1.6</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
21 changes: 11 additions & 10 deletions src/main/java/org/omnifaces/persistence/Provider.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

import java.io.Serializable;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
Expand All @@ -50,7 +49,7 @@ public enum Provider {

@Override
public String getDialectName(EntityManagerFactory entityManagerFactory) {
Object unwrappedEntityManagerFactory = unwrapEntityManagerFactoryIfNecessary(entityManagerFactory);
var unwrappedEntityManagerFactory = unwrapEntityManagerFactoryIfNecessary(entityManagerFactory);

if (HIBERNATE_SESSION_FACTORY.get().isInstance(unwrappedEntityManagerFactory)) {
// 5.2+ has merged hibernate-entitymanager into hibernate-core, and made EntityManagerFactory impl an instance of SessionFactory, and removed getDialect() shortcut method.
Expand All @@ -66,8 +65,10 @@ public boolean isAggregation(Expression<?> expression) {
if (HIBERNATE_6_0_0_AGGREGATE_FUNCTION.isPresent()) {
return HIBERNATE_6_0_0_AGGREGATE_FUNCTION.get().isInstance(expression);
}
return (HIBERNATE_BASIC_FUNCTION_EXPRESSION.get().isInstance(expression) && (boolean) invokeMethod(expression, "isAggregation"))
|| (HIBERNATE_COMPARISON_PREDICATE.get().isInstance(expression) && (isAggregation(invokeMethod(expression, "getLeftHandOperand")) || isAggregation(invokeMethod(expression, "getRightHandOperand"))));
else {
return HIBERNATE_BASIC_FUNCTION_EXPRESSION.get().isInstance(expression) && (boolean) invokeMethod(expression, "isAggregation")
|| HIBERNATE_COMPARISON_PREDICATE.get().isInstance(expression) && (isAggregation(invokeMethod(expression, "getLeftHandOperand")) || isAggregation(invokeMethod(expression, "getRightHandOperand")));
}
}

@Override
Expand Down Expand Up @@ -105,7 +106,7 @@ private <T, I extends Comparable<I> & Serializable, E extends BaseEntity<I>> T i

@Override
public String getDialectName(EntityManagerFactory entityManagerFactory) {
Object unwrappedEntityManagerFactory = unwrapEntityManagerFactoryIfNecessary(entityManagerFactory);
var unwrappedEntityManagerFactory = unwrapEntityManagerFactoryIfNecessary(entityManagerFactory);
return invokeMethod(invokeMethod(unwrappedEntityManagerFactory, "getDatabaseSession"), "getDatasourcePlatform").getClass().getSimpleName();
}

Expand All @@ -119,7 +120,7 @@ public boolean isAggregation(Expression<?> expression) {

@Override
public String getDialectName(EntityManagerFactory entityManagerFactory) {
Object unwrappedEntityManagerFactory = unwrapEntityManagerFactoryIfNecessary(entityManagerFactory);
var unwrappedEntityManagerFactory = unwrapEntityManagerFactoryIfNecessary(entityManagerFactory);
return invokeMethod(invokeMethod(unwrappedEntityManagerFactory, "getConfiguration"), "getDBDictionaryInstance").getClass().getSimpleName();
}

Expand Down Expand Up @@ -164,18 +165,18 @@ public boolean isOneToMany(Attribute<?, ?> attribute) {
private static final Set<String> AGGREGATE_FUNCTIONS = unmodifiableSet("MIN", "MAX", "SUM", "AVG", "COUNT");

private static Object unwrapEntityManagerFactoryIfNecessary(EntityManagerFactory entityManagerFactory) {
String packageName = entityManagerFactory.getClass().getPackage().getName();
var packageName = entityManagerFactory.getClass().getPackage().getName();

if (packageName.startsWith("org.apache.openejb.")) {
Optional<Method> getDelegate = findMethod(entityManagerFactory, "getDelegate");
var getDelegate = findMethod(entityManagerFactory, "getDelegate");
return getDelegate.isPresent() ? invokeMethod(entityManagerFactory, getDelegate.get()) : entityManagerFactory;
}

return entityManagerFactory;
}

public static Provider of(EntityManager entityManager) {
String packageName = entityManager.getDelegate().getClass().getPackage().getName();
var packageName = entityManager.getDelegate().getClass().getPackage().getName();

if (packageName.startsWith("org.hibernate.")) {
return HIBERNATE;
Expand Down Expand Up @@ -253,7 +254,7 @@ public <I extends Comparable<I> & Serializable, E extends BaseEntity<I>> String
}

Class<E> entityType = getEntityType(entity);
Table table = entityType.getAnnotation(Table.class);
var table = entityType.getAnnotation(Table.class);
return table != null ? table.name() : entityType.getSimpleName().toUpperCase();
}

Expand Down
Loading

0 comments on commit c6e2b2e

Please sign in to comment.