From 0f9b0ab52e8598e217a5fb66fa6ff8e7fbd603f7 Mon Sep 17 00:00:00 2001 From: Gavin King Date: Fri, 20 Sep 2024 21:27:53 +0200 Subject: [PATCH] add PUI.getAllManagedClassNames and PP.getClassTransformer see issue #650 Signed-off-by: Gavin King --- .../persistence/spi/PersistenceProvider.java | 33 +++++++++++++++++++ .../persistence/spi/PersistenceUnitInfo.java | 22 +++++++++++-- 2 files changed, 52 insertions(+), 3 deletions(-) diff --git a/api/src/main/java/jakarta/persistence/spi/PersistenceProvider.java b/api/src/main/java/jakarta/persistence/spi/PersistenceProvider.java index d9dd73e5..c5f3df93 100644 --- a/api/src/main/java/jakarta/persistence/spi/PersistenceProvider.java +++ b/api/src/main/java/jakarta/persistence/spi/PersistenceProvider.java @@ -11,6 +11,7 @@ */ // Contributors: +// Gavin King - 4.0 // Gavin King - 3.2 // Linda DeMichiel - 2.1 // Linda DeMichiel - 2.0 @@ -138,5 +139,37 @@ public interface PersistenceProvider { * @since 2.0 */ ProviderUtil getProviderUtil(); + + /** + * Obtain a transformer supplied by the provider that is called + * for every new class definition or class redefinition that gets + * loaded by the loader returned by the + * {@link PersistenceUnitInfo#getClassLoader} method. The + * transformer has no effect on the result returned by the + * {@link PersistenceUnitInfo#getNewTempClassLoader} method. + * Classes are only transformed once within the same classloading + * scope, regardless of how many persistence units they may be + * a part of. + *

The given instance of {@link PersistenceUnitInfo} may + * return {@code null} when any one the accessor methods + * {@link PersistenceUnitInfo#getClassLoader()}, + * {@link PersistenceUnitInfo#getJtaDataSource()}, or + * {@link PersistenceUnitInfo#getNonJtaDataSource()} is called + * by an implementation of this method. + *

If the container calls this method before invoking + * {@link #createContainerEntityManagerFactory} to create the + * {@link EntityManagerFactory}, then the transformer returned + * by this method is used instead of any transformer registered + * via {@link PersistenceUnitInfo#addTransformer}. The container + * is not required to call this method. + * @return provider-supplied transformer that the + * container invokes at class-(re)definition time + * @param info metadata for use by the persistence provider + * @param map a Map of integration-level properties for use + * by the persistence provider, which will not usually contain + * a {@code ValidatorFactory} or {@code BeanManager}. + * @since 4.0 + */ + ClassTransformer getClassTransformer(PersistenceUnitInfo info, Map map); } diff --git a/api/src/main/java/jakarta/persistence/spi/PersistenceUnitInfo.java b/api/src/main/java/jakarta/persistence/spi/PersistenceUnitInfo.java index f6cbb4aa..a114526a 100644 --- a/api/src/main/java/jakarta/persistence/spi/PersistenceUnitInfo.java +++ b/api/src/main/java/jakarta/persistence/spi/PersistenceUnitInfo.java @@ -11,6 +11,7 @@ */ // Contributors: +// Gavin King - 4.0 // Lukas Jungmann - 3.2 // Linda DeMichiel - 2.1 // Linda DeMichiel - 2.0 @@ -19,6 +20,7 @@ import javax.sql.DataSource; import java.util.List; +import java.util.Map; import java.util.Properties; import java.net.URL; import jakarta.persistence.SharedCacheMode; @@ -147,14 +149,25 @@ public interface PersistenceUnitInfo { /** * Returns the list of the names of the classes that the * persistence provider must add to its set of managed - * classes. Each name corresponds to a named {@code class} element in the - * {@code persistence.xml} file. + * classes. Each name corresponds to a named {@code class} + * element in the {@code persistence.xml} file. * @return the list of the names of the classes that the * persistence provider must add to its set of managed * classes */ List getManagedClassNames(); + /** + * Returns the list of names of all managed classes in + * the persistence unit, whether named explicitly in the + * {@code persistence.xml} file, or discovered by the + * container via scanning. + * @return the list of names of all managed classes in + * the persistence unit + * @since 4.0 + */ + List getAllManagedClassNames(); + /** * Returns whether classes in the root of the persistence unit * that have not been explicitly listed are to be included in the @@ -225,7 +238,10 @@ public interface PersistenceUnitInfo { * Classes are only transformed once within the same classloading * scope, regardless of how many persistence units they may be * a part of. - * @param transformer provider-supplied transformer that the + *

If the container previously called + * {@link PersistenceProvider#getClassTransformer} with this + * {@code PersistenceUnitInfo}, then this method has no effect. + * @param transformer provider-supplied transformer that the * container invokes at class-(re)definition time */ void addTransformer(ClassTransformer transformer);