Skip to content

Commit bca2adc

Browse files
committed
Polishing.
Guard String.format in debug logs with isDebugEnabled. See spring-projects#2359
1 parent 2231d57 commit bca2adc

File tree

4 files changed

+28
-10
lines changed

4 files changed

+28
-10
lines changed

src/main/java/org/springframework/data/jpa/repository/cdi/JpaRepositoryExtension.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public class JpaRepositoryExtension extends CdiRepositoryExtensionSupport {
4949

5050
private static final Log LOGGER = LogFactory.getLog(JpaRepositoryExtension.class);
5151

52-
private final Map<Set<Annotation>, Bean<EntityManager>> entityManagers = new HashMap<Set<Annotation>, Bean<EntityManager>>();
52+
private final Map<Set<Annotation>, Bean<EntityManager>> entityManagers = new HashMap<>();
5353

5454
public JpaRepositoryExtension() {
5555
LOGGER.info("Activating CDI extension for Spring Data JPA repositories.");
@@ -64,11 +64,12 @@ public JpaRepositoryExtension() {
6464
*/
6565
@SuppressWarnings("unchecked")
6666
<X> void processBean(@Observes ProcessBean<X> processBean) {
67+
6768
Bean<X> bean = processBean.getBean();
6869
for (Type type : bean.getTypes()) {
6970
// Check if the bean is an EntityManager.
7071
if (type instanceof Class<?> && EntityManager.class.isAssignableFrom((Class<?>) type)) {
71-
Set<Annotation> qualifiers = new HashSet<Annotation>(bean.getQualifiers());
72+
Set<Annotation> qualifiers = new HashSet<>(bean.getQualifiers());
7273
if (bean.isAlternative() || !entityManagers.containsKey(qualifiers)) {
7374
LOGGER.debug(String.format("Discovered '%s' with qualifiers %s.", EntityManager.class.getName(), qualifiers));
7475
entityManagers.put(qualifiers, (Bean<EntityManager>) bean);
@@ -121,7 +122,7 @@ private <T> CdiRepositoryBean<T> createRepositoryBean(Class<T> repositoryType, S
121122
}
122123

123124
// Construct and return the repository bean.
124-
return new JpaRepositoryBean<T>(beanManager, entityManagerBean, qualifiers, repositoryType,
125+
return new JpaRepositoryBean<>(beanManager, entityManagerBean, qualifiers, repositoryType,
125126
Optional.of(getCustomImplementationDetector()));
126127
}
127128
}

src/main/java/org/springframework/data/jpa/repository/config/JpaMetamodelMappingContextFactoryBean.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public Class<?> getObjectType() {
7171
* @see org.springframework.beans.factory.config.AbstractFactoryBean#createInstance()
7272
*/
7373
@Override
74-
protected JpaMetamodelMappingContext createInstance() throws Exception {
74+
protected JpaMetamodelMappingContext createInstance() {
7575

7676
if (LOG.isDebugEnabled()) {
7777
LOG.debug("Initializing JpaMetamodelMappingContext…");

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

+11-3
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,10 @@ static boolean hasNamedQuery(EntityManager em, String queryName) {
115115
lookupEm.createNamedQuery(queryName);
116116
return true;
117117
} catch (IllegalArgumentException e) {
118-
LOG.debug(String.format("Did not find named query %s", queryName));
118+
119+
if (LOG.isDebugEnabled()) {
120+
LOG.debug(String.format("Did not find named query %s", queryName));
121+
}
119122
return false;
120123
} finally {
121124
lookupEm.close();
@@ -134,15 +137,20 @@ public static RepositoryQuery lookupFrom(JpaQueryMethod method, EntityManager em
134137

135138
final String queryName = method.getNamedQueryName();
136139

137-
LOG.debug(String.format("Looking up named query %s", queryName));
140+
if (LOG.isDebugEnabled()) {
141+
LOG.debug(String.format("Looking up named query %s", queryName));
142+
}
138143

139144
if (!hasNamedQuery(em, queryName)) {
140145
return null;
141146
}
142147

143148
try {
149+
144150
RepositoryQuery query = new NamedQuery(method, em);
145-
LOG.debug(String.format("Found named query %s!", queryName));
151+
if (LOG.isDebugEnabled()) {
152+
LOG.debug(String.format("Found named query %s!", queryName));
153+
}
146154
return query;
147155
} catch (IllegalArgumentException e) {
148156
return null;

src/main/java/org/springframework/data/jpa/support/MergingPersistenceUnitManager.java

+12-3
Original file line numberDiff line numberDiff line change
@@ -68,21 +68,30 @@ void postProcessPersistenceUnitInfo(MutablePersistenceUnitInfo pui, PersistenceU
6868

6969
for (URL url : oldPui.getJarFileUrls()) {
7070
if (!pui.getJarFileUrls().contains(url)) {
71-
LOG.debug(String.format("Adding JAR file URL %s to persistence unit %s.", url, persistenceUnitName));
71+
72+
if (LOG.isDebugEnabled()) {
73+
LOG.debug(String.format("Adding JAR file URL %s to persistence unit %s.", url, persistenceUnitName));
74+
}
7275
pui.addJarFileUrl(url);
7376
}
7477
}
7578

7679
for (String className : oldPui.getManagedClassNames()) {
7780
if (!pui.getManagedClassNames().contains(className)) {
78-
LOG.debug(String.format("Adding class %s to PersistenceUnit %s", className, persistenceUnitName));
81+
82+
if (LOG.isDebugEnabled()) {
83+
LOG.debug(String.format("Adding class %s to PersistenceUnit %s", className, persistenceUnitName));
84+
}
7985
pui.addManagedClassName(className);
8086
}
8187
}
8288

8389
for (String mappingFileName : oldPui.getMappingFileNames()) {
8490
if (!pui.getMappingFileNames().contains(mappingFileName)) {
85-
LOG.debug(String.format("Adding mapping file to persistence unit %s.", mappingFileName, persistenceUnitName));
91+
92+
if (LOG.isDebugEnabled()) {
93+
LOG.debug(String.format("Adding mapping file to persistence unit %s.", mappingFileName, persistenceUnitName));
94+
}
8695
pui.addMappingFileName(mappingFileName);
8796
}
8897
}

0 commit comments

Comments
 (0)