clean up some warnings in engine.jdbc package

This commit is contained in:
Gavin King 2022-01-25 21:44:11 +01:00
parent 6b51952137
commit 6b5c11b1ff
31 changed files with 102 additions and 254 deletions

View File

@ -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 {

View File

@ -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;

View File

@ -122,30 +122,15 @@ public class ContextualLobCreator extends AbstractLobCreator implements LobCreat
/**
* Callback for performing contextual BLOB creation
*/
public static final LobCreationContext.Callback<Blob> CREATE_BLOB_CALLBACK = new LobCreationContext.Callback<Blob>() {
@Override
public Blob executeOnConnection(Connection connection) throws SQLException {
return connection.createBlob();
}
};
public static final LobCreationContext.Callback<Blob> CREATE_BLOB_CALLBACK = Connection::createBlob;
/**
* Callback for performing contextual CLOB creation
*/
public static final LobCreationContext.Callback<Clob> CREATE_CLOB_CALLBACK = new LobCreationContext.Callback<Clob>() {
@Override
public Clob executeOnConnection(Connection connection) throws SQLException {
return connection.createClob();
}
};
public static final LobCreationContext.Callback<Clob> CREATE_CLOB_CALLBACK = Connection::createClob;
/**
* Callback for performing contextual NCLOB creation
*/
public static final LobCreationContext.Callback<NClob> CREATE_NCLOB_CALLBACK = new LobCreationContext.Callback<NClob>() {
@Override
public NClob executeOnConnection(Connection connection) throws SQLException {
return connection.createNClob();
}
};
public static final LobCreationContext.Callback<NClob> CREATE_NCLOB_CALLBACK = Connection::createNClob;
}

View File

@ -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 );

View File

@ -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

View File

@ -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;

View File

@ -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;

View File

@ -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}.

View File

@ -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;
}

View File

@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
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() {
}
}

View File

@ -41,8 +41,8 @@ public abstract class AbstractBatchImpl implements Batch {
private final SqlStatementLogger sqlStatementLogger;
private final SqlExceptionHelper sqlExceptionHelper;
private LinkedHashMap<String, PreparedStatement> statements = new LinkedHashMap<>();
private LinkedHashSet<BatchObserver> observers = new LinkedHashSet<>();
private final LinkedHashMap<String, PreparedStatement> statements = new LinkedHashMap<>();
private final LinkedHashSet<BatchObserver> observers = new LinkedHashSet<>();
protected AbstractBatchImpl(BatchKey key, JdbcCoordinator jdbcCoordinator) {
if ( key == null ) {

View File

@ -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;
}

View File

@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.engine.jdbc.batch.internal;
/**
* The BatchBuilderImpl JMX management interface
*
* @author Steve Ebersole
*/
public interface BatchBuilderMXBean {
int getJdbcBatchSize();
void setJdbcBatchSize(int size);
}

View File

@ -93,7 +93,7 @@ public abstract class BasicConnectionCreator implements ConnectionCreator {
return conn;
}
private ValueHolder<SQLExceptionConversionDelegate> simpleConverterAccess =
private final ValueHolder<SQLExceptionConversionDelegate> simpleConverterAccess =
new ValueHolder<>( () -> new SQLExceptionConversionDelegate() {
private final SQLStateConversionDelegate sqlStateDelegate = new SQLStateConversionDelegate(
() -> {

View File

@ -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()

View File

@ -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;

View File

@ -42,7 +42,7 @@ public class DefaultSchemaNameResolver implements SchemaNameResolver {
try {
final Class<? extends Connection> 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;
}
}

View File

@ -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 );
}

View File

@ -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<String,Object> 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<String,Object> 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;
}

View File

@ -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.

View File

@ -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;

View File

@ -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;

View File

@ -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<ResultSet> wrapper = (InvalidatableWrapper<ResultSet>) 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() );

View File

@ -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<String,Object> 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<String,Object> 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<Connection> 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;
}

View File

@ -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
*/

View File

@ -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
*/

View File

@ -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
*/

View File

@ -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,

View File

@ -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
*/

View File

@ -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 {
}
}

View File

@ -151,7 +151,7 @@ public class JtaWithFailingBatchTest extends AbstractJtaBatchTest {
public static class TestBatch extends BatchingBatch {
private int numberOfStatementsAfterReleasing;
private List<PreparedStatement> createdStatements = new ArrayList<>();
private final List<PreparedStatement> createdStatements = new ArrayList<>();
private boolean calledReleaseStatements;
private String currentStatementSql;