HHH-17355 Add array_fill function to NodeBuilder

This commit is contained in:
Christian Beikov 2023-10-30 14:43:56 +01:00
parent 1a5184e89b
commit fe9289ba57
2 changed files with 132 additions and 0 deletions

View File

@ -707,6 +707,34 @@ public interface NodeBuilder extends HibernateCriteriaBuilder {
*/ */
<T> SqmExpression<T[]> arrayTrim(T[] array, Integer elementCount); <T> SqmExpression<T[]> arrayTrim(T[] array, Integer elementCount);
/**
* Creates array with the same element N times, as specified by the arguments.
*
* @since 6.4
*/
<T> SqmExpression<T[]> arrayFill(SqmExpression<T> elementExpression, SqmExpression<Integer> elementCountExpression);
/**
* Creates array with the same element N times, as specified by the arguments.
*
* @since 6.4
*/
<T> SqmExpression<T[]> arrayFill(SqmExpression<T> elementExpression, Integer elementCount);
/**
* Creates array with the same element N times, as specified by the arguments.
*
* @since 6.4
*/
<T> SqmExpression<T[]> arrayFill(T element, SqmExpression<Integer> elementCountExpression);
/**
* Creates array with the same element N times, as specified by the arguments.
*
* @since 6.4
*/
<T> SqmExpression<T[]> arrayFill(T element, Integer elementCount);
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Array functions for collection types // Array functions for collection types
@ -1277,6 +1305,34 @@ public interface NodeBuilder extends HibernateCriteriaBuilder {
*/ */
<C extends Collection<?>> SqmExpression<C> collectionTrim(C collection, Integer elementCount); <C extends Collection<?>> SqmExpression<C> collectionTrim(C collection, Integer elementCount);
/**
* Creates basic collection with the same element N times, as specified by the arguments.
*
* @since 6.4
*/
<T> SqmExpression<Collection<T>> collectionFill(SqmExpression<T> elementExpression, SqmExpression<Integer> elementCountExpression);
/**
* Creates basic collection with the same element N times, as specified by the arguments.
*
* @since 6.4
*/
<T> SqmExpression<Collection<T>> collectionFill(SqmExpression<T> elementExpression, Integer elementCount);
/**
* Creates basic collection with the same element N times, as specified by the arguments.
*
* @since 6.4
*/
<T> SqmExpression<Collection<T>> collectionFill(T element, SqmExpression<Integer> elementCountExpression);
/**
* Creates basic collection with the same element N times, as specified by the arguments.
*
* @since 6.4
*/
<T> SqmExpression<Collection<T>> collectionFill(T element, Integer elementCount);
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Covariant overrides // Covariant overrides

View File

@ -4437,6 +4437,44 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext,
); );
} }
@Override
public <T> SqmExpression<T[]> arrayFill(
SqmExpression<T> elementExpression,
SqmExpression<Integer> elementCountExpression) {
return getFunctionDescriptor( "array_fill" ).generateSqmExpression(
asList( elementExpression, elementCountExpression ),
null,
queryEngine
);
}
@Override
public <T> SqmExpression<T[]> arrayFill(SqmExpression<T> elementExpression, Integer elementCount) {
return getFunctionDescriptor( "array_fill" ).generateSqmExpression(
asList( elementExpression, value( elementCount ) ),
null,
queryEngine
);
}
@Override
public <T> SqmExpression<T[]> arrayFill(T element, SqmExpression<Integer> elementCountExpression) {
return getFunctionDescriptor( "array_fill" ).generateSqmExpression(
asList( value( element ), elementCountExpression ),
null,
queryEngine
);
}
@Override
public <T> SqmExpression<T[]> arrayFill(T element, Integer elementCount) {
return getFunctionDescriptor( "array_fill" ).generateSqmExpression(
asList( value( element ), value( elementCount ) ),
null,
queryEngine
);
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Array functions for collection types // Array functions for collection types
@ -5308,4 +5346,42 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext,
queryEngine queryEngine
); );
} }
@Override
public <T> SqmExpression<Collection<T>> collectionFill(
SqmExpression<T> elementExpression,
SqmExpression<Integer> elementCountExpression) {
return getFunctionDescriptor( "array_fill" ).generateSqmExpression(
asList( elementExpression, elementCountExpression ),
null,
queryEngine
);
}
@Override
public <T> SqmExpression<Collection<T>> collectionFill(SqmExpression<T> elementExpression, Integer elementCount) {
return getFunctionDescriptor( "array_fill" ).generateSqmExpression(
asList( elementExpression, value( elementCount ) ),
null,
queryEngine
);
}
@Override
public <T> SqmExpression<Collection<T>> collectionFill(T element, SqmExpression<Integer> elementCountExpression) {
return getFunctionDescriptor( "array_fill" ).generateSqmExpression(
asList( value( element ), elementCountExpression ),
null,
queryEngine
);
}
@Override
public <T> SqmExpression<Collection<T>> collectionFill(T element, Integer elementCount) {
return getFunctionDescriptor( "array_fill" ).generateSqmExpression(
asList( value( element ), value( elementCount ) ),
null,
queryEngine
);
}
} }