diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/AbstractLobCreator.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/AbstractLobCreator.java index 7001ccaccb..16f21bbd2e 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/AbstractLobCreator.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/AbstractLobCreator.java @@ -22,7 +22,7 @@ public abstract class AbstractLobCreator implements LobCreator { @Override public Clob wrap(Clob clob) { - if ( NClob.class.isInstance( clob ) ) { + if ( clob instanceof NClob ) { return wrap( (NClob) clob ); } else { diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/ClobProxy.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/ClobProxy.java index 4ee5dc3bc0..45ee3aa10d 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/ClobProxy.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/ClobProxy.java @@ -27,7 +27,7 @@ import org.hibernate.type.descriptor.java.DataHelper; * @author Gail Badner */ public class ClobProxy implements InvocationHandler { - private static final Class[] PROXY_INTERFACES = new Class[] { Clob.class, ClobImplementer.class }; + private static final Class[] PROXY_INTERFACES = new Class[] { Clob.class, ClobImplementer.class }; private final CharacterStream characterStream; private boolean needsReset; diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/ContextualLobCreator.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/ContextualLobCreator.java index 4e4bb4e533..c2460b9fbf 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/ContextualLobCreator.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/ContextualLobCreator.java @@ -122,30 +122,15 @@ public class ContextualLobCreator extends AbstractLobCreator implements LobCreat /** * Callback for performing contextual BLOB creation */ - public static final LobCreationContext.Callback CREATE_BLOB_CALLBACK = new LobCreationContext.Callback() { - @Override - public Blob executeOnConnection(Connection connection) throws SQLException { - return connection.createBlob(); - } - }; + public static final LobCreationContext.Callback CREATE_BLOB_CALLBACK = Connection::createBlob; /** * Callback for performing contextual CLOB creation */ - public static final LobCreationContext.Callback CREATE_CLOB_CALLBACK = new LobCreationContext.Callback() { - @Override - public Clob executeOnConnection(Connection connection) throws SQLException { - return connection.createClob(); - } - }; + public static final LobCreationContext.Callback CREATE_CLOB_CALLBACK = Connection::createClob; /** * Callback for performing contextual NCLOB creation */ - public static final LobCreationContext.Callback CREATE_NCLOB_CALLBACK = new LobCreationContext.Callback() { - @Override - public NClob executeOnConnection(Connection connection) throws SQLException { - return connection.createNClob(); - } - }; + public static final LobCreationContext.Callback CREATE_NCLOB_CALLBACK = Connection::createNClob; } diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/NClobProxy.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/NClobProxy.java index a60a934712..413d123eac 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/NClobProxy.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/NClobProxy.java @@ -23,7 +23,7 @@ public class NClobProxy extends ClobProxy { /** * The interfaces used to generate the proxy */ - public static final Class[] PROXY_INTERFACES = new Class[] { NClob.class, NClobImplementer.class }; + public static final Class[] PROXY_INTERFACES = new Class[] { NClob.class, NClobImplementer.class }; protected NClobProxy(String string) { super( string ); diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/ReaderInputStream.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/ReaderInputStream.java index f41a487492..ce63f9aec9 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/ReaderInputStream.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/ReaderInputStream.java @@ -16,7 +16,7 @@ import java.io.Reader; * @author Gavin King */ public class ReaderInputStream extends InputStream { - private Reader reader; + private final Reader reader; /** * Constructs a ReaderInputStream from a Reader diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/SerializableBlobProxy.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/SerializableBlobProxy.java index bd179800b5..ecaca07659 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/SerializableBlobProxy.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/SerializableBlobProxy.java @@ -23,7 +23,7 @@ import org.hibernate.HibernateException; * @author Gail Badner */ public class SerializableBlobProxy implements InvocationHandler, Serializable { - private static final Class[] PROXY_INTERFACES = new Class[] { Blob.class, WrappedBlob.class, Serializable.class }; + private static final Class[] PROXY_INTERFACES = new Class[] { Blob.class, WrappedBlob.class, Serializable.class }; private final transient Blob blob; diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/SerializableClobProxy.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/SerializableClobProxy.java index fb3e85f84a..d7bbb405a3 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/SerializableClobProxy.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/SerializableClobProxy.java @@ -23,7 +23,7 @@ import org.hibernate.HibernateException; * @author Gail Badner */ public class SerializableClobProxy implements InvocationHandler, Serializable { - private static final Class[] PROXY_INTERFACES = new Class[] { Clob.class, WrappedClob.class, Serializable.class }; + private static final Class[] PROXY_INTERFACES = new Class[] { Clob.class, WrappedClob.class, Serializable.class }; private final transient Clob clob; diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/SerializableNClobProxy.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/SerializableNClobProxy.java index 230ee1f829..2e2622bab1 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/SerializableNClobProxy.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/SerializableNClobProxy.java @@ -16,7 +16,7 @@ import java.sql.NClob; * @author Steve Ebersole */ public class SerializableNClobProxy extends SerializableClobProxy { - private static final Class[] PROXY_INTERFACES = new Class[] { NClob.class, WrappedNClob.class }; + private static final Class[] PROXY_INTERFACES = new Class[] { NClob.class, WrappedNClob.class }; /** * Builds a serializable {@link Clob} wrapper around the given {@link Clob}. diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/Size.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/Size.java index 72de119bbb..c2002112b6 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/Size.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/Size.java @@ -20,15 +20,15 @@ import java.io.Serializable; * @author Steve Ebersole */ public class Size implements Serializable { - public static enum LobMultiplier { + public enum LobMultiplier { NONE( 1 ), K( NONE.factor * 1024 ), M( K.factor * 1024 ), G( M.factor * 1024 ); - private long factor; + private final long factor; - private LobMultiplier(long factor) { + LobMultiplier(long factor) { this.factor = factor; } diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/StreamUtils.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/StreamUtils.java deleted file mode 100644 index e54906a57b..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/StreamUtils.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.engine.jdbc; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.Reader; -import java.io.Writer; - -/** - * Stream copying utilities - * - * @author Steve Ebersole - */ -public class StreamUtils { - /** - * Default size to use for reading buffers. - */ - public static final int DEFAULT_CHUNK_SIZE = 1024; - - /** - * Copy the inputStream to the outputStream. Uses a buffer of the default size ({@link #DEFAULT_CHUNK_SIZE}). - * - * @param inputStream The input stream to read - * @param outputStream The output stream to write to - * - * @return The number of bytes read - * - * @throws IOException If a problem occurred accessing either stream - */ - public static long copy(InputStream inputStream, OutputStream outputStream) throws IOException { - return copy( inputStream, outputStream, DEFAULT_CHUNK_SIZE ); - } - - /** - * Copy the inputStream to the outputStream using a buffer of the specified size - * - * @param inputStream The input stream to read - * @param outputStream The output stream to write to - * @param bufferSize The size of the buffer to use for reading - * - * @return The number of bytes read - * - * @throws IOException If a problem occurred accessing either stream - */ - public static long copy(InputStream inputStream, OutputStream outputStream, int bufferSize) throws IOException { - final byte[] buffer = new byte[bufferSize]; - long count = 0; - int n; - while ( -1 != ( n = inputStream.read( buffer ) ) ) { - outputStream.write( buffer, 0, n ); - count += n; - } - return count; - } - - /** - * Copy the reader to the writer. Uses a buffer of the default size ({@link #DEFAULT_CHUNK_SIZE}). - * - * @param reader The reader to read from - * @param writer The writer to write to - * - * @return The number of bytes read - * - * @throws IOException If a problem occurred accessing reader or writer - */ - public static long copy(Reader reader, Writer writer) throws IOException { - return copy( reader, writer, DEFAULT_CHUNK_SIZE ); - } - - /** - * Copy the reader to the writer using a buffer of the specified size - * - * @param reader The reader to read from - * @param writer The writer to write to - * @param bufferSize The size of the buffer to use for reading - * - * @return The number of bytes read - * - * @throws IOException If a problem occurred accessing either stream - */ - public static long copy(Reader reader, Writer writer, int bufferSize) throws IOException { - final char[] buffer = new char[bufferSize]; - long count = 0; - int n; - while ( -1 != ( n = reader.read( buffer ) ) ) { - writer.write( buffer, 0, n ); - count += n; - } - return count; - } - - private StreamUtils() { - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/batch/internal/AbstractBatchImpl.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/batch/internal/AbstractBatchImpl.java index d749b0f927..bcd53f89f6 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/batch/internal/AbstractBatchImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/batch/internal/AbstractBatchImpl.java @@ -41,8 +41,8 @@ public abstract class AbstractBatchImpl implements Batch { private final SqlStatementLogger sqlStatementLogger; private final SqlExceptionHelper sqlExceptionHelper; - private LinkedHashMap statements = new LinkedHashMap<>(); - private LinkedHashSet observers = new LinkedHashSet<>(); + private final LinkedHashMap statements = new LinkedHashMap<>(); + private final LinkedHashSet observers = new LinkedHashSet<>(); protected AbstractBatchImpl(BatchKey key, JdbcCoordinator jdbcCoordinator) { if ( key == null ) { diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/batch/internal/BatchBuilderImpl.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/batch/internal/BatchBuilderImpl.java index 5a90b12181..7c3b854868 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/batch/internal/BatchBuilderImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/batch/internal/BatchBuilderImpl.java @@ -10,16 +10,13 @@ import org.hibernate.engine.jdbc.batch.spi.Batch; import org.hibernate.engine.jdbc.batch.spi.BatchBuilder; import org.hibernate.engine.jdbc.batch.spi.BatchKey; import org.hibernate.engine.jdbc.spi.JdbcCoordinator; -import org.hibernate.internal.CoreLogging; -import org.hibernate.internal.CoreMessageLogger; /** * A builder for {@link Batch} instances. * * @author Steve Ebersole */ -public class BatchBuilderImpl implements BatchBuilder, BatchBuilderMXBean { - private static final CoreMessageLogger LOG = CoreLogging.messageLogger( BatchBuilderImpl.class ); +public class BatchBuilderImpl implements BatchBuilder { private volatile int jdbcBatchSize; @@ -38,12 +35,10 @@ public class BatchBuilderImpl implements BatchBuilder, BatchBuilderMXBean { this.jdbcBatchSize = jdbcBatchSize; } - @Override public int getJdbcBatchSize() { return jdbcBatchSize; } - @Override public void setJdbcBatchSize(int jdbcBatchSize) { this.jdbcBatchSize = jdbcBatchSize; } diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/batch/internal/BatchBuilderMXBean.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/batch/internal/BatchBuilderMXBean.java deleted file mode 100644 index 012c65f093..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/batch/internal/BatchBuilderMXBean.java +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.engine.jdbc.batch.internal; - -/** - * The BatchBuilderImpl JMX management interface - * - * @author Steve Ebersole - */ -public interface BatchBuilderMXBean { - int getJdbcBatchSize(); - void setJdbcBatchSize(int size); -} diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/BasicConnectionCreator.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/BasicConnectionCreator.java index 9449d62d5f..b9948066eb 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/BasicConnectionCreator.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/BasicConnectionCreator.java @@ -93,7 +93,7 @@ public abstract class BasicConnectionCreator implements ConnectionCreator { return conn; } - private ValueHolder simpleConverterAccess = + private final ValueHolder simpleConverterAccess = new ValueHolder<>( () -> new SQLExceptionConversionDelegate() { private final SQLStateConversionDelegate sqlStateDelegate = new SQLStateConversionDelegate( () -> { diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/spi/DataSourceBasedMultiTenantConnectionProviderImpl.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/spi/DataSourceBasedMultiTenantConnectionProviderImpl.java index ece3ff9625..82721465d2 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/spi/DataSourceBasedMultiTenantConnectionProviderImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/spi/DataSourceBasedMultiTenantConnectionProviderImpl.java @@ -76,7 +76,7 @@ public class DataSourceBasedMultiTenantConnectionProviderImpl final Object dataSourceConfigValue = serviceRegistry.getService( ConfigurationService.class ) .getSettings() .get( AvailableSettings.DATASOURCE ); - if ( !String.class.isInstance( dataSourceConfigValue ) ) { + if ( !(dataSourceConfigValue instanceof String) ) { throw new HibernateException( "Improper set up of DataSourceBasedMultiTenantConnectionProviderImpl" ); } final String jndiName = (String) dataSourceConfigValue; @@ -91,13 +91,13 @@ public class DataSourceBasedMultiTenantConnectionProviderImpl throw new HibernateException( "JNDI name [" + jndiName + "] could not be resolved" ); } - if ( DataSource.class.isInstance( namedObject ) ) { + if ( namedObject instanceof DataSource ) { final int loc = jndiName.lastIndexOf( '/' ); this.baseJndiNamespace = jndiName.substring( 0, loc ); this.tenantIdentifierForAny = jndiName.substring( loc + 1 ); dataSourceMap().put( tenantIdentifierForAny, (DataSource) namedObject ); } - else if ( Context.class.isInstance( namedObject ) ) { + else if ( namedObject instanceof Context ) { this.baseJndiNamespace = jndiName; this.tenantIdentifierForAny = (String) serviceRegistry.getService( ConfigurationService.class ) .getSettings() diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/cursor/internal/StandardRefCursorSupport.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/cursor/internal/StandardRefCursorSupport.java index c8266fc22b..66f2d22b33 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/cursor/internal/StandardRefCursorSupport.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/cursor/internal/StandardRefCursorSupport.java @@ -6,8 +6,6 @@ */ package org.hibernate.engine.jdbc.cursor.internal; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.sql.CallableStatement; import java.sql.DatabaseMetaData; import java.sql.ResultSet; diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/env/internal/DefaultSchemaNameResolver.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/env/internal/DefaultSchemaNameResolver.java index 6b01740bb7..9170ab9a5b 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/env/internal/DefaultSchemaNameResolver.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/env/internal/DefaultSchemaNameResolver.java @@ -42,7 +42,7 @@ public class DefaultSchemaNameResolver implements SchemaNameResolver { try { final Class jdbcConnectionClass = connection.getClass(); final Method getSchemaMethod = jdbcConnectionClass.getMethod( "getSchema" ); - if ( getSchemaMethod != null && getSchemaMethod.getReturnType().equals( String.class ) ) { + if ( getSchemaMethod.getReturnType().equals( String.class ) ) { try { // If the JDBC driver does not implement the Java 7 spec, but the JRE is Java 7 // then the getSchemaMethod is not null but the call to getSchema() throws an java.lang.AbstractMethodError @@ -59,10 +59,10 @@ public class DefaultSchemaNameResolver implements SchemaNameResolver { return SchemaNameResolverFallbackDelegate.INSTANCE; } } - catch (Exception ignore) { + catch (Exception e) { log.debugf( "Unable to use Java 1.7 Connection#getSchema : An error occurred trying to resolve the connection default schema resolver: %s", - ignore.getMessage() ); + e.getMessage() ); return SchemaNameResolverFallbackDelegate.INSTANCE; } } diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/env/internal/JdbcEnvironmentImpl.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/env/internal/JdbcEnvironmentImpl.java index 05fb4eca92..d0d4dd61de 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/env/internal/JdbcEnvironmentImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/env/internal/JdbcEnvironmentImpl.java @@ -155,9 +155,6 @@ public class JdbcEnvironmentImpl implements JdbcEnvironment { /** * Constructor form used from testing - * - * @param dialect The dialect - * @param jdbcConnectionAccess */ public JdbcEnvironmentImpl( DatabaseMetaData databaseMetaData, @@ -337,13 +334,13 @@ public class JdbcEnvironmentImpl implements JdbcEnvironment { } } - @SuppressWarnings("deprecation") private SqlExceptionHelper buildSqlExceptionHelper(Dialect dialect, boolean logWarnings) { - final StandardSQLExceptionConverter sqlExceptionConverter = new StandardSQLExceptionConverter(); - sqlExceptionConverter.addDelegate( dialect.buildSQLExceptionConversionDelegate() ); - sqlExceptionConverter.addDelegate( new SQLExceptionTypeDelegate( dialect ) ); - // todo : vary this based on extractedMetaDataSupport.getSqlStateType() - sqlExceptionConverter.addDelegate( new SQLStateConversionDelegate( dialect ) ); + final StandardSQLExceptionConverter sqlExceptionConverter = new StandardSQLExceptionConverter( + dialect.buildSQLExceptionConversionDelegate(), + new SQLExceptionTypeDelegate( dialect ), + // todo : vary this based on extractedMetaDataSupport.getSqlStateType() + new SQLStateConversionDelegate( dialect ) + ); return new SqlExceptionHelper( sqlExceptionConverter, logWarnings ); } diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/env/internal/LobCreatorBuilderImpl.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/env/internal/LobCreatorBuilderImpl.java index 5e5445edd5..deffc99a7b 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/env/internal/LobCreatorBuilderImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/env/internal/LobCreatorBuilderImpl.java @@ -53,7 +53,7 @@ public class LobCreatorBuilderImpl implements LobCreatorBuilder { * @param jdbcConnection A JDBC {@link Connection} which can be used to gauge the drivers level of support, * specifically for creating LOB references. */ - public static LobCreatorBuilderImpl makeLobCreatorBuilder(Dialect dialect, Map configValues, Connection jdbcConnection) { + public static LobCreatorBuilderImpl makeLobCreatorBuilder(Dialect dialect, Map configValues, Connection jdbcConnection) { return new LobCreatorBuilderImpl( useContextualLobCreation( dialect, configValues, jdbcConnection ) ); } @@ -67,7 +67,7 @@ public class LobCreatorBuilderImpl implements LobCreatorBuilder { return new LobCreatorBuilderImpl( false ); } - private static final Class[] NO_ARG_SIG = ArrayHelper.EMPTY_CLASS_ARRAY; + private static final Class[] NO_ARG_SIG = ArrayHelper.EMPTY_CLASS_ARRAY; private static final Object[] NO_ARGS = ArrayHelper.EMPTY_OBJECT_ARRAY; /** @@ -82,8 +82,7 @@ public class LobCreatorBuilderImpl implements LobCreatorBuilder { * * @return True if the connection can be used to create LOBs; false otherwise. */ - @SuppressWarnings("unchecked") - private static boolean useContextualLobCreation(Dialect dialect, Map configValues, Connection jdbcConnection) { + private static boolean useContextualLobCreation(Dialect dialect, Map configValues, Connection jdbcConnection) { final boolean isNonContextualLobCreationRequired = ConfigurationHelper.getBoolean( Environment.NON_CONTEXTUAL_LOB_CREATION, configValues ); if ( isNonContextualLobCreationRequired ) { @@ -112,20 +111,20 @@ public class LobCreatorBuilderImpl implements LobCreatorBuilder { // ignore exception and continue } - final Class connectionClass = Connection.class; + final Class connectionClass = Connection.class; final Method createClobMethod = connectionClass.getMethod( "createClob", NO_ARG_SIG ); if ( createClobMethod.getDeclaringClass().equals( Connection.class ) ) { - // If we get here we are running in a jdk 1.6 (jdbc 4) environment... - // Further check to make sure the driver actually implements the LOB creation methods. We - // check against createClob() as indicative of all; should we check against all 3 explicitly? + // If we get here we are running in a jdk 1.6 (jdbc 4) environment: + // Further check to make sure the driver actually implements the LOB creation methods. + // We check against createClob() as indicative of all; should we check against all 3 explicitly? try { final Object clob = createClobMethod.invoke( jdbcConnection, NO_ARGS ); try { final Method freeMethod = clob.getClass().getMethod( "free", NO_ARG_SIG ); freeMethod.invoke( clob, NO_ARGS ); } - catch ( Throwable ignore ) { - LOG.tracef( "Unable to free CLOB created to test createClob() implementation : %s", ignore ); + catch ( Throwable e ) { + LOG.tracef( "Unable to free CLOB created to test createClob() implementation : %s", e ); } return true; } diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/env/spi/ExtractedDatabaseMetaData.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/env/spi/ExtractedDatabaseMetaData.java index 54bdc8acf3..df11225a45 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/env/spi/ExtractedDatabaseMetaData.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/env/spi/ExtractedDatabaseMetaData.java @@ -7,11 +7,8 @@ package org.hibernate.engine.jdbc.env.spi; import java.util.Collections; -import java.util.LinkedHashSet; import java.util.List; -import java.util.Set; -import org.hibernate.engine.jdbc.spi.TypeInfo; import org.hibernate.tool.schema.extract.spi.SequenceInformation; /** @@ -21,7 +18,6 @@ import org.hibernate.tool.schema.extract.spi.SequenceInformation; * * @author Steve Ebersole */ -@SuppressWarnings( {"UnusedDeclaration"}) public interface ExtractedDatabaseMetaData { /** * Obtain the JDBC Environment from which this metadata came. diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/env/spi/JdbcEnvironment.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/env/spi/JdbcEnvironment.java index a5ea4611e4..f4bf91c894 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/env/spi/JdbcEnvironment.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/env/spi/JdbcEnvironment.java @@ -9,7 +9,6 @@ package org.hibernate.engine.jdbc.env.spi; import org.hibernate.boot.model.naming.Identifier; import org.hibernate.dialect.Dialect; import org.hibernate.engine.jdbc.spi.SqlExceptionHelper; -import org.hibernate.engine.jdbc.spi.TypeInfo; import org.hibernate.service.Service; import org.hibernate.sql.ast.SqlAstTranslatorFactory; diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/internal/HighlightingFormatter.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/internal/HighlightingFormatter.java index 967bfa8b5a..a3fa919603 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/internal/HighlightingFormatter.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/internal/HighlightingFormatter.java @@ -37,7 +37,7 @@ public final class HighlightingFormatter implements Formatter { private static String escape(String code) { return "\u001b[" + code + "m"; - }; + } private final String keywordEscape; private final String stringEscape; diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/internal/JdbcCoordinatorImpl.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/internal/JdbcCoordinatorImpl.java index 9e46bbac59..06b7eea6bd 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/internal/JdbcCoordinatorImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/internal/JdbcCoordinatorImpl.java @@ -53,10 +53,10 @@ import org.hibernate.resource.transaction.backend.jdbc.spi.JdbcResourceTransacti public class JdbcCoordinatorImpl implements JdbcCoordinator { private static final CoreMessageLogger LOG = CoreLogging.messageLogger( JdbcCoordinatorImpl.class ); - private transient LogicalConnectionImplementor logicalConnection; - private transient JdbcSessionOwner owner; + private transient final LogicalConnectionImplementor logicalConnection; + private transient final JdbcSessionOwner owner; - private transient JdbcServices jdbcServices; + private transient final JdbcServices jdbcServices; private transient Batch currentBatch; @@ -225,7 +225,7 @@ public class JdbcCoordinatorImpl implements JdbcCoordinator { @Override public void setTransactionTimeOut(int seconds) { - transactionTimeOutInstant = System.currentTimeMillis() + ( seconds * 1000 ); + transactionTimeOutInstant = System.currentTimeMillis() + ( seconds * 1000L ); } @Override @@ -339,7 +339,7 @@ public class JdbcCoordinatorImpl implements JdbcCoordinator { catch (SQLException sqle) { SqlExceptionHelper sqlExceptionHelper = jdbcServices.getSqlExceptionHelper(); //Should always be non-null, but to make sure as the implementation is lazy: - if ( sqlExceptionHelper != null ) { + if ( sqlExceptionHelper == null ) { sqlExceptionHelper = new SqlExceptionHelper( false ); } throw sqlExceptionHelper.convert( sqle, "Cannot cancel query" ); @@ -398,20 +398,17 @@ public class JdbcCoordinatorImpl implements JdbcCoordinator { lastQuery = null; } } - catch( SQLException e ) { - LOG.debugf( "Unable to release JDBC statement [%s]", e.getMessage() ); - } catch ( Exception e ) { - // try to handle general errors more elegantly LOG.debugf( "Unable to release JDBC statement [%s]", e.getMessage() ); } } - @SuppressWarnings({ "unchecked" }) + protected void close(ResultSet resultSet) { LOG.tracev( "Closing result set [{0}]", resultSet ); if ( resultSet instanceof InvalidatableWrapper ) { + @SuppressWarnings({ "unchecked" }) final InvalidatableWrapper wrapper = (InvalidatableWrapper) resultSet; close( wrapper.getWrappedObject() ); wrapper.invalidate(); @@ -421,9 +418,6 @@ public class JdbcCoordinatorImpl implements JdbcCoordinator { try { resultSet.close(); } - catch( SQLException e ) { - LOG.debugf( "Unable to release JDBC result set [%s]", e.getMessage() ); - } catch ( Exception e ) { // try to handle general errors more elegantly LOG.debugf( "Unable to release JDBC result set [%s]", e.getMessage() ); diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/internal/LobCreatorBuilder.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/internal/LobCreatorBuilder.java index f69e0bdbe2..e33e95330c 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/internal/LobCreatorBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/internal/LobCreatorBuilder.java @@ -11,6 +11,7 @@ import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.SQLException; import java.util.Map; +import java.util.Properties; import org.hibernate.cfg.Environment; import org.hibernate.engine.jdbc.ContextualLobCreator; @@ -18,6 +19,7 @@ import org.hibernate.engine.jdbc.LobCreationContext; import org.hibernate.engine.jdbc.LobCreator; import org.hibernate.engine.jdbc.NonContextualLobCreator; import org.hibernate.internal.CoreMessageLogger; +import org.hibernate.internal.util.PropertiesHelper; import org.hibernate.internal.util.collections.ArrayHelper; import org.hibernate.internal.util.config.ConfigurationHelper; @@ -34,20 +36,24 @@ public class LobCreatorBuilder { LobCreatorBuilder.class.getName() ); - private boolean useContextualLobCreation; + private final boolean useContextualLobCreation; /** - * The public factory method for obtaining the appropriate (according to given JDBC {@link Connection}. + * The public factory method for obtaining the appropriate according to given JDBC {@link Connection}. * * @param configValues The map of settings * @param jdbcConnection A JDBC {@link Connection} which can be used to gauge the drivers level of support, * specifically for creating LOB references. */ - public LobCreatorBuilder(Map configValues, Connection jdbcConnection) { + public LobCreatorBuilder(Map configValues, Connection jdbcConnection) { this.useContextualLobCreation = useContextualLobCreation( configValues, jdbcConnection ); } - private static final Class[] NO_ARG_SIG = ArrayHelper.EMPTY_CLASS_ARRAY; + public LobCreatorBuilder(Properties configValues, Connection jdbcConnection) { + this( PropertiesHelper.map(configValues), jdbcConnection ); + } + + private static final Class[] NO_ARG_SIG = ArrayHelper.EMPTY_CLASS_ARRAY; private static final Object[] NO_ARGS = ArrayHelper.EMPTY_OBJECT_ARRAY; /** @@ -60,8 +66,7 @@ public class LobCreatorBuilder { * * @return True if the connection can be used to create LOBs; false otherwise. */ - @SuppressWarnings("unchecked") - private static boolean useContextualLobCreation(Map configValues, Connection jdbcConnection) { + private static boolean useContextualLobCreation(Map configValues, Connection jdbcConnection) { final boolean isNonContextualLobCreationRequired = ConfigurationHelper.getBoolean( Environment.NON_CONTEXTUAL_LOB_CREATION, configValues ); if ( isNonContextualLobCreationRequired ) { @@ -86,20 +91,20 @@ public class LobCreatorBuilder { // ignore exception and continue } - final Class connectionClass = Connection.class; + final Class connectionClass = Connection.class; final Method createClobMethod = connectionClass.getMethod( "createClob", NO_ARG_SIG ); if ( createClobMethod.getDeclaringClass().equals( Connection.class ) ) { - // If we get here we are running in a jdk 1.6 (jdbc 4) environment... - // Further check to make sure the driver actually implements the LOB creation methods. We - // check against createClob() as indicative of all; should we check against all 3 explicitly? + // If we get here we are running in a jdk 1.6 (jdbc 4) environment: + // Further check to make sure the driver actually implements the LOB creation methods. + // We check against createClob() as indicative of all; should we check against all 3 explicitly? try { final Object clob = createClobMethod.invoke( jdbcConnection, NO_ARGS ); try { final Method freeMethod = clob.getClass().getMethod( "free", NO_ARG_SIG ); freeMethod.invoke( clob, NO_ARGS ); } - catch ( Throwable ignore ) { - LOG.tracef( "Unable to free CLOB created to test createClob() implementation : %s", ignore ); + catch ( Throwable e ) { + LOG.tracef( "Unable to free CLOB created to test createClob() implementation : %s", e ); } return true; } diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/spi/ConnectionObserverAdapter.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/spi/ConnectionObserverAdapter.java index b61c31a9b1..aae09217fb 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/spi/ConnectionObserverAdapter.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/spi/ConnectionObserverAdapter.java @@ -9,7 +9,7 @@ package org.hibernate.engine.jdbc.spi; import java.sql.Connection; /** - * A no-op adapter for ConnectionObserver. + * A no-op adapter for {@link ConnectionObserver}. * * @author Steve Ebersole */ diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/spi/InvalidatableWrapper.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/spi/InvalidatableWrapper.java index 80621f0e60..f6f647af10 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/spi/InvalidatableWrapper.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/spi/InvalidatableWrapper.java @@ -8,7 +8,7 @@ package org.hibernate.engine.jdbc.spi; /** - * Specialized {@link JdbcWrapper} contract for wrapped objects that can additioanlly be invalidated + * Specialized {@link JdbcWrapper} contract for wrapped objects that can additionally be invalidated * * @author Steve Ebersole */ diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/spi/NonDurableConnectionObserver.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/spi/NonDurableConnectionObserver.java index a60ce5fb7a..e4a84a7622 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/spi/NonDurableConnectionObserver.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/spi/NonDurableConnectionObserver.java @@ -7,8 +7,8 @@ package org.hibernate.engine.jdbc.spi; /** - * Additional optional contract for connection observers to indicate that they should be released when the physical - * connection is released. + * Additional optional contract for connection observers to indicate that + * they should be released when the physical connection is released. * * @author Steve Ebersole */ diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/spi/TypeInfo.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/spi/TypeInfo.java index 1b0208fee2..6e838e3b68 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/spi/TypeInfo.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/spi/TypeInfo.java @@ -21,7 +21,6 @@ import org.jboss.logging.Logger; * * @author Steve Ebersole */ -@SuppressWarnings("UnusedDeclaration") public class TypeInfo { private static final CoreMessageLogger LOG = Logger.getMessageLogger( CoreMessageLogger.class, diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/spi/TypeNullability.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/spi/TypeNullability.java index 7948e528fc..de4ef70e0e 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/spi/TypeNullability.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/spi/TypeNullability.java @@ -9,7 +9,7 @@ package org.hibernate.engine.jdbc.spi; import java.sql.DatabaseMetaData; /** - * Describes the instrinsic nullability of a data type as reported by the JDBC driver. + * Describes the intrinsic nullability of a data type as reported by the JDBC driver. * * @author Steve Ebersole */ diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jdbc/LobCreatorTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jdbc/LobCreatorTest.java index ae36affc32..3d7795528c 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/jdbc/LobCreatorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jdbc/LobCreatorTest.java @@ -126,7 +126,7 @@ public class LobCreatorTest extends org.hibernate.testing.junit4.BaseUnitTestCas else { assertTrue( nclob instanceof JdbcNClob ); } - assertTrue( NClob.class.isInstance( nclob ) ); +// assertTrue( nclob instanceof NClob ); nclob = lobCreator.wrap( nclob ); assertTrue( nclob instanceof WrappedClob ); @@ -135,8 +135,8 @@ public class LobCreatorTest extends org.hibernate.testing.junit4.BaseUnitTestCas nclob.free(); } - private class LobCreationContextImpl implements LobCreationContext { - private Connection connection; + private static class LobCreationContextImpl implements LobCreationContext { + private final Connection connection; private LobCreationContextImpl(Connection connection) { this.connection = connection; @@ -153,12 +153,12 @@ public class LobCreatorTest extends org.hibernate.testing.junit4.BaseUnitTestCas } private interface JdbcLobBuilder { - public Blob createBlob() throws SQLException ; - public Clob createClob() throws SQLException ; - public NClob createNClob() throws SQLException ; + Blob createBlob() throws SQLException ; + Clob createClob() throws SQLException ; + NClob createNClob() throws SQLException ; } - private class JdbcLobBuilderImpl implements JdbcLobBuilder { + private static class JdbcLobBuilderImpl implements JdbcLobBuilder { private final boolean isSupported; private JdbcLobBuilderImpl(boolean isSupported) { @@ -199,31 +199,29 @@ public class LobCreatorTest extends org.hibernate.testing.junit4.BaseUnitTestCas // the only methods we are interested in are the LOB creation methods... if ( args == null || args.length == 0 ) { final String methodName = method.getName(); - if ( "createBlob".equals( methodName ) ) { - return lobBuilder.createBlob(); - } - else if ( "createClob".equals( methodName ) ) { - return lobBuilder.createClob(); - } - else if ( "createNClob".equals( methodName ) ) { - return lobBuilder.createNClob(); - } - else if ( "getMetaData".equals( methodName ) ) { - return metadata; + switch (methodName) { + case "createBlob": + return lobBuilder.createBlob(); + case "createClob": + return lobBuilder.createClob(); + case "createNClob": + return lobBuilder.createNClob(); + case "getMetaData": + return metadata; } } return null; } } - private static Class[] CONN_PROXY_TYPES = new Class[] { Connection.class }; + private static final Class[] CONN_PROXY_TYPES = new Class[] { Connection.class }; private Connection createConnectionProxy(int version, JdbcLobBuilder jdbcLobBuilder) { ConnectionProxyHandler handler = new ConnectionProxyHandler( version, jdbcLobBuilder ); return ( Connection ) Proxy.newProxyInstance( getClass().getClassLoader(), CONN_PROXY_TYPES, handler ); } - private class MetadataProxyHandler implements InvocationHandler { + private static class MetadataProxyHandler implements InvocationHandler { private final int jdbcVersion; private MetadataProxyHandler(int jdbcVersion) { @@ -239,14 +237,14 @@ public class LobCreatorTest extends org.hibernate.testing.junit4.BaseUnitTestCas } } - private static Class[] META_PROXY_TYPES = new Class[] { DatabaseMetaData.class }; + private static final Class[] META_PROXY_TYPES = new Class[] { DatabaseMetaData.class }; private DatabaseMetaData createMetadataProxy(int version) { MetadataProxyHandler handler = new MetadataProxyHandler( version ); return ( DatabaseMetaData ) Proxy.newProxyInstance( getClass().getClassLoader(), META_PROXY_TYPES, handler ); } - private class JdbcBlob implements Blob { + private static class JdbcBlob implements Blob { public long length() throws SQLException { return 0; } @@ -255,7 +253,7 @@ public class LobCreatorTest extends org.hibernate.testing.junit4.BaseUnitTestCas return new byte[0]; } - public InputStream getBinaryStream() throws SQLException { + public InputStream getBinaryStream() { return null; } @@ -275,35 +273,35 @@ public class LobCreatorTest extends org.hibernate.testing.junit4.BaseUnitTestCas return 0; } - public OutputStream setBinaryStream(long pos) throws SQLException { + public OutputStream setBinaryStream(long pos) { return null; } - public void truncate(long len) throws SQLException { + public void truncate(long len) { } public void free() throws SQLException { } - public InputStream getBinaryStream(long pos, long length) throws SQLException { + public InputStream getBinaryStream(long pos, long length) { return null; } } - private class JdbcClob implements Clob { + private static class JdbcClob implements Clob { public long length() throws SQLException { return 0; } - public String getSubString(long pos, int length) throws SQLException { + public String getSubString(long pos, int length) { return null; } - public Reader getCharacterStream() throws SQLException { + public Reader getCharacterStream() { return null; } - public InputStream getAsciiStream() throws SQLException { + public InputStream getAsciiStream() { return null; } @@ -323,25 +321,25 @@ public class LobCreatorTest extends org.hibernate.testing.junit4.BaseUnitTestCas return 0; } - public OutputStream setAsciiStream(long pos) throws SQLException { + public OutputStream setAsciiStream(long pos) { return null; } - public Writer setCharacterStream(long pos) throws SQLException { + public Writer setCharacterStream(long pos) { return null; } - public void truncate(long len) throws SQLException { + public void truncate(long len) { } public void free() throws SQLException { } - public Reader getCharacterStream(long pos, long length) throws SQLException { + public Reader getCharacterStream(long pos, long length) { return null; } } - private class JdbcNClob extends JdbcClob implements NClob { + private static class JdbcNClob extends JdbcClob implements NClob { } } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/transaction/batch/JtaWithFailingBatchTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/transaction/batch/JtaWithFailingBatchTest.java index b863cb5991..9967940fe7 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/transaction/batch/JtaWithFailingBatchTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/transaction/batch/JtaWithFailingBatchTest.java @@ -151,7 +151,7 @@ public class JtaWithFailingBatchTest extends AbstractJtaBatchTest { public static class TestBatch extends BatchingBatch { private int numberOfStatementsAfterReleasing; - private List createdStatements = new ArrayList<>(); + private final List createdStatements = new ArrayList<>(); private boolean calledReleaseStatements; private String currentStatementSql;