Skip to content

Commit b6b5e20

Browse files
서민재christophstrobl
서민재
authored andcommitted
Polishing.
Add missing generic type argument, pre initialize collection in Meta and make use of try-with-resources in NamedQuery. Closes: spring-projects#3408
1 parent a13c829 commit b6b5e20

File tree

3 files changed

+4
-11
lines changed

3 files changed

+4
-11
lines changed

spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/JSqlParserUtils.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public static Function getJSqlCount(final List<String> countFields, final boolea
4949
.map(Column::new) //
5050
.collect(Collectors.toList());
5151

52-
ExpressionList countExpression = new ExpressionList(countColumns);
52+
ExpressionList<Expression> countExpression = new ExpressionList<>(countColumns);
5353

5454
return new Function() //
5555
.withName("count") //
@@ -66,7 +66,7 @@ public static Function getJSqlCount(final List<String> countFields, final boolea
6666
public static Function getJSqlLower(String column) {
6767

6868
List<Expression> expressions = Collections.singletonList(new Column(column));
69-
ExpressionList lowerParamExpression = new ExpressionList(expressions);
69+
ExpressionList<Expression> lowerParamExpression = new ExpressionList<>(expressions);
7070

7171
return new Function() //
7272
.withName("lower") //

spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/Meta.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ private enum MetaKey {
4343
}
4444
}
4545

46-
private Map<String, Object> values = Collections.emptyMap();
46+
private Map<String, Object> values = new LinkedHashMap<>(2);
4747

4848
public Meta() {}
4949

@@ -100,10 +100,6 @@ void setValue(String key, @Nullable Object value) {
100100

101101
Assert.hasText(key, "Meta key must not be 'null' or blank");
102102

103-
if (values == Collections.EMPTY_MAP) {
104-
values = new LinkedHashMap<>(2);
105-
}
106-
107103
if (value == null || (value instanceof String stringValue && !StringUtils.hasText(stringValue))) {
108104
this.values.remove(key);
109105
}

spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/NamedQuery.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,8 @@ static boolean hasNamedQuery(EntityManager em, String queryName) {
107107
* See DATAJPA-617, we have to use a dedicated em for the lookups to avoid a
108108
* potential rollback of the running tx.
109109
*/
110-
EntityManager lookupEm = em.getEntityManagerFactory().createEntityManager();
111110

112-
try {
111+
try (EntityManager lookupEm = em.getEntityManagerFactory().createEntityManager()) {
113112
lookupEm.createNamedQuery(queryName);
114113
return true;
115114
} catch (IllegalArgumentException e) {
@@ -118,8 +117,6 @@ static boolean hasNamedQuery(EntityManager em, String queryName) {
118117
LOG.debug(String.format("Did not find named query %s", queryName));
119118
}
120119
return false;
121-
} finally {
122-
lookupEm.close();
123120
}
124121
}
125122

0 commit comments

Comments
 (0)