+ *
+ * @return a non-{@code null} {@link TransactionManager}
+ *
+ * @see #CDISEJtaPlatform(TransactionManager, UserTransaction)
+ */
+ @Override
+ protected TransactionManager locateTransactionManager() {
+ return this.transactionManager;
+ }
+
+ /**
+ * Customizes the supplied {@link PersistenceUnitInfo}, when it is fired as a CDI event by, for example, the {@code
+ * io.helidon.integrations.cdi.jpa.PersistenceExtension} portable extension, by ensuring that certain important
+ * Hibernate properties are always set on the persistence unit.
+ *
+ * @param pui the {@link PersistenceUnitInfo} to customize; must not be {@code null}
+ *
+ * @exception NullPointerException if {@code pui} is {@code null}
+ *
+ * @see
+ * org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode#DELAYED_ACQUISITION_AND_RELEASE_AFTER_TRANSACTION
+ */
+ private static void customizePersistenceUnitInfo(@Observes PersistenceUnitInfo pui) {
+ Properties p = pui.getProperties();
+ if (p != null && p.getProperty(CONNECTION_HANDLING) == null && p.get(CONNECTION_HANDLING) == null) {
+ if (LOGGER.isLoggable(DEBUG)) {
+ LOGGER.log(DEBUG, "Setting " + CONNECTION_HANDLING + " property to "
+ + DELAYED_ACQUISITION_AND_RELEASE_AFTER_TRANSACTION
+ + " on persistence unit " + pui.getPersistenceUnitName());
+ }
+ p.setProperty(CONNECTION_HANDLING, DELAYED_ACQUISITION_AND_RELEASE_AFTER_TRANSACTION.toString());
+ }
+ }
}
diff --git a/integrations/cdi/hibernate-cdi/src/main/java/module-info.java b/integrations/cdi/hibernate-cdi/src/main/java/module-info.java
index 796ad93e635..7ce24bf0496 100644
--- a/integrations/cdi/hibernate-cdi/src/main/java/module-info.java
+++ b/integrations/cdi/hibernate-cdi/src/main/java/module-info.java
@@ -35,15 +35,15 @@
@Aot(description = "Experimental support, tested on limited use cases")
@SuppressWarnings({ "requires-automatic", "requires-transitive-automatic" })
module io.helidon.integrations.cdi.hibernate {
- requires jakarta.cdi;
- requires jakarta.inject;
- requires java.sql;
-
- requires static io.helidon.common.features.api;
+ requires transitive jakarta.cdi;
+ requires transitive jakarta.inject;
+ requires jakarta.persistence;
requires transitive jakarta.transaction;
requires transitive org.hibernate.orm.core;
+ requires static io.helidon.common.features.api;
+
exports io.helidon.integrations.cdi.hibernate;
provides org.hibernate.engine.transaction.jta.platform.spi.JtaPlatformProvider
diff --git a/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/BeanManagerBackedDataSourceProvider.java b/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/BeanManagerBackedDataSourceProvider.java
index 5c1691cba7f..58b22f310d8 100644
--- a/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/BeanManagerBackedDataSourceProvider.java
+++ b/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/BeanManagerBackedDataSourceProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, 2021 Oracle and/or its affiliates.
+ * Copyright (c) 2019, 2023 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -34,8 +34,12 @@
* @see PersistenceUnitInfoBean.DataSourceProvider
*
* @see JtaDataSourceProvider
+ *
+ * @deprecated This is an internal class used by the now-deprecated {@link JpaExtension} class. Its replacement is an
+ * internal class, {@link JtaAbsentDataSourceProvider}, used by the {@link PersistenceExtension} class.
*/
@ApplicationScoped
+@Deprecated(since = "4.0")
class BeanManagerBackedDataSourceProvider implements PersistenceUnitInfoBean.DataSourceProvider {
diff --git a/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/CdiTransactionScoped.java b/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/CdiTransactionScoped.java
index 4b0b692601c..406b9c32283 100644
--- a/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/CdiTransactionScoped.java
+++ b/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/CdiTransactionScoped.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, 2021 Oracle and/or its affiliates.
+ * Copyright (c) 2019, 2023 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,7 +28,10 @@
*
*
This qualifier must not be combined with {@link Extended},
* {@link JpaTransactionScoped} or {@link NonTransactional}.
+ *
+ * @deprecated No replacement.
*/
+@Deprecated(since = "4.0")
@Qualifier
@Retention(RetentionPolicy.RUNTIME)
@Target({}) // can only be programmatically added
diff --git a/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/CdiTransactionScopedEntityManager.java b/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/CdiTransactionScopedEntityManager.java
index 818770b7c90..8615c05dc77 100644
--- a/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/CdiTransactionScopedEntityManager.java
+++ b/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/CdiTransactionScopedEntityManager.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, 2021 Oracle and/or its affiliates.
+ * Copyright (c) 2019, 2023 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -50,7 +50,11 @@
* this class are not safe for concurrent use by multiple threads.
*
* @see JpaExtension
+ *
+ * @deprecated This is an internal class used by the now-deprecated {@link JpaExtension} class. Its replacement is an
+ * internal detail of the {@link PersistenceExtension} class.
*/
+@Deprecated(since = "4.0")
@Vetoed
class CdiTransactionScopedEntityManager extends DelegatingEntityManager {
diff --git a/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/ClearingQuery.java b/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/ClearingQuery.java
index 6ac39fc2578..27d054531c7 100644
--- a/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/ClearingQuery.java
+++ b/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/ClearingQuery.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, 2021 Oracle and/or its affiliates.
+ * Copyright (c) 2019, 2023 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@
import jakarta.persistence.EntityManager;
import jakarta.persistence.Query;
+@Deprecated(since = "4.0")
final class ClearingQuery extends DelegatingQuery {
private final EntityManager entityManager;
diff --git a/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/ClearingStoredProcedureQuery.java b/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/ClearingStoredProcedureQuery.java
index 8077a080c7a..7f903b97140 100644
--- a/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/ClearingStoredProcedureQuery.java
+++ b/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/ClearingStoredProcedureQuery.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, 2021 Oracle and/or its affiliates.
+ * Copyright (c) 2019, 2023 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@
import jakarta.persistence.EntityManager;
import jakarta.persistence.StoredProcedureQuery;
+@Deprecated(since = "4.0")
final class ClearingStoredProcedureQuery extends DelegatingStoredProcedureQuery {
private final EntityManager entityManager;
diff --git a/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/ClearingTypedQuery.java b/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/ClearingTypedQuery.java
index f3658fc8d06..7218e8d37a6 100644
--- a/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/ClearingTypedQuery.java
+++ b/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/ClearingTypedQuery.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, 2021 Oracle and/or its affiliates.
+ * Copyright (c) 2019, 2023 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@
import jakarta.persistence.EntityManager;
import jakarta.persistence.TypedQuery;
+@Deprecated(since = "4.0")
final class ClearingTypedQuery extends DelegatingTypedQuery {
private final EntityManager entityManager;
diff --git a/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/EntityManagerFactories.java b/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/EntityManagerFactories.java
index 1a2bd558b2b..bec60f163f5 100644
--- a/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/EntityManagerFactories.java
+++ b/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/EntityManagerFactories.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, 2021 Oracle and/or its affiliates.
+ * Copyright (c) 2019, 2023 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -46,7 +46,10 @@
*
* @see PersistenceProvider#createContainerEntityManagerFactory(PersistenceUnitInfo,
* Map)
+ *
+ * @deprecated This is an internal class used only by the now-deprecated {@link JpaExtension} class.
*/
+@Deprecated(since = "4.0")
final class EntityManagerFactories {
diff --git a/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/EntityManagers.java b/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/EntityManagers.java
index a0edc72daf0..d951a3a8a3d 100644
--- a/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/EntityManagers.java
+++ b/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/EntityManagers.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, 2021 Oracle and/or its affiliates.
+ * Copyright (c) 2019, 2023 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -38,7 +38,10 @@
* requirements of the JPA specification.
*
* @see #createContainerManagedEntityManager(Instance, Set)
+ *
+ * @deprecated This is an internal class used only by the now-deprecated {@link JpaExtension} class.
*/
+@Deprecated(since = "4.0")
final class EntityManagers {
diff --git a/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/ExtendedEntityManager.java b/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/ExtendedEntityManager.java
index 7818fde33a1..4581aab3ded 100644
--- a/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/ExtendedEntityManager.java
+++ b/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/ExtendedEntityManager.java
@@ -30,7 +30,10 @@
/**
* A {@link DelegatingEntityManager} created to support extended
* persistence contexts.
+ *
+ * @deprecated This is an internal class used by the now-deprecated {@link JpaExtension} class.
*/
+@Deprecated(since = "4.0")
class ExtendedEntityManager extends DelegatingEntityManager {
diff --git a/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/JpaCdiQualifiers.java b/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/JpaCdiQualifiers.java
index 135cc71e8b1..9452109dde6 100644
--- a/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/JpaCdiQualifiers.java
+++ b/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/JpaCdiQualifiers.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, 2021 Oracle and/or its affiliates.
+ * Copyright (c) 2019, 2023 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,7 +25,11 @@
* defined by this package.
*
* @see #JPA_CDI_QUALIFIERS
+ *
+ * @deprecated This is an internal class used only by the now-deprecated {@link JpaExtension}, {@link EntityManagers}
+ * and {@link EntityManagerFactories} classes.
*/
+@Deprecated(since = "4.0")
final class JpaCdiQualifiers {
diff --git a/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/JpaExtension.java b/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/JpaExtension.java
index 86594a348ac..074e8c28321 100644
--- a/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/JpaExtension.java
+++ b/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/JpaExtension.java
@@ -20,6 +20,7 @@
import java.io.InputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
+import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLClassLoader;
import java.security.CodeSource;
@@ -114,7 +115,10 @@
* multiple threads.
*
* @see PersistenceUnitInfoBean
+ *
+ * @deprecated Please use {@link PersistenceExtension} instead.
*/
+@Deprecated(since = "4.0")
public class JpaExtension implements Extension {
@@ -158,7 +162,9 @@ public class JpaExtension implements Extension {
/**
* Whether or not this extension will do anything.
*
- *
This field's value is {@code true} by default.
+ *
This field's value is {@code false} by default.
+ *
+ * @see PersistenceExtension
*/
private final boolean enabled;
@@ -309,7 +315,7 @@ public JpaExtension() {
if (LOGGER.isLoggable(Level.FINER)) {
LOGGER.entering(cn, mn);
}
- this.enabled = Boolean.parseBoolean(System.getProperty(this.getClass().getName() + ".enabled", "true"));
+ this.enabled = Boolean.parseBoolean(System.getProperty(this.getClass().getName() + ".enabled", "false"));
if (LOGGER.isLoggable(Level.FINE) && !this.enabled) {
LOGGER.logp(Level.FINE, cn, mn, "jpaExtensionDisabled", this.getClass().getName());
}
@@ -812,7 +818,7 @@ private void afterBeanDiscovery(@Observes
@Priority(LIBRARY_AFTER)
AfterBeanDiscovery event,
BeanManager beanManager)
- throws IOException, JAXBException, ReflectiveOperationException, XMLStreamException {
+ throws IOException, JAXBException, ReflectiveOperationException, URISyntaxException, XMLStreamException {
String cn = JpaExtension.class.getName();
String mn = "afterBeanDiscovery";
if (LOGGER.isLoggable(Level.FINER)) {
@@ -1357,7 +1363,7 @@ private void processPersistenceXmls(AfterBeanDiscovery event,
Enumeration urls,
Collection extends PersistenceProvider> providers,
boolean userSuppliedPersistenceUnitInfoBeans)
- throws IOException, JAXBException, ReflectiveOperationException, XMLStreamException {
+ throws IOException, JAXBException, ReflectiveOperationException, URISyntaxException, XMLStreamException {
String cn = JpaExtension.class.getName();
String mn = "processPersistenceXmls";
if (LOGGER.isLoggable(Level.FINER)) {
@@ -1428,7 +1434,7 @@ private void processPersistenceXmls(AfterBeanDiscovery event,
.add(PersistenceUnitInfoBean.fromPersistenceUnit(persistenceUnit,
classLoader,
tempClassLoaderSupplier,
- new URL(url, ".."), // i.e. META-INF/..
+ url.toURI().resolve("..").toURL(),
unlistedManagedClassesByPersistenceUnitNames,
dataSourceProviderSupplier));
}
diff --git a/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/JpaTransactionScoped.java b/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/JpaTransactionScoped.java
index d6dfc6c65b4..0d135d1fe0a 100644
--- a/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/JpaTransactionScoped.java
+++ b/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/JpaTransactionScoped.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, 2021 Oracle and/or its affiliates.
+ * Copyright (c) 2019, 2023 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,7 +28,10 @@
*
*
This qualifier must not be combined with {@link Extended},
* {@link CdiTransactionScoped} or {@link NonTransactional}.
+ *
+ * @deprecated This is an internal class used only by the now-deprecated {@link JpaExtension} class.
*/
+@Deprecated(since = "4.0")
@Qualifier
@Retention(RetentionPolicy.RUNTIME)
@Target({}) // can only be programmatically added
diff --git a/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/JpaTransactionScopedEntityManager.java b/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/JpaTransactionScopedEntityManager.java
index e26f499fb81..4e52e9afb34 100644
--- a/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/JpaTransactionScopedEntityManager.java
+++ b/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/JpaTransactionScopedEntityManager.java
@@ -57,7 +57,10 @@
*
*
As with all {@link EntityManager} implementations, instances of
* this class are not safe for concurrent use by multiple threads.
+ *
+ * @deprecated This is an internal class used only by the now-deprecated {@link JpaExtension} class.
*/
+@Deprecated(since = "4.0")
@Vetoed
final class JpaTransactionScopedEntityManager extends DelegatingEntityManager {
diff --git a/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/JtaDataSourceProvider.java b/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/JtaDataSourceProvider.java
index 7656815cc89..d2ea58cf26f 100644
--- a/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/JtaDataSourceProvider.java
+++ b/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/JtaDataSourceProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, 2021 Oracle and/or its affiliates.
+ * Copyright (c) 2019, 2023 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -46,6 +46,7 @@
import jakarta.transaction.TransactionSynchronizationRegistry;
@ApplicationScoped
+@Deprecated(since = "4.0")
class JtaDataSourceProvider implements PersistenceUnitInfoBean.DataSourceProvider {
diff --git a/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/JtaTransactionSupport.java b/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/JtaTransactionSupport.java
index 7ce0355214f..f0be504555c 100644
--- a/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/JtaTransactionSupport.java
+++ b/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/JtaTransactionSupport.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, 2021 Oracle and/or its affiliates.
+ * Copyright (c) 2019, 2023 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -41,8 +41,11 @@
* @see TransactionSupport
*
* @see NoTransactionSupport
+ *
+ * @deprecated This is an internal class used only by the now-deprecated {@link JpaExtension} class.
*/
@ApplicationScoped
+@Deprecated(since = "4.0")
class JtaTransactionSupport implements TransactionSupport {
diff --git a/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/Messages.java b/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/Messages.java
index e047697eb0e..eb5ee4a36a0 100644
--- a/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/Messages.java
+++ b/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/Messages.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, 2021 Oracle and/or its affiliates.
+ * Copyright (c) 2019, 2023 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@
import java.text.MessageFormat;
import java.util.ResourceBundle;
+@Deprecated(since = "4.0")
final class Messages {
private static final ResourceBundle MESSAGES = ResourceBundle.getBundle(Messages.class.getName());
diff --git a/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/NoTransactionSupport.java b/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/NoTransactionSupport.java
index e87ecfe729c..6bbbb863ff1 100644
--- a/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/NoTransactionSupport.java
+++ b/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/NoTransactionSupport.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, 2021 Oracle and/or its affiliates.
+ * Copyright (c) 2019, 2023 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -31,8 +31,11 @@
* @see TransactionSupport
*
* @see JtaTransactionSupport
+ *
+ * @deprecated This is an internal class used only by the now-deprecated {@link JpaExtension} class.
*/
@ApplicationScoped
+@Deprecated(since = "4.0")
final class NoTransactionSupport implements TransactionSupport {
diff --git a/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/NonTransactional.java b/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/NonTransactional.java
index 2c639124ebf..d47008c38b0 100644
--- a/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/NonTransactional.java
+++ b/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/NonTransactional.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, 2021 Oracle and/or its affiliates.
+ * Copyright (c) 2019, 2023 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -29,7 +29,10 @@
*
This qualifier must not be combined with {@link
* CdiTransactionScoped}, {@link Extended} or {@code
* JpaTransactionScoped}.
+ *
+ * @deprecated This is an internal class used only by the now-deprecated {@link JpaExtension} class.
*/
+@Deprecated(since = "4.0")
@Qualifier
@Retention(RetentionPolicy.RUNTIME)
@Target({}) // can only be programmatically added
diff --git a/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/NonTransactionalEntityManager.java b/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/NonTransactionalEntityManager.java
index 6516b8352ca..68e374cd0b8 100644
--- a/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/NonTransactionalEntityManager.java
+++ b/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/NonTransactionalEntityManager.java
@@ -44,7 +44,7 @@
* #acquireDelegate()} method and only under appropriate
* circumstances.
*
- *
This class is added as a synthetic bean by the {@link
+ *
This class is added as a synthetic bean by the (now-deprecated) {@link
* JpaExtension} class.
*
*
Implementation Notes
@@ -60,7 +60,10 @@
* this class are not safe for concurrent use by multiple threads.
*
* @see JpaExtension
+ *
+ * @deprecated This is an internal class used only by the now-deprecated {@link JpaExtension} class.
*/
+@Deprecated(since = "4.0")
@Vetoed
class NonTransactionalEntityManager extends DelegatingEntityManager {
diff --git a/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/PersistenceExtension.java b/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/PersistenceExtension.java
index 31767003a1d..a48a031c642 100644
--- a/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/PersistenceExtension.java
+++ b/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/PersistenceExtension.java
@@ -21,6 +21,7 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.net.MalformedURLException;
+import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLClassLoader;
import java.security.CodeSource;
@@ -55,6 +56,7 @@
import jakarta.annotation.Priority;
import jakarta.enterprise.context.Dependent;
import jakarta.enterprise.context.spi.CreationalContext;
+import jakarta.enterprise.event.Event;
import jakarta.enterprise.event.Observes;
import jakarta.enterprise.inject.Any;
import jakarta.enterprise.inject.CreationException;
@@ -110,8 +112,8 @@
/**
* An {@link Extension} that integrates container-modeJakarta Persistence
- * 3.0 into CDI SE 3.0-based
+ * href="https://jakarta.ee/specifications/persistence/3.1/jakarta-persistence-spec-3.1.html">Jakarta Persistence
+ * 3.1 into CDI SE 4.0-based
* applications.
*/
public final class PersistenceExtension implements Extension {
@@ -136,12 +138,13 @@ public final class PersistenceExtension implements Extension {
*
*
In such a case, the injection point will be effectively rewritten such that it will appear to the CDI
* container as though there were a value specified for the {@link PersistenceContext#unitName() unitName}
- * element—namely this field's value. Additionally, a bean identical to the existing solitary {@link
- * PersistenceUnitInfo}-typed bean will be added with this field's value as the {@linkplain Named#value() value of
- * its Named qualifier}, thus serving as a kind of alias for the "real" bean.
+ * element—namely this field's value ({@value #DEFAULT_PERSISTENCE_UNIT_NAME}). Additionally, a bean
+ * identical to the existing solitary {@link PersistenceUnitInfo}-typed bean will be added with this field's value
+ * as the {@linkplain Named#value() value of its Named qualifier}, thus serving as a kind of alias for
+ * the "real" bean.
*
*
This is necessary because the empty string ({@code ""}) as the value of the {@link Named#value()} element can
- * have special
+ * have special
* semantics, so cannot be used to designate an unnamed or otherwise default persistence unit.
*
*
The value of this field is subject to change without prior notice at any point. In general the mechanics
@@ -151,6 +154,9 @@ public final class PersistenceExtension implements Extension {
private static final Annotation[] EMPTY_ANNOTATION_ARRAY = new Annotation[0];
+ private static final TypeLiteral> EVENT_PERSISTENCEUNITINFOBEAN_TYPELITERAL =
+ new TypeLiteral<>() {};
+
private static final Logger LOGGER = Logger.getLogger(PersistenceExtension.class.getName());
@@ -228,7 +234,7 @@ public final class PersistenceExtension implements Extension {
/**
* Indicates if JTA transactions can be supported.
*
- * @see #addAllocatorBeanAndInstallTransactionSupport(AfterTypeDiscovery)
+ * @see #addTypes(AfterTypeDiscovery)
*/
private boolean transactionsSupported;
@@ -260,7 +266,7 @@ public final class PersistenceExtension implements Extension {
@Deprecated // For invocation by CDI only.
public PersistenceExtension() {
super();
- this.enabled = Boolean.parseBoolean(System.getProperty(this.getClass().getName() + ".enabled", "false"));
+ this.enabled = Boolean.parseBoolean(System.getProperty(this.getClass().getName() + ".enabled", "true"));
this.containerManagedEntityManagerQualifiers = new HashSet<>();
this.containerManagedEntityManagerFactoryQualifiers = new HashSet<>();
this.entityManagerFactoryQualifiers = new HashSet<>();
@@ -311,6 +317,7 @@ private void makePersistencePropertyARepeatableQualifier(@Observes BeforeBea
*
* @see JtaAdaptingDataSourceProvider
*/
+ @SuppressWarnings("deprecation")
private void vetoDeprecatedJtaDataSourceProvider(@Observes ProcessBeanAttributes event) {
if (!this.enabled) {
return;
@@ -326,6 +333,33 @@ private void vetoDeprecatedJtaDataSourceProvider(@Observes ProcessBeanAttributes
event.veto();
}
+ /**
+ * {@linkplain ProcessBeanAttributes#veto() Vetoes} any bean whose bean types includes the deprecated {@link
+ * BeanManagerBackedDataSourceProvider} class, since it is replaced by {@link JtaAbsentDataSourceProvider}.
+ *
+ * @param event the {@link ProcessBeanAttributes} event in question; must not be {@code null}
+ *
+ * @exception NullPointerException if {@code event} is {@code null}
+ *
+ * @see JtaAbsentDataSourceProvider
+ */
+ @SuppressWarnings("deprecation")
+ private void vetoDeprecatedBeanManagerBackedDataSourceProvider(@Observes
+ ProcessBeanAttributes e) {
+ if (!this.enabled) {
+ return;
+ }
+ if (LOGGER.isLoggable(Level.FINE)) {
+ LOGGER.logp(Level.FINE, this.getClass().getName(), "vetoDeprecatedBeanManagerBackedDataSourceProvider",
+ "Vetoing BeanAttributes {0} representing "
+ + BeanManagerBackedDataSourceProvider.class
+ + " because it is deprecated and "
+ + JtaAbsentDataSourceProvider.class
+ + " replaces it", e.getBeanAttributes());
+ }
+ e.veto();
+ }
+
private void rewriteJpaAnnotations(@Observes
@WithAnnotations({PersistenceContext.class, PersistenceUnit.class})
ProcessAnnotatedType event) {
@@ -452,8 +486,8 @@ private void discoverManagedClasses(@Observes
*
* @exception NullPointerException if {@code e} is {@code null}
*/
- @SuppressWarnings("checkstyle:LineLength")
- private void saveContainerManagedEntityManagerFactoryQualifiers(@Observes ProcessInjectionPoint, T> e) {
+ private void
+ saveContainerManagedEntityManagerFactoryQualifiers(@Observes ProcessInjectionPoint, T> e) {
if (!this.enabled) {
return;
}
@@ -529,7 +563,8 @@ private void saveContainerManagedEntityManagerQualifie
*
* @see #addContainerManagedJpaBeans(AfterBeanDiscovery)
*/
- private void addSyntheticBeans(@Observes @Priority(LIBRARY_AFTER) AfterBeanDiscovery event, BeanManager bm) {
+ private void addSyntheticBeans(@Observes @Priority(LIBRARY_AFTER) AfterBeanDiscovery event, BeanManager bm)
+ throws URISyntaxException {
if (!this.enabled) {
return;
}
@@ -958,7 +993,7 @@ private void addPersistenceProviderBeanIfAbsent(AfterBeanDiscovery event,
.addTransitiveTypeClosure(PersistenceProvider.class)
.scope(Singleton.class)
.qualifiers(NamedLiteral.of(unitName))
- .createWith(cc -> {
+ .produceWith(i -> {
try {
ClassLoader classLoader = pui.getClassLoader();
if (classLoader == null) {
@@ -976,7 +1011,8 @@ private void processPersistenceXmls(AfterBeanDiscovery event,
ClassLoader classLoader,
Enumeration persistenceXmlUrls,
Iterable extends PersistenceProvider> providers,
- boolean userSuppliedPuiBeans) {
+ boolean userSuppliedPuiBeans)
+ throws URISyntaxException {
if (!persistenceXmlUrls.hasMoreElements()) {
return;
}
@@ -997,7 +1033,7 @@ private void processPersistenceXmls(AfterBeanDiscovery event,
}
Supplier extends DataSourceProvider> dataSourceProviderSupplier =
() -> bm.createInstance().select(DataSourceProvider.class).get();
- PersistenceUnitInfo solePui = null;
+ PersistenceUnitInfoBean solePui = null;
Supplier extends ClassLoader> tempClassLoaderSupplier =
classLoader instanceof URLClassLoader ucl ? () -> new URLClassLoader(ucl.getURLs()) : () -> classLoader;
for (int puCount = 0; persistenceXmlUrls.hasMoreElements();) {
@@ -1021,7 +1057,7 @@ private void processPersistenceXmls(AfterBeanDiscovery event,
PersistenceUnitInfoBean.fromPersistenceUnit(pu,
classLoader,
tempClassLoaderSupplier,
- new URL(persistenceXmlUrl, ".."), // i.e. META-INF/..
+ persistenceXmlUrl.toURI().resolve("..").toURL(),
unlistedManagedClassesByUnitNames,
dataSourceProviderSupplier);
} catch (MalformedURLException e) {
@@ -1032,6 +1068,7 @@ private void processPersistenceXmls(AfterBeanDiscovery event,
if (unitName == null || unitName.isBlank()) {
unitName = DEFAULT_PERSISTENCE_UNIT_NAME;
}
+ Named qualifier = NamedLiteral.of(unitName);
// Provide support for, e.g.:
// @Inject
// @Named("test")
@@ -1040,8 +1077,8 @@ private void processPersistenceXmls(AfterBeanDiscovery event,
.beanClass(PersistenceUnitInfoBean.class)
.addTransitiveTypeClosure(PersistenceUnitInfoBean.class)
.scope(Singleton.class)
- .qualifiers(NamedLiteral.of(unitName))
- .createWith(cc -> pui);
+ .qualifiers(qualifier)
+ .produceWith(i -> producePersistenceUnitInfoBean(i, pui, qualifier));
addPersistenceProviderBeanIfAbsent(event, pui, providers);
if (puCount == 0) {
solePui = pui;
@@ -1056,17 +1093,18 @@ private void processPersistenceXmls(AfterBeanDiscovery event,
assert soleUnitName != null;
assert !soleUnitName.isBlank();
if (!soleUnitName.equals(DEFAULT_PERSISTENCE_UNIT_NAME)) {
- PersistenceUnitInfo pui = solePui;
+ PersistenceUnitInfoBean pui = solePui;
// Provide support for, e.g.:
// @Inject
// @Named("__DEFAULT__"))
// private PersistenceUnitInfo persistenceUnitInfo;
+ Named qualifier = NamedLiteral.of(DEFAULT_PERSISTENCE_UNIT_NAME);
event.addBean()
.beanClass(PersistenceUnitInfoBean.class)
.addTransitiveTypeClosure(PersistenceUnitInfoBean.class)
.scope(Singleton.class)
- .qualifiers(NamedLiteral.of(DEFAULT_PERSISTENCE_UNIT_NAME))
- .createWith(cc -> pui);
+ .qualifiers(qualifier)
+ .produceWith(i -> producePersistenceUnitInfoBean(i, pui, qualifier));
}
}
}
@@ -1087,6 +1125,7 @@ private void processImplicitPersistenceUnits(AfterBeanDiscovery event, Iterable<
}
}
}
+ Named qualifier = NamedLiteral.of(unitName);
// Provide support for, e.g.:
// @Inject
// @Named("test")
@@ -1095,8 +1134,8 @@ private void processImplicitPersistenceUnits(AfterBeanDiscovery event, Iterable<
.beanClass(PersistenceUnitInfoBean.class)
.addTransitiveTypeClosure(PersistenceUnitInfoBean.class)
.scope(Singleton.class)
- .qualifiers(NamedLiteral.of(unitName))
- .createWith(cc -> pui);
+ .qualifiers(qualifier)
+ .produceWith(i -> producePersistenceUnitInfoBean(i, pui, qualifier));
addPersistenceProviderBeanIfAbsent(event, pui, providers);
if (puCount == 0) {
solePui = pui;
@@ -1112,6 +1151,7 @@ private void processImplicitPersistenceUnits(AfterBeanDiscovery event, Iterable<
assert !soleUnitName.isBlank();
if (!soleUnitName.equals(DEFAULT_PERSISTENCE_UNIT_NAME)) {
PersistenceUnitInfoBean pui = solePui;
+ Named qualifier = NamedLiteral.of(DEFAULT_PERSISTENCE_UNIT_NAME);
// Provide support for, e.g.:
// @Inject
// @Named("__DEFAULT__")
@@ -1120,8 +1160,8 @@ private void processImplicitPersistenceUnits(AfterBeanDiscovery event, Iterable<
.beanClass(PersistenceUnitInfoBean.class)
.addTransitiveTypeClosure(PersistenceUnitInfoBean.class)
.scope(Singleton.class)
- .qualifiers(NamedLiteral.of(DEFAULT_PERSISTENCE_UNIT_NAME))
- .createWith(cc -> pui);
+ .qualifiers(qualifier)
+ .produceWith(i -> producePersistenceUnitInfoBean(i, pui, qualifier));
}
}
}
@@ -1316,6 +1356,14 @@ private static void disposeJtaExtendedEntityManager(JtaExtendedEntityManager em,
containerManagedSelectionQualifiers);
}
+ private static PersistenceUnitInfoBean producePersistenceUnitInfoBean(Instance