From a3c49c09387ae65a67b4a1a45a9182194788e22f Mon Sep 17 00:00:00 2001 From: kimjg Date: Sun, 9 Feb 2025 18:17:54 +0900 Subject: [PATCH] Refactor string constants. Signed-off-by: kimjg --- .../data/jpa/repository/query/NamedQuery.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/NamedQuery.java b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/NamedQuery.java index 1e4c5fb8f4..0a62591f88 100644 --- a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/NamedQuery.java +++ b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/NamedQuery.java @@ -46,6 +46,8 @@ final class NamedQuery extends AbstractJpaQuery { + "discovering the concrete persistence provider"; private static final Log LOG = LogFactory.getLog(NamedQuery.class); + private static final String NATIVE_QUERY = "NativeQuery"; + private static final String QUERY = "Query"; private final String queryName; private final String countQueryName; @@ -70,8 +72,8 @@ private NamedQuery(JpaQueryMethod method, EntityManager em) { if (parameters.hasSortParameter()) { throw new IllegalStateException(String.format("Query method %s is backed by a NamedQuery and must " - + "not contain a sort parameter as we cannot modify the query; Use @%s(value=…) instead to apply sorting or remove the 'Sort' parameter.", - method, method.isNativeQuery() ? "NativeQuery" : "Query")); + + "not contain a sort parameter as we cannot modify the query; Use @%s(value=…) instead to apply sorting or remove the 'Sort' parameter.", + method, method.isNativeQuery() ? NATIVE_QUERY : QUERY)); } this.namedCountQueryIsPresent = hasNamedQuery(em, countQueryName); @@ -87,13 +89,13 @@ private NamedQuery(JpaQueryMethod method, EntityManager em) { if (parameters.hasPageableParameter()) { LOG.warn(String.format( "Query method %s is backed by a NamedQuery but contains a Pageable parameter; Sorting delivered via this Pageable will not be applied; Use @%s(value=…) instead to apply sorting.", - method, method.isNativeQuery() ? "NativeQuery" : "Query")); + method, method.isNativeQuery() ? NATIVE_QUERY : QUERY)); } String queryString = extractor.extractQueryString(query); this.declaredQuery = Lazy - .of(() -> DeclaredQuery.of(queryString, method.isNativeQuery() || query.toString().contains("NativeQuery"))); + .of(() -> DeclaredQuery.of(queryString, method.isNativeQuery() || query.toString().contains(NATIVE_QUERY))); this.metadataCache = new QueryParameterSetter.QueryMetadataCache(); } @@ -144,7 +146,7 @@ public static RepositoryQuery lookupFrom(JpaQueryMethod method, EntityManager em if (method.isScrollQuery()) { throw QueryCreationException.create(method, String.format( "Scroll queries are not supported using String-based queries as we cannot rewrite the query string. Use @%s(value=…) instead.", - method.isNativeQuery() ? "NativeQuery" : "Query")); + method.isNativeQuery() ? NATIVE_QUERY : QUERY)); } RepositoryQuery query = new NamedQuery(method, em);