Skip to content

Commit

Permalink
HHH-17355 Add array_fill function to NodeBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
beikov committed Nov 6, 2023
1 parent 1a5184e commit fe9289b
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,34 @@ <T> JpaExpression<T[]> arrayAgg(
*/
<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

Expand Down Expand Up @@ -1277,6 +1305,34 @@ <T> JpaExpression<T[]> arrayAgg(
*/
<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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4437,6 +4437,44 @@ public <T> SqmExpression<T[]> arrayTrim(T[] array, Integer elementCount) {
);
}

@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

Expand Down Expand Up @@ -5308,4 +5346,42 @@ public <C extends Collection<?>> SqmExpression<C> collectionTrim(C collection, I
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
);
}
}

0 comments on commit fe9289b

Please sign in to comment.