8000 Upgrade to the Quarkus 3.24.2 version by mabartos · Pull Request #40867 · keycloak/keycloak · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Upgrade to the Quarkus 3.24.2 version #40867

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,33 @@

package org.keycloak.connections.jpa.util;

import jakarta.persistence.PersistenceUnitTransactionType;
import jakarta.persistence.ValidationMode;
import org.hibernate.dialect.Dialect;
import org.hibernate.internal.SessionFactoryImpl;
import org.hibernate.jpa.boot.spi.PersistenceUnitDescriptor;
import org.hibernate.jpa.boot.spi.PersistenceXmlParser;
import org.jboss.logging.Logger;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.jpa.boot.internal.ParsedPersistenceXmlDescriptor;
import org.hibernate.jpa.boot.internal.PersistenceXmlParser;
import org.hibernate.jpa.boot.spi.Bootstrap;
import org.keycloak.connections.jpa.entityprovider.JpaEntityProvider;
import org.keycloak.models.KeycloakSession;

import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.spi.PersistenceUnitTransactionType;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Properties;
import java.util.Set;
import java.util.stream.Collectors;

/**
* @author <a href="mailto:mposolda@redhat.com">Marek Posolda</a>
Expand All @@ -56,11 +61,22 @@ public static String getTableNameForNativeQuery(String tableName, EntityManager
return (schema==null) ? tableName : dialect.openQuote() + schema + dialect.closeQuote() + "." + tableName;
}

private static List<ParsedPersistenceXmlDescriptor> transformPersistenceUnits(Collection<PersistenceUnitDescriptor> descriptors) {
return descriptors.stream().map(descriptor -> (ParsedPersistenceXmlDescriptor) descriptor).collect(Collectors.toList());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Persistence unit descriptor is always ParsedPersistenceXmlDescriptor when parsed from the persistence XML -> see https://github.com/hibernate/hibernate-orm/blob/7.0.5/hibernate-core/src/main/java/org/hibernate/jpa/boot/spi/PersistenceXmlParser.java#L181

}

public static EntityManagerFactory createEntityManagerFactory(KeycloakSession session, String unitName, Map<String, Object> properties, boolean jta) {
PersistenceUnitTransactionType txType = jta ? PersistenceUnitTransactionType.JTA : PersistenceUnitTransactionType.RESOURCE_LOCAL;
List<ParsedPersistenceXmlDescriptor> persistenceUnits = new ArrayList<>(PersistenceXmlParser.locatePersistenceUnits(properties));
PersistenceXmlParser parser = PersistenceXmlParser.create(properties);
List<URL> urls = parser.getClassLoaderService().locateResources("META-INF/persistence.xml");

persistenceUnits.add(PersistenceXmlParser.locateIndividualPersistenceUnit(JpaUtils.class.getClassLoader().getResource("default-persistence.xml")));
List<ParsedPersistenceXmlDescriptor> persistenceUnits = urls.isEmpty() ? new ArrayList<>() : transformPersistenceUnits(parser.parse(urls).values());
Comment on lines -61 to +73
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mimic the behavior of the PersistenceXmlParser#locatePersistenceUnits with the new approach for locating all these persistence.xml resources - inspired by the HibernateOrmProcessor#parsePersistenceXmlDescriptors in Quarkus.

ParsedPersistenceXmlDescriptor defaultPersistenceUnit = transformPersistenceUnits(parser.parse(Collections.singletonList(JpaUtils.class.getClassLoader().getResource("default-persistence.xml")), txType)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrap as a singletonList to be able to use the custom NoSuchElementException specified below. List.of() might potentially throw NPE, and we would not have the exact information about the failure.

I can share the reasoning if necessary.

.values())
.stream()
.findFirst()
.orElseThrow(() -> new NoSuchElementException("Cannot find the file 'default-persistence.xml'"));
persistenceUnits.add(defaultPersistenceUnit);

for (ParsedPersistenceXmlDescriptor persistenceUnit : persistenceUnits) {
if (persistenceUnit.getName().equals(unitName)) {
Expand Down
12 changes: 6 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@

<asciidoctor.plugin.version>1.5.8</asciidoctor.plugin.version>

<quarkus.version>3.20.1</quarkus.version>
<quarkus.build.version>3.20.1</quarkus.build.version>
<quarkus.version>3.24.2</quarkus.version>
<quarkus.build.version>3.24.2</quarkus.build.version>
<jboss-logging-annotations.version>3.0.4.Final</jboss-logging-annotations.version> <!-- keep in sync with the version used by quarkus -->

<project.build-time>${timestamp}</project.build-time>
Expand Down Expand Up @@ -120,7 +120,7 @@
<undertow.version>${undertow-legacy.version}</undertow.version>
<undertow-legacy.version>2.2.24.Final</undertow-legacy.version>
<undertow-jakarta.version>2.3.2.Final</undertow-jakarta.version>
<wildfly-elytron.version>2.6.3.Final</wildfly-elytron.version>
<wildfly-elytron.version>2.6.4.Final</wildfly-elytron.version>
<elytron.undertow-server.version>1.9.0.Final</elytron.undertow-server.version>
<woodstox.version>6.0.3</woodstox.version>
<wildfly.common.quarkus.aligned.version>1.5.4.Final-format-001</wildfly.common.quarkus.aligned.version>
Expand Down Expand Up @@ -158,14 +158,14 @@
<postgresql.container>mirror.gcr.io/postgres:${postgresql.version}</postgresql.container>
<aurora-postgresql.version>16.8</aurora-postgresql.version>
<aws-jdbc-wrapper.version>2.5.6</aws-jdbc-wrapper.version>
<postgresql-jdbc.version>42.7.5</postgresql-jdbc.version>
<postgresql-jdbc.version>42.7.7</postgresql-jdbc.version>
<mariadb.version>11.4</mariadb.version>
<mariadb.container>mirror.gcr.io/mariadb:${mariadb.version}</mariadb.container>
<mariadb-jdbc.version>3.5.2</mariadb-jdbc.version>
<mariadb-jdbc.version>3.5.4</mariadb-jdbc.version>
<mssql.version>2022</mssql.version>
<mssql.container>mcr.microsoft.com/mssql/server:${mssql.version}-latest</mssql.container>
<!-- this is the mssql driver version also used in the Quarkus BOM -->
<mssql-jdbc.version>12.8.1.jre11</mssql-jdbc.version>
<mssql-jdbc.version>12.10.0.jre11</mssql-jdbc.version>
<oracledb.version>23.5</oracledb.version>
<oracledb.container>mirror.gcr.io/gvenzl/oracle-free:${oracledb.version}-slim-faststart</oracledb.container>
<!-- this is the oracle driver version also used in the Quarkus BOM -->
Expand Down
20 changes: 20 additions & 0 deletions quarkus/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc-deployment</artifactId>
<exclusions>
<exclusion>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc-dev</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
Expand All @@ -52,6 +58,10 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-vertx-http-dev-ui-resources</artifactId>
</exclusion>
<exclusion>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-assistant-dev</artifactId>
</exclusion>
<exclusion>
<groupId>io.mvnpm</groupId>
<artifactId>importmap</artifactId>
Expand Down Expand Up @@ -115,6 +125,12 @@
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-deployment</artifactId>
<exclusions>
<exclusion>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-dev</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
Expand All @@ -132,6 +148,10 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-devservices-deployment</artifactId>
</exclusion>
<exclusion>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-datasource-dev</artifactId>
</exclusion>
<exclusion>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-agroal-dev</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@
import io.quarkus.vertx.http.deployment.NonApplicationRootPathBuildItem;
import io.quarkus.vertx.http.deployment.RouteBuildItem;
import jakarta.persistence.Entity;
import jakarta.persistence.spi.PersistenceUnitTransactionType;
import jakarta.persistence.PersistenceUnitTransactionType;
import org.eclipse.microprofile.health.Readiness;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.jpa.boot.internal.ParsedPersistenceXmlDescriptor;
import org.hibernate.jpa.boot.internal.PersistenceXmlParser;
import org.hibernate.jpa.boot.spi.PersistenceUnitDescriptor;
import org.hibernate.jpa.boot.spi.PersistenceXmlParser;
import org.infinispan.protostream.SerializationContextInitializer;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationTarget;
Expand Down Expand Up @@ -141,11 +141,13 @@
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.NoSuchElementException;
import java.util.Optional;
import java.util.Properties;
import java.util.ServiceLoader;
Expand Down Expand Up @@ -413,8 +415,12 @@ void configurePersistenceUnits(HibernateOrmConfig config,
@Consume(CheckJdbcBuildStep.class)
@Consume(CheckMultipleDatasourcesBuildStep.class)
void produceDefaultPersistenceUnit(BuildProducer<PersistenceXmlDescriptorBuildItem> producer) {
ParsedPersistenceXmlDescriptor descriptor = PersistenceXmlParser.locateIndividualPersistenceUnit(
Thread.currentThread().getContextClassLoader().getResource("default-persistence.xml"));
PersistenceXmlParser parser = PersistenceXmlParser.create();
PersistenceUnitDescriptor descriptor = parser.parse(Collections.singletonList(parser.getClassLoaderService().locateResource("default-persistence.xml")))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as described for the JPAUtils.

.values()
.stream()
.findAny()
.orElseThrow(() -> new NoSuchElementException("Cannot find the file 'default-persistence.xml'"));

producer.produce(new PersistenceXmlDescriptorBuildItem(descriptor));
}
Expand Down Expand Up @@ -546,7 +552,8 @@ private void configureUserDefinedPersistenceUnits(List<PersistenceXmlDescriptorB
descriptors.stream()
.map(PersistenceXmlDescriptorBuildItem::getDescriptor)
.map(PersistenceUnitDescriptor::getName)
.filter(Predicate.not("keycloak-default"::equals)).forEach((String unitName) -> {
.filter(Predicate.not("keycloak-default"::equals))
.forEach((String unitName) -> {
NamedJpaConnectionProviderFactory factory = new NamedJpaConnectionProviderFactory();

factory.setUnitName(unitName);
Expand Down
Loading
0