diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/NodeBuilder.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/NodeBuilder.java index b353820ef5..bca66ab628 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/NodeBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/NodeBuilder.java @@ -735,6 +735,62 @@ public interface NodeBuilder extends HibernateCriteriaBuilder { */ SqmExpression arrayFill(T element, Integer elementCount); + /** + * Determines all 1-based positions of an element in an array. + * + * @since 6.4 + */ + SqmExpression arrayPositions(SqmExpression arrayExpression, SqmExpression elementExpression); + + /** + * Determines all 1-based positions of an element in an array. + * + * @since 6.4 + */ + SqmExpression arrayPositions(SqmExpression arrayExpression, T element); + + /** + * Determines all 1-based positions of an element in an array. + * + * @since 6.4 + */ + SqmExpression arrayPositions(T[] array, SqmExpression elementExpression); + + /** + * Determines all 1-based positions of an element in an array. + * + * @since 6.4 + */ + SqmExpression arrayPositions(T[] array, T element); + + /** + * Determines all 1-based positions of an element in an array. + * + * @since 6.4 + */ + SqmExpression> arrayPositionsList(SqmExpression arrayExpression, SqmExpression elementExpression); + + /** + * Determines all 1-based positions of an element in an array. + * + * @since 6.4 + */ + SqmExpression> arrayPositionsList(SqmExpression arrayExpression, T element); + + /** + * Determines all 1-based positions of an element in an array. + * + * @since 6.4 + */ + SqmExpression> arrayPositionsList(T[] array, SqmExpression elementExpression); + + /** + * Determines all 1-based positions of an element in an array. + * + * @since 6.4 + */ + SqmExpression> arrayPositionsList(T[] array, T element); + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Array functions for collection types @@ -1333,6 +1389,62 @@ public interface NodeBuilder extends HibernateCriteriaBuilder { */ SqmExpression> collectionFill(T element, Integer elementCount); + /** + * Determines all 1-based positions of an element in a basic collection. + * + * @since 6.4 + */ + SqmExpression collectionPositions(SqmExpression> collectionExpression, SqmExpression elementExpression); + + /** + * Determines all 1-based positions of an element in a basic collection. + * + * @since 6.4 + */ + SqmExpression collectionPositions(SqmExpression> collectionExpression, T element); + + /** + * Determines all 1-based positions of an element in a basic collection. + * + * @since 6.4 + */ + SqmExpression collectionPositions(Collection collection, SqmExpression elementExpression); + + /** + * Determines all 1-based positions of an element in a basic collection. + * + * @since 6.4 + */ + SqmExpression collectionPositions(Collection collection, T element); + + /** + * Determines all 1-based positions of an element in a basic collection. + * + * @since 6.4 + */ + SqmExpression> collectionPositionsList(SqmExpression> collectionExpression, SqmExpression elementExpression); + + /** + * Determines all 1-based positions of an element in a basic collection. + * + * @since 6.4 + */ + SqmExpression> collectionPositionsList(SqmExpression> collectionExpression, T element); + + /** + * Determines all 1-based positions of an element in a basic collection. + * + * @since 6.4 + */ + SqmExpression> collectionPositionsList(Collection collection, SqmExpression elementExpression); + + /** + * Determines all 1-based positions of an element in a basic collection. + * + * @since 6.4 + */ + SqmExpression> collectionPositionsList(Collection collection, T element); + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Covariant overrides diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmCriteriaNodeBuilder.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmCriteriaNodeBuilder.java index 6ad9c8cd38..3ca5875a7b 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmCriteriaNodeBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmCriteriaNodeBuilder.java @@ -3685,6 +3685,82 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, ); } + @Override + public SqmExpression arrayPositions( + SqmExpression arrayExpression, + SqmExpression elementExpression) { + return getFunctionDescriptor( "array_positions" ).generateSqmExpression( + asList( arrayExpression, elementExpression ), + null, + queryEngine + ); + } + + @Override + public SqmExpression arrayPositions(SqmExpression arrayExpression, T element) { + return getFunctionDescriptor( "array_positions" ).generateSqmExpression( + asList( arrayExpression, value( element ) ), + null, + queryEngine + ); + } + + @Override + public SqmExpression arrayPositions(T[] array, SqmExpression elementExpression) { + return getFunctionDescriptor( "array_positions" ).generateSqmExpression( + asList( value( array ), elementExpression ), + null, + queryEngine + ); + } + + @Override + public SqmExpression arrayPositions(T[] array, T element) { + return getFunctionDescriptor( "array_positions" ).generateSqmExpression( + asList( value( array ), value( element ) ), + null, + queryEngine + ); + } + + @Override + public SqmExpression> arrayPositionsList( + SqmExpression arrayExpression, + SqmExpression elementExpression) { + return getFunctionDescriptor( "array_positions_list" ).generateSqmExpression( + asList( arrayExpression, elementExpression ), + null, + queryEngine + ); + } + + @Override + public SqmExpression> arrayPositionsList(SqmExpression arrayExpression, T element) { + return getFunctionDescriptor( "array_positions_list" ).generateSqmExpression( + asList( arrayExpression, value( element ) ), + null, + queryEngine + ); + } + + @Override + public SqmExpression> arrayPositionsList(T[] array, SqmExpression elementExpression) { + return getFunctionDescriptor( "array_positions_list" ).generateSqmExpression( + asList( value( array ), elementExpression ), + null, + queryEngine + ); + } + + @Override + public SqmExpression> arrayPositionsList(T[] array, T element) { + return getFunctionDescriptor( "array_positions_list" ).generateSqmExpression( + asList( value( array ), value( element ) ), + null, + queryEngine + ); + } + @Override public SqmExpression arrayLength(SqmExpression arrayExpression) { return getFunctionDescriptor( "array_length" ).generateSqmExpression( @@ -5384,4 +5460,88 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, queryEngine ); } + + @Override + public SqmExpression collectionPositions( + SqmExpression> collectionExpression, + SqmExpression elementExpression) { + return getFunctionDescriptor( "array_positions" ).generateSqmExpression( + asList( collectionExpression, elementExpression ), + null, + queryEngine + ); + } + + @Override + public SqmExpression collectionPositions( + SqmExpression> collectionExpression, + T element) { + return getFunctionDescriptor( "array_positions" ).generateSqmExpression( + asList( collectionExpression, value( element ) ), + null, + queryEngine + ); + } + + @Override + public SqmExpression collectionPositions( + Collection collection, + SqmExpression elementExpression) { + return getFunctionDescriptor( "array_positions" ).generateSqmExpression( + asList( value( collection ), elementExpression ), + null, + queryEngine + ); + } + + @Override + public SqmExpression collectionPositions(Collection collection, T element) { + return getFunctionDescriptor( "array_positions" ).generateSqmExpression( + asList( value( collection ), value( element ) ), + null, + queryEngine + ); + } + + @Override + public SqmExpression> collectionPositionsList( + SqmExpression> collectionExpression, + SqmExpression elementExpression) { + return getFunctionDescriptor( "array_positions_list" ).generateSqmExpression( + asList( collectionExpression, elementExpression ), + null, + queryEngine + ); + } + + @Override + public SqmExpression> collectionPositionsList( + SqmExpression> collectionExpression, + T element) { + return getFunctionDescriptor( "array_positions_list" ).generateSqmExpression( + asList( collectionExpression, value( element ) ), + null, + queryEngine + ); + } + + @Override + public SqmExpression> collectionPositionsList( + Collection collection, + SqmExpression elementExpression) { + return getFunctionDescriptor( "array_positions_list" ).generateSqmExpression( + asList( value( collection ), elementExpression ), + null, + queryEngine + ); + } + + @Override + public SqmExpression> collectionPositionsList(Collection collection, T element) { + return getFunctionDescriptor( "array_positions_list" ).generateSqmExpression( + asList( value( collection ), value( element ) ), + null, + queryEngine + ); + } }