Polishing.

Guard String.format in debug logs with isDebugEnabled.

See #2359
This commit is contained in:
Jens Schauder
2021-11-17 13:50:56 +01:00
parent 2231d574de
commit bca2adc32a
4 changed files with 28 additions and 10 deletions

View File

@@ -49,7 +49,7 @@ public class JpaRepositoryExtension extends CdiRepositoryExtensionSupport {
private static final Log LOGGER = LogFactory.getLog(JpaRepositoryExtension.class);
private final Map<Set<Annotation>, Bean<EntityManager>> entityManagers = new HashMap<Set<Annotation>, Bean<EntityManager>>();
private final Map<Set<Annotation>, Bean<EntityManager>> entityManagers = new HashMap<>();
public JpaRepositoryExtension() {
LOGGER.info("Activating CDI extension for Spring Data JPA repositories.");
@@ -64,11 +64,12 @@ public class JpaRepositoryExtension extends CdiRepositoryExtensionSupport {
*/
@SuppressWarnings("unchecked")
<X> void processBean(@Observes ProcessBean<X> processBean) {
Bean<X> bean = processBean.getBean();
for (Type type : bean.getTypes()) {
// Check if the bean is an EntityManager.
if (type instanceof Class<?> && EntityManager.class.isAssignableFrom((Class<?>) type)) {
Set<Annotation> qualifiers = new HashSet<Annotation>(bean.getQualifiers());
Set<Annotation> qualifiers = new HashSet<>(bean.getQualifiers());
if (bean.isAlternative() || !entityManagers.containsKey(qualifiers)) {
LOGGER.debug(String.format("Discovered '%s' with qualifiers %s.", EntityManager.class.getName(), qualifiers));
entityManagers.put(qualifiers, (Bean<EntityManager>) bean);
@@ -121,7 +122,7 @@ public class JpaRepositoryExtension extends CdiRepositoryExtensionSupport {
}
// Construct and return the repository bean.
return new JpaRepositoryBean<T>(beanManager, entityManagerBean, qualifiers, repositoryType,
return new JpaRepositoryBean<>(beanManager, entityManagerBean, qualifiers, repositoryType,
Optional.of(getCustomImplementationDetector()));
}
}

View File

@@ -71,7 +71,7 @@ public class JpaMetamodelMappingContextFactoryBean extends AbstractFactoryBean<J
* @see org.springframework.beans.factory.config.AbstractFactoryBean#createInstance()
*/
@Override
protected JpaMetamodelMappingContext createInstance() throws Exception {
protected JpaMetamodelMappingContext createInstance() {
if (LOG.isDebugEnabled()) {
LOG.debug("Initializing JpaMetamodelMappingContext…");

View File

@@ -115,7 +115,10 @@ final class NamedQuery extends AbstractJpaQuery {
lookupEm.createNamedQuery(queryName);
return true;
} catch (IllegalArgumentException e) {
LOG.debug(String.format("Did not find named query %s", queryName));
if (LOG.isDebugEnabled()) {
LOG.debug(String.format("Did not find named query %s", queryName));
}
return false;
} finally {
lookupEm.close();
@@ -134,15 +137,20 @@ final class NamedQuery extends AbstractJpaQuery {
final String queryName = method.getNamedQueryName();
LOG.debug(String.format("Looking up named query %s", queryName));
if (LOG.isDebugEnabled()) {
LOG.debug(String.format("Looking up named query %s", queryName));
}
if (!hasNamedQuery(em, queryName)) {
return null;
}
try {
RepositoryQuery query = new NamedQuery(method, em);
LOG.debug(String.format("Found named query %s!", queryName));
if (LOG.isDebugEnabled()) {
LOG.debug(String.format("Found named query %s!", queryName));
}
return query;
} catch (IllegalArgumentException e) {
return null;

View File

@@ -68,21 +68,30 @@ public class MergingPersistenceUnitManager extends DefaultPersistenceUnitManager
for (URL url : oldPui.getJarFileUrls()) {
if (!pui.getJarFileUrls().contains(url)) {
LOG.debug(String.format("Adding JAR file URL %s to persistence unit %s.", url, persistenceUnitName));
if (LOG.isDebugEnabled()) {
LOG.debug(String.format("Adding JAR file URL %s to persistence unit %s.", url, persistenceUnitName));
}
pui.addJarFileUrl(url);
}
}
for (String className : oldPui.getManagedClassNames()) {
if (!pui.getManagedClassNames().contains(className)) {
LOG.debug(String.format("Adding class %s to PersistenceUnit %s", className, persistenceUnitName));
if (LOG.isDebugEnabled()) {
LOG.debug(String.format("Adding class %s to PersistenceUnit %s", className, persistenceUnitName));
}
pui.addManagedClassName(className);
}
}
for (String mappingFileName : oldPui.getMappingFileNames()) {
if (!pui.getMappingFileNames().contains(mappingFileName)) {
LOG.debug(String.format("Adding mapping file to persistence unit %s.", mappingFileName, persistenceUnitName));
if (LOG.isDebugEnabled()) {
LOG.debug(String.format("Adding mapping file to persistence unit %s.", mappingFileName, persistenceUnitName));
}
pui.addMappingFileName(mappingFileName);
}
}