Skip to content

Commit d8773f3

Browse files
committed
HHH-17355 Add array_to_string to NodeBuilder
1 parent 60f5427 commit d8773f3

File tree

2 files changed

+198
-60
lines changed

2 files changed

+198
-60
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
@@ -791,6 +791,34 @@ <T> JpaExpression<T[]> arrayAgg(
791791
*/
792792
<T> SqmExpression<List<Integer>> arrayPositionsList(T[] array, T element);
793793

794+
/**
795+
* Concatenates the non-null array elements with a separator, as specified by the arguments.
796+
*
797+
* @since 6.4
798+
*/
799+
<T> SqmExpression<String> arrayToString(SqmExpression<? extends Object[]> arrayExpression, SqmExpression<String> separatorExpression);
800+
801+
/**
802+
* Concatenates the non-null array elements with a separator, as specified by the arguments.
803+
*
804+
* @since 6.4
805+
*/
806+
<T> SqmExpression<String> arrayToString(SqmExpression<? extends Object[]> arrayExpression, String separator);
807+
808+
/**
809+
* Concatenates the non-null array elements with a separator, as specified by the arguments.
810+
*
811+
* @since 6.4
812+
*/
813+
<T> SqmExpression<String> arrayToString(Object[] array, SqmExpression<String> separatorExpression);
814+
815+
/**
816+
* Concatenates the non-null array elements with a separator, as specified by the arguments.
817+
*
818+
* @since 6.4
819+
*/
820+
<T> SqmExpression<String> arrayToString(Object[] array, String separator);
821+
794822
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
795823
// Array functions for collection types
796824

@@ -1445,6 +1473,34 @@ <T> JpaExpression<T[]> arrayAgg(
14451473
*/
14461474
<T> SqmExpression<List<Integer>> collectionPositionsList(Collection<? super T> collection, T element);
14471475

1476+
/**
1477+
* Concatenates the non-null basic collection elements with a separator, as specified by the arguments.
1478+
*
1479+
* @since 6.4
1480+
*/
1481+
<T> SqmExpression<String> collectionToString(SqmExpression<? extends Collection<?>> collectionExpression, SqmExpression<String> separatorExpression);
1482+
1483+
/**
1484+
* Concatenates the non-null basic collection elements with a separator, as specified by the arguments.
1485+
*
1486+
* @since 6.4
1487+
*/
1488+
<T> SqmExpression<String> collectionToString(SqmExpression<? extends Collection<?>> collectionExpression, String separator);
1489+
1490+
/**
1491+
* Concatenates the non-null basic collection elements with a separator, as specified by the arguments.
1492+
*
1493+
* @since 6.4
1494+
*/
1495+
<T> SqmExpression<String> collectionToString(Collection<?> collection, SqmExpression<String> separatorExpression);
1496+
1497+
/**
1498+
* Concatenates the non-null basic collection elements with a separator, as specified by the arguments.
1499+
*
1500+
* @since 6.4
1501+
*/
1502+
<T> SqmExpression<String> collectionToString(Collection<?> collection, String separator);
1503+
14481504
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
14491505
// Covariant overrides
14501506

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

Lines changed: 142 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -4551,6 +4551,46 @@ public <T> SqmExpression<T[]> arrayFill(T element, Integer elementCount) {
45514551
);
45524552
}
45534553

4554+
@Override
4555+
public <T> SqmExpression<String> arrayToString(
4556+
SqmExpression<? extends Object[]> arrayExpression,
4557+
SqmExpression<String> separatorExpression) {
4558+
return getFunctionDescriptor( "array_to_string" ).generateSqmExpression(
4559+
asList( arrayExpression, separatorExpression ),
4560+
null,
4561+
queryEngine
4562+
);
4563+
}
4564+
4565+
@Override
4566+
public <T> SqmExpression<String> arrayToString(
4567+
SqmExpression<? extends Object[]> arrayExpression,
4568+
String separator) {
4569+
return getFunctionDescriptor( "array_to_string" ).generateSqmExpression(
4570+
asList( arrayExpression, value( separator ) ),
4571+
null,
4572+
queryEngine
4573+
);
4574+
}
4575+
4576+
@Override
4577+
public <T> SqmExpression<String> arrayToString(Object[] array, SqmExpression<String> separatorExpression) {
4578+
return getFunctionDescriptor( "array_to_string" ).generateSqmExpression(
4579+
asList( value( array ), separatorExpression ),
4580+
null,
4581+
queryEngine
4582+
);
4583+
}
4584+
4585+
@Override
4586+
public <T> SqmExpression<String> arrayToString(Object[] array, String separator) {
4587+
return getFunctionDescriptor( "array_to_string" ).generateSqmExpression(
4588+
asList( value( array ), value( separator ) ),
4589+
null,
4590+
queryEngine
4591+
);
4592+
}
4593+
45544594
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
45554595
// Array functions for collection types
45564596

@@ -4586,6 +4626,90 @@ public <E> SqmExpression<Integer> collectionPosition(
45864626
);
45874627
}
45884628

4629+
@Override
4630+
public <T> SqmExpression<int[]> collectionPositions(
4631+
SqmExpression<? extends Collection<? super T>> collectionExpression,
4632+
SqmExpression<T> elementExpression) {
4633+
return getFunctionDescriptor( "array_positions" ).generateSqmExpression(
4634+
asList( collectionExpression, elementExpression ),
4635+
null,
4636+
queryEngine
4637+
);
4638+
}
4639+
4640+
@Override
4641+
public <T> SqmExpression<int[]> collectionPositions(
4642+
SqmExpression<? extends Collection<? super T>> collectionExpression,
4643+
T element) {
4644+
return getFunctionDescriptor( "array_positions" ).generateSqmExpression(
4645+
asList( collectionExpression, value( element ) ),
4646+
null,
4647+
queryEngine
4648+
);
4649+
}
4650+
4651+
@Override
4652+
public <T> SqmExpression<int[]> collectionPositions(
4653+
Collection<? super T> collection,
4654+
SqmExpression<T> elementExpression) {
4655+
return getFunctionDescriptor( "array_positions" ).generateSqmExpression(
4656+
asList( value( collection ), elementExpression ),
4657+
null,
4658+
queryEngine
4659+
);
4660+
}
4661+
4662+
@Override
4663+
public <T> SqmExpression<int[]> collectionPositions(Collection<? super T> collection, T element) {
4664+
return getFunctionDescriptor( "array_positions" ).generateSqmExpression(
4665+
asList( value( collection ), value( element ) ),
4666+
null,
4667+
queryEngine
4668+
);
4669+
}
4670+
4671+
@Override
4672+
public <T> SqmExpression<List<Integer>> collectionPositionsList(
4673+
SqmExpression<? extends Collection<? super T>> collectionExpression,
4674+
SqmExpression<T> elementExpression) {
4675+
return getFunctionDescriptor( "array_positions_list" ).generateSqmExpression(
4676+
asList( collectionExpression, elementExpression ),
4677+
null,
4678+
queryEngine
4679+
);
4680+
}
4681+
4682+
@Override
4683+
public <T> SqmExpression<List<Integer>> collectionPositionsList(
4684+
SqmExpression<? extends Collection<? super T>> collectionExpression,
4685+
T element) {
4686+
return getFunctionDescriptor( "array_positions_list" ).generateSqmExpression(
4687+
asList( collectionExpression, value( element ) ),
4688+
null,
4689+
queryEngine
4690+
);
4691+
}
4692+
4693+
@Override
4694+
public <T> SqmExpression<List<Integer>> collectionPositionsList(
4695+
Collection<? super T> collection,
4696+
SqmExpression<T> elementExpression) {
4697+
return getFunctionDescriptor( "array_positions_list" ).generateSqmExpression(
4698+
asList( value( collection ), elementExpression ),
4699+
null,
4700+
queryEngine
4701+
);
4702+
}
4703+
4704+
@Override
4705+
public <T> SqmExpression<List<Integer>> collectionPositionsList(Collection<? super T> collection, T element) {
4706+
return getFunctionDescriptor( "array_positions_list" ).generateSqmExpression(
4707+
asList( value( collection ), value( element ) ),
4708+
null,
4709+
queryEngine
4710+
);
4711+
}
4712+
45894713
@Override
45904714
public SqmExpression<Integer> collectionLength(SqmExpression<? extends Collection<?>> collectionExpression) {
45914715
return getFunctionDescriptor( "array_length" ).generateSqmExpression(
@@ -5462,84 +5586,42 @@ public <T> SqmExpression<Collection<T>> collectionFill(T element, Integer elemen
54625586
}
54635587

54645588
@Override
5465-
public <T> SqmExpression<int[]> collectionPositions(
5466-
SqmExpression<? extends Collection<? super T>> collectionExpression,
5467-
SqmExpression<T> elementExpression) {
5468-
return getFunctionDescriptor( "array_positions" ).generateSqmExpression(
5469-
asList( collectionExpression, elementExpression ),
5589+
public <T> SqmExpression<String> collectionToString(
5590+
SqmExpression<? extends Collection<?>> collectionExpression,
5591+
SqmExpression<String> separatorExpression) {
5592+
return getFunctionDescriptor( "array_to_string" ).generateSqmExpression(
5593+
asList( collectionExpression, separatorExpression ),
54705594
null,
54715595
queryEngine
54725596
);
54735597
}
54745598

54755599
@Override
5476-
public <T> SqmExpression<int[]> collectionPositions(
5477-
SqmExpression<? extends Collection<? super T>> collectionExpression,
5478-
T element) {
5479-
return getFunctionDescriptor( "array_positions" ).generateSqmExpression(
5480-
asList( collectionExpression, value( element ) ),
5481-
null,
5482-
queryEngine
5483-
);
5484-
}
5485-
5486-
@Override
5487-
public <T> SqmExpression<int[]> collectionPositions(
5488-
Collection<? super T> collection,
5489-
SqmExpression<T> elementExpression) {
5490-
return getFunctionDescriptor( "array_positions" ).generateSqmExpression(
5491-
asList( value( collection ), elementExpression ),
5492-
null,
5493-
queryEngine
5494-
);
5495-
}
5496-
5497-
@Override
5498-
public <T> SqmExpression<int[]> collectionPositions(Collection<? super T> collection, T element) {
5499-
return getFunctionDescriptor( "array_positions" ).generateSqmExpression(
5500-
asList( value( collection ), value( element ) ),
5501-
null,
5502-
queryEngine
5503-
);
5504-
}
5505-
5506-
@Override
5507-
public <T> SqmExpression<List<Integer>> collectionPositionsList(
5508-
SqmExpression<? extends Collection<? super T>> collectionExpression,
5509-
SqmExpression<T> elementExpression) {
5510-
return getFunctionDescriptor( "array_positions_list" ).generateSqmExpression(
5511-
asList( collectionExpression, elementExpression ),
5512-
null,
5513-
queryEngine
5514-
);
5515-
}
5516-
5517-
@Override
5518-
public <T> SqmExpression<List<Integer>> collectionPositionsList(
5519-
SqmExpression<? extends Collection<? super T>> collectionExpression,
5520-
T element) {
5521-
return getFunctionDescriptor( "array_positions_list" ).generateSqmExpression(
5522-
asList( collectionExpression, value( element ) ),
5600+
public <T> SqmExpression<String> collectionToString(
5601+
SqmExpression<? extends Collection<?>> collectionExpression,
5602+
String separator) {
5603+
return getFunctionDescriptor( "array_to_string" ).generateSqmExpression(
5604+
asList( collectionExpression, value( separator ) ),
55235605
null,
55245606
queryEngine
55255607
);
55265608
}
55275609

55285610
@Override
5529-
public <T> SqmExpression<List<Integer>> collectionPositionsList(
5530-
Collection<? super T> collection,
5531-
SqmExpression<T> elementExpression) {
5532-
return getFunctionDescriptor( "array_positions_list" ).generateSqmExpression(
5533-
asList( value( collection ), elementExpression ),
5611+
public <T> SqmExpression<String> collectionToString(
5612+
Collection<?> collection,
5613+
SqmExpression<String> separatorExpression) {
5614+
return getFunctionDescriptor( "array_to_string" ).generateSqmExpression(
5615+
asList( value( collection ), separatorExpression ),
55345616
null,
55355617
queryEngine
55365618
);
55375619
}
55385620

55395621
@Override
5540-
public <T> SqmExpression<List<Integer>> collectionPositionsList(Collection<? super T> collection, T element) {
5541-
return getFunctionDescriptor( "array_positions_list" ).generateSqmExpression(
5542-
asList( value( collection ), value( element ) ),
5622+
public <T> SqmExpression<String> collectionToString(Collection<?> collection, String separator) {
5623+
return getFunctionDescriptor( "array_to_string" ).generateSqmExpression(
5624+
asList( value( collection ), value( separator ) ),
55435625
null,
55445626
queryEngine
55455627
);

0 commit comments

Comments
 (0)