|
16 | 16 | package io.helidon.data; |
17 | 17 |
|
18 | 18 | import java.lang.annotation.ElementType; |
| 19 | +import java.lang.annotation.Repeatable; |
19 | 20 | import java.lang.annotation.Retention; |
20 | 21 | import java.lang.annotation.RetentionPolicy; |
21 | 22 | import java.lang.annotation.Target; |
@@ -134,6 +135,175 @@ private Data() { |
134 | 135 | String value(); |
135 | 136 | } |
136 | 137 |
|
| 138 | + /** |
| 139 | + * Result mapping from a provider result field to a model property. |
| 140 | + * <p> |
| 141 | + * This annotation is intended for compile-time repository processing. Providers may use it to generate mapper code |
| 142 | + * without relying on runtime reflection or implicit column/property naming. |
| 143 | + */ |
| 144 | + @Target({ElementType.TYPE, ElementType.METHOD}) |
| 145 | + @Retention(RetentionPolicy.SOURCE) |
| 146 | + @Repeatable(Maps.class) |
| 147 | + public @interface Map { |
| 148 | + /** |
| 149 | + * Source result field, such as a SQL column label. |
| 150 | + * <p> |
| 151 | + * This is an alias for {@link #source()}. |
| 152 | + * |
| 153 | + * @return source result field |
| 154 | + */ |
| 155 | + String value() default ""; |
| 156 | + |
| 157 | + /** |
| 158 | + * Source result field, such as a SQL column label. |
| 159 | + * <p> |
| 160 | + * This is an alias for {@link #value()}. |
| 161 | + * |
| 162 | + * @return source result field |
| 163 | + */ |
| 164 | + String source() default ""; |
| 165 | + |
| 166 | + /** |
| 167 | + * Target model property. |
| 168 | + * |
| 169 | + * @return target model property |
| 170 | + */ |
| 171 | + String target(); |
| 172 | + } |
| 173 | + |
| 174 | + /** |
| 175 | + * Container annotation for repeatable {@link Data.Map} declarations. |
| 176 | + */ |
| 177 | + @Target({ElementType.TYPE, ElementType.METHOD}) |
| 178 | + @Retention(RetentionPolicy.SOURCE) |
| 179 | + public @interface Maps { |
| 180 | + /** |
| 181 | + * Mapping declarations. |
| 182 | + * |
| 183 | + * @return mapping declarations |
| 184 | + */ |
| 185 | + Map[] value(); |
| 186 | + } |
| 187 | + |
| 188 | + /** |
| 189 | + * Result aggregation key. |
| 190 | + * <p> |
| 191 | + * Providers may use this annotation when generating relationship reducers for joined result sets. When omitted, |
| 192 | + * providers may use their documented key conventions, such as {@code id} for the root object and |
| 193 | + * {@code relation.id} for collection elements. |
| 194 | + */ |
| 195 | + @Target({ElementType.TYPE, ElementType.METHOD}) |
| 196 | + @Retention(RetentionPolicy.SOURCE) |
| 197 | + @Repeatable(Keys.class) |
| 198 | + public @interface Key { |
| 199 | + /** |
| 200 | + * Source result fields that make up the key. |
| 201 | + * <p> |
| 202 | + * This is an alias for {@link #source()}. |
| 203 | + * |
| 204 | + * @return source result fields |
| 205 | + */ |
| 206 | + String[] value() default {}; |
| 207 | + |
| 208 | + /** |
| 209 | + * Source result fields that make up the key. |
| 210 | + * <p> |
| 211 | + * This is an alias for {@link #value()}. |
| 212 | + * |
| 213 | + * @return source result fields |
| 214 | + */ |
| 215 | + String[] source() default {}; |
| 216 | + |
| 217 | + /** |
| 218 | + * Target aggregate path. An empty value identifies the root aggregate. |
| 219 | + * |
| 220 | + * @return target aggregate path |
| 221 | + */ |
| 222 | + String target() default ""; |
| 223 | + } |
| 224 | + |
| 225 | + /** |
| 226 | + * Container annotation for repeatable {@link Data.Key} declarations. |
| 227 | + */ |
| 228 | + @Target({ElementType.TYPE, ElementType.METHOD}) |
| 229 | + @Retention(RetentionPolicy.SOURCE) |
| 230 | + public @interface Keys { |
| 231 | + /** |
| 232 | + * Key declarations. |
| 233 | + * |
| 234 | + * @return key declarations |
| 235 | + */ |
| 236 | + Key[] value(); |
| 237 | + } |
| 238 | + |
| 239 | + /** |
| 240 | + * Declarative result mapper contract. |
| 241 | + * <p> |
| 242 | + * Providers may generate mapper implementations from this annotation and companion {@link Data.Map} declarations. |
| 243 | + * The annotated type describes mapping metadata only; applications are not expected to implement JDBC row-reading logic. |
| 244 | + */ |
| 245 | + @Target(ElementType.TYPE) |
| 246 | + @Retention(RetentionPolicy.SOURCE) |
| 247 | + public @interface Mapper { |
| 248 | + /** |
| 249 | + * Target model type created by the generated mapper. |
| 250 | + * |
| 251 | + * @return target model type |
| 252 | + */ |
| 253 | + Class<?> target(); |
| 254 | + } |
| 255 | + |
| 256 | + /** |
| 257 | + * Selects a result mapper for a repository method. |
| 258 | + * <p> |
| 259 | + * The selected type may be a declarative {@link Data.Mapper} contract whose implementation is generated at build time. |
| 260 | + * Providers may also use this annotation later for explicit mapper service extension points. |
| 261 | + */ |
| 262 | + @Target(ElementType.METHOD) |
| 263 | + @Retention(RetentionPolicy.SOURCE) |
| 264 | + public @interface MapWith { |
| 265 | + /** |
| 266 | + * Mapper contract or mapper service type. |
| 267 | + * |
| 268 | + * @return mapper type |
| 269 | + */ |
| 270 | + Class<?> value(); |
| 271 | + } |
| 272 | + |
| 273 | + /** |
| 274 | + * Selects a result reducer for a repository method. |
| 275 | + * <p> |
| 276 | + * The selected type may be a declarative {@link Data.Mapper} contract whose reducer implementation is generated at |
| 277 | + * build time. Providers may also use this annotation later for explicit reducer service extension points. |
| 278 | + */ |
| 279 | + @Target(ElementType.METHOD) |
| 280 | + @Retention(RetentionPolicy.SOURCE) |
| 281 | + public @interface ReduceWith { |
| 282 | + /** |
| 283 | + * Reducer contract or reducer service type. |
| 284 | + * |
| 285 | + * @return reducer type |
| 286 | + */ |
| 287 | + Class<?> value(); |
| 288 | + } |
| 289 | + |
| 290 | + /** |
| 291 | + * Generated keys requested by a repository method. |
| 292 | + * <p> |
| 293 | + * This annotation is provider-neutral. JDBC providers may translate the supplied column names to |
| 294 | + * {@link java.sql.Connection#prepareStatement(String, String[])} generated-key handling. |
| 295 | + */ |
| 296 | + @Target(ElementType.METHOD) |
| 297 | + @Retention(RetentionPolicy.SOURCE) |
| 298 | + public @interface GeneratedKeys { |
| 299 | + /** |
| 300 | + * Generated-key column names. When empty, the provider default generated-key behavior is used. |
| 301 | + * |
| 302 | + * @return generated-key column names |
| 303 | + */ |
| 304 | + String[] value() default {}; |
| 305 | + } |
| 306 | + |
137 | 307 | /** |
138 | 308 | * Data repository interface for basic entity operations. |
139 | 309 | * |
|
0 commit comments