|
18 | 18 | import static org.springframework.data.jpa.provider.JpaClassUtils.*;
|
19 | 19 | import static org.springframework.data.jpa.provider.PersistenceProvider.Constants.*;
|
20 | 20 |
|
21 |
| -import java.util.Collections; |
22 |
| -import java.util.NoSuchElementException; |
23 |
| -import java.util.Set; |
24 |
| - |
25 | 21 | import jakarta.persistence.EntityManager;
|
26 | 22 | import jakarta.persistence.Query;
|
27 | 23 | import jakarta.persistence.metamodel.IdentifiableType;
|
28 | 24 | import jakarta.persistence.metamodel.Metamodel;
|
29 | 25 | import jakarta.persistence.metamodel.SingularAttribute;
|
30 | 26 |
|
| 27 | +import java.util.Collections; |
| 28 | +import java.util.NoSuchElementException; |
| 29 | +import java.util.Set; |
| 30 | + |
| 31 | +import org.eclipse.persistence.config.QueryHints; |
31 | 32 | import org.eclipse.persistence.jpa.JpaQuery;
|
32 | 33 | import org.eclipse.persistence.queries.ScrollableCursor;
|
33 | 34 | import org.hibernate.ScrollMode;
|
34 | 35 | import org.hibernate.ScrollableResults;
|
35 | 36 | import org.hibernate.proxy.HibernateProxy;
|
36 |
| - |
37 | 37 | import org.springframework.data.jpa.repository.query.JpaParameters;
|
38 | 38 | import org.springframework.data.jpa.repository.query.JpaParametersParameterAccessor;
|
39 | 39 | import org.springframework.data.util.CloseableIterator;
|
|
49 | 49 | * @author Thomas Darimont
|
50 | 50 | * @author Mark Paluch
|
51 | 51 | * @author Jens Schauder
|
| 52 | + * @author Greg Turnquist |
52 | 53 | */
|
53 |
| -public enum PersistenceProvider implements QueryExtractor, ProxyIdAccessor { |
| 54 | +public enum PersistenceProvider implements QueryExtractor, ProxyIdAccessor, QueryComment { |
54 | 55 |
|
55 | 56 | /**
|
56 | 57 | * Hibernate persistence provider.
|
@@ -102,9 +103,15 @@ public CloseableIterator<Object> executeQueryWithResultStream(Query jpaQuery) {
|
102 | 103 | }
|
103 | 104 |
|
104 | 105 | @Override
|
105 |
| - public JpaParametersParameterAccessor getParameterAccessor(JpaParameters parameters, Object[] values, EntityManager em) { |
| 106 | + public JpaParametersParameterAccessor getParameterAccessor(JpaParameters parameters, Object[] values, |
| 107 | + EntityManager em) { |
106 | 108 | return new HibernateJpaParametersParameterAccessor(parameters, values, em);
|
107 | 109 | }
|
| 110 | + |
| 111 | + @Override |
| 112 | + public String getCommentHintKey() { |
| 113 | + return "org.hibernate.comment"; |
| 114 | + } |
108 | 115 | },
|
109 | 116 |
|
110 | 117 | /**
|
@@ -133,6 +140,16 @@ public Object getIdentifierFrom(Object entity) {
|
133 | 140 | public CloseableIterator<Object> executeQueryWithResultStream(Query jpaQuery) {
|
134 | 141 | return new EclipseLinkScrollableResultsIterator<>(jpaQuery);
|
135 | 142 | }
|
| 143 | + |
| 144 | + @Override |
| 145 | + public String getCommentHintKey() { |
| 146 | + return QueryHints.HINT; |
| 147 | + } |
| 148 | + |
| 149 | + @Override |
| 150 | + public String getCommentHintValue(String comment) { |
| 151 | + return "/* " + comment + " */"; |
| 152 | + } |
136 | 153 | },
|
137 | 154 |
|
138 | 155 | /**
|
@@ -161,11 +178,18 @@ public boolean shouldUseAccessorFor(Object entity) {
|
161 | 178 | public Object getIdentifierFrom(Object entity) {
|
162 | 179 | return null;
|
163 | 180 | }
|
| 181 | + |
| 182 | + @Nullable |
| 183 | + @Override |
| 184 | + public String getCommentHintKey() { |
| 185 | + return null; |
| 186 | + } |
164 | 187 | };
|
165 | 188 |
|
166 | 189 | static ConcurrentReferenceHashMap<Class<?>, PersistenceProvider> CACHE = new ConcurrentReferenceHashMap<>();
|
167 | 190 | private final Iterable<String> entityManagerClassNames;
|
168 | 191 | private final Iterable<String> metamodelClassNames;
|
| 192 | + |
169 | 193 | /**
|
170 | 194 | * Creates a new {@link PersistenceProvider}.
|
171 | 195 | *
|
@@ -249,7 +273,8 @@ public static PersistenceProvider fromMetamodel(Metamodel metamodel) {
|
249 | 273 | return cacheAndReturn(metamodelType, GENERIC_JPA);
|
250 | 274 | }
|
251 | 275 |
|
252 |
| - public JpaParametersParameterAccessor getParameterAccessor(JpaParameters parameters, Object[] values, EntityManager em) { |
| 276 | + public JpaParametersParameterAccessor getParameterAccessor(JpaParameters parameters, Object[] values, |
| 277 | + EntityManager em) { |
253 | 278 | return new JpaParametersParameterAccessor(parameters, values);
|
254 | 279 | }
|
255 | 280 |
|
|
0 commit comments