Skip to content

Commit fe9289b

Browse files
committed
HHH-17355 Add array_fill function to NodeBuilder
1 parent 1a5184e commit fe9289b

File tree

2 files changed

+132
-0
lines changed

2 files changed

+132
-0
lines changed

hibernate-core/src/main/java/org/hibernate/query/sqm/NodeBuilder.java

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,34 @@ <T> JpaExpression<T[]> arrayAgg(
707707
*/
708708
<T> SqmExpression<T[]> arrayTrim(T[] array, Integer elementCount);
709709

710+
/**
711+
* Creates array with the same element N times, as specified by the arguments.
712+
*
713+
* @since 6.4
714+
*/
715+
<T> SqmExpression<T[]> arrayFill(SqmExpression<T> elementExpression, SqmExpression<Integer> elementCountExpression);
716+
717+
/**
718+
* Creates array with the same element N times, as specified by the arguments.
719+
*
720+
* @since 6.4
721+
*/
722+
<T> SqmExpression<T[]> arrayFill(SqmExpression<T> elementExpression, Integer elementCount);
723+
724+
/**
725+
* Creates array with the same element N times, as specified by the arguments.
726+
*
727+
* @since 6.4
728+
*/
729+
<T> SqmExpression<T[]> arrayFill(T element, SqmExpression<Integer> elementCountExpression);
730+
731+
/**
732+
* Creates array with the same element N times, as specified by the arguments.
733+
*
734+
* @since 6.4
735+
*/
736+
<T> SqmExpression<T[]> arrayFill(T element, Integer elementCount);
737+
710738
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
711739
// Array functions for collection types
712740

@@ -1277,6 +1305,34 @@ <T> JpaExpression<T[]> arrayAgg(
12771305
*/
12781306
<C extends Collection<?>> SqmExpression<C> collectionTrim(C collection, Integer elementCount);
12791307

1308+
/**
1309+
* Creates basic collection with the same element N times, as specified by the arguments.
1310+
*
1311+
* @since 6.4
1312+
*/
1313+
<T> SqmExpression<Collection<T>> collectionFill(SqmExpression<T> elementExpression, SqmExpression<Integer> elementCountExpression);
1314+
1315+
/**
1316+
* Creates basic collection with the same element N times, as specified by the arguments.
1317+
*
1318+
* @since 6.4
1319+
*/
1320+
<T> SqmExpression<Collection<T>> collectionFill(SqmExpression<T> elementExpression, Integer elementCount);
1321+
1322+
/**
1323+
* Creates basic collection with the same element N times, as specified by the arguments.
1324+
*
1325+
* @since 6.4
1326+
*/
1327+
<T> SqmExpression<Collection<T>> collectionFill(T element, SqmExpression<Integer> elementCountExpression);
1328+
1329+
/**
1330+
* Creates basic collection with the same element N times, as specified by the arguments.
1331+
*
1332+
* @since 6.4
1333+
*/
1334+
<T> SqmExpression<Collection<T>> collectionFill(T element, Integer elementCount);
1335+
12801336
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
12811337
// Covariant overrides
12821338

hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmCriteriaNodeBuilder.java

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4437,6 +4437,44 @@ public <T> SqmExpression<T[]> arrayTrim(T[] array, Integer elementCount) {
44374437
);
44384438
}
44394439

4440+
@Override
4441+
public <T> SqmExpression<T[]> arrayFill(
4442+
SqmExpression<T> elementExpression,
4443+
SqmExpression<Integer> elementCountExpression) {
4444+
return getFunctionDescriptor( "array_fill" ).generateSqmExpression(
4445+
asList( elementExpression, elementCountExpression ),
4446+
null,
4447+
queryEngine
4448+
);
4449+
}
4450+
4451+
@Override
4452+
public <T> SqmExpression<T[]> arrayFill(SqmExpression<T> elementExpression, Integer elementCount) {
4453+
return getFunctionDescriptor( "array_fill" ).generateSqmExpression(
4454+
asList( elementExpression, value( elementCount ) ),
4455+
null,
4456+
queryEngine
4457+
);
4458+
}
4459+
4460+
@Override
4461+
public <T> SqmExpression<T[]> arrayFill(T element, SqmExpression<Integer> elementCountExpression) {
4462+
return getFunctionDescriptor( "array_fill" ).generateSqmExpression(
4463+
asList( value( element ), elementCountExpression ),
4464+
null,
4465+
queryEngine
4466+
);
4467+
}
4468+
4469+
@Override
4470+
public <T> SqmExpression<T[]> arrayFill(T element, Integer elementCount) {
4471+
return getFunctionDescriptor( "array_fill" ).generateSqmExpression(
4472+
asList( value( element ), value( elementCount ) ),
4473+
null,
4474+
queryEngine
4475+
);
4476+
}
4477+
44404478
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
44414479
// Array functions for collection types
44424480

@@ -5308,4 +5346,42 @@ public <C extends Collection<?>> SqmExpression<C> collectionTrim(C collection, I
53085346
queryEngine
53095347
);
53105348
}
5349+
5350+
@Override
5351+
public <T> SqmExpression<Collection<T>> collectionFill(
5352+
SqmExpression<T> elementExpression,
5353+
SqmExpression<Integer> elementCountExpression) {
5354+
return getFunctionDescriptor( "array_fill" ).generateSqmExpression(
5355+
asList( elementExpression, elementCountExpression ),
5356+
null,
5357+
queryEngine
5358+
);
5359+
}
5360+
5361+
@Override
5362+
public <T> SqmExpression<Collection<T>> collectionFill(SqmExpression<T> elementExpression, Integer elementCount) {
5363+
return getFunctionDescriptor( "array_fill" ).generateSqmExpression(
5364+
asList( elementExpression, value( elementCount ) ),
5365+
null,
5366+
queryEngine
5367+
);
5368+
}
5369+
5370+
@Override
5371+
public <T> SqmExpression<Collection<T>> collectionFill(T element, SqmExpression<Integer> elementCountExpression) {
5372+
return getFunctionDescriptor( "array_fill" ).generateSqmExpression(
5373+
asList( value( element ), elementCountExpression ),
5374+
null,
5375+
queryEngine
5376+
);
5377+
}
5378+
5379+
@Override
5380+
public <T> SqmExpression<Collection<T>> collectionFill(T element, Integer elementCount) {
5381+
return getFunctionDescriptor( "array_fill" ).generateSqmExpression(
5382+
asList( value( element ), value( elementCount ) ),
5383+
null,
5384+
queryEngine
5385+
);
5386+
}
53115387
}

0 commit comments

Comments
 (0)