From 44c61e5d5f018a808ecc0c07df757abefa201ff2 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 1 Jul 2014 12:09:29 +0200 Subject: [PATCH] Consistent declaration of private static final logger variables Issue: SPR-11905 (cherry picked from commit c16032b) --- .../aop/framework/JdkDynamicAopProxy.java | 12 +-- .../validation/ValidationUtils.java | 4 +- ...lVariableTableParameterNameDiscoverer.java | 2 +- .../embedded/EmbeddedDatabaseFactory.java | 85 ++++++++++++------- .../support/AsyncRequestInterceptor.java | 19 +++-- .../jpa/support/AsyncRequestInterceptor.java | 19 +++-- .../async/CallableInterceptorChain.java | 5 +- .../async/DeferredResultInterceptorChain.java | 4 +- 8 files changed, 97 insertions(+), 53 deletions(-) diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/JdkDynamicAopProxy.java b/spring-aop/src/main/java/org/springframework/aop/framework/JdkDynamicAopProxy.java index 7e10c4c2283..c41e14c8c86 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/JdkDynamicAopProxy.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/JdkDynamicAopProxy.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -75,7 +75,7 @@ final class JdkDynamicAopProxy implements AopProxy, InvocationHandler, Serializa */ /** We use a static Log to avoid serialization issues */ - private static Log logger = LogFactory.getLog(JdkDynamicAopProxy.class); + private static final Log logger = LogFactory.getLog(JdkDynamicAopProxy.class); /** Config used to configure this proxy */ private final AdvisedSupport advised; @@ -114,7 +114,7 @@ final class JdkDynamicAopProxy implements AopProxy, InvocationHandler, Serializa if (logger.isDebugEnabled()) { logger.debug("Creating JDK dynamic proxy: target source is " + this.advised.getTargetSource()); } - Class[] proxiedInterfaces = AopProxyUtils.completeProxiedInterfaces(this.advised); + Class[] proxiedInterfaces = AopProxyUtils.completeProxiedInterfaces(this.advised); findDefinedEqualsAndHashCodeMethods(proxiedInterfaces); return Proxy.newProxyInstance(classLoader, proxiedInterfaces, this); } @@ -124,8 +124,8 @@ final class JdkDynamicAopProxy implements AopProxy, InvocationHandler, Serializa * on the supplied set of interfaces. * @param proxiedInterfaces the interfaces to introspect */ - private void findDefinedEqualsAndHashCodeMethods(Class[] proxiedInterfaces) { - for (Class proxiedInterface : proxiedInterfaces) { + private void findDefinedEqualsAndHashCodeMethods(Class[] proxiedInterfaces) { + for (Class proxiedInterface : proxiedInterfaces) { Method[] methods = proxiedInterface.getDeclaredMethods(); for (Method method : methods) { if (AopUtils.isEqualsMethod(method)) { @@ -153,7 +153,7 @@ final class JdkDynamicAopProxy implements AopProxy, InvocationHandler, Serializa boolean setProxyContext = false; TargetSource targetSource = this.advised.targetSource; - Class targetClass = null; + Class targetClass = null; Object target = null; try { diff --git a/spring-context/src/main/java/org/springframework/validation/ValidationUtils.java b/spring-context/src/main/java/org/springframework/validation/ValidationUtils.java index 9da8e3d26b8..5db89a4c5df 100644 --- a/spring-context/src/main/java/org/springframework/validation/ValidationUtils.java +++ b/spring-context/src/main/java/org/springframework/validation/ValidationUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,7 +38,7 @@ import org.springframework.util.StringUtils; */ public abstract class ValidationUtils { - private static Log logger = LogFactory.getLog(ValidationUtils.class); + private static final Log logger = LogFactory.getLog(ValidationUtils.class); /** diff --git a/spring-core/src/main/java/org/springframework/core/LocalVariableTableParameterNameDiscoverer.java b/spring-core/src/main/java/org/springframework/core/LocalVariableTableParameterNameDiscoverer.java index 953cce667a0..151dcb30512 100644 --- a/spring-core/src/main/java/org/springframework/core/LocalVariableTableParameterNameDiscoverer.java +++ b/spring-core/src/main/java/org/springframework/core/LocalVariableTableParameterNameDiscoverer.java @@ -54,7 +54,7 @@ import org.springframework.util.ClassUtils; */ public class LocalVariableTableParameterNameDiscoverer implements ParameterNameDiscoverer { - private static Log logger = LogFactory.getLog(LocalVariableTableParameterNameDiscoverer.class); + private static final Log logger = LogFactory.getLog(LocalVariableTableParameterNameDiscoverer.class); // marker object for classes that do not have any debug info private static final Map NO_DEBUG_INFO_MAP = Collections.emptyMap(); diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseFactory.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseFactory.java index 20a5bfdf617..e9b9559d723 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseFactory.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,26 +30,42 @@ import org.springframework.jdbc.datasource.init.DatabasePopulatorUtils; import org.springframework.util.Assert; /** - * Creates a {@link EmbeddedDatabase} instance. Callers are guaranteed that the returned database has been fully - * initialized and populated. + * Factory for creating {@link EmbeddedDatabase} instances. * - *

Can be configured:
- * Call {@link #setDatabaseName(String)} to change the name of the database.
- * Call {@link #setDatabaseType(EmbeddedDatabaseType)} to set the database type if you wish to use one of the supported types.
- * Call {@link #setDatabaseConfigurer(EmbeddedDatabaseConfigurer)} to configure support for your own embedded database type.
- * Call {@link #setDatabasePopulator(DatabasePopulator)} to change the algorithm used to populate the database.
- * Call {@link #setDataSourceFactory(DataSourceFactory)} to change the type of DataSource used to connect to the database.
- * Call {@link #getDatabase()} to get the {@link EmbeddedDatabase} instance.
+ *

Callers are guaranteed that a returned database has been fully initialized + * and populated. + * + *

Can be configured: + *

+ * + *

Call {@link #getDatabase()} to get the {@link EmbeddedDatabase} instance. * * @author Keith Donald * @author Juergen Hoeller + * @author Sam Brannen * @since 3.0 */ public class EmbeddedDatabaseFactory { - private static Log logger = LogFactory.getLog(EmbeddedDatabaseFactory.class); + /** + * Default name for an embedded database: "testdb". + */ + public static final String DEFAULT_DATABASE_NAME = "testdb"; + + + private static final Log logger = LogFactory.getLog(EmbeddedDatabaseFactory.class); - private String databaseName = "testdb"; + private String databaseName = DEFAULT_DATABASE_NAME; private DataSourceFactory dataSourceFactory = new SimpleDriverDataSourceFactory(); @@ -61,16 +77,18 @@ public class EmbeddedDatabaseFactory { /** - * Set the name of the database. Defaults to "testdb". - * @param databaseName name of the test database + * Set the name of the database. + *

Defaults to {@value #DEFAULT_DATABASE_NAME}. + * @param databaseName name of the embedded database */ public void setDatabaseName(String databaseName) { - Assert.notNull(databaseName, "Database name is required"); + Assert.hasText(databaseName, "Database name is required"); this.databaseName = databaseName; } /** - * Set the factory to use to create the DataSource instance that connects to the embedded database. + * Set the factory to use to create the {@link DataSource} instance that + * connects to the embedded database. *

Defaults to {@link SimpleDriverDataSourceFactory}. */ public void setDataSourceFactory(DataSourceFactory dataSourceFactory) { @@ -79,9 +97,10 @@ public class EmbeddedDatabaseFactory { } /** - * Set the type of embedded database to use. Call this when you wish to configure - * one of the pre-supported types. Defaults to HSQL. - * @param type the test database type + * Set the type of embedded database to use. + *

Call this when you wish to configure one of the pre-supported types. + *

Defaults to HSQL. + * @param type the database type */ public void setDatabaseType(EmbeddedDatabaseType type) { this.databaseConfigurer = EmbeddedDatabaseConfigurerFactory.getConfigurer(type); @@ -96,15 +115,17 @@ public class EmbeddedDatabaseFactory { } /** - * Set the strategy that will be used to populate the embedded database. Defaults to null. - * @see org.springframework.jdbc.datasource.init.DataSourceInitializer#setDatabasePopulator + * Set the strategy that will be used to initialize or populate the embedded + * database. + *

Defaults to {@code null}. */ public void setDatabasePopulator(DatabasePopulator populator) { this.databasePopulator = populator; } /** - * Factory method that returns the embedded database instance. + * Factory method that returns the {@link EmbeddedDatabase embedded database} + * instance, which is also a {@link DataSource}. */ public EmbeddedDatabase getDatabase() { if (this.dataSource == null) { @@ -115,8 +136,10 @@ public class EmbeddedDatabaseFactory { /** - * Hook to initialize the embedded database. Subclasses may call to force initialization. After calling this method, - * {@link #getDataSource()} returns the DataSource providing connectivity to the db. + * Hook to initialize the embedded database. Subclasses may call this method + * to force initialization. + *

After calling this method, {@link #getDataSource()} returns the + * {@link DataSource} providing connectivity to the database. */ protected void initDatabase() { // Create the embedded database source first @@ -144,8 +167,10 @@ public class EmbeddedDatabaseFactory { } /** - * Hook to shutdown the embedded database. Subclasses may call to force shutdown. - * After calling, {@link #getDataSource()} returns null. Does nothing if no embedded database has been initialized. + * Hook to shutdown the embedded database. Subclasses may call this method + * to force shutdown. + *

After calling, {@link #getDataSource()} returns {@code null}. + *

Does nothing if no embedded database has been initialized. */ protected void shutdownDatabase() { if (this.dataSource != null) { @@ -155,9 +180,11 @@ public class EmbeddedDatabaseFactory { } /** - * Hook that gets the DataSource that provides the connectivity to the embedded database. - *

Returns {@code null} if the DataSource has not been initialized or the database - * has been shut down. Subclasses may call to access the DataSource instance directly. + * Hook that gets the {@link DataSource} that provides the connectivity to the + * embedded database. + *

Returns {@code null} if the {@code DataSource} has not been initialized + * or if the database has been shut down. Subclasses may call this method to + * access the {@code DataSource} instance directly. */ protected final DataSource getDataSource() { return this.dataSource; diff --git a/spring-orm-hibernate4/src/main/java/org/springframework/orm/hibernate4/support/AsyncRequestInterceptor.java b/spring-orm-hibernate4/src/main/java/org/springframework/orm/hibernate4/support/AsyncRequestInterceptor.java index 38879158544..30875ce3215 100644 --- a/spring-orm-hibernate4/src/main/java/org/springframework/orm/hibernate4/support/AsyncRequestInterceptor.java +++ b/spring-orm-hibernate4/src/main/java/org/springframework/orm/hibernate4/support/AsyncRequestInterceptor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -44,7 +44,7 @@ import java.util.concurrent.Callable; public class AsyncRequestInterceptor extends CallableProcessingInterceptorAdapter implements DeferredResultProcessingInterceptor { - private static Log logger = LogFactory.getLog(AsyncRequestInterceptor.class); + private static final Log logger = LogFactory.getLog(AsyncRequestInterceptor.class); private final SessionFactory sessionFactory; @@ -52,11 +52,13 @@ public class AsyncRequestInterceptor extends CallableProcessingInterceptorAdapte private volatile boolean timeoutInProgress; + public AsyncRequestInterceptor(SessionFactory sessionFactory, SessionHolder sessionHolder) { this.sessionFactory = sessionFactory; this.sessionHolder = sessionHolder; } + @Override public void preProcess(NativeWebRequest request, Callable task) { bindSession(); @@ -90,11 +92,17 @@ public class AsyncRequestInterceptor extends CallableProcessingInterceptorAdapte } } + // Implementation of DeferredResultProcessingInterceptor methods - public void beforeConcurrentHandling(NativeWebRequest request, DeferredResult deferredResult) { } - public void preProcess(NativeWebRequest request, DeferredResult deferredResult) { } - public void postProcess(NativeWebRequest request, DeferredResult deferredResult, Object result) { } + public void beforeConcurrentHandling(NativeWebRequest request, DeferredResult deferredResult) { + } + + public void preProcess(NativeWebRequest request, DeferredResult deferredResult) { + } + + public void postProcess(NativeWebRequest request, DeferredResult deferredResult, Object result) { + } @Override public boolean handleTimeout(NativeWebRequest request, DeferredResult deferredResult) { @@ -106,4 +114,5 @@ public class AsyncRequestInterceptor extends CallableProcessingInterceptorAdapte public void afterCompletion(NativeWebRequest request, DeferredResult deferredResult) { closeAfterTimeout(); } + } diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/support/AsyncRequestInterceptor.java b/spring-orm/src/main/java/org/springframework/orm/jpa/support/AsyncRequestInterceptor.java index 046bd8f6501..eabd41ecb44 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/support/AsyncRequestInterceptor.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/support/AsyncRequestInterceptor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -44,7 +44,7 @@ import java.util.concurrent.Callable; public class AsyncRequestInterceptor extends CallableProcessingInterceptorAdapter implements DeferredResultProcessingInterceptor { - private static Log logger = LogFactory.getLog(AsyncRequestInterceptor.class); + private static final Log logger = LogFactory.getLog(AsyncRequestInterceptor.class); private final EntityManagerFactory emFactory; @@ -58,6 +58,7 @@ public class AsyncRequestInterceptor extends CallableProcessingInterceptorAdapte this.emHolder = emHolder; } + @Override public void preProcess(NativeWebRequest request, Callable task) { bindSession(); @@ -91,11 +92,17 @@ public class AsyncRequestInterceptor extends CallableProcessingInterceptorAdapte } } + // Implementation of DeferredResultProcessingInterceptor methods - public void beforeConcurrentHandling(NativeWebRequest request, DeferredResult deferredResult) { } - public void preProcess(NativeWebRequest request, DeferredResult deferredResult) { } - public void postProcess(NativeWebRequest request, DeferredResult deferredResult, Object result) { } + public void beforeConcurrentHandling(NativeWebRequest request, DeferredResult deferredResult) { + } + + public void preProcess(NativeWebRequest request, DeferredResult deferredResult) { + } + + public void postProcess(NativeWebRequest request, DeferredResult deferredResult, Object result) { + } @Override public boolean handleTimeout(NativeWebRequest request, DeferredResult deferredResult) { @@ -107,5 +114,5 @@ public class AsyncRequestInterceptor extends CallableProcessingInterceptorAdapte public void afterCompletion(NativeWebRequest request, DeferredResult deferredResult) { closeAfterTimeout(); } -} +} diff --git a/spring-web/src/main/java/org/springframework/web/context/request/async/CallableInterceptorChain.java b/spring-web/src/main/java/org/springframework/web/context/request/async/CallableInterceptorChain.java index ba3885330d0..3cf4f889f89 100644 --- a/spring-web/src/main/java/org/springframework/web/context/request/async/CallableInterceptorChain.java +++ b/spring-web/src/main/java/org/springframework/web/context/request/async/CallableInterceptorChain.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,7 +31,7 @@ import org.springframework.web.context.request.NativeWebRequest; */ class CallableInterceptorChain { - private static Log logger = LogFactory.getLog(CallableInterceptorChain.class); + private static final Log logger = LogFactory.getLog(CallableInterceptorChain.class); private final List interceptors; @@ -102,4 +102,5 @@ class CallableInterceptorChain { } } } + } diff --git a/spring-web/src/main/java/org/springframework/web/context/request/async/DeferredResultInterceptorChain.java b/spring-web/src/main/java/org/springframework/web/context/request/async/DeferredResultInterceptorChain.java index ffe9bb81265..fba37f178a0 100644 --- a/spring-web/src/main/java/org/springframework/web/context/request/async/DeferredResultInterceptorChain.java +++ b/spring-web/src/main/java/org/springframework/web/context/request/async/DeferredResultInterceptorChain.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,7 +29,7 @@ import org.springframework.web.context.request.NativeWebRequest; */ class DeferredResultInterceptorChain { - private static Log logger = LogFactory.getLog(DeferredResultInterceptorChain.class); + private static final Log logger = LogFactory.getLog(DeferredResultInterceptorChain.class); private final List interceptors;