Skip to content

Commit

Permalink
Jpa vendor native support extended for in of collections (#2150)
Browse files Browse the repository at this point in the history
Signed-off-by: Avgustin Marinov <[email protected]>
  • Loading branch information
avgustinmm authored Dec 17, 2024
1 parent c684b03 commit 1c211c8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -34,13 +35,14 @@ public enum JpaVendor {

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());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/
package org.eclipse.hawkbit.repository.jpa;

import java.util.Collection;
import java.util.List;

import jakarta.persistence.Query;
Expand All @@ -32,11 +33,11 @@ public enum JpaVendor {

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);
}
}

0 comments on commit 1c211c8

Please sign in to comment.