Jpa vendor native support extended for in of collections (#2150)
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
package org.eclipse.hawkbit.repository.jpa;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
@@ -34,13 +35,14 @@ public class Jpa {
|
||||
|
||||
public static final char NATIVE_QUERY_PARAMETER_PREFIX = '?';
|
||||
|
||||
public static <T> String formatNativeQueryInClause(final String name, final List<T> list) {
|
||||
return formatEclipseLinkNativeQueryInClause(IntStream.range(0, list.size()).mapToObj(i -> name + "_" + i).toList());
|
||||
public static <T> String formatNativeQueryInClause(final String name, final Collection<T> collection) {
|
||||
return formatEclipseLinkNativeQueryInClause(IntStream.range(0, collection.size()).mapToObj(i -> name + "_" + i).toList());
|
||||
}
|
||||
|
||||
public static <T> void setNativeQueryInParameter(final Query deleteQuery, final String name, final List<T> list) {
|
||||
for (int i = 0, len = list.size(); i < len; i++) {
|
||||
deleteQuery.setParameter(name + "_" + i, list.get(i));
|
||||
public static <T> void setNativeQueryInParameter(final Query query, final String name, final Collection<T> collection) {
|
||||
int i = 0;
|
||||
for (final Iterator<T> iterator = collection.iterator(); iterator.hasNext(); i++) {
|
||||
query.setParameter(name + "_" + i, iterator.next());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import jakarta.persistence.Query;
|
||||
@@ -32,11 +33,11 @@ public class Jpa {
|
||||
|
||||
public static final char NATIVE_QUERY_PARAMETER_PREFIX = ':';
|
||||
|
||||
public static <T> String formatNativeQueryInClause(final String name, final List<T> list) {
|
||||
public static <T> String formatNativeQueryInClause(final String name, final Collection<T> collection) {
|
||||
return ":" + name;
|
||||
}
|
||||
|
||||
public static <T> void setNativeQueryInParameter(final Query deleteQuery, final String name, final List<T> list) {
|
||||
deleteQuery.setParameter(name, list);
|
||||
public static <T> void setNativeQueryInParameter(final Query query, final String name, final Collection<T> collection) {
|
||||
query.setParameter(name, collection);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user