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 supplier; /* @@ -80,7 +70,7 @@ abstract class DelegatingEntityManager implements EntityManager, AutoCloseable { * @see #acquireDelegate() */ DelegatingEntityManager() { - this(null); + this((Supplier) null); } /** @@ -96,9 +86,13 @@ abstract class DelegatingEntityManager implements EntityManager, AutoCloseable { * * @see #acquireDelegate() */ - DelegatingEntityManager(final EntityManager delegate) { + DelegatingEntityManager(EntityManager delegate) { + this(delegate == null ? (Supplier) null : () -> delegate); + } + + DelegatingEntityManager(Supplier 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..6302e973d43 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. @@ -316,7 +316,7 @@ public class JpaExtension implements Extension { * persistence unit. This has implications on how beans are * installed. * - * @see #validate(AfterDeploymentValidation) + * @see #validate(AfterDeploymentValidation, BeanManager) */ private boolean defaultPersistenceUnitInEffect; @@ -324,7 +324,7 @@ public class JpaExtension implements Extension { * Indicates whether a bean for the default persistence unit * has been added. * - * @see #validate(AfterDeploymentValidation) + * @see #validate(AfterDeploymentValidation, BeanManager) */ private boolean addedDefaultPersistenceUnit; @@ -380,8 +380,8 @@ public JpaExtension() { * field to {@code false}. * * @param event a {@link ProcessAnnotatedType - * ProcessAnnotatedType<}{@link NoTransactionSupport - * NoTransactionSupport>} whose presence indicates that JTA + * 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 diff --git a/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/JpaTransactionScopedEntityManager.java b/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/JpaTransactionScopedEntityManager.java index 0db024200c7..e26f499fb81 100644 --- a/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/JpaTransactionScopedEntityManager.java +++ b/integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/JpaTransactionScopedEntityManager.java @@ -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. @@ -215,10 +215,9 @@ final class JpaTransactionScopedEntityManager extends DelegatingEntityManager { * *

This method never returns {@code null}.

* - *

If a {@linkplain TransactionSupport#inTransaction() JTA - * transaction is active}, then an {@link EntityManager} that is - * joined to it is returned. Otherwise a non-transactional {@link - * EntityManager} is returned.

+ *

If a JTA transaction is active, then an + * {@link EntityManager}} that is joined to it is returned. Otherwise a + * non-transactional {@link EntityManager} is returned.

* *

Recall that this method is invoked by all {@link * DelegatingEntityManager} methods.