diff --git a/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/AfterCompletionSynchronization.java b/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/AfterCompletionSynchronization.java
new file mode 100644
index 00000000000..75846c28507
--- /dev/null
+++ b/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/AfterCompletionSynchronization.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package io.helidon.integrations.cdi.jpa;
+
+import java.util.Objects;
+import java.util.function.IntConsumer;
+
+import jakarta.transaction.Synchronization;
+
+final class AfterCompletionSynchronization implements IntConsumer, Synchronization {
+
+ private final IntConsumer afterCompletion;
+
+ AfterCompletionSynchronization(IntConsumer afterCompletion) {
+ super();
+ this.afterCompletion = Objects.requireNonNull(afterCompletion, "afterCompletion");
+ }
+
+ @Override
+ public void beforeCompletion() {
+
+ }
+
+ @Override
+ public void afterCompletion(int completedTransactionStatus) {
+ this.accept(completedTransactionStatus);
+ }
+
+ @Override
+ public void accept(int completedTransactionStatus) {
+ this.afterCompletion.accept(completedTransactionStatus);
+ }
+
+}
diff --git a/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/DelegatingEntityManager.java b/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/DelegatingEntityManager.java
index af20d071626..130f20aaa87 100644
--- a/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/DelegatingEntityManager.java
+++ b/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/DelegatingEntityManager.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.
@@ -17,6 +17,7 @@
import java.util.List;
import java.util.Map;
+import java.util.function.Supplier;
import jakarta.persistence.EntityGraph;
import jakarta.persistence.EntityManager;
@@ -24,6 +25,7 @@
import jakarta.persistence.EntityTransaction;
import jakarta.persistence.FlushModeType;
import jakarta.persistence.LockModeType;
+import jakarta.persistence.PersistenceException;
import jakarta.persistence.Query;
import jakarta.persistence.StoredProcedureQuery;
import jakarta.persistence.TypedQuery;
@@ -50,19 +52,7 @@ abstract class DelegatingEntityManager implements EntityManager, AutoCloseable {
*/
- /**
- * The {@link EntityManager} to which all operations will be
- * forwarded if it is non-{@code null}.
- *
- * This field may be {@code null}.
- *
- * @see #DelegatingEntityManager(EntityManager)
- *
- * @see #delegate()
- *
- * @see #acquireDelegate()
- */
- private final EntityManager delegate;
+ private final Supplier extends EntityManager> supplier;
/*
@@ -80,7 +70,7 @@ abstract class DelegatingEntityManager implements EntityManager, AutoCloseable {
* @see #acquireDelegate()
*/
DelegatingEntityManager() {
- this(null);
+ this((Supplier extends EntityManager>) null);
}
/**
@@ -96,9 +86,13 @@ abstract class DelegatingEntityManager implements EntityManager, AutoCloseable {
*
* @see #acquireDelegate()
*/
- DelegatingEntityManager(final EntityManager delegate) {
+ DelegatingEntityManager(EntityManager delegate) {
+ this(delegate == null ? (Supplier extends EntityManager>) null : () -> delegate);
+ }
+
+ DelegatingEntityManager(Supplier extends EntityManager> supplier) {
super();
- this.delegate = delegate;
+ this.supplier = supplier == null ? this::acquireDelegate : supplier;
}
@@ -118,31 +112,23 @@ abstract class DelegatingEntityManager implements EntityManager, AutoCloseable {
* {@linkplain #DelegatingEntityManager(EntityManager) supplied at
* construction time}.
*
- * @return an {@link EntityManager}; never {@code null}
+ * @return an {@link EntityManager}
*
- * @exception jakarta.persistence.PersistenceException if an error
- * occurs
+ * @exception PersistenceException if an error occurs
*
* @see #acquireDelegate()
*
* @see #DelegatingEntityManager(EntityManager)
*/
- protected EntityManager delegate() {
- final EntityManager returnValue;
- if (this.delegate == null) {
- returnValue = this.acquireDelegate();
- } else {
- returnValue = this.delegate;
- }
- return returnValue;
+ EntityManager delegate() {
+ return this.supplier.get();
}
/**
* Returns an {@link EntityManager} to which all operations will
* be forwarded.
*
- * Implementations of this method must not return {@code
- * null}.
+ * Overrides of this method must not return {@code null}.
*
* This method is called by the {@link #delegate()} method and
* potentially on every method invocation of instances of this
@@ -154,55 +140,56 @@ protected EntityManager delegate() {
*
* @return a non-{@code null} {@link EntityManager}
*
- * @exception jakarta.persistence.PersistenceException if an error
- * occurs
+ * @exception PersistenceException if an error occurs
*
* @see #delegate()
*
* @see #DelegatingEntityManager(EntityManager)
*/
- protected abstract EntityManager acquireDelegate();
+ EntityManager acquireDelegate() {
+ throw new PersistenceException();
+ }
@Override
- public void persist(final Object entity) {
+ public void persist(Object entity) {
this.delegate().persist(entity);
}
@Override
- public T merge(final T entity) {
+ public T merge(T entity) {
return this.delegate().merge(entity);
}
@Override
- public void remove(final Object entity) {
+ public void remove(Object entity) {
this.delegate().remove(entity);
}
@Override
- public T find(final Class entityClass, final Object primaryKey) {
+ public T find(Class entityClass, Object primaryKey) {
return this.delegate().find(entityClass, primaryKey);
}
@Override
- public T find(final Class entityClass, final Object primaryKey, final Map properties) {
+ public T find(Class entityClass, Object primaryKey, Map properties) {
return this.delegate().find(entityClass, primaryKey, properties);
}
@Override
- public T find(final Class entityClass, final Object primaryKey, final LockModeType lockMode) {
+ public T find(Class entityClass, Object primaryKey, LockModeType lockMode) {
return this.delegate().find(entityClass, primaryKey, lockMode);
}
@Override
- public T find(final Class entityClass,
- final Object primaryKey,
- final LockModeType lockMode,
- final Map properties) {
+ public T find(Class entityClass,
+ Object primaryKey,
+ LockModeType lockMode,
+ Map properties) {
return this.delegate().find(entityClass, primaryKey, lockMode, properties);
}
@Override
- public T getReference(final Class entityClass, final Object primaryKey) {
+ public T getReference(Class entityClass, Object primaryKey) {
return this.delegate().getReference(entityClass, primaryKey);
}
@@ -212,7 +199,7 @@ public void flush() {
}
@Override
- public void setFlushMode(final FlushModeType flushMode) {
+ public void setFlushMode(FlushModeType flushMode) {
this.delegate().setFlushMode(flushMode);
}
@@ -222,39 +209,39 @@ public FlushModeType getFlushMode() {
}
@Override
- public void lock(final Object entity,
- final LockModeType lockMode) {
+ public void lock(Object entity,
+ LockModeType lockMode) {
this.delegate().lock(entity, lockMode);
}
@Override
- public void lock(final Object entity,
- final LockModeType lockMode,
- final Map properties) {
+ public void lock(Object entity,
+ LockModeType lockMode,
+ Map properties) {
this.delegate().lock(entity, lockMode, properties);
}
@Override
- public void refresh(final Object entity) {
+ public void refresh(Object entity) {
this.delegate().refresh(entity);
}
@Override
- public void refresh(final Object entity,
- final Map properties) {
+ public void refresh(Object entity,
+ Map properties) {
this.delegate().refresh(entity, properties);
}
@Override
- public void refresh(final Object entity,
- final LockModeType lockMode) {
+ public void refresh(Object entity,
+ LockModeType lockMode) {
this.delegate().refresh(entity, lockMode);
}
@Override
- public void refresh(final Object entity,
- final LockModeType lockMode,
- final Map properties) {
+ public void refresh(Object entity,
+ LockModeType lockMode,
+ Map properties) {
this.delegate().refresh(entity, lockMode, properties);
}
@@ -264,22 +251,22 @@ public void clear() {
}
@Override
- public void detach(final Object entity) {
+ public void detach(Object entity) {
this.delegate().detach(entity);
}
@Override
- public boolean contains(final Object entity) {
+ public boolean contains(Object entity) {
return this.delegate().contains(entity);
}
@Override
- public LockModeType getLockMode(final Object entity) {
+ public LockModeType getLockMode(Object entity) {
return this.delegate().getLockMode(entity);
}
@Override
- public void setProperty(final String propertyName, final Object propertyValue) {
+ public void setProperty(String propertyName, Object propertyValue) {
this.delegate().setProperty(propertyName, propertyValue);
}
@@ -289,76 +276,76 @@ public Map getProperties() {
}
@Override
- public Query createQuery(final String qlString) {
+ public Query createQuery(String qlString) {
return this.delegate().createQuery(qlString);
}
@Override
- public TypedQuery createQuery(final CriteriaQuery criteriaQuery) {
+ public TypedQuery createQuery(CriteriaQuery criteriaQuery) {
return this.delegate().createQuery(criteriaQuery);
}
@Override
@SuppressWarnings("rawtypes")
- public Query createQuery(final CriteriaUpdate criteriaUpdate) {
+ public Query createQuery(CriteriaUpdate criteriaUpdate) {
return this.delegate().createQuery(criteriaUpdate);
}
@Override
@SuppressWarnings("rawtypes")
- public Query createQuery(final CriteriaDelete criteriaDelete) {
+ public Query createQuery(CriteriaDelete criteriaDelete) {
return this.delegate().createQuery(criteriaDelete);
}
@Override
- public TypedQuery createQuery(final String qlString, final Class resultClass) {
+ public TypedQuery createQuery(String qlString, Class resultClass) {
return this.delegate().createQuery(qlString, resultClass);
}
@Override
- public Query createNamedQuery(final String sqlString) {
+ public Query createNamedQuery(String sqlString) {
return this.delegate().createNamedQuery(sqlString);
}
@Override
- public TypedQuery createNamedQuery(final String sqlString, final Class resultClass) {
+ public TypedQuery createNamedQuery(String sqlString, Class resultClass) {
return this.delegate().createNamedQuery(sqlString, resultClass);
}
@Override
- public Query createNativeQuery(final String sqlString) {
+ public Query createNativeQuery(String sqlString) {
return this.delegate().createNativeQuery(sqlString);
}
@Override
@SuppressWarnings("rawtypes")
- public Query createNativeQuery(final String sqlString, final Class resultClass) {
+ public Query createNativeQuery(String sqlString, Class resultClass) {
return this.delegate().createNativeQuery(sqlString, resultClass);
}
@Override
- public Query createNativeQuery(final String sqlString, final String resultSetMapping) {
+ public Query createNativeQuery(String sqlString, String resultSetMapping) {
return this.delegate().createNativeQuery(sqlString, resultSetMapping);
}
@Override
- public StoredProcedureQuery createNamedStoredProcedureQuery(final String procedureName) {
+ public StoredProcedureQuery createNamedStoredProcedureQuery(String procedureName) {
return this.delegate().createNamedStoredProcedureQuery(procedureName);
}
@Override
- public StoredProcedureQuery createStoredProcedureQuery(final String procedureName) {
+ public StoredProcedureQuery createStoredProcedureQuery(String procedureName) {
return this.delegate().createStoredProcedureQuery(procedureName);
}
@Override
@SuppressWarnings("rawtypes")
- public StoredProcedureQuery createStoredProcedureQuery(final String procedureName, final Class... resultClasses) {
+ public StoredProcedureQuery createStoredProcedureQuery(String procedureName, Class... resultClasses) {
return this.delegate().createStoredProcedureQuery(procedureName, resultClasses);
}
@Override
- public StoredProcedureQuery createStoredProcedureQuery(final String procedureName, final String... resultSetMappings) {
+ public StoredProcedureQuery createStoredProcedureQuery(String procedureName, String... resultSetMappings) {
return this.delegate().createStoredProcedureQuery(procedureName, resultSetMappings);
}
@@ -373,7 +360,10 @@ public boolean isJoinedToTransaction() {
}
@Override
- public T unwrap(final Class c) {
+ public T unwrap(Class c) {
+ if (c != null && c.isInstance(this)) {
+ return c.cast(this);
+ }
return this.delegate().unwrap(c);
}
@@ -413,22 +403,22 @@ public Metamodel getMetamodel() {
}
@Override
- public EntityGraph createEntityGraph(final Class rootType) {
+ public EntityGraph createEntityGraph(Class rootType) {
return this.delegate().createEntityGraph(rootType);
}
@Override
- public EntityGraph> createEntityGraph(final String graphName) {
+ public EntityGraph> createEntityGraph(String graphName) {
return this.delegate().createEntityGraph(graphName);
}
@Override
- public EntityGraph> getEntityGraph(final String graphName) {
+ public EntityGraph> getEntityGraph(String graphName) {
return this.delegate().getEntityGraph(graphName);
}
@Override
- public List> getEntityGraphs(final Class entityClass) {
+ public List> getEntityGraphs(Class entityClass) {
return this.delegate().getEntityGraphs(entityClass);
}
diff --git a/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/DelegatingQuery.java b/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/DelegatingQuery.java
index abe5c506927..492611ae4a8 100644
--- a/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/DelegatingQuery.java
+++ b/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/DelegatingQuery.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,11 +28,11 @@
import jakarta.persistence.Query;
import jakarta.persistence.TemporalType;
-abstract class DelegatingQuery implements Query {
+class DelegatingQuery implements Query {
private final Query delegate;
- DelegatingQuery(final Query delegate) {
+ DelegatingQuery(Query delegate) {
super();
this.delegate = Objects.requireNonNull(delegate);
}
@@ -57,7 +57,7 @@ public int getMaxResults() {
}
@Override
- public Query setMaxResults(final int maxResults) {
+ public Query setMaxResults(int maxResults) {
this.delegate.setMaxResults(maxResults);
return this;
}
@@ -69,7 +69,7 @@ public int getFirstResult() {
}
@Override
- public Query setFirstResult(final int firstResult) {
+ public Query setFirstResult(int firstResult) {
this.delegate.setFirstResult(firstResult);
return this;
}
@@ -82,29 +82,29 @@ public Map getHints() {
@Override
- public Query setHint(final String hintName, final Object value) {
+ public Query setHint(String hintName, Object value) {
this.delegate.setHint(hintName, value);
return this;
}
@Override
- public Parameter> getParameter(final int position) {
+ public Parameter> getParameter(int position) {
return this.delegate.getParameter(position);
}
@Override
- public Parameter getParameter(final int position, final Class type) {
+ public Parameter getParameter(int position, Class type) {
return this.delegate.getParameter(position, type);
}
@Override
- public Parameter> getParameter(final String name) {
+ public Parameter> getParameter(String name) {
return this.delegate.getParameter(name);
}
@Override
- public Parameter getParameter(final String name, final Class type) {
+ public Parameter getParameter(String name, Class type) {
return this.delegate.getParameter(name, type);
}
@@ -116,80 +116,80 @@ public Set> getParameters() {
@Override
- public T getParameterValue(final Parameter parameter) {
+ public T getParameterValue(Parameter parameter) {
return this.delegate.getParameterValue(parameter);
}
@Override
- public Object getParameterValue(final int position) {
+ public Object getParameterValue(int position) {
return this.delegate.getParameterValue(position);
}
@Override
- public Object getParameterValue(final String name) {
+ public Object getParameterValue(String name) {
return this.delegate.getParameterValue(name);
}
@Override
- public boolean isBound(final Parameter> parameter) {
+ public boolean isBound(Parameter> parameter) {
return this.delegate.isBound(parameter);
}
@Override
- public Query setParameter(final Parameter parameter, final T value) {
+ public Query setParameter(Parameter parameter, T value) {
this.delegate.setParameter(parameter, value);
return this;
}
@Override
- public Query setParameter(final Parameter parameter, final Calendar value, final TemporalType temporalType) {
+ public Query setParameter(Parameter parameter, Calendar value, TemporalType temporalType) {
this.delegate.setParameter(parameter, value, temporalType);
return this;
}
@Override
- public Query setParameter(final Parameter parameter, final Date value, final TemporalType temporalType) {
+ public Query setParameter(Parameter parameter, Date value, TemporalType temporalType) {
this.delegate.setParameter(parameter, value, temporalType);
return this;
}
@Override
- public Query setParameter(final int position, final Calendar value, final TemporalType temporalType) {
+ public Query setParameter(int position, Calendar value, TemporalType temporalType) {
this.delegate.setParameter(position, value, temporalType);
return this;
}
@Override
- public Query setParameter(final String name, final Calendar value, final TemporalType temporalType) {
+ public Query setParameter(String name, Calendar value, TemporalType temporalType) {
this.delegate.setParameter(name, value, temporalType);
return this;
}
@Override
- public Query setParameter(final int position, final Date value, final TemporalType temporalType) {
+ public Query setParameter(int position, Date value, TemporalType temporalType) {
this.delegate.setParameter(position, value, temporalType);
return this;
}
@Override
- public Query setParameter(final String name, final Date value, final TemporalType temporalType) {
+ public Query setParameter(String name, Date value, TemporalType temporalType) {
this.delegate.setParameter(name, value, temporalType);
return this;
}
@Override
- public Query setParameter(final int position, final Object value) {
+ public Query setParameter(int position, Object value) {
this.delegate.setParameter(position, value);
return this;
}
@Override
- public Query setParameter(final String name, final Object value) {
+ public Query setParameter(String name, Object value) {
this.delegate.setParameter(name, value);
return this;
}
@@ -201,7 +201,7 @@ public FlushModeType getFlushMode() {
}
@Override
- public Query setFlushMode(final FlushModeType flushMode) {
+ public Query setFlushMode(FlushModeType flushMode) {
this.delegate.setFlushMode(flushMode);
return this;
}
@@ -213,7 +213,7 @@ public LockModeType getLockMode() {
}
@Override
- public Query setLockMode(final LockModeType lockMode) {
+ public Query setLockMode(LockModeType lockMode) {
this.delegate.setLockMode(lockMode);
return this;
}
@@ -226,7 +226,10 @@ public int executeUpdate() {
@Override
- public T unwrap(final Class cls) {
+ public T unwrap(Class cls) {
+ if (cls != null && cls.isInstance(this)) {
+ return cls.cast(this);
+ }
return this.delegate.unwrap(cls);
}
diff --git a/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/DelegatingStoredProcedureQuery.java b/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/DelegatingStoredProcedureQuery.java
index 928837622bf..f8b040b15d9 100644
--- a/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/DelegatingStoredProcedureQuery.java
+++ b/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/DelegatingStoredProcedureQuery.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.
@@ -24,23 +24,23 @@
import jakarta.persistence.StoredProcedureQuery;
import jakarta.persistence.TemporalType;
-abstract class DelegatingStoredProcedureQuery extends DelegatingQuery implements StoredProcedureQuery {
+class DelegatingStoredProcedureQuery extends DelegatingQuery implements StoredProcedureQuery {
private final StoredProcedureQuery delegate;
- DelegatingStoredProcedureQuery(final StoredProcedureQuery delegate) {
+ DelegatingStoredProcedureQuery(StoredProcedureQuery delegate) {
super(delegate);
this.delegate = delegate;
}
@Override
- public Object getOutputParameterValue(final int position) {
+ public Object getOutputParameterValue(int position) {
return this.delegate.getOutputParameterValue(position);
}
@Override
- public Object getOutputParameterValue(final String parameterName) {
+ public Object getOutputParameterValue(String parameterName) {
return this.delegate.getOutputParameterValue(parameterName);
}
@@ -59,18 +59,18 @@ public int getUpdateCount() {
@Override
@SuppressWarnings("rawtypes")
- public DelegatingStoredProcedureQuery registerStoredProcedureParameter(final int position,
- final Class type,
- final ParameterMode mode) {
+ public DelegatingStoredProcedureQuery registerStoredProcedureParameter(int position,
+ Class type,
+ ParameterMode mode) {
this.delegate.registerStoredProcedureParameter(position, type, mode);
return this;
}
@Override
@SuppressWarnings("rawtypes")
- public DelegatingStoredProcedureQuery registerStoredProcedureParameter(final String parameterName,
- final Class type,
- final ParameterMode mode) {
+ public DelegatingStoredProcedureQuery registerStoredProcedureParameter(String parameterName,
+ Class type,
+ ParameterMode mode) {
this.delegate.registerStoredProcedureParameter(parameterName, type, mode);
return this;
}
@@ -83,71 +83,71 @@ public DelegatingStoredProcedureQuery setFlushMode(FlushModeType flushMode) {
@Override
- public DelegatingStoredProcedureQuery setHint(final String hintName,
- final Object value) {
+ public DelegatingStoredProcedureQuery setHint(String hintName,
+ Object value) {
return (DelegatingStoredProcedureQuery) super.setHint(hintName, value);
}
@Override
- public DelegatingStoredProcedureQuery setParameter(final Parameter parameter,
- final T value) {
+ public DelegatingStoredProcedureQuery setParameter(Parameter parameter,
+ T value) {
return (DelegatingStoredProcedureQuery) super.setParameter(parameter, value);
}
@Override
- public DelegatingStoredProcedureQuery setParameter(final Parameter parameter,
- final Calendar value,
- final TemporalType temporalType) {
+ public DelegatingStoredProcedureQuery setParameter(Parameter parameter,
+ Calendar value,
+ TemporalType temporalType) {
return (DelegatingStoredProcedureQuery) super.setParameter(parameter, value, temporalType);
}
@Override
- public DelegatingStoredProcedureQuery setParameter(final Parameter parameter,
- final Date value,
- final TemporalType temporalType) {
+ public DelegatingStoredProcedureQuery setParameter(Parameter parameter,
+ Date value,
+ TemporalType temporalType) {
return (DelegatingStoredProcedureQuery) super.setParameter(parameter, value, temporalType);
}
@Override
- public DelegatingStoredProcedureQuery setParameter(final int position,
- final Object value) {
+ public DelegatingStoredProcedureQuery setParameter(int position,
+ Object value) {
return (DelegatingStoredProcedureQuery) super.setParameter(position, value);
}
@Override
- public DelegatingStoredProcedureQuery setParameter(final int position,
- final Calendar value,
- final TemporalType temporalType) {
+ public DelegatingStoredProcedureQuery setParameter(int position,
+ Calendar value,
+ TemporalType temporalType) {
return (DelegatingStoredProcedureQuery) super.setParameter(position, value, temporalType);
}
@Override
- public DelegatingStoredProcedureQuery setParameter(final int position,
- final Date value,
- final TemporalType temporalType) {
+ public DelegatingStoredProcedureQuery setParameter(int position,
+ Date value,
+ TemporalType temporalType) {
return (DelegatingStoredProcedureQuery) super.setParameter(position, value, temporalType);
}
@Override
- public DelegatingStoredProcedureQuery setParameter(final String name,
- final Object value) {
+ public DelegatingStoredProcedureQuery setParameter(String name,
+ Object value) {
return (DelegatingStoredProcedureQuery) super.setParameter(name, value);
}
@Override
- public DelegatingStoredProcedureQuery setParameter(final String name,
- final Calendar value,
- final TemporalType temporalType) {
+ public DelegatingStoredProcedureQuery setParameter(String name,
+ Calendar value,
+ TemporalType temporalType) {
return (DelegatingStoredProcedureQuery) super.setParameter(name, value, temporalType);
}
@Override
- public DelegatingStoredProcedureQuery setParameter(final String name,
- final Date value,
- final TemporalType temporalType) {
+ public DelegatingStoredProcedureQuery setParameter(String name,
+ Date value,
+ TemporalType temporalType) {
return (DelegatingStoredProcedureQuery) super.setParameter(name, value, temporalType);
}
diff --git a/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/DelegatingTypedQuery.java b/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/DelegatingTypedQuery.java
index a4d2e1bd2ac..fbf72e2c999 100644
--- a/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/DelegatingTypedQuery.java
+++ b/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/DelegatingTypedQuery.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,11 +28,11 @@
import jakarta.persistence.TemporalType;
import jakarta.persistence.TypedQuery;
-abstract class DelegatingTypedQuery implements TypedQuery {
+class DelegatingTypedQuery implements TypedQuery {
private final TypedQuery delegate;
- DelegatingTypedQuery(final TypedQuery delegate) {
+ DelegatingTypedQuery(TypedQuery delegate) {
super();
this.delegate = Objects.requireNonNull(delegate);
}
@@ -56,7 +56,7 @@ public int getMaxResults() {
}
@Override
- public TypedQuery setMaxResults(final int maxResults) {
+ public TypedQuery setMaxResults(int maxResults) {
this.delegate.setMaxResults(maxResults);
return this;
}
@@ -68,7 +68,7 @@ public int getFirstResult() {
}
@Override
- public TypedQuery setFirstResult(final int startPosition) {
+ public TypedQuery setFirstResult(int startPosition) {
this.delegate.setFirstResult(startPosition);
return this;
}
@@ -80,7 +80,7 @@ public Map getHints() {
}
@Override
- public TypedQuery setHint(final String hintName, final Object value) {
+ public TypedQuery setHint(String hintName, Object value) {
this.delegate.setHint(hintName, value);
return this;
}
@@ -92,113 +92,113 @@ public Set> getParameters() {
}
@Override
- public Parameter> getParameter(final String name) {
+ public Parameter> getParameter(String name) {
return this.delegate.getParameter(name);
}
@Override
- public Parameter getParameter(final String name, final Class type) {
+ public Parameter getParameter(String name, Class type) {
return this.delegate.getParameter(name, type);
}
@Override
- public Parameter> getParameter(final int position) {
+ public Parameter> getParameter(int position) {
return this.delegate.getParameter(position);
}
@Override
- public Parameter getParameter(final int position, final Class type) {
+ public Parameter getParameter(int position, Class type) {
return this.delegate.getParameter(position, type);
}
@Override
- public T getParameterValue(final Parameter parameter) {
+ public T getParameterValue(Parameter parameter) {
return this.delegate.getParameterValue(parameter);
}
@Override
- public Object getParameterValue(final String name) {
+ public Object getParameterValue(String name) {
return this.delegate.getParameterValue(name);
}
@Override
- public Object getParameterValue(final int position) {
+ public Object getParameterValue(int position) {
return this.delegate.getParameterValue(position);
}
@Override
- public boolean isBound(final Parameter> parameter) {
+ public boolean isBound(Parameter> parameter) {
return this.delegate.isBound(parameter);
}
@Override
- public TypedQuery setParameter(final Parameter parameter,
- final T value) {
+ public TypedQuery setParameter(Parameter parameter,
+ T value) {
this.delegate.setParameter(parameter, value);
return this;
}
@Override
- public TypedQuery setParameter(final Parameter parameter,
- final Calendar value,
- final TemporalType temporalType) {
+ public TypedQuery setParameter(Parameter parameter,
+ Calendar value,
+ TemporalType temporalType) {
this.delegate.setParameter(parameter, value, temporalType);
return this;
}
@Override
- public TypedQuery setParameter(final Parameter parameter,
- final Date value,
- final TemporalType temporalType) {
+ public TypedQuery setParameter(Parameter parameter,
+ Date value,
+ TemporalType temporalType) {
this.delegate.setParameter(parameter, value, temporalType);
return this;
}
@Override
- public TypedQuery setParameter(final int position,
- final Object value) {
+ public TypedQuery setParameter(int position,
+ Object value) {
this.delegate.setParameter(position, value);
return this;
}
@Override
- public TypedQuery setParameter(final int position,
- final Calendar value,
- final TemporalType temporalType) {
+ public TypedQuery setParameter(int position,
+ Calendar value,
+ TemporalType temporalType) {
this.delegate.setParameter(position, value, temporalType);
return this;
}
@Override
- public TypedQuery setParameter(final int position,
- final Date value,
- final TemporalType temporalType) {
+ public TypedQuery setParameter(int position,
+ Date value,
+ TemporalType temporalType) {
this.delegate.setParameter(position, value, temporalType);
return this;
}
@Override
- public TypedQuery setParameter(final String name,
- final Object value) {
+ public TypedQuery setParameter(String name,
+ Object value) {
this.delegate.setParameter(name, value);
return this;
}
@Override
- public TypedQuery setParameter(final String name,
- final Calendar value,
- final TemporalType temporalType) {
+ public TypedQuery setParameter(String name,
+ Calendar value,
+ TemporalType temporalType) {
this.delegate.setParameter(name, value, temporalType);
return this;
}
@Override
- public TypedQuery setParameter(final String name,
- final Date value,
- final TemporalType temporalType) {
+ public TypedQuery setParameter(String name,
+ Date value,
+ TemporalType temporalType) {
this.delegate.setParameter(name, value, temporalType);
return this;
}
@@ -210,7 +210,7 @@ public FlushModeType getFlushMode() {
}
@Override
- public TypedQuery setFlushMode(final FlushModeType flushMode) {
+ public TypedQuery setFlushMode(FlushModeType flushMode) {
this.delegate.setFlushMode(flushMode);
return this;
}
@@ -222,7 +222,7 @@ public LockModeType getLockMode() {
}
@Override
- public TypedQuery setLockMode(final LockModeType lockMode) {
+ public TypedQuery setLockMode(LockModeType lockMode) {
this.delegate.setLockMode(lockMode);
return this;
}
@@ -235,7 +235,10 @@ public int executeUpdate() {
@Override
- public T unwrap(final Class cls) {
+ public T unwrap(Class cls) {
+ if (cls != null && cls.isInstance(this)) {
+ return cls.cast(this);
+ }
return this.delegate.unwrap(cls);
}
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 08c1c9b8622..86594a348ac 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
@@ -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.
@@ -104,21 +104,20 @@
import static jakarta.interceptor.Interceptor.Priority.LIBRARY_BEFORE;
/**
- * A {@linkplain Extension portable extension} normally instantiated
- * by the Java {@linkplain java.util.ServiceLoader service provider
- * infrastructure} that integrates the provider-independent parts of
- * JPA into CDI.
+ * A {@linkplain Extension portable extension} normally instantiated by the Java {@linkplain java.util.ServiceLoader
+ * service provider infrastructure} that integrates the provider-independent parts of JPA into CDI.
*
* Thread Safety
*
- * As with all CDI portable extensions, instances of this class are
- * not safe for concurrent use by multiple
- * threads.
+ * As with all CDI portable extensions, instances of this class are not safe for concurrent use by
+ * multiple threads.
*
* @see PersistenceUnitInfoBean
*/
public class JpaExtension implements Extension {
+
+
/*
* Static fields.
*/
@@ -132,32 +131,21 @@ public class JpaExtension implements Extension {
JpaExtension.class.getPackage().getName() + ".Messages");
/**
- * The name used to designate the only persistence unit in the
- * environment, when there is exactly one persistence unit in the
- * environment, and there is at least one {@link
- * PersistenceContext @PersistenceContext}-annotated injection
- * point that does not specify a value for the {@link
- * PersistenceContext#unitName() unitName} element.
- *
- * 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.
- *
- * This is necessary because the empty string ({@code ""}) as
- * the value of the {@link Named#value()} element has special
- * semantics, so cannot be used to designate an unnamed
- * persistence unit.
- *
- * The value of this field is subject to change without prior
- * notice at any point. In general the mechanics around injection
- * point rewriting are also subject to change without prior notice
- * at any point.
+ * The name used to designate the only persistence unit in the environment, when there is exactly one persistence
+ * unit in the environment, and there is at least one {@link PersistenceContext @PersistenceContext}-annotated
+ * injection point that does not specify a value for the {@link PersistenceContext#unitName() unitName} element.
+ *
+ * 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.
+ *
+ * This is necessary because the empty string ({@code ""}) as the value of the {@link Named#value()} element has
+ * special semantics, so cannot be used to designate an unnamed persistence unit.
+ *
+ * The value of this field is subject to change without prior notice at any point. In general the mechanics
+ * around injection point rewriting are also subject to change without prior notice at any point.
*/
static final String DEFAULT_PERSISTENCE_UNIT_NAME = "__DEFAULT__";
@@ -167,6 +155,13 @@ public class JpaExtension implements Extension {
*/
+ /**
+ * Whether or not this extension will do anything.
+ *
+ * This field's value is {@code true} by default.
+ */
+ private final boolean enabled;
+
/**
* Indicates if JTA transactions can be supported.
*
@@ -175,22 +170,17 @@ public class JpaExtension implements Extension {
private boolean transactionsSupported;
/**
- * A {@link Map} of {@link PersistenceUnitInfoBean} instances that
- * were created by the {@link
- * #gatherImplicitPersistenceUnits(ProcessAnnotatedType,
- * BeanManager)} observer method, indexed by the names of
+ * A {@link Map} of {@link PersistenceUnitInfoBean} instances that were created by the {@link
+ * #gatherImplicitPersistenceUnits(ProcessAnnotatedType, BeanManager)} observer method, indexed by the names of
* persistence units.
*
* This field is never {@code null}.
*
- * The contents of this field are used only when no explicit
- * {@link PersistenceUnitInfo} beans are otherwise available in
- * the container.
+ * The contents of this field are used only when no explicit {@link PersistenceUnitInfo} beans are otherwise
+ * available in the container.
*
- * This field is {@linkplain Map#clear() cleared} at the
- * termination of the {@link
- * #afterBeanDiscovery(AfterBeanDiscovery, BeanManager)} container
- * lifecycle method.
+ * This field is {@linkplain Map#clear() cleared} at the termination of the {@link
+ * #afterBeanDiscovery(AfterBeanDiscovery, BeanManager)} container lifecycle method.
*
* @see #gatherImplicitPersistenceUnits(ProcessAnnotatedType, BeanManager)
*
@@ -199,132 +189,102 @@ public class JpaExtension implements Extension {
private final Map implicitPersistenceUnits;
/**
- * A {@link Map} of {@link Set}s of {@link Class}es whose keys are
- * persistence unit names and whose values are {@link Set}s of
- * {@link Class}es discovered by CDI (and hence consist of
- * unlisted classes in the sense that they might not be found in
- * any {@link PersistenceUnitInfo}).
+ * A {@link Map} of {@link Set}s of {@link Class}es whose keys are persistence unit names and whose values are
+ * {@link Set}s of {@link Class}es discovered by CDI (and hence consist of unlisted classes in the sense that they
+ * might not be found in any {@link PersistenceUnitInfo}).
*
- * Such {@link Class}es, of course, might not have been weaved
- * appropriately by the relevant {@link PersistenceProvider}.
+ * Such {@link Class}es, of course, might not have been weaved appropriately by the relevant {@link
+ * PersistenceProvider}.
*
* This field is never {@code null}.
*
- * This field is {@linkplain Map#clear() cleared} at the
- * termination of the {@link
- * #afterBeanDiscovery(AfterBeanDiscovery, BeanManager)} container
- * lifecycle method.
+ * This field is {@linkplain Map#clear() cleared} at the termination of the {@link
+ * #afterBeanDiscovery(AfterBeanDiscovery, BeanManager)} container lifecycle method.
*/
private final Map>> unlistedManagedClassesByPersistenceUnitNames;
/**
- * A {@link Set} of {@link Set}s of CDI qualifiers annotating CDI
- * injection points related to JPA.
+ * A {@link Set} of {@link Set}s of CDI qualifiers annotating CDI injection points related to JPA.
*
* This field is never {@code null}.
*
- * These qualifiers are built up as this portable extension
- * {@linkplain ProcessInjectionPoint discovers {@link
+ *
These qualifiers are built up as this portable extension {@linkplain ProcessInjectionPoint discovers {@link
* EntityManager}-typed InjectionPoint
s}.
*
- * This field is {@linkplain Collection#clear() cleared} at the
- * termination of the {@link
- * #afterBeanDiscovery(AfterBeanDiscovery, BeanManager)} container
- * lifecycle method.
+ * This field is {@linkplain Collection#clear() cleared} at the termination of the {@link
+ * #afterBeanDiscovery(AfterBeanDiscovery, BeanManager)} container lifecycle method.
*
* @see #saveEntityManagerQualifiers(ProcessInjectionPoint)
*/
private final Set> persistenceContextQualifiers;
/**
- * A {@link Set} of {@link Set}s of CDI qualifiers for which
- * {@link EntityManagerFactory} beans may be created.
+ * A {@link Set} of {@link Set}s of CDI qualifiers for which {@link EntityManagerFactory} beans may be created.
*
* This field is never {@code null}.
*
- * These qualifiers are built up as this portable extension
- * {@linkplain ProcessInjectionPoint discovers {@link
+ *
These qualifiers are built up as this portable extension {@linkplain ProcessInjectionPoint discovers {@link
* EntityManagerFactory}-typed InjectionPoint
s}.
*
- * This field is {@linkplain Collection#clear() cleared} at the
- * termination of the {@link
- * #afterBeanDiscovery(AfterBeanDiscovery, BeanManager)} container
- * lifecycle method.
+ * This field is {@linkplain Collection#clear() cleared} at the termination of the {@link
+ * #afterBeanDiscovery(AfterBeanDiscovery, BeanManager)} container lifecycle method.
*
* @see #saveEntityManagerFactoryQualifiers(ProcessInjectionPoint)
*/
private final Set> persistenceUnitQualifiers;
/**
- * A {@link Set} of {@link Set}s of CDI qualifiers that serves as
- * a kind of cache, preventing more than one {@link
- * CdiTransactionScoped}-qualified {@link EntityManager}-typed
- * bean from being added for the same set of qualifiers.
+ * A {@link Set} of {@link Set}s of CDI qualifiers that serves as a kind of cache, preventing more than one {@link
+ * CdiTransactionScoped}-qualified {@link EntityManager}-typed bean from being added for the same set of qualifiers.
*
* This field is never {@code null}.
*
- * This field is {@linkplain Collection#clear() cleared} at the
- * termination of the {@link
- * #afterBeanDiscovery(AfterBeanDiscovery, BeanManager)} container
- * lifecycle method.
+ * This field is {@linkplain Collection#clear() cleared} at the termination of the {@link
+ * #afterBeanDiscovery(AfterBeanDiscovery, BeanManager)} container lifecycle method.
*
- * @see
- * #addCdiTransactionScopedEntityManagerBeans(AfterBeanDiscovery,
- * Set)
+ * @see #addCdiTransactionScopedEntityManagerBeans(AfterBeanDiscovery, Set)
*/
private final Set> cdiTransactionScopedEntityManagerQualifiers;
/**
- * A {@link Set} of {@link Set}s of CDI qualifiers that serves as
- * a kind of cache, preventing more than one {@link
- * NonTransactional}-qualified {@link EntityManager}-typed bean
- * from being added for the same set of qualifiers.
+ * A {@link Set} of {@link Set}s of CDI qualifiers that serves as a kind of cache, preventing more than one {@link
+ * NonTransactional}-qualified {@link EntityManager}-typed bean from being added for the same set of qualifiers.
*
* This field is never {@code null}.
*
- * This field is {@linkplain Collection#clear() cleared} at the
- * termination of the {@link
- * #afterBeanDiscovery(AfterBeanDiscovery, BeanManager)} container
- * lifecycle method.
+ * This field is {@linkplain Collection#clear() cleared} at the termination of the {@link
+ * #afterBeanDiscovery(AfterBeanDiscovery, BeanManager)} container lifecycle method.
*
- * @see #addNonTransactionalEntityManagerBeans(AfterBeanDiscovery,
- * Set, BeanManager)
+ * @see #addNonTransactionalEntityManagerBeans(AfterBeanDiscovery, Set, BeanManager)
*/
private final Set> nonTransactionalEntityManagerQualifiers;
/**
- * A {@link Set} of {@link Set}s of CDI qualifiers that serves as
- * a kind of cache, preventing more than one {@link
- * ContainerManaged}-qualified {@link EntityManagerFactory}-typed
- * bean from being added for the same set of qualifiers.
+ * A {@link Set} of {@link Set}s of CDI qualifiers that serves as a kind of cache, preventing more than one {@link
+ * ContainerManaged}-qualified {@link EntityManagerFactory}-typed bean from being added for the same set of
+ * qualifiers.
*
* This field is never {@code null}.
*
- * This field is {@linkplain Collection#clear() cleared} at the
- * termination of the {@link
- * #afterBeanDiscovery(AfterBeanDiscovery, BeanManager)} container
- * lifecycle method.
+ * This field is {@linkplain Collection#clear() cleared} at the termination of the {@link
+ * #afterBeanDiscovery(AfterBeanDiscovery, BeanManager)} container lifecycle method.
*
- * @see
- * #addContainerManagedEntityManagerFactoryBeans(AfterBeanDiscovery,
- * Set, BeanManager)
+ * @see #addContainerManagedEntityManagerFactoryBeans(AfterBeanDiscovery, Set, BeanManager)
*/
private final Set> containerManagedEntityManagerFactoryQualifiers;
/**
- * Indicates whether an injection point has called for the default
- * persistence unit. This has implications on how beans are
- * installed.
+ * Indicates whether an injection point has called for the default persistence unit. This has implications on how
+ * beans are installed.
*
- * @see #validate(AfterDeploymentValidation)
+ * @see #validate(AfterDeploymentValidation, BeanManager)
*/
private boolean defaultPersistenceUnitInEffect;
/**
- * Indicates whether a bean for the default persistence unit
- * has been added.
+ * Indicates whether a bean for the default persistence unit has been added.
*
- * @see #validate(AfterDeploymentValidation)
+ * @see #validate(AfterDeploymentValidation, BeanManager)
*/
private boolean addedDefaultPersistenceUnit;
@@ -337,20 +297,22 @@ public class JpaExtension implements Extension {
/**
* Creates a new {@link JpaExtension}.
*
- * Normally {@link JpaExtension} classes are created
- * automatically and only as needed by the CDI container. End
- * users should have no need to create instances of this
- * class.
+ * Normally {@link JpaExtension} classes are created automatically and only as needed by the CDI container. End
+ * users should have no need to create instances of this class.
*
* @see Extension
*/
public JpaExtension() {
super();
- final String cn = JpaExtension.class.getName();
- final String mn = "";
+ String cn = JpaExtension.class.getName();
+ String mn = "";
if (LOGGER.isLoggable(Level.FINER)) {
LOGGER.entering(cn, mn);
}
+ this.enabled = Boolean.parseBoolean(System.getProperty(this.getClass().getName() + ".enabled", "true"));
+ if (LOGGER.isLoggable(Level.FINE) && !this.enabled) {
+ LOGGER.logp(Level.FINE, cn, mn, "jpaExtensionDisabled", this.getClass().getName());
+ }
this.unlistedManagedClassesByPersistenceUnitNames = new HashMap<>();
this.implicitPersistenceUnits = new HashMap<>();
this.persistenceContextQualifiers = new HashSet<>();
@@ -358,10 +320,8 @@ public JpaExtension() {
this.containerManagedEntityManagerFactoryQualifiers = new HashSet<>();
this.nonTransactionalEntityManagerQualifiers = new HashSet<>();
this.persistenceUnitQualifiers = new HashSet<>();
- // We start by presuming that JTA transactions can be
- // supported. See the
- // #disableTransactionSupport(ProcessAnnotatedType) method
- // where this decision might be reversed.
+ // We start by presuming that JTA transactions can be supported. See the
+ // #disableTransactionSupport(ProcessAnnotatedType) method where this decision might be reversed.
this.transactionsSupported = true;
if (LOGGER.isLoggable(Level.FINER)) {
LOGGER.exiting(cn, mn);
@@ -375,17 +335,13 @@ public JpaExtension() {
/**
- * If {@code event} is non-{@code null}, then when this method is
- * invoked it irrevocably sets the {@link #transactionsSupported}
- * field to {@code false}.
+ * If {@code event} is non-{@code null}, then when this method is invoked it irrevocably sets the {@link
+ * #transactionsSupported} field to {@code false}.
*
- * @param event a {@link ProcessAnnotatedType
- * ProcessAnnotatedType<}{@link NoTransactionSupport
- * NoTransactionSupport>} whose presence indicates that JTA
- * support is not available; must not be {@code null}
+ * @param event a {@link ProcessAnnotatedType ProcessAnnotatedType<}{@link NoTransactionSupport
+ * NoTransactionSupport>} whose presence indicates that JTA support is not available; must not be {@code null}
*
- * @exception NullPointerException if {@code event} is {@code
- * null}
+ * @exception NullPointerException if {@code event} is {@code null}
*
* @see #transactionsSupported
*
@@ -393,22 +349,25 @@ public JpaExtension() {
*/
private void disableTransactionSupport(@Observes
@Priority(LIBRARY_BEFORE)
- final ProcessAnnotatedType event) {
- final String cn = JpaExtension.class.getName();
- final String mn = "disableTransactionSupport";
+ ProcessAnnotatedType event) {
+ String cn = JpaExtension.class.getName();
+ String mn = "disableTransactionSupport";
if (LOGGER.isLoggable(Level.FINER)) {
LOGGER.entering(cn, mn, event);
}
+ if (!this.enabled) {
+ if (LOGGER.isLoggable(Level.FINER)) {
+ LOGGER.exiting(cn, mn);
+ }
+ return;
+ }
Objects.requireNonNull(event);
- // If we receive an event of this type, then beans.xml
- // exclusions have fired such that it has been determined that
- // JTA is not loadable. This of course means that JTA
- // transactions cannot be supported, and hence many (but not
- // all) features of JPA integration cannot be supported as
- // well. See ../../../../../../resources/META-INF/beans.xml
- // and note the if-class-available and if-class-not-available
+ // If we receive an event of this type, then beans.xml exclusions have fired such that it has been determined
+ // that JTA is not loadable. This of course means that JTA transactions cannot be supported, and hence many
+ // (but not all) features of JPA integration cannot be supported as well. See
+ // ../../../../../../resources/META-INF/beans.xml and note the if-class-available and if-class-not-available
// elements.
this.transactionsSupported = false;
@@ -418,15 +377,11 @@ private void disableTransactionSupport(@Observes
}
/**
- * Converts fields and setter methods annotated with {@link
- * PersistenceContext} to CDI injection points annotated with an
- * appropriate combination of {@link Inject}, {@link
- * ContainerManaged}, {@link Extended}, {@link
- * JpaTransactionScoped}, {@link Synchronized} and/or {@link
- * Unsynchronized}.
+ * Converts fields and setter methods annotated with {@link PersistenceContext} to CDI injection points annotated
+ * with an appropriate combination of {@link Inject}, {@link ContainerManaged}, {@link Extended}, {@link
+ * JpaTransactionScoped}, {@link Synchronized} and/or {@link Unsynchronized}.
*
- * @param event the {@link ProcessAnnotatedType} container
- * lifecycle event being observed; must not be {@code null}
+ * @param event the {@link ProcessAnnotatedType} container lifecycle event being observed; must not be {@code null}
*
* @exception NullPointerException if {@code event} is {@code null}
*/
@@ -435,16 +390,22 @@ private void rewriteJpaAnnotations(@Observes
PersistenceContext.class,
PersistenceUnit.class
})
- final ProcessAnnotatedType event) {
- final String cn = JpaExtension.class.getName();
- final String mn = "rewriteJpaAnnotations";
+ ProcessAnnotatedType event) {
+ String cn = JpaExtension.class.getName();
+ String mn = "rewriteJpaAnnotations";
if (LOGGER.isLoggable(Level.FINER)) {
LOGGER.entering(cn, mn, event);
}
+ if (!this.enabled) {
+ if (LOGGER.isLoggable(Level.FINER)) {
+ LOGGER.exiting(cn, mn);
+ }
+ return;
+ }
Objects.requireNonNull(event);
- final AnnotatedTypeConfigurator atc = event.configureAnnotatedType();
+ AnnotatedTypeConfigurator atc = event.configureAnnotatedType();
atc.filterFields(JpaExtension::isEligiblePersistenceContextField)
.forEach(this::rewritePersistenceContextFieldAnnotations);
atc.filterFields(JpaExtension::isEligiblePersistenceUnitField)
@@ -460,21 +421,15 @@ private void rewriteJpaAnnotations(@Observes
}
/**
- * Looks for type-level {@link PersistenceContext} annotations
- * that have at least one {@link PersistenceProperty} annotation
- * {@linkplain PersistenceContext#properties() associated with}
- * them and uses them to define persistence units, potentially
- * preventing the need for {@code META-INF/persistence.xml}
- * processing.
- *
- * @param event the {@link ProcessAnnotatedType} event occurring;
- * must not be {@code null}
+ * Looks for type-level {@link PersistenceContext} annotations that have at least one {@link PersistenceProperty}
+ * annotation {@linkplain PersistenceContext#properties() associated with} them and uses them to define persistence
+ * units, potentially preventing the need for {@code META-INF/persistence.xml} processing.
*
- * @param beanManager the {@link BeanManager} in effect; must not
- * be {@code null}
+ * @param event the {@link ProcessAnnotatedType} event occurring; must not be {@code null}
*
- * @exception NullPointerException if either {@code event} or
- * {@code beanManager} is {@code null}
+ * @param beanManager the {@link BeanManager} in effect; must not be {@code null}
+ *
+ * @exception NullPointerException if either {@code event} or {@code beanManager} is {@code null}
*
* @see PersistenceContext
*
@@ -485,54 +440,60 @@ private void rewriteJpaAnnotations(@Observes
private void gatherImplicitPersistenceUnits(@Observes
// yes, @PersistenceContext, not @PersistenceUnit
@WithAnnotations(PersistenceContext.class)
- final ProcessAnnotatedType> event,
- final BeanManager beanManager) {
- final String cn = JpaExtension.class.getName();
- final String mn = "gatherImplicitPersistenceUnits";
+ ProcessAnnotatedType> event,
+ BeanManager beanManager) {
+ String cn = JpaExtension.class.getName();
+ String mn = "gatherImplicitPersistenceUnits";
if (LOGGER.isLoggable(Level.FINER)) {
LOGGER.entering(cn, mn, new Object[] {event, beanManager});
}
+ if (!this.enabled) {
+ if (LOGGER.isLoggable(Level.FINER)) {
+ LOGGER.exiting(cn, mn);
+ }
+ return;
+ }
Objects.requireNonNull(event);
Objects.requireNonNull(beanManager);
- final AnnotatedType> annotatedType = event.getAnnotatedType();
+ AnnotatedType> annotatedType = event.getAnnotatedType();
if (annotatedType != null && !annotatedType.isAnnotationPresent(Vetoed.class)) {
- final Set extends PersistenceContext> persistenceContexts =
+ Set extends PersistenceContext> persistenceContexts =
annotatedType.getAnnotations(PersistenceContext.class);
if (persistenceContexts != null && !persistenceContexts.isEmpty()) {
- for (final PersistenceContext persistenceContext : persistenceContexts) {
+ for (PersistenceContext persistenceContext : persistenceContexts) {
if (LOGGER.isLoggable(Level.INFO)) {
- final String name = persistenceContext.name().trim();
+ String name = persistenceContext.name().trim();
if (!name.isEmpty()) {
LOGGER.logp(Level.INFO, cn, mn,
"persistenceContextNameIgnored", new Object[] {annotatedType, name});
}
}
- final PersistenceProperty[] persistenceProperties = persistenceContext.properties();
+ PersistenceProperty[] persistenceProperties = persistenceContext.properties();
if (persistenceProperties != null && persistenceProperties.length > 0) {
- final String persistenceUnitName = persistenceContext.unitName();
+ String persistenceUnitName = persistenceContext.unitName();
assert persistenceUnitName != null;
PersistenceUnitInfoBean persistenceUnit = this.implicitPersistenceUnits.get(persistenceUnitName);
if (persistenceUnit == null) {
- final String jtaDataSourceName;
+ String jtaDataSourceName;
if (persistenceUnitName.isEmpty()) {
jtaDataSourceName = null;
} else {
jtaDataSourceName = persistenceUnitName;
}
- final Class> javaClass = annotatedType.getJavaClass();
+ Class> javaClass = annotatedType.getJavaClass();
URL persistenceUnitRoot = null;
- final ProtectionDomain pd = javaClass.getProtectionDomain();
+ ProtectionDomain pd = javaClass.getProtectionDomain();
if (pd != null) {
- final CodeSource cs = pd.getCodeSource();
+ CodeSource cs = pd.getCodeSource();
if (cs != null) {
persistenceUnitRoot = cs.getLocation();
}
}
- final Properties properties = new Properties();
- for (final PersistenceProperty persistenceProperty : persistenceProperties) {
- final String persistencePropertyName = persistenceProperty.name();
+ Properties properties = new Properties();
+ for (PersistenceProperty persistenceProperty : persistenceProperties) {
+ String persistencePropertyName = persistenceProperty.name();
if (!persistencePropertyName.isEmpty()) {
properties.setProperty(persistencePropertyName, persistenceProperty.value());
}
@@ -559,24 +520,17 @@ private void gatherImplicitPersistenceUnits(@Observes
}
/**
- * Tracks {@linkplain Converter converters}, {@linkplain Entity
- * entities}, {@linkplain Embeddable embeddables} and {@linkplain
- * MappedSuperclass mapped superclasses} that were auto-discovered
- * by CDI bean discovery, and makes sure that they are not
- * actually CDI beans, since according to the JPA specification
- * they cannot be.
- *
- * This method also keeps track of these classes as potential
- * "unlisted classes" to be used by a {@linkplain
- * PersistenceUnitInfo persistence unit} if its {@linkplain
- * PersistenceUnitInfo#excludeUnlistedClasses()} method returns
- * {@code false}.
- *
- * @param event the event describing the {@link AnnotatedType}
- * being processed; must not be {@code null}
- *
- * @exception NullPointerException if {@code event} is {@code
- * null}
+ * Tracks {@linkplain Converter converters}, {@linkplain Entity entities}, {@linkplain Embeddable embeddables} and
+ * {@linkplain MappedSuperclass mapped superclasses} that were auto-discovered by CDI bean discovery, and makes sure
+ * that they are not actually CDI beans, since according to the JPA specification they cannot be.
+ *
+ * This method also keeps track of these classes as potential "unlisted classes" to be used by a {@linkplain
+ * PersistenceUnitInfo persistence unit} if its {@linkplain PersistenceUnitInfo#excludeUnlistedClasses()} method
+ * returns {@code false}.
+ *
+ * @param event the event describing the {@link AnnotatedType} being processed; must not be {@code null}
+ *
+ * @exception NullPointerException if {@code event} is {@code null}
*
* @see Converter
*
@@ -595,16 +549,22 @@ private void discoverManagedClasses(@Observes
Entity.class,
MappedSuperclass.class
})
- final ProcessAnnotatedType> event) {
- final String cn = JpaExtension.class.getName();
- final String mn = "discoverManagedClasses";
+ ProcessAnnotatedType> event) {
+ String cn = JpaExtension.class.getName();
+ String mn = "discoverManagedClasses";
if (LOGGER.isLoggable(Level.FINER)) {
LOGGER.entering(cn, mn, event);
}
+ if (!this.enabled) {
+ if (LOGGER.isLoggable(Level.FINER)) {
+ LOGGER.exiting(cn, mn);
+ }
+ return;
+ }
Objects.requireNonNull(event);
- final AnnotatedType> annotatedType = event.getAnnotatedType();
+ AnnotatedType> annotatedType = event.getAnnotatedType();
if (annotatedType != null && !annotatedType.isAnnotationPresent(Vetoed.class)) {
this.assignManagedClassToPersistenceUnit(annotatedType.getAnnotations(PersistenceContext.class),
annotatedType.getAnnotations(PersistenceUnit.class),
@@ -618,33 +578,28 @@ private void discoverManagedClasses(@Observes
}
/**
- * Given {@link Set}s of {@link PersistenceContext} and {@link
- * PersistenceUnit} annotations that will be used for their {@code
- * unitName} elements only, associates the supplied {@link Class}
- * with the persistence units implied by the annotations.
+ * Given {@link Set}s of {@link PersistenceContext} and {@link PersistenceUnit} annotations that will be used for
+ * their {@code unitName} elements only, associates the supplied {@link Class} with the persistence units implied by
+ * the annotations.
*
- * @param persistenceContexts a {@link Set} of {@link
- * PersistenceContext}s whose {@link PersistenceContext#unitName()
- * unitName} elements identify persistence units; may be {@code
- * null} or {@linkplain Collection#isEmpty() empty}
+ * @param persistenceContexts a {@link Set} of {@link PersistenceContext}s whose {@link
+ * PersistenceContext#unitName() unitName} elements identify persistence units; may be {@code null} or {@linkplain
+ * Collection#isEmpty() empty}
*
- * @param persistenceUnits a {@link Set} of {@link
- * PersistenceUnit}s whose {@link PersistenceUnit#unitName()
- * unitName} elements identify persistence units; may be {@code
- * null} or {@linkplain Collection#isEmpty() empty}
+ * @param persistenceUnits a {@link Set} of {@link PersistenceUnit}s whose {@link PersistenceUnit#unitName()
+ * unitName} elements identify persistence units; may be {@code null} or {@linkplain Collection#isEmpty() empty}
*
- * @param c the {@link Class} to associate; may be {@code null} in
- * which case no action will be taken
+ * @param c the {@link Class} to associate; may be {@code null} in which case no action will be taken
*
* @see PersistenceContext
*
* @see PersistenceUnit
*/
- private void assignManagedClassToPersistenceUnit(final Set extends PersistenceContext> persistenceContexts,
- final Set extends PersistenceUnit> persistenceUnits,
- final Class> c) {
- final String cn = JpaExtension.class.getName();
- final String mn = "assignManagedClassToPersistenceUnit";
+ private void assignManagedClassToPersistenceUnit(Set extends PersistenceContext> persistenceContexts,
+ Set extends PersistenceUnit> persistenceUnits,
+ Class> c) {
+ String cn = JpaExtension.class.getName();
+ String mn = "assignManagedClassToPersistenceUnit";
if (LOGGER.isLoggable(Level.FINER)) {
LOGGER.entering(cn, mn, new Object[] {persistenceContexts, persistenceUnits, c});
}
@@ -652,7 +607,7 @@ private void assignManagedClassToPersistenceUnit(final Set extends Persistence
if (c != null) {
boolean processed = false;
if (persistenceContexts != null && !persistenceContexts.isEmpty()) {
- for (final PersistenceContext persistenceContext : persistenceContexts) {
+ for (PersistenceContext persistenceContext : persistenceContexts) {
if (persistenceContext != null) {
String unitName = persistenceContext.unitName();
if (unitName == null || unitName.isEmpty()) {
@@ -665,7 +620,7 @@ private void assignManagedClassToPersistenceUnit(final Set extends Persistence
}
}
if (persistenceUnits != null && !persistenceUnits.isEmpty()) {
- for (final PersistenceUnit persistenceUnit : persistenceUnits) {
+ for (PersistenceUnit persistenceUnit : persistenceUnits) {
if (persistenceUnit != null) {
String unitName = persistenceUnit.unitName();
if (unitName == null || unitName.isEmpty()) {
@@ -689,21 +644,18 @@ private void assignManagedClassToPersistenceUnit(final Set extends Persistence
}
/**
- * Given a {@link Class} and a name of a persistence unit,
- * associates the {@link Class} with that persistence unit as a
- * member of its list of governed classes.
+ * Given a {@link Class} and a name of a persistence unit, associates the {@link Class} with that persistence unit
+ * as a member of its list of governed classes.
*
- * @param name the name of the persistence unit in question; may
- * be {@code null}
+ * @param name the name of the persistence unit in question; may be {@code null}
*
- * @param managedClass the {@link Class} to associate; may be
- * {@code null} in which case no action will be taken
+ * @param managedClass the {@link Class} to associate; may be {@code null} in which case no action will be taken
*
* @see PersistenceUnitInfo#getManagedClassNames()
*/
- private void addUnlistedManagedClass(String name, final Class> managedClass) {
- final String cn = JpaExtension.class.getName();
- final String mn = "addUnlistedManagedClass";
+ private void addUnlistedManagedClass(String name, Class> managedClass) {
+ String cn = JpaExtension.class.getName();
+ String mn = "addUnlistedManagedClass";
if (LOGGER.isLoggable(Level.FINER)) {
LOGGER.entering(cn, mn, new Object[] {name, managedClass});
}
@@ -727,29 +679,31 @@ private void addUnlistedManagedClass(String name, final Class> managedClass) {
}
/**
- * Stores {@link Set}s of qualifiers that annotate {@link
- * EntityManagerFactory}-typed injection points.
+ * Stores {@link Set}s of qualifiers that annotate {@link EntityManagerFactory}-typed injection points.
*
- * {@link EntityManagerFactory}-typed beans will be added for
- * each such {@link Set}.
+ * {@link EntityManagerFactory}-typed beans will be added for each such {@link Set}.
*
- * @param event a {@link ProcessInjectionPoint} container
- * lifecycle event; must not be {@code null}
+ * @param event a {@link ProcessInjectionPoint} container lifecycle event; must not be {@code null}
*
- * @exception NullPointerException if {@code event} is {@code
- * null}
+ * @exception NullPointerException if {@code event} is {@code null}
*/
private void saveEntityManagerFactoryQualifiers(@Observes
- final ProcessInjectionPoint, T> event) {
- final String cn = JpaExtension.class.getName();
- final String mn = "saveEntityManagerFactoryQualifiers";
+ ProcessInjectionPoint, T> event) {
+ String cn = JpaExtension.class.getName();
+ String mn = "saveEntityManagerFactoryQualifiers";
if (LOGGER.isLoggable(Level.FINER)) {
LOGGER.entering(cn, mn, event);
}
+ if (!this.enabled) {
+ if (LOGGER.isLoggable(Level.FINER)) {
+ LOGGER.exiting(cn, mn);
+ }
+ return;
+ }
Objects.requireNonNull(event);
- final InjectionPoint injectionPoint = event.getInjectionPoint();
+ InjectionPoint injectionPoint = event.getInjectionPoint();
assert injectionPoint != null;
this.persistenceUnitQualifiers.add(injectionPoint.getQualifiers());
@@ -760,32 +714,34 @@ private void saveEntityManagerFactoryQualifiers
}
/**
- * Stores {@link Set}s of qualifiers that annotate {@link
- * EntityManager}-typed injection points.
+ * Stores {@link Set}s of qualifiers that annotate {@link EntityManager}-typed injection points.
*
- * {@link EntityManager}-typed beans will be added for each
- * such {@link Set}.
+ * {@link EntityManager}-typed beans will be added for each such {@link Set}.
*
- * @param event a {@link ProcessInjectionPoint} container
- * lifecycle event; must not be {@code null}
+ * @param event a {@link ProcessInjectionPoint} container lifecycle event; must not be {@code null}
*
- * @exception NullPointerException if {@code event} is {@code
- * null}
+ * @exception NullPointerException if {@code event} is {@code null}
*/
private void saveEntityManagerQualifiers(@Observes
- final ProcessInjectionPoint, T> event) {
- final String cn = JpaExtension.class.getName();
- final String mn = "saveEntityManagerQualifiers";
+ ProcessInjectionPoint, T> event) {
+ String cn = JpaExtension.class.getName();
+ String mn = "saveEntityManagerQualifiers";
if (LOGGER.isLoggable(Level.FINER)) {
LOGGER.entering(cn, mn, event);
}
+ if (!this.enabled) {
+ if (LOGGER.isLoggable(Level.FINER)) {
+ LOGGER.exiting(cn, mn);
+ }
+ return;
+ }
Objects.requireNonNull(event);
- final InjectionPoint injectionPoint = event.getInjectionPoint();
+ InjectionPoint injectionPoint = event.getInjectionPoint();
assert injectionPoint != null;
- final Set qualifiers = injectionPoint.getQualifiers();
+ Set qualifiers = injectionPoint.getQualifiers();
assert qualifiers != null;
boolean error = false;
if (qualifiers.contains(JpaTransactionScoped.Literal.INSTANCE)) {
@@ -823,82 +779,74 @@ private void saveEntityManagerQualifiers(@Observes
/**
* Adds various beans that integrate JPA into CDI SE.
*
- * This method first converts {@code META-INF/persistence.xml}
- * resources into {@link PersistenceUnitInfo} objects and takes
- * into account any other {@link PersistenceUnitInfo} objects that
- * already exist and ensures that all of them are registered as
- * CDI beans.
+ * This method first converts {@code META-INF/persistence.xml} resources into {@link PersistenceUnitInfo} objects
+ * and takes into account any other {@link PersistenceUnitInfo} objects that already exist and ensures that all of
+ * them are registered as CDI beans.
*
- * This allows other CDI-provider-specific mechanisms to use
- * these {@link PersistenceUnitInfo} beans as inputs for creating
- * {@link EntityManager} instances.
+ * This allows other CDI-provider-specific mechanisms to use these {@link PersistenceUnitInfo} beans as inputs
+ * for creating {@link EntityManager} instances.
*
- * Next, this method adds beans to produce {@link
- * EntityManager}s and {@link EntityManagerFactory} instances in
+ *
Next, this method adds beans to produce {@link EntityManager}s and {@link EntityManagerFactory} instances in
* accordance with the JPA specification.
*
- * @param event the {@link AfterBeanDiscovery} event describing
- * the fact that bean discovery has been performed; must not be
- * {@code null}
- *
- * @param beanManager the {@link BeanManager} currently in effect;
+ * @param event the {@link AfterBeanDiscovery} event describing the fact that bean discovery has been performed;
* must not be {@code null}
*
- * @exception IOException if an input or output error occurs,
- * typically because a {@code META-INF/persistence.xml} resource
- * was found but could not be loaded for some reason
+ * @param beanManager the {@link BeanManager} currently in effect; must not be {@code null}
*
- * @exception JAXBException if there was a problem {@linkplain
- * Unmarshaller#unmarshal(Reader) unmarshalling} a {@code
- * META-INF/persistence.xml} resource
+ * @exception IOException if an input or output error occurs, typically because a {@code META-INF/persistence.xml}
+ * resource was found but could not be loaded for some reason
*
- * @exception NullPointerException if either {@code event} or
- * {@code beanManager} is {@code null}
+ * @exception JAXBException if there was a problem {@linkplain Unmarshaller#unmarshal(Reader) unmarshalling} a
+ * {@code META-INF/persistence.xml} resource
+ *
+ * @exception NullPointerException if either {@code event} or {@code beanManager} is {@code null}
*
* @exception ReflectiveOperationException if reflection failed
*
- * @exception XMLStreamException if there was a problem setting up
- * JAXB
+ * @exception XMLStreamException if there was a problem setting up JAXB
*
* @see PersistenceUnitInfo
*/
private void afterBeanDiscovery(@Observes
@Priority(LIBRARY_AFTER)
- final AfterBeanDiscovery event,
- final BeanManager beanManager)
+ AfterBeanDiscovery event,
+ BeanManager beanManager)
throws IOException, JAXBException, ReflectiveOperationException, XMLStreamException {
- final String cn = JpaExtension.class.getName();
- final String mn = "afterBeanDiscovery";
+ String cn = JpaExtension.class.getName();
+ String mn = "afterBeanDiscovery";
if (LOGGER.isLoggable(Level.FINER)) {
LOGGER.entering(cn, mn, new Object[] {event, beanManager});
}
+ if (!this.enabled) {
+ if (LOGGER.isLoggable(Level.FINER)) {
+ LOGGER.exiting(cn, mn);
+ }
+ return;
+ }
Objects.requireNonNull(event);
Objects.requireNonNull(beanManager);
- final Collection extends PersistenceProvider> providers = addPersistenceProviderBeans(event);
+ Collection extends PersistenceProvider> providers = addPersistenceProviderBeans(event);
- // Should we consider type-level @PersistenceContext
- // definitions of persistence units ("implicits")?
+ // Should we consider type-level @PersistenceContext definitions of persistence units ("implicits")?
boolean processImplicits = true;
- // Collect all pre-existing PersistenceUnitInfo beans
- // (i.e. supplied by the end user) and make sure their
- // associated PersistenceProviders are beanified. (Almost
- // always this Set will be empty.)
- final Set> preexistingPersistenceUnitInfoBeans =
+ // Collect all pre-existing PersistenceUnitInfo beans (i.e. supplied by the end user) and make sure their
+ // associated PersistenceProviders are beanified. (Almost always this Set will be empty.)
+ Set> preexistingPersistenceUnitInfoBeans =
beanManager.getBeans(PersistenceUnitInfo.class, Any.Literal.INSTANCE);
if (preexistingPersistenceUnitInfoBeans != null && !preexistingPersistenceUnitInfoBeans.isEmpty()) {
processImplicits = false;
this.maybeAddPersistenceProviderBeans(event, beanManager, preexistingPersistenceUnitInfoBeans, providers);
}
- // Next, and most commonly, load all META-INF/persistence.xml
- // resources with JAXB, and turn them into PersistenceUnitInfo
- // instances, and add beans for all of them as well as their
- // associated PersistenceProviders (if applicable).
- final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
- final Enumeration urls = classLoader.getResources("META-INF/persistence.xml");
+ // Next, and most commonly, load all META-INF/persistence.xml resources with JAXB, and turn them into
+ // PersistenceUnitInfo instances, and add beans for all of them as well as their associated PersistenceProviders
+ // (if applicable).
+ ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ Enumeration urls = classLoader.getResources("META-INF/persistence.xml");
if (urls != null && urls.hasMoreElements()) {
processImplicits = false;
this.processPersistenceXmls(event,
@@ -910,21 +858,17 @@ private void afterBeanDiscovery(@Observes
&& !preexistingPersistenceUnitInfoBeans.isEmpty());
}
- // If we did not find any PersistenceUnitInfo instances via
- // any other means, only then look at those defined "implicitly",
- // i.e. via type-level @PersistenceContext annotations.
+ // If we did not find any PersistenceUnitInfo instances via any other means, only then look at those defined
+ // "implicitly", i.e. via type-level @PersistenceContext annotations.
if (processImplicits) {
this.processImplicitPersistenceUnits(event, providers);
}
- // Add beans to support JPA. In some cases, JTA must be
- // present (see JPA section 7.5, for example: "A
- // container-managed entity manager must be a JTA entity
- // manager.").
+ // Add beans to support JPA. In some cases, JTA must be present (see JPA section 7.5, for example: "A
+ // container-managed entity manager must be a JTA entity manager.").
this.addContainerManagedJpaBeans(event, beanManager);
- // Clear out no-longer-needed-or-used collections to save
- // memory.
+ // Clear out no-longer-needed-or-used collections to save memory.
this.cdiTransactionScopedEntityManagerQualifiers.clear();
this.containerManagedEntityManagerFactoryQualifiers.clear();
this.implicitPersistenceUnits.clear();
@@ -939,46 +883,45 @@ private void afterBeanDiscovery(@Observes
}
/**
- * Ensures that {@link PersistenceUnitInfo}-typed injection points
- * are satisfied.
+ * Ensures that {@link PersistenceUnitInfo}-typed injection points are satisfied.
*
- * @param event the {@link AfterDeploymentValidation} container
- * lifecycle event; must not be {@code null}
+ * @param event the {@link AfterDeploymentValidation} container lifecycle event; must not be {@code null}
*
- * @param beanManager the {@link BeanManager} currently in effect;
- * must not be {@code null}
+ * @param beanManager the {@link BeanManager} currently in effect; must not be {@code null}
*
- * @exception NullPointerException if either {@code event} or
- * {@code beanManager} is {@code null}
+ * @exception NullPointerException if either {@code event} or {@code beanManager} is {@code null}
*/
- private void validate(@Observes final AfterDeploymentValidation event, final BeanManager beanManager) {
- final String cn = JpaExtension.class.getName();
- final String mn = "validateJpaInjectionPoints";
+ private void validate(@Observes AfterDeploymentValidation event, BeanManager beanManager) {
+ String cn = JpaExtension.class.getName();
+ String mn = "validateJpaInjectionPoints";
if (LOGGER.isLoggable(Level.FINER)) {
LOGGER.entering(cn, mn, new Object[] {event, beanManager});
}
+ if (!this.enabled) {
+ if (LOGGER.isLoggable(Level.FINER)) {
+ LOGGER.exiting(cn, mn);
+ }
+ return;
+ }
Objects.requireNonNull(event);
Objects.requireNonNull(beanManager);
if (this.defaultPersistenceUnitInEffect && !this.addedDefaultPersistenceUnit) {
- // The user had originally specified something like
- // just @PersistenceContext (instead
- // of @PersistenceContext(unitName = "something")), but
- // for whatever reason a default PersistenceUnitInfo bean
- // was not added. This will only ever be the case if
- // multiple persistence units are present.
- final Set> persistenceUnitInfoBeans = beanManager.getBeans(PersistenceUnitInfo.class, Any.Literal.INSTANCE);
+ // The user had originally specified something like just @PersistenceContext (instead
+ // of @PersistenceContext(unitName = "something")), but for whatever reason a default PersistenceUnitInfo
+ // bean was not added. This will only ever be the case if multiple persistence units are present.
+ Set> persistenceUnitInfoBeans = beanManager.getBeans(PersistenceUnitInfo.class, Any.Literal.INSTANCE);
assert persistenceUnitInfoBeans != null;
assert persistenceUnitInfoBeans.size() > 1 : "Unexpected persistenceUnitInfoBeans: " + persistenceUnitInfoBeans;
try {
beanManager.resolve(persistenceUnitInfoBeans);
- } catch (final AmbiguousResolutionException expected) {
- final Set names = new HashSet<>();
- for (final Bean> bean : persistenceUnitInfoBeans) {
+ } catch (AmbiguousResolutionException expected) {
+ Set names = new HashSet<>();
+ for (Bean> bean : persistenceUnitInfoBeans) {
assert bean != null;
- final Set qualifiers = bean.getQualifiers();
- for (final Annotation qualifier : qualifiers) {
+ Set qualifiers = bean.getQualifiers();
+ for (Annotation qualifier : qualifiers) {
if (qualifier instanceof Named) {
names.add(((Named) qualifier).value());
break;
@@ -997,41 +940,29 @@ private void validate(@Observes final AfterDeploymentValidation event, final Bea
}
/**
- * Adds certain beans to support injection of {@link
- * EntityManagerFactory} and {@link EntityManager} instances
+ * Adds certain beans to support injection of {@link EntityManagerFactory} and {@link EntityManager} instances
* according to the JPA specification.
*
- * @param event an {@link AfterBeanDiscovery} container lifecycle
- * event; must not be {@code null}
+ * @param event an {@link AfterBeanDiscovery} container lifecycle event; must not be {@code null}
*
- * @param beanManager the current {@link BeanManager}; must not be
- * {@code null}
+ * @param beanManager the current {@link BeanManager}; must not be {@code null}
*
- * @exception NullPointerException if either {@code event} or
- * {@code beanManager} is {@code null}
+ * @exception NullPointerException if either {@code event} or {@code beanManager} is {@code null}
*
- * @see
- * #addContainerManagedEntityManagerFactoryBeans(AfterBeanDiscovery,
- * Set, BeanManager)
+ * @see #addContainerManagedEntityManagerFactoryBeans(AfterBeanDiscovery, Set, BeanManager)
*
- * @see
- * #addCdiTransactionScopedEntityManagerBeans(AfterBeanDiscovery,
- * Set)
+ * @see #addCdiTransactionScopedEntityManagerBeans(AfterBeanDiscovery, Set)
*
- * @see #addExtendedEntityManagerBeans(AfterBeanDiscovery, Set,
- * BeanManager)
+ * @see #addExtendedEntityManagerBeans(AfterBeanDiscovery, Set, BeanManager)
*
- * @see #addNonTransactionalEntityManagerBeans(AfterBeanDiscovery,
- * Set, BeanManager)
+ * @see #addNonTransactionalEntityManagerBeans(AfterBeanDiscovery, Set, BeanManager)
*
- * @see
- * #addJpaTransactionScopedEntityManagerBeans(AfterBeanDiscovery,
- * Set)
+ * @see #addJpaTransactionScopedEntityManagerBeans(AfterBeanDiscovery, Set)
*/
- private void addContainerManagedJpaBeans(final AfterBeanDiscovery event, final BeanManager beanManager)
+ private void addContainerManagedJpaBeans(AfterBeanDiscovery event, BeanManager beanManager)
throws ReflectiveOperationException {
- final String cn = JpaExtension.class.getName();
- final String mn = "addContainerManagedJpaBeans";
+ String cn = JpaExtension.class.getName();
+ String mn = "addContainerManagedJpaBeans";
if (LOGGER.isLoggable(Level.FINER)) {
LOGGER.entering(cn, mn, new Object[] {event, beanManager});
}
@@ -1039,16 +970,13 @@ private void addContainerManagedJpaBeans(final AfterBeanDiscovery event, final B
Objects.requireNonNull(event);
Objects.requireNonNull(beanManager);
- for (final Set qualifiers : this.persistenceUnitQualifiers) {
+ for (Set qualifiers : this.persistenceUnitQualifiers) {
addContainerManagedEntityManagerFactoryBeans(event, qualifiers, beanManager);
}
if (this.transactionsSupported) {
- for (final Set qualifiers : this.persistenceContextQualifiers) {
- // Note that each add* method invoked below is
- // responsible for ensuring that it adds beans only
- // once if at all, i.e. for validating and
- // de-duplicating the qualifiers that it is supplied
- // with if necessary.
+ for (Set qualifiers : this.persistenceContextQualifiers) {
+ // Note that each add* method invoked below is responsible for ensuring that it adds beans only once if
+ // at all, i.e. for validating and de-duplicating the qualifiers that it is supplied with if necessary.
addContainerManagedEntityManagerFactoryBeans(event, qualifiers, beanManager);
addCdiTransactionScopedEntityManagerBeans(event, qualifiers);
if (qualifiers.contains(Extended.Literal.INSTANCE)) {
@@ -1060,11 +988,9 @@ private void addContainerManagedJpaBeans(final AfterBeanDiscovery event, final B
}
}
} else {
- for (final Set qualifiers : this.persistenceContextQualifiers) {
- // Note that each add* method invoked below is
- // responsible for ensuring that it adds beans only
- // once if at all, i.e. for validating the qualifiers
- // that it is supplied with.
+ for (Set qualifiers : this.persistenceContextQualifiers) {
+ // Note that each add* method invoked below is responsible for ensuring that it adds beans only once if
+ // at all, i.e. for validating the qualifiers that it is supplied with.
addContainerManagedEntityManagerFactoryBeans(event, qualifiers, beanManager);
}
}
@@ -1074,11 +1000,11 @@ private void addContainerManagedJpaBeans(final AfterBeanDiscovery event, final B
}
}
- private void addContainerManagedEntityManagerFactoryBeans(final AfterBeanDiscovery event,
- final Set suppliedQualifiers,
- final BeanManager beanManager) {
- final String cn = JpaExtension.class.getName();
- final String mn = "addContainerManagedEntityManagerFactoryBeans";
+ private void addContainerManagedEntityManagerFactoryBeans(AfterBeanDiscovery event,
+ Set suppliedQualifiers,
+ BeanManager beanManager) {
+ String cn = JpaExtension.class.getName();
+ String mn = "addContainerManagedEntityManagerFactoryBeans";
if (LOGGER.isLoggable(Level.FINER)) {
LOGGER.entering(cn, mn, new Object[] {event, suppliedQualifiers, beanManager});
}
@@ -1092,7 +1018,7 @@ private void addContainerManagedEntityManagerFactoryBeans(final AfterBeanDiscove
// @ContainerManaged
// @Named("test")
// private final EntityManagerFactory emf;
- final Set qualifiers = new HashSet<>(suppliedQualifiers);
+ Set qualifiers = new HashSet<>(suppliedQualifiers);
qualifiers.removeAll(JpaCdiQualifiers.JPA_CDI_QUALIFIERS);
qualifiers.add(ContainerManaged.Literal.INSTANCE);
if (this.containerManagedEntityManagerFactoryQualifiers.add(qualifiers)) {
@@ -1118,11 +1044,11 @@ private void addContainerManagedEntityManagerFactoryBeans(final AfterBeanDiscove
}
}
- private void addCdiTransactionScopedEntityManagerBeans(final AfterBeanDiscovery event,
- final Set suppliedQualifiers)
+ private void addCdiTransactionScopedEntityManagerBeans(AfterBeanDiscovery event,
+ Set suppliedQualifiers)
throws ReflectiveOperationException {
- final String cn = JpaExtension.class.getName();
- final String mn = "addCdiTransactionScopedEntityManagerBeans";
+ String cn = JpaExtension.class.getName();
+ String mn = "addCdiTransactionScopedEntityManagerBeans";
if (LOGGER.isLoggable(Level.FINER)) {
LOGGER.entering(cn, mn, new Object[] {event, suppliedQualifiers});
}
@@ -1149,7 +1075,7 @@ private void addCdiTransactionScopedEntityManagerBeans(final AfterBeanDiscovery
// @Unsynchronized // <-- NOTE
// @Named("test")
// private final EntityManager cdiTransactionScopedEm;
- final Set qualifiers = new HashSet<>(suppliedQualifiers);
+ Set qualifiers = new HashSet<>(suppliedQualifiers);
qualifiers.add(ContainerManaged.Literal.INSTANCE);
qualifiers.add(CdiTransactionScoped.Literal.INSTANCE);
qualifiers.remove(Extended.Literal.INSTANCE);
@@ -1159,20 +1085,18 @@ private void addCdiTransactionScopedEntityManagerBeans(final AfterBeanDiscovery
qualifiers.remove(Unsynchronized.Literal.INSTANCE);
if (!this.cdiTransactionScopedEntityManagerQualifiers.contains(qualifiers)) {
this.cdiTransactionScopedEntityManagerQualifiers.add(new HashSet<>(qualifiers));
- final Class extends Annotation> scope;
+ Class extends Annotation> scope;
Class extends Annotation> temp = null;
try {
@SuppressWarnings("unchecked")
- final Class extends Annotation> transactionScopedAnnotationClass =
+ Class extends Annotation> transactionScopedAnnotationClass =
(Class extends Annotation>) Class.forName("jakarta.transaction.TransactionScoped",
true,
Thread.currentThread().getContextClassLoader());
temp = transactionScopedAnnotationClass;
- } catch (final ClassNotFoundException classNotFoundException) {
- // This will not happen if this.transactionsSupported
- // is true, or else CDI's exclusion mechanisms are
- // broken. If somehow it does we throw a severe
- // error.
+ } catch (ClassNotFoundException classNotFoundException) {
+ // This will not happen if this.transactionsSupported is true, or else CDI's exclusion mechanisms are
+ // broken. If somehow it does we throw a severe error.
throw new InternalError(classNotFoundException.getMessage(),
classNotFoundException);
} finally {
@@ -1181,7 +1105,7 @@ private void addCdiTransactionScopedEntityManagerBeans(final AfterBeanDiscovery
assert scope != null;
qualifiers.add(Synchronized.Literal.INSTANCE);
- final Set synchronizedQualifiers = new HashSet<>(qualifiers);
+ Set synchronizedQualifiers = new HashSet<>(qualifiers);
event.addBean()
.addTransitiveTypeClosure(CdiTransactionScopedEntityManager.class)
.scope(scope)
@@ -1194,7 +1118,7 @@ private void addCdiTransactionScopedEntityManagerBeans(final AfterBeanDiscovery
qualifiers.remove(Synchronized.Literal.INSTANCE);
qualifiers.add(Unsynchronized.Literal.INSTANCE);
- final Set unsynchronizedQualifiers = new HashSet<>(qualifiers);
+ Set unsynchronizedQualifiers = new HashSet<>(qualifiers);
event.addBean()
.addTransitiveTypeClosure(CdiTransactionScopedEntityManager.class)
.scope(scope)
@@ -1211,10 +1135,10 @@ private void addCdiTransactionScopedEntityManagerBeans(final AfterBeanDiscovery
}
}
- private void addJpaTransactionScopedEntityManagerBeans(final AfterBeanDiscovery event,
- final Set suppliedQualifiers) {
- final String cn = JpaExtension.class.getName();
- final String mn = "addJpaTransactionScopedEntityManagerBeans";
+ private void addJpaTransactionScopedEntityManagerBeans(AfterBeanDiscovery event,
+ Set suppliedQualifiers) {
+ String cn = JpaExtension.class.getName();
+ String mn = "addJpaTransactionScopedEntityManagerBeans";
if (LOGGER.isLoggable(Level.FINER)) {
LOGGER.entering(cn, mn, new Object[] {event, suppliedQualifiers});
}
@@ -1225,8 +1149,7 @@ private void addJpaTransactionScopedEntityManagerBeans(final AfterBeanDiscovery
throw new IllegalStateException();
}
- // The JpaTransactionScopedEntityManager "tunnels" another
- // scope through it.
+ // The JpaTransactionScopedEntityManager "tunnels" another scope through it.
// Provide support for, e.g.:
// @Inject
@@ -1235,7 +1158,7 @@ private void addJpaTransactionScopedEntityManagerBeans(final AfterBeanDiscovery
// @Synchronized // or @Unsynchronized, or none
// @Named("test")
// private final EntityManager jpaTransactionScopedEm;
- final Set qualifiers = new HashSet<>(suppliedQualifiers);
+ Set