Non static native query prefix (#2152)
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -33,7 +33,9 @@ public class Jpa {
|
|||||||
log.info("JPA vendor: {}", JPA_VENDOR);
|
log.info("JPA vendor: {}", JPA_VENDOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final char NATIVE_QUERY_PARAMETER_PREFIX = '?';
|
public static char nativeQueryParamPrefix() {
|
||||||
|
return '?';
|
||||||
|
}
|
||||||
|
|
||||||
public static <T> String formatNativeQueryInClause(final String name, final Collection<T> collection) {
|
public static <T> String formatNativeQueryInClause(final String name, final Collection<T> collection) {
|
||||||
return formatEclipseLinkNativeQueryInClause(IntStream.range(0, collection.size()).mapToObj(i -> name + "_" + i).toList());
|
return formatEclipseLinkNativeQueryInClause(IntStream.range(0, collection.size()).mapToObj(i -> name + "_" + i).toList());
|
||||||
|
|||||||
@@ -28,10 +28,12 @@ public class Jpa {
|
|||||||
|
|
||||||
public static final JpaVendor JPA_VENDOR = JpaVendor.HIBERNATE;
|
public static final JpaVendor JPA_VENDOR = JpaVendor.HIBERNATE;
|
||||||
static {
|
static {
|
||||||
log.info("JPA vendor: {}", JPA_VENDOR);
|
log.info("JPA Vendor: {}", JPA_VENDOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final char NATIVE_QUERY_PARAMETER_PREFIX = ':';
|
public static char nativeQueryParamPrefix() {
|
||||||
|
return ':';
|
||||||
|
}
|
||||||
|
|
||||||
public static <T> String formatNativeQueryInClause(final String name, final Collection<T> collection) {
|
public static <T> String formatNativeQueryInClause(final String name, final Collection<T> collection) {
|
||||||
return ":" + name;
|
return ":" + name;
|
||||||
|
|||||||
@@ -746,9 +746,9 @@ public class JpaControllerManagement extends JpaActionManagement implements Cont
|
|||||||
*/
|
*/
|
||||||
private void setLastTargetQuery(final String tenant, final long currentTimeMillis, final List<String> chunk) {
|
private void setLastTargetQuery(final String tenant, final long currentTimeMillis, final List<String> chunk) {
|
||||||
final Query updateQuery = entityManager.createNativeQuery(
|
final Query updateQuery = entityManager.createNativeQuery(
|
||||||
"UPDATE sp_target SET last_target_query = " + Jpa.NATIVE_QUERY_PARAMETER_PREFIX + "last_target_query " +
|
"UPDATE sp_target SET last_target_query = " + Jpa.nativeQueryParamPrefix() + "last_target_query " +
|
||||||
"WHERE controller_id IN (" + Jpa.formatNativeQueryInClause("cid", chunk) + ")" +
|
"WHERE controller_id IN (" + Jpa.formatNativeQueryInClause("cid", chunk) + ")" +
|
||||||
" AND tenant = " + Jpa.NATIVE_QUERY_PARAMETER_PREFIX + "tenant");
|
" AND tenant = " + Jpa.nativeQueryParamPrefix() + "tenant");
|
||||||
|
|
||||||
updateQuery.setParameter("last_target_query", currentTimeMillis);
|
updateQuery.setParameter("last_target_query", currentTimeMillis);
|
||||||
Jpa.setNativeQueryInParameter(updateQuery, "cid", chunk);
|
Jpa.setNativeQueryInParameter(updateQuery, "cid", chunk);
|
||||||
|
|||||||
@@ -124,9 +124,9 @@ public class JpaDeploymentManagement extends JpaActionManagement implements Depl
|
|||||||
private static final int ACTION_PAGE_LIMIT = 1000;
|
private static final int ACTION_PAGE_LIMIT = 1000;
|
||||||
private static final String QUERY_DELETE_ACTIONS_BY_STATE_AND_LAST_MODIFIED_DEFAULT =
|
private static final String QUERY_DELETE_ACTIONS_BY_STATE_AND_LAST_MODIFIED_DEFAULT =
|
||||||
"DELETE FROM sp_action " +
|
"DELETE FROM sp_action " +
|
||||||
"WHERE tenant=" + Jpa.NATIVE_QUERY_PARAMETER_PREFIX + "tenant" +
|
"WHERE tenant=" + Jpa.nativeQueryParamPrefix() + "tenant" +
|
||||||
" AND status IN (%s)" +
|
" AND status IN (%s)" +
|
||||||
" AND last_modified_at<" + Jpa.NATIVE_QUERY_PARAMETER_PREFIX + "last_modified_at LIMIT " + ACTION_PAGE_LIMIT;
|
" AND last_modified_at<" + Jpa.nativeQueryParamPrefix() + "last_modified_at LIMIT " + ACTION_PAGE_LIMIT;
|
||||||
private static final EnumMap<Database, String> QUERY_DELETE_ACTIONS_BY_STATE_AND_LAST_MODIFIED;
|
private static final EnumMap<Database, String> QUERY_DELETE_ACTIONS_BY_STATE_AND_LAST_MODIFIED;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
@@ -134,16 +134,16 @@ public class JpaDeploymentManagement extends JpaActionManagement implements Depl
|
|||||||
QUERY_DELETE_ACTIONS_BY_STATE_AND_LAST_MODIFIED.put(
|
QUERY_DELETE_ACTIONS_BY_STATE_AND_LAST_MODIFIED.put(
|
||||||
Database.SQL_SERVER,
|
Database.SQL_SERVER,
|
||||||
"DELETE TOP (" + ACTION_PAGE_LIMIT + ") FROM sp_action " +
|
"DELETE TOP (" + ACTION_PAGE_LIMIT + ") FROM sp_action " +
|
||||||
"WHERE tenant=" + Jpa.NATIVE_QUERY_PARAMETER_PREFIX + "tenant" +
|
"WHERE tenant=" + Jpa.nativeQueryParamPrefix() + "tenant" +
|
||||||
" AND status IN (%s)" +
|
" AND status IN (%s)" +
|
||||||
" AND last_modified_at<" + Jpa.NATIVE_QUERY_PARAMETER_PREFIX + "last_modified_at ");
|
" AND last_modified_at<" + Jpa.nativeQueryParamPrefix() + "last_modified_at ");
|
||||||
QUERY_DELETE_ACTIONS_BY_STATE_AND_LAST_MODIFIED.put(
|
QUERY_DELETE_ACTIONS_BY_STATE_AND_LAST_MODIFIED.put(
|
||||||
Database.POSTGRESQL,
|
Database.POSTGRESQL,
|
||||||
"DELETE FROM sp_action " +
|
"DELETE FROM sp_action " +
|
||||||
"WHERE id IN (SELECT id FROM sp_action " +
|
"WHERE id IN (SELECT id FROM sp_action " +
|
||||||
"WHERE tenant=" + Jpa.NATIVE_QUERY_PARAMETER_PREFIX + "tenant" +
|
"WHERE tenant=" + Jpa.nativeQueryParamPrefix() + "tenant" +
|
||||||
" AND status IN (%s)" +
|
" AND status IN (%s)" +
|
||||||
" AND last_modified_at<" + Jpa.NATIVE_QUERY_PARAMETER_PREFIX + "last_modified_at LIMIT " + ACTION_PAGE_LIMIT + ")");
|
" AND last_modified_at<" + Jpa.nativeQueryParamPrefix() + "last_modified_at LIMIT " + ACTION_PAGE_LIMIT + ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
private final EntityManager entityManager;
|
private final EntityManager entityManager;
|
||||||
|
|||||||
Reference in New Issue
Block a user