Skip to content

Commit 6d392f5

Browse files
committed
HHH-17355 Add array_trim functions to NodeBuilder
1 parent faf6345 commit 6d392f5

File tree

2 files changed

+136
-0
lines changed

2 files changed

+136
-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
@@ -679,6 +679,34 @@ <T> JpaExpression<T[]> arrayAgg(
679679
*/
680680
<T> SqmExpression<T[]> arrayReplace(T[] array, T oldElement, T newElement);
681681

682+
/**
683+
* Creates array copy without the last N elements, specified by the second argument.
684+
*
685+
* @since 6.4
686+
*/
687+
<T> SqmExpression<T[]> arrayTrim(SqmExpression<T[]> arrayExpression, SqmExpression<Integer> elementCountExpression);
688+
689+
/**
690+
* Creates array copy without the last N elements, specified by the second argument.
691+
*
692+
* @since 6.4
693+
*/
694+
<T> SqmExpression<T[]> arrayTrim(SqmExpression<T[]> arrayExpression, Integer elementCount);
695+
696+
/**
697+
* Creates array copy without the last N elements, specified by the second argument.
698+
*
699+
* @since 6.4
700+
*/
701+
<T> SqmExpression<T[]> arrayTrim(T[] array, SqmExpression<Integer> elementCountExpression);
702+
703+
/**
704+
* Creates array copy without the last N elements, specified by the second argument.
705+
*
706+
* @since 6.4
707+
*/
708+
<T> SqmExpression<T[]> arrayTrim(T[] array, Integer elementCount);
709+
682710
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
683711
// Array functions for collection types
684712

@@ -1221,6 +1249,34 @@ <T> JpaExpression<T[]> arrayAgg(
12211249
*/
12221250
<E, C extends Collection<? super E>> SqmExpression<C> collectionReplace(C collection, E oldElement, E newElement);
12231251

1252+
/**
1253+
* Creates basic collection copy without the last N elements, specified by the second argument.
1254+
*
1255+
* @since 6.4
1256+
*/
1257+
<C extends Collection<?>> SqmExpression<C> collectionTrim(SqmExpression<C> arrayExpression, SqmExpression<Integer> elementCountExpression);
1258+
1259+
/**
1260+
* Creates basic collection copy without the last N elements, specified by the second argument.
1261+
*
1262+
* @since 6.4
1263+
*/
1264+
<C extends Collection<?>> SqmExpression<C> collectionTrim(SqmExpression<C> arrayExpression, Integer elementCount);
1265+
1266+
/**
1267+
* Creates basic collection copy without the last N elements, specified by the second argument.
1268+
*
1269+
* @since 6.4
1270+
*/
1271+
<C extends Collection<?>> SqmExpression<C> collectionTrim(C collection, SqmExpression<Integer> elementCountExpression);
1272+
1273+
/**
1274+
* Creates basic collection copy without the last N elements, specified by the second argument.
1275+
*
1276+
* @since 6.4
1277+
*/
1278+
<C extends Collection<?>> SqmExpression<C> collectionTrim(C collection, Integer elementCount);
1279+
12241280
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
12251281
// Covariant overrides
12261282

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

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4399,6 +4399,44 @@ public <T> SqmExpression<T[]> arrayReplace(T[] array, T oldElement, T newElement
43994399
);
44004400
}
44014401

4402+
@Override
4403+
public <T> SqmExpression<T[]> arrayTrim(
4404+
SqmExpression<T[]> arrayExpression,
4405+
SqmExpression<Integer> elementCountExpression) {
4406+
return getFunctionDescriptor( "array_trim" ).generateSqmExpression(
4407+
asList( arrayExpression, elementCountExpression ),
4408+
null,
4409+
queryEngine
4410+
);
4411+
}
4412+
4413+
@Override
4414+
public <T> SqmExpression<T[]> arrayTrim(SqmExpression<T[]> arrayExpression, Integer elementCount) {
4415+
return getFunctionDescriptor( "array_trim" ).generateSqmExpression(
4416+
asList( arrayExpression, value( elementCount ) ),
4417+
null,
4418+
queryEngine
4419+
);
4420+
}
4421+
4422+
@Override
4423+
public <T> SqmExpression<T[]> arrayTrim(T[] array, SqmExpression<Integer> elementCountExpression) {
4424+
return getFunctionDescriptor( "array_trim" ).generateSqmExpression(
4425+
asList( value( array ), elementCountExpression ),
4426+
null,
4427+
queryEngine
4428+
);
4429+
}
4430+
4431+
@Override
4432+
public <T> SqmExpression<T[]> arrayTrim(T[] array, Integer elementCount) {
4433+
return getFunctionDescriptor( "array_trim" ).generateSqmExpression(
4434+
asList( value( array ), value( elementCount ) ),
4435+
null,
4436+
queryEngine
4437+
);
4438+
}
4439+
44024440
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
44034441
// Array functions for collection types
44044442

@@ -5228,4 +5266,46 @@ public <E, C extends Collection<? super E>> SqmExpression<C> collectionReplace(
52285266
queryEngine
52295267
);
52305268
}
5269+
5270+
@Override
5271+
public <C extends Collection<?>> SqmExpression<C> collectionTrim(
5272+
SqmExpression<C> collectionExpression,
5273+
SqmExpression<Integer> indexExpression) {
5274+
return getFunctionDescriptor( "array_trim" ).generateSqmExpression(
5275+
asList( collectionExpression, indexExpression ),
5276+
null,
5277+
queryEngine
5278+
);
5279+
}
5280+
5281+
@Override
5282+
public <C extends Collection<?>> SqmExpression<C> collectionTrim(
5283+
SqmExpression<C> collectionExpression,
5284+
Integer index) {
5285+
return getFunctionDescriptor( "array_trim" ).generateSqmExpression(
5286+
asList( collectionExpression, value( index ) ),
5287+
null,
5288+
queryEngine
5289+
);
5290+
}
5291+
5292+
@Override
5293+
public <C extends Collection<?>> SqmExpression<C> collectionTrim(
5294+
C collection,
5295+
SqmExpression<Integer> indexExpression) {
5296+
return getFunctionDescriptor( "array_trim" ).generateSqmExpression(
5297+
asList( value( collection ), indexExpression ),
5298+
null,
5299+
queryEngine
5300+
);
5301+
}
5302+
5303+
@Override
5304+
public <C extends Collection<?>> SqmExpression<C> collectionTrim(C collection, Integer index) {
5305+
return getFunctionDescriptor( "array_trim" ).generateSqmExpression(
5306+
asList( value( collection ), value( index ) ),
5307+
null,
5308+
queryEngine
5309+
);
5310+
}
52315311
}

0 commit comments

Comments
 (0)