|
4 | 4 | */ |
5 | 5 | package org.hibernate.query.specification; |
6 | 6 |
|
7 | | -import jakarta.persistence.TypedQueryReference; |
8 | 7 | import jakarta.persistence.EntityManager; |
9 | | -import jakarta.persistence.criteria.CriteriaQuery; |
| 8 | +import jakarta.persistence.TypedQueryReference; |
10 | 9 | import jakarta.persistence.criteria.CriteriaBuilder; |
| 10 | +import jakarta.persistence.criteria.CriteriaQuery; |
11 | 11 | import jakarta.persistence.criteria.Root; |
| 12 | +import jakarta.persistence.metamodel.SingularAttribute; |
12 | 13 |
|
13 | 14 | import org.hibernate.Incubating; |
14 | 15 | import org.hibernate.Session; |
|
17 | 18 | import org.hibernate.query.Order; |
18 | 19 | import org.hibernate.query.Page; |
19 | 20 | import org.hibernate.query.SelectionQuery; |
20 | | -import org.hibernate.query.specification.internal.SelectionSpecificationImpl; |
21 | 21 | import org.hibernate.query.restriction.Path; |
22 | 22 | import org.hibernate.query.restriction.Restriction; |
| 23 | +import org.hibernate.query.specification.internal.SelectionSpecificationImpl; |
23 | 24 |
|
24 | 25 | import java.util.List; |
25 | 26 |
|
@@ -242,4 +243,50 @@ static <T> SelectionSpecification<T> create(Class<T> resultType, String hql) { |
242 | 243 | static <T> SelectionSpecification<T> create(CriteriaQuery<T> criteria) { |
243 | 244 | return new SelectionSpecificationImpl<>( criteria ); |
244 | 245 | } |
| 246 | + |
| 247 | + /** |
| 248 | + * Create a {@link ProjectionSpecification} allowing selection of specific |
| 249 | + * {@linkplain ProjectionSpecification#select(SingularAttribute) fields} |
| 250 | + * and {@linkplain ProjectionSpecification#select(Path) compound paths}. |
| 251 | + * The returned projection holds a reference to this specification, |
| 252 | + * and so mutation of this object also affects the projection. |
| 253 | + * |
| 254 | + * @return a new {@link ProjectionSpecification} |
| 255 | + * |
| 256 | + * @since 7.2 |
| 257 | + */ |
| 258 | + @Incubating |
| 259 | + default ProjectionSpecification<T> createProjection() { |
| 260 | + return ProjectionSpecification.create( this ); |
| 261 | + } |
| 262 | + |
| 263 | + /** |
| 264 | + * Create a {@link SimpleProjectionSpecification} for the given |
| 265 | + * {@linkplain ProjectionSpecification#select(SingularAttribute) field}. |
| 266 | + * The returned projection holds a reference to this specification, |
| 267 | + * and so mutation of this object also affects the projection. |
| 268 | + * |
| 269 | + * @return a new {@link SimpleProjectionSpecification} |
| 270 | + * |
| 271 | + * @since 7.2 |
| 272 | + */ |
| 273 | + @Incubating |
| 274 | + default <X> SimpleProjectionSpecification<T,X> createProjection(SingularAttribute<? super T, X> attribute) { |
| 275 | + return SimpleProjectionSpecification.create( this, attribute ); |
| 276 | + } |
| 277 | + |
| 278 | + /** |
| 279 | + * Create a {@link SimpleProjectionSpecification} for the given |
| 280 | + * {@linkplain ProjectionSpecification#select(Path) compound path}. |
| 281 | + * The returned projection holds a reference to this specification, |
| 282 | + * and so mutation of this object also affects the projection. |
| 283 | + * |
| 284 | + * @return a new {@link SimpleProjectionSpecification} |
| 285 | + * |
| 286 | + * @since 7.2 |
| 287 | + */ |
| 288 | + @Incubating |
| 289 | + default <X> SimpleProjectionSpecification<T,X> createProjection(Path<T, X> path) { |
| 290 | + return SimpleProjectionSpecification.create( this, path ); |
| 291 | + } |
245 | 292 | } |
0 commit comments