|
15 | 15 | */
|
16 | 16 | package org.springframework.data.jpa.repository;
|
17 | 17 |
|
18 |
| -import org.springframework.core.annotation.AliasFor; |
19 |
| -import org.springframework.data.annotation.QueryAnnotation; |
| 18 | +import java.lang.annotation.Documented; |
| 19 | +import java.lang.annotation.ElementType; |
| 20 | +import java.lang.annotation.Retention; |
| 21 | +import java.lang.annotation.RetentionPolicy; |
| 22 | +import java.lang.annotation.Target; |
20 | 23 |
|
21 |
| -import java.lang.annotation.*; |
| 24 | +import org.springframework.core.annotation.AliasFor; |
22 | 25 |
|
23 | 26 | /**
|
24 |
| - * Annotation to declare native queries directly on repository methods. |
| 27 | + * Annotation to declare native queries directly on repository query methods. |
| 28 | + * <p> |
| 29 | + * Specifically {@code @NativeQuery} is a <em>composed annotation</em> that acts as a shortcut for |
| 30 | + * {@code @Query(nativeQuery = true)} for most attributes. |
25 | 31 | * <p>
|
26 |
| - * Specifically {@code @NativeQuery} is a <em>composed annotation</em> that |
27 |
| - * acts as a shortcut for {@code @Query(nativeQuery = true)}. |
| 32 | + * This annotation defines {@code sqlResultSetMapping} to apply JPA SQL ResultSet mapping for native queries. Make sure |
| 33 | + * to use the corresponding return type as defined in {@code @SqlResultSetMapping}. When using named native queries, |
| 34 | + * define SQL result set mapping through {@code @NamedNativeQuery(resultSetMapping=…)} as named queries do not accept |
| 35 | + * {@code sqlResultSetMapping}. |
28 | 36 | *
|
29 | 37 | * @author Danny van den Elshout
|
30 |
| - * @since 3.3 |
| 38 | + * @author Mark Paluch |
| 39 | + * @since 3.4 |
31 | 40 | * @see Query
|
| 41 | + * @see Modifying |
32 | 42 | */
|
33 |
| - |
34 | 43 | @Retention(RetentionPolicy.RUNTIME)
|
35 | 44 | @Target({ ElementType.METHOD, ElementType.ANNOTATION_TYPE })
|
36 |
| -@QueryAnnotation |
37 | 45 | @Documented
|
38 | 46 | @Query(nativeQuery = true)
|
39 | 47 | public @interface NativeQuery {
|
40 | 48 |
|
41 |
| - /** |
42 |
| - * Alias for {@link Query#value()} |
43 |
| - */ |
44 |
| - @AliasFor(annotation = Query.class) |
45 |
| - String value() default ""; |
| 49 | + /** |
| 50 | + * Defines the native query to be executed when the annotated method is called. Alias for {@link Query#value()}. |
| 51 | + */ |
| 52 | + @AliasFor(annotation = Query.class) |
| 53 | + String value() default ""; |
| 54 | + |
| 55 | + /** |
| 56 | + * Defines a special count query that shall be used for pagination queries to look up the total number of elements for |
| 57 | + * a page. If none is configured we will derive the count query from the original query or {@link #countProjection()} |
| 58 | + * query if any. Alias for {@link Query#countQuery()}. |
| 59 | + */ |
| 60 | + @AliasFor(annotation = Query.class) |
| 61 | + String countQuery() default ""; |
46 | 62 |
|
47 |
| - /** |
48 |
| - * Alias for {@link Query#countQuery()} |
49 |
| - */ |
50 |
| - @AliasFor(annotation = Query.class) |
51 |
| - String countQuery() default ""; |
| 63 | + /** |
| 64 | + * Defines the projection part of the count query that is generated for pagination. If neither {@link #countQuery()} |
| 65 | + * nor {@code countProjection()} is configured we will derive the count query from the original query. Alias for |
| 66 | + * {@link Query#countProjection()}. |
| 67 | + */ |
| 68 | + @AliasFor(annotation = Query.class) |
| 69 | + String countProjection() default ""; |
52 | 70 |
|
53 |
| - /** |
54 |
| - * Alias for {@link Query#countProjection()} |
55 |
| - */ |
56 |
| - @AliasFor(annotation = Query.class) |
57 |
| - String countProjection() default ""; |
| 71 | + /** |
| 72 | + * The named query to be used. If not defined, a {@link jakarta.persistence.NamedQuery} with name of |
| 73 | + * {@code ${domainClass}.${queryMethodName}} will be used. Alias for {@link Query#name()}. |
| 74 | + */ |
| 75 | + @AliasFor(annotation = Query.class) |
| 76 | + String name() default ""; |
58 | 77 |
|
59 |
| - /** |
60 |
| - * Alias for {@link Query#name()} |
61 |
| - */ |
62 |
| - @AliasFor(annotation = Query.class) |
63 |
| - String name() default ""; |
| 78 | + /** |
| 79 | + * Returns the name of the {@link jakarta.persistence.NamedQuery} to be used to execute count queries when pagination |
| 80 | + * is used. Will default to the named query name configured suffixed by {@code .count}. Alias for |
| 81 | + * {@link Query#countName()}. |
| 82 | + */ |
| 83 | + @AliasFor(annotation = Query.class) |
| 84 | + String countName() default ""; |
64 | 85 |
|
65 |
| - /** |
66 |
| - * Alias for {@link Query#countName()} |
67 |
| - */ |
68 |
| - @AliasFor(annotation = Query.class) |
69 |
| - String countName() default ""; |
| 86 | + /** |
| 87 | + * Define a {@link QueryRewriter} that should be applied to the query string after the query is fully assembled. Alias |
| 88 | + * for {@link Query#queryRewriter()}. |
| 89 | + */ |
| 90 | + @AliasFor(annotation = Query.class) |
| 91 | + Class<? extends QueryRewriter> queryRewriter() default QueryRewriter.IdentityQueryRewriter.class; |
70 | 92 |
|
71 |
| - /** |
72 |
| - * Alias for {@link Query#queryRewriter()} |
73 |
| - */ |
74 |
| - @AliasFor(annotation = Query.class) |
75 |
| - Class<? extends QueryRewriter> queryRewriter() default QueryRewriter.IdentityQueryRewriter.class; |
| 93 | + /** |
| 94 | + * Name of the {@link jakarta.persistence.SqlResultSetMapping @SqlResultSetMapping(name)} to apply for this query. |
| 95 | + */ |
| 96 | + String sqlResultSetMapping() default ""; |
76 | 97 | }
|
0 commit comments