diff --git a/cache-infinispan/pom.xml b/cache-infinispan/pom.xml index 328c7afa03..fb1fbbb32d 100644 --- a/cache-infinispan/pom.xml +++ b/cache-infinispan/pom.xml @@ -115,10 +115,6 @@ org.apache.maven.plugins maven-compiler-plugin - 1.6 - 1.6 - 1.6 - ${jdk16_home}/bin/javac true true @@ -127,7 +123,6 @@ org.apache.maven.plugins maven-surefire-plugin - ${jdk16_home}/bin/java **/ClusteredConcurrentTimestampRegionTestCase.java diff --git a/cache-jbosscache/pom.xml b/cache-jbosscache/pom.xml index c725ed3043..911bd4c835 100644 --- a/cache-jbosscache/pom.xml +++ b/cache-jbosscache/pom.xml @@ -92,14 +92,6 @@ - - org.apache.maven.plugins - maven-compiler-plugin - - 1.5 - 1.5 - - org.apache.maven.plugins maven-surefire-plugin diff --git a/core/src/main/java/org/hibernate/Hibernate.java b/core/src/main/java/org/hibernate/Hibernate.java index 7fea791475..a9fde91cf5 100644 --- a/core/src/main/java/org/hibernate/Hibernate.java +++ b/core/src/main/java/org/hibernate/Hibernate.java @@ -23,12 +23,6 @@ */ package org.hibernate; -import java.io.IOException; -import java.io.InputStream; -import java.io.Reader; -import java.io.ByteArrayOutputStream; -import java.sql.Blob; -import java.sql.Clob; import java.util.Iterator; import java.util.Properties; @@ -36,13 +30,10 @@ import org.hibernate.collection.PersistentCollection; import org.hibernate.engine.HibernateIterator; import org.hibernate.engine.SessionFactoryImplementor; import org.hibernate.engine.SessionImplementor; -import org.hibernate.engine.jdbc.NonContextualLobCreator; import org.hibernate.engine.jdbc.LobCreationContext; import org.hibernate.engine.jdbc.LobCreator; -import org.hibernate.engine.jdbc.StreamUtils; import org.hibernate.intercept.FieldInterceptionHelper; import org.hibernate.intercept.FieldInterceptor; -import org.hibernate.mapping.ManyToOne; import org.hibernate.proxy.HibernateProxy; import org.hibernate.proxy.LazyInitializer; import org.hibernate.type.AnyType; @@ -54,6 +45,8 @@ import org.hibernate.type.BooleanType; import org.hibernate.type.ByteType; import org.hibernate.type.CalendarDateType; import org.hibernate.type.CalendarType; +import org.hibernate.type.CharArrayType; +import org.hibernate.type.CharacterArrayType; import org.hibernate.type.CharacterType; import org.hibernate.type.ClassType; import org.hibernate.type.ClobType; @@ -61,10 +54,13 @@ import org.hibernate.type.CurrencyType; import org.hibernate.type.DateType; import org.hibernate.type.DoubleType; import org.hibernate.type.FloatType; +import org.hibernate.type.ImageType; import org.hibernate.type.IntegerType; import org.hibernate.type.LocaleType; import org.hibernate.type.LongType; import org.hibernate.type.ManyToOneType; +import org.hibernate.type.MaterializedBlobType; +import org.hibernate.type.MaterializedClobType; import org.hibernate.type.ObjectType; import org.hibernate.type.SerializableType; import org.hibernate.type.ShortType; @@ -76,13 +72,8 @@ import org.hibernate.type.TimestampType; import org.hibernate.type.TrueFalseType; import org.hibernate.type.Type; import org.hibernate.type.TypeFactory; -import org.hibernate.type.YesNoType; -import org.hibernate.type.CharArrayType; import org.hibernate.type.WrapperBinaryType; -import org.hibernate.type.CharacterArrayType; -import org.hibernate.type.MaterializedBlobType; -import org.hibernate.type.ImageType; -import org.hibernate.type.MaterializedClobType; +import org.hibernate.type.YesNoType; import org.hibernate.usertype.CompositeUserType; /** @@ -434,31 +425,6 @@ public final class Hibernate { } } - /** - * Create a new {@link Blob}. The returned object will be initially immutable. - * - * @param bytes a byte array - * @return the Blob - * @deprecated Use {@link LobHelper#createBlob(byte[])} instead. - */ - public static Blob createBlob(byte[] bytes) { - return NonContextualLobCreator.INSTANCE.wrap( - NonContextualLobCreator.INSTANCE.createBlob( bytes ) - ); - } - - /** - * Create a new {@link Blob}. - * - * @param bytes a byte array - * @param session The session in which the {@link Blob} will be used. - * @return the Blob - * @deprecated Use {@link LobHelper#createBlob(byte[])} instead. - */ - public static Blob createBlob(byte[] bytes, Session session) { - return getLobCreator( session ).createBlob( bytes ); - } - public static LobCreator getLobCreator(Session session) { return getLobCreator( ( SessionImplementor ) session ); } @@ -470,140 +436,6 @@ public final class Hibernate { .getLobCreator( ( LobCreationContext ) session ); } - /** - * Create a new {@link Blob}. The returned object will be initially immutable. - * - * @param stream a binary stream - * @param length the number of bytes in the stream - * @return the Blob - * @deprecated Use {@link LobHelper#createBlob(InputStream, long)} instead. - */ - @Deprecated - public static Blob createBlob(InputStream stream, int length) { - return NonContextualLobCreator.INSTANCE.wrap( - NonContextualLobCreator.INSTANCE.createBlob( stream, length ) - ); - } - - /** - * Create a new {@link Blob}. The returned object will be initially immutable. - * - * @param stream a binary stream - * @param length the number of bytes in the stream - * @return the Blob - * @deprecated Use {@link LobHelper#createBlob(InputStream, long)} instead. - */ - @Deprecated - public static Blob createBlob(InputStream stream, long length) { - return NonContextualLobCreator.INSTANCE.wrap( - NonContextualLobCreator.INSTANCE.createBlob( stream, length ) - ); - } - - /** - * Create a new {@link Blob}. - * - * @param stream a binary stream - * @param length the number of bytes in the stream - * @param session The session in which the {@link Blob} will be used. - * @return the Blob - * @deprecated Use {@link LobHelper#createBlob(InputStream, long)} instead. - */ - @Deprecated - public static Blob createBlob(InputStream stream, long length, Session session) { - return getLobCreator( session ).createBlob( stream, length ); - } - - /** - * Create a new {@link Blob}. The returned object will be initially immutable. - *

- * NOTE: this method will read the entire contents of the incoming stream in order to properly - * handle the {@link Blob#length()} method. If you do not want the stream read, use the - * {@link #createBlob(InputStream,long)} version instead. - * - * @param stream a binary stream - * @return the Blob - * @throws IOException Indicates an I/O problem accessing the stream - * @deprecated With no direct replacement. Use {@link #createBlob(InputStream,long)} instead, passing in the length - */ - @Deprecated - public static Blob createBlob(InputStream stream) throws IOException { - ByteArrayOutputStream buffer = new ByteArrayOutputStream( stream.available() ); - StreamUtils.copy( stream, buffer ); - return createBlob( buffer.toByteArray() ); - } - - /** - * Create a new {@link Clob}. The returned object will be initially immutable. - * - * @param string The string data - * @return The created {@link Clob} - * @deprecated Use {@link LobHelper#createClob(String)} instead - */ - @Deprecated - public static Clob createClob(String string) { - return NonContextualLobCreator.INSTANCE.wrap( - NonContextualLobCreator.INSTANCE.createClob( string ) - ); - } - - /** - * Create a new {@link Clob}. - * - * @param string The string data - * @param session The session in which the {@link Clob} will be used. - * @return The created {@link Clob} - * @deprecated Use {@link LobHelper#createClob(String)} instead - */ - @Deprecated - public static Clob createClob(String string, Session session) { - return getLobCreator( session ).createClob( string ); - } - - /** - * Create a new {@link Clob}. The returned object will be initially immutable. - * - * @param reader a character stream - * @param length the number of characters in the stream - * @return The created {@link Clob} - * @deprecated Use {@link LobHelper#createClob(Reader, long)} instead - */ - @Deprecated - public static Clob createClob(Reader reader, int length) { - return NonContextualLobCreator.INSTANCE.wrap( - NonContextualLobCreator.INSTANCE.createClob( reader, length ) - ); - } - - /** - * Create a new {@link Clob}. The returned object will be initially immutable. - * - * @param reader a character stream - * @param length the number of characters in the stream - * @return The created {@link Clob} - * @deprecated Use {@link LobHelper#createClob(Reader, long)} instead - */ - @Deprecated - public static Clob createClob(Reader reader, long length) { - return NonContextualLobCreator.INSTANCE.wrap( - NonContextualLobCreator.INSTANCE.createClob( reader, length ) - ); - } - - /** - * Create a new {@link Clob}. - * - * @param reader a character stream - * @param length the number of characters in the stream - * @param session The session in which the {@link Clob} will be used. - * @return The created {@link Clob} - * @deprecated Use {@link LobHelper#createClob(Reader, long)} instead - */ - @Deprecated - public static Clob createClob(Reader reader, long length, Session session) { - return getLobCreator( session ).createClob( reader, length ); - } - /** * Close an Iterator created by iterate() immediately, * instead of waiting until the session is closed or disconnected. diff --git a/core/src/main/java/org/hibernate/cfg/SettingsFactory.java b/core/src/main/java/org/hibernate/cfg/SettingsFactory.java index cb620795e7..bfd2609b04 100644 --- a/core/src/main/java/org/hibernate/cfg/SettingsFactory.java +++ b/core/src/main/java/org/hibernate/cfg/SettingsFactory.java @@ -24,7 +24,6 @@ package org.hibernate.cfg; import java.io.Serializable; -import java.lang.reflect.Constructor; import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.ResultSet; @@ -39,7 +38,6 @@ import org.hibernate.ConnectionReleaseMode; import org.hibernate.EntityMode; import org.hibernate.HibernateException; import org.hibernate.engine.jdbc.JdbcSupport; -import org.hibernate.engine.jdbc.JdbcSupportLoader; import org.hibernate.bytecode.BytecodeProvider; import org.hibernate.cache.QueryCacheFactory; import org.hibernate.cache.RegionFactory; @@ -99,7 +97,6 @@ public class SettingsFactory implements Serializable { boolean metaReportsDDLCausesTxnCommit = false; boolean metaReportsDDLInTxnSupported = true; Dialect dialect = null; - JdbcSupport jdbcSupport = null; // 'hibernate.temp.use_jdbc_metadata_defaults' is a temporary magic value. // The need for it is intended to be alleviated with future development, thus it is @@ -128,7 +125,6 @@ public class SettingsFactory implements Serializable { ); dialect = DialectFactory.buildDialect( props, conn ); - jdbcSupport = JdbcSupportLoader.loadJdbcSupport( conn ); metaSupportsScrollable = meta.supportsResultSetType( ResultSet.TYPE_SCROLL_INSENSITIVE ); metaSupportsBatchUpdates = meta.supportsBatchUpdates(); @@ -159,10 +155,7 @@ public class SettingsFactory implements Serializable { settings.setDataDefinitionImplicitCommit( metaReportsDDLCausesTxnCommit ); settings.setDataDefinitionInTransactionSupported( metaReportsDDLInTxnSupported ); settings.setDialect( dialect ); - if ( jdbcSupport == null ) { - jdbcSupport = JdbcSupportLoader.loadJdbcSupport( null ); - } - settings.setJdbcSupport( jdbcSupport ); + settings.setJdbcSupport( new JdbcSupport() ); //use dialect default properties final Properties properties = new Properties(); diff --git a/core/src/main/java/org/hibernate/engine/jdbc/AbstractLobCreator.java b/core/src/main/java/org/hibernate/engine/jdbc/AbstractLobCreator.java index 6f76e4a0ba..e8f2a7091d 100644 --- a/core/src/main/java/org/hibernate/engine/jdbc/AbstractLobCreator.java +++ b/core/src/main/java/org/hibernate/engine/jdbc/AbstractLobCreator.java @@ -1,10 +1,10 @@ /* * Hibernate, Relational Persistence for Idiomatic Java * - * Copyright (c) 2009 by Red Hat Inc and/or its affiliates or by - * third-party contributors as indicated by either @author tags or express - * copyright attribution statements applied by the authors. All - * third-party contributions are distributed under license by Red Hat Inc. + * Copyright (c) 2010, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU diff --git a/core/src/main/java/org/hibernate/engine/jdbc/ContextualLobCreator.java b/core/src/main/java/org/hibernate/engine/jdbc/ContextualLobCreator.java index 0573cb8e2c..9bc261aac5 100644 --- a/core/src/main/java/org/hibernate/engine/jdbc/ContextualLobCreator.java +++ b/core/src/main/java/org/hibernate/engine/jdbc/ContextualLobCreator.java @@ -24,6 +24,7 @@ package org.hibernate.engine.jdbc; import java.sql.Blob; +import java.sql.NClob; import java.sql.SQLException; import java.sql.Clob; import java.sql.Connection; @@ -32,8 +33,6 @@ import java.io.OutputStream; import java.io.IOException; import java.io.Reader; import java.io.Writer; -import java.lang.reflect.Method; -import java.lang.reflect.InvocationTargetException; import org.hibernate.HibernateException; import org.hibernate.JDBCException; @@ -58,7 +57,7 @@ public class ContextualLobCreator extends AbstractLobCreator implements LobCreat * @return The created BLOB reference. */ public Blob createBlob() { - return ( Blob ) lobCreationContext.execute( CREATE_BLOB_CALLBACK ); + return lobCreationContext.execute( CREATE_BLOB_CALLBACK ); } /** @@ -102,7 +101,7 @@ public class ContextualLobCreator extends AbstractLobCreator implements LobCreat * @return The created CLOB reference. */ public Clob createClob() { - return ( Clob ) lobCreationContext.execute( CREATE_CLOB_CALLBACK ); + return lobCreationContext.execute( CREATE_CLOB_CALLBACK ); } /** @@ -144,18 +143,18 @@ public class ContextualLobCreator extends AbstractLobCreator implements LobCreat * * @return The created NCLOB reference. */ - public Clob createNClob() { - return ( Clob ) lobCreationContext.execute( CREATE_NCLOB_CALLBACK ); + public NClob createNClob() { + return lobCreationContext.execute( CREATE_NCLOB_CALLBACK ); } /** * {@inheritDoc} */ - public Clob createNClob(String string) { + public NClob createNClob(String string) { try { - Clob clob = createNClob(); - clob.setString( 1, string ); - return clob; + NClob nclob = createNClob(); + nclob.setString( 1, string ); + return nclob; } catch ( SQLException e ) { throw new JDBCException( "Unable to set NCLOB string after creation", e ); @@ -165,14 +164,14 @@ public class ContextualLobCreator extends AbstractLobCreator implements LobCreat /** * {@inheritDoc} */ - public Clob createNClob(Reader reader, long length) { + public NClob createNClob(Reader reader, long length) { try { - Clob clob = createNClob(); - Writer writer = clob.setCharacterStream( 1 ); + NClob nclob = createNClob(); + Writer writer = nclob.setCharacterStream( 1 ); StreamUtils.copy( reader, writer ); writer.flush(); writer.close(); - return clob; + return nclob; } catch ( SQLException e ) { throw new JDBCException( "Unable to prepare NCLOB stream for writing", e ); @@ -182,57 +181,21 @@ public class ContextualLobCreator extends AbstractLobCreator implements LobCreat } } - - private static final Class[] CREATION_METHOD_SIG = new Class[0]; - private static final Object[] CREATION_METHOD_ARGS = new Object[0]; - - private static final LobCreationContext.Callback CREATE_BLOB_CALLBACK; - private static final LobCreationContext.Callback CREATE_CLOB_CALLBACK; - private static final LobCreationContext.Callback CREATE_NCLOB_CALLBACK; - - static { - CREATE_BLOB_CALLBACK = new CallbackImpl( getConnectionlobCreationMethod( "createBlob" ) ); - CREATE_CLOB_CALLBACK = new CallbackImpl( getConnectionlobCreationMethod( "createClob" ) ); - CREATE_NCLOB_CALLBACK = new CallbackImpl( getConnectionlobCreationMethod( "createNClob" ) ); - } - - private static class CallbackImpl implements LobCreationContext.Callback { - private final Method creationMethod; - - private CallbackImpl(Method creationMethod) { - this.creationMethod = creationMethod; + public static final LobCreationContext.Callback CREATE_BLOB_CALLBACK = new LobCreationContext.Callback() { + public Blob executeOnConnection(Connection connection) throws SQLException { + return connection.createBlob(); } + }; - public Object executeOnConnection(Connection connection) throws SQLException { - try { - return creationMethod.invoke( connection, CREATION_METHOD_ARGS ); - } - catch ( InvocationTargetException e ) { - if ( e.getTargetException() instanceof SQLException ) { - throw ( SQLException ) e.getTargetException(); - } - else { - throw new HibernateException( "Exception invoking " + creationMethod.getName(), e.getTargetException() ); - } - } - catch ( AbstractMethodError e ) { - // this again is a big big error... - throw new IllegalStateException( "Useable implementation of " + creationMethod.getName() + " not found." ); - } - catch ( IllegalAccessException e ) { - // this again is a big big error... - throw new IllegalStateException( "Illegal access attempt on JDBC method " + creationMethod.getName() ); - } + public static final LobCreationContext.Callback CREATE_CLOB_CALLBACK = new LobCreationContext.Callback() { + public Clob executeOnConnection(Connection connection) throws SQLException { + return connection.createClob(); } - } + }; - private static Method getConnectionlobCreationMethod(String methodName) { - try { - return Connection.class.getMethod( methodName, CREATION_METHOD_SIG ); + public static final LobCreationContext.Callback CREATE_NCLOB_CALLBACK = new LobCreationContext.Callback() { + public NClob executeOnConnection(Connection connection) throws SQLException { + return connection.createNClob(); } - catch ( NoSuchMethodException e ) { - // this is a big big error if we get here and these methods are not part of the Connection interface... - throw new IllegalStateException( "JDBC driver did not implement " + methodName); - } - } + }; } diff --git a/core/src/main/java/org/hibernate/engine/jdbc/JdbcSupport.java b/core/src/main/java/org/hibernate/engine/jdbc/JdbcSupport.java index 0f5d30ca7b..2527d7b38a 100644 --- a/core/src/main/java/org/hibernate/engine/jdbc/JdbcSupport.java +++ b/core/src/main/java/org/hibernate/engine/jdbc/JdbcSupport.java @@ -26,40 +26,20 @@ package org.hibernate.engine.jdbc; import java.sql.ResultSet; /** - * Isolates Hibernate interactions with JDBC in terms of variations between JDBC 3 (JDK 1.4 and 1.5) - * and JDBC 4 (JDK 1.6). + * Central place for locating JDBC support elements. * * @author Steve Ebersole */ -public interface JdbcSupport { - /** - * Creates an instance of a {@link LobCreator} that does not use the underlying JDBC {@link java.sql.Connection} - * to create LOBs. - *

- * This method is here solely to support the older, now-deprecated method of creating LOBs via - * the various {@link org.hibernate.Hibernate#createBlob} and {@link org.hibernate.Hibernate#createClob} methods on - * {@link org.hibernate.Hibernate}. - * - * @return The LOB creator. - * @deprecated Use {@link #getLobCreator(LobCreationContext)} instead. - */ - public LobCreator getLobCreator(); +public class JdbcSupport { + public LobCreator getLobCreator() { + return NonContextualLobCreator.INSTANCE; + } - /** - * Create an instance of a {@link LobCreator} appropriate for the current environment, mainly meant to account for - * variance between JDBC 4 (<= JDK 1.6) and JDBC3 (>= JDK 1.5). - * - * @param lobCreationContext The context in which the LOB is being created - * @return The LOB creator. - */ - public LobCreator getLobCreator(LobCreationContext lobCreationContext); + public LobCreator getLobCreator(LobCreationContext lobCreationContext) { + return new ContextualLobCreator( lobCreationContext ); + } - /** - * Wrap the given {@link ResultSet} in one that caches the column-name -> column-index resolution. - * - * @param resultSet The {@link ResultSet} to wrap. - * @param columnNameCache The resolution cache. - * @return The wrapper. - */ - public ResultSet wrap(ResultSet resultSet, ColumnNameCache columnNameCache); + public ResultSet wrap(ResultSet resultSet, ColumnNameCache columnNameCache) { + return ResultSetWrapperProxy.generateProxy( resultSet, columnNameCache ); + } } diff --git a/core/src/main/java/org/hibernate/engine/jdbc/JdbcSupportImpl.java b/core/src/main/java/org/hibernate/engine/jdbc/JdbcSupportImpl.java deleted file mode 100644 index 75567debfb..0000000000 --- a/core/src/main/java/org/hibernate/engine/jdbc/JdbcSupportImpl.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * Copyright (c) 2009 by Red Hat Inc and/or its affiliates or by - * third-party contributors as indicated by either @author tags or express - * copyright attribution statements applied by the authors. All - * third-party contributions are distributed under license by Red Hat Inc. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License, as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package org.hibernate.engine.jdbc; - -import java.sql.ResultSet; - -/** - * TODO : javadoc - * - * @author Steve Ebersole - */ -public class JdbcSupportImpl implements JdbcSupport { - private final boolean useContextualLobCreation; - - public JdbcSupportImpl(boolean useContextualLobCreation) { - this.useContextualLobCreation = useContextualLobCreation; - } - - /** - * {@inheritDoc} - */ - public LobCreator getLobCreator() { - return NonContextualLobCreator.INSTANCE; - } - - public LobCreator getLobCreator(LobCreationContext lobCreationContext) { - if ( useContextualLobCreation ) { - return new ContextualLobCreator( lobCreationContext ); - } - else { - return NonContextualLobCreator.INSTANCE; - } - } - - public ResultSet wrap(ResultSet resultSet, ColumnNameCache columnNameCache) { - return ResultSetWrapperProxy.generateProxy( resultSet, columnNameCache ); - } -} diff --git a/core/src/main/java/org/hibernate/engine/jdbc/JdbcSupportLoader.java b/core/src/main/java/org/hibernate/engine/jdbc/JdbcSupportLoader.java deleted file mode 100644 index 88f60af4ef..0000000000 --- a/core/src/main/java/org/hibernate/engine/jdbc/JdbcSupportLoader.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * Copyright (c) 2009 by Red Hat Inc and/or its affiliates or by - * third-party contributors as indicated by either @author tags or express - * copyright attribution statements applied by the authors. All - * third-party contributions are distributed under license by Red Hat Inc. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License, as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package org.hibernate.engine.jdbc; - -import java.sql.Connection; -import java.sql.SQLException; -import java.sql.DatabaseMetaData; -import java.lang.reflect.Method; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Builds {@link JdbcSupport} instances based on the capabilities of the environment. - * - * @author Steve Ebersole - */ -public class JdbcSupportLoader { - private static final Logger log = LoggerFactory.getLogger( JdbcSupportLoader.class ); - - /** - * The public factory method for obtaining the appropriate (according to given JDBC {@link java.sql.Connection}) - * {@link JdbcSupport}. - * - * @param jdbcConnection A JDBC {@link java.sql.Connection} which can be used to gauge the drivers level of support, - * specifically for creating LOB references. - * - * @return An appropriate {@link JdbcSupport} instance. - */ - public static JdbcSupport loadJdbcSupport(Connection jdbcConnection) { - return new JdbcSupportImpl( useContextualLobCreation( jdbcConnection ) ); - } - - private static final Class[] NO_ARG_SIG = new Class[0]; - private static final Object[] NO_ARGS = new Object[0]; - - /** - * Basically here we are simply checking whether we can call the {@link Connection} methods for - * LOB creation added in JDBC 4. We not only check whether the {@link Connection} declares these methods, - * but also whether the actual {@link Connection} instance implements them (i.e. can be called without simply - * throwing an exception). - * - * @param jdbcConnection The connection which can be used in level-of-support testing. - * - * @return True if the connection can be used to create LOBs; false otherwise. - */ - private static boolean useContextualLobCreation(Connection jdbcConnection) { - if ( jdbcConnection == null ) { - log.info( "Disabling contextual LOB creation as connection was null" ); - return false; - } - - try { - try { - DatabaseMetaData meta = jdbcConnection.getMetaData(); - // if the jdbc driver version is less than 4, it shouldn't have createClob - if ( meta.getJDBCMajorVersion() < 4 ) { - log.info( - "Disabling contextual LOB creation as JDBC driver reported JDBC version [" + - meta.getJDBCMajorVersion() + "] less than 4" - ); - return false; - } - } - catch ( SQLException ignore ) { - // ignore exception and continue - } - - Class connectionClass = Connection.class; - 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? - try { - Object clob = createClobMethod.invoke( jdbcConnection, NO_ARGS ); - try { - Method freeMethod = clob.getClass().getMethod( "free", NO_ARG_SIG ); - freeMethod.invoke( clob, NO_ARGS ); - } - catch ( Throwable ignore ) { - log.trace( "Unable to free CLOB created to test createClob() implementation : " + ignore ); - } - return true; - } - catch ( Throwable t ) { - log.info( "Disabling contextual LOB creation as createClob() method threw error : " + t ); - } - } - } - catch ( NoSuchMethodException ignore ) { - } - - return false; - } -} diff --git a/core/src/main/java/org/hibernate/engine/jdbc/LobCreationContext.java b/core/src/main/java/org/hibernate/engine/jdbc/LobCreationContext.java index bee2017fae..1d352e134e 100644 --- a/core/src/main/java/org/hibernate/engine/jdbc/LobCreationContext.java +++ b/core/src/main/java/org/hibernate/engine/jdbc/LobCreationContext.java @@ -27,8 +27,7 @@ import java.sql.Connection; import java.sql.SQLException; /** - * Provides callback access into the context in which the LOB is to be created. Mainly this is useful - * for gaining access to the JDBC {@link Connection} for use in JDBC 4 environments. + * Provides callback access into the context in which the LOB is to be created. * * @author Steve Ebersole */ @@ -36,7 +35,7 @@ public interface LobCreationContext { /** * The callback contract for making use of the JDBC {@link Connection}. */ - public static interface Callback { + public static interface Callback { /** * Perform whatever actions are necessary using the provided JDBC {@link Connection}. * @@ -44,7 +43,7 @@ public interface LobCreationContext { * @return The created LOB. * @throws SQLException */ - public Object executeOnConnection(Connection connection) throws SQLException; + public T executeOnConnection(Connection connection) throws SQLException; } /** @@ -53,5 +52,5 @@ public interface LobCreationContext { * @param callback The callback to execute . * @return The LOB created by the callback. */ - public Object execute(Callback callback); + public T execute(Callback callback); } diff --git a/core/src/main/java/org/hibernate/engine/jdbc/LobCreator.java b/core/src/main/java/org/hibernate/engine/jdbc/LobCreator.java index fd37622b49..0250cdcd83 100644 --- a/core/src/main/java/org/hibernate/engine/jdbc/LobCreator.java +++ b/core/src/main/java/org/hibernate/engine/jdbc/LobCreator.java @@ -27,10 +27,13 @@ import java.sql.Blob; import java.sql.Clob; import java.io.InputStream; import java.io.Reader; +import java.sql.NClob; /** * Contract for creating various LOB references. * + * @todo LobCreator really needs to be an api since we expose it to users. + * * @author Steve Ebersole * @author Gail Badner */ @@ -92,7 +95,7 @@ public interface LobCreator { * @return The created NCLOB, castable as {@link Clob} as well as {@link NClobImplementer}. In JDK 1.6 * environments, also castable to java.sql.NClob */ - public Clob createNClob(String string); + public NClob createNClob(String string); /** * Create a NCLOB reference encapsulating the given character data. @@ -102,5 +105,5 @@ public interface LobCreator { * @return The created NCLOB, castable as {@link Clob} as well as {@link NClobImplementer}. In JDK 1.6 * environments, also castable to java.sql.NClob */ - public Clob createNClob(Reader reader, long length); + public NClob createNClob(Reader reader, long length); } diff --git a/core/src/main/java/org/hibernate/engine/jdbc/NClobProxy.java b/core/src/main/java/org/hibernate/engine/jdbc/NClobProxy.java index e5a1739a14..6ae78d1b31 100644 --- a/core/src/main/java/org/hibernate/engine/jdbc/NClobProxy.java +++ b/core/src/main/java/org/hibernate/engine/jdbc/NClobProxy.java @@ -26,6 +26,7 @@ package org.hibernate.engine.jdbc; import java.sql.Clob; import java.io.Reader; import java.lang.reflect.Proxy; +import java.sql.NClob; /** * Manages aspects of proxying java.sql.NClobs for non-contextual creation, including proxy creation and @@ -37,18 +38,7 @@ import java.lang.reflect.Proxy; * @author Steve Ebersole */ public class NClobProxy extends ClobProxy { - public static final Class[] PROXY_INTERFACES = new Class[] { determineNClobInterface(), NClobImplementer.class }; - - private static Class determineNClobInterface() { - // java.sql.NClob is a simple marker interface extending java.sql.Clob. So if java.sql.NClob is not available - // on the classloader, just use java.sql.Clob - try { - return getProxyClassLoader().loadClass( "java.sql.NClob" ); - } - catch ( ClassNotFoundException e ) { - return Clob.class; - } - } + public static final Class[] PROXY_INTERFACES = new Class[] { NClob.class, NClobImplementer.class }; protected NClobProxy(String string) { super( string ); @@ -65,8 +55,8 @@ public class NClobProxy extends ClobProxy { * * @return The generated proxy. */ - public static Clob generateProxy(String string) { - return ( Clob ) Proxy.newProxyInstance( + public static NClob generateProxy(String string) { + return ( NClob ) Proxy.newProxyInstance( getProxyClassLoader(), PROXY_INTERFACES, new ClobProxy( string ) @@ -81,8 +71,8 @@ public class NClobProxy extends ClobProxy { * * @return The generated proxy. */ - public static Clob generateProxy(Reader reader, long length) { - return ( Clob ) Proxy.newProxyInstance( + public static NClob generateProxy(Reader reader, long length) { + return ( NClob ) Proxy.newProxyInstance( getProxyClassLoader(), PROXY_INTERFACES, new ClobProxy( reader, length ) diff --git a/core/src/main/java/org/hibernate/engine/jdbc/NonContextualLobCreator.java b/core/src/main/java/org/hibernate/engine/jdbc/NonContextualLobCreator.java index ee7d938501..c5ec8b966a 100644 --- a/core/src/main/java/org/hibernate/engine/jdbc/NonContextualLobCreator.java +++ b/core/src/main/java/org/hibernate/engine/jdbc/NonContextualLobCreator.java @@ -1,10 +1,10 @@ /* * Hibernate, Relational Persistence for Idiomatic Java * - * Copyright (c) 2009 by Red Hat Inc and/or its affiliates or by - * third-party contributors as indicated by either @author tags or express - * copyright attribution statements applied by the authors. All - * third-party contributions are distributed under license by Red Hat Inc. + * Copyright (c) 2010, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU @@ -27,6 +27,7 @@ import java.sql.Blob; import java.sql.Clob; import java.io.InputStream; import java.io.Reader; +import java.sql.NClob; /** * {@link LobCreator} implementation using non-contextual or local creation, meaning that we generate the LOB @@ -72,14 +73,14 @@ public class NonContextualLobCreator extends AbstractLobCreator implements LobCr /** * {@inheritDoc} */ - public Clob createNClob(String string) { + public NClob createNClob(String string) { return NClobProxy.generateProxy( string ); } /** * {@inheritDoc} */ - public Clob createNClob(Reader reader, long length) { + public NClob createNClob(Reader reader, long length) { return NClobProxy.generateProxy( reader, length ); } } diff --git a/jdbc4-testing/src/test/java/org/hibernate/engine/jdbc/jdbc4/JdbcSupportTest.java b/core/src/test/java/org/hibernate/jdbc/JdbcSupportTest.java similarity index 81% rename from jdbc4-testing/src/test/java/org/hibernate/engine/jdbc/jdbc4/JdbcSupportTest.java rename to core/src/test/java/org/hibernate/jdbc/JdbcSupportTest.java index 8659dee99e..134469fdca 100644 --- a/jdbc4-testing/src/test/java/org/hibernate/engine/jdbc/jdbc4/JdbcSupportTest.java +++ b/core/src/test/java/org/hibernate/jdbc/JdbcSupportTest.java @@ -21,7 +21,7 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.engine.jdbc.jdbc4; +package org.hibernate.jdbc; import java.sql.*; import java.lang.reflect.InvocationHandler; @@ -34,9 +34,9 @@ import java.io.Writer; import junit.framework.TestCase; +import org.hibernate.engine.jdbc.JdbcSupport; import org.hibernate.engine.jdbc.LobCreationContext; import org.hibernate.engine.jdbc.LobCreator; -import org.hibernate.engine.jdbc.JdbcSupportLoader; import org.hibernate.engine.jdbc.ContextualLobCreator; import org.hibernate.engine.jdbc.BlobImplementer; import org.hibernate.engine.jdbc.ClobImplementer; @@ -51,6 +51,8 @@ import org.hibernate.engine.jdbc.WrappedClob; * @author Steve Ebersole */ public class JdbcSupportTest extends TestCase { + private static JdbcSupport jdbcSupport = new JdbcSupport(); + public void testConnectedLobCreator() throws SQLException { final Connection connection = createConnectionProxy( 4, @@ -79,7 +81,7 @@ public class JdbcSupportTest extends TestCase { } }; - LobCreator lobCreator = JdbcSupportLoader.loadJdbcSupport( connection ).getLobCreator( lobCreationContext ); + LobCreator lobCreator = jdbcSupport.getLobCreator( lobCreationContext ); assertTrue( lobCreator instanceof ContextualLobCreator ); Blob blob = lobCreator.createBlob( new byte[] {} ); @@ -103,61 +105,8 @@ public class JdbcSupportTest extends TestCase { connection.close(); } - public void testConnectedLobCreatorWithUnSupportedCreations() throws SQLException { - final Connection connection = createConnectionProxy( - 3, - new JdbcLobBuilder() { - public Blob createBlob() { - throw new UnsupportedOperationException(); - } - - public Clob createClob() { - throw new UnsupportedOperationException(); - } - - public NClob createNClob() { - throw new UnsupportedOperationException(); - } - } - ); - final LobCreationContext lobCreationContext = new LobCreationContext() { - public Object execute(Callback callback) { - try { - return callback.executeOnConnection( connection ); - } - catch ( SQLException e ) { - throw new RuntimeException( "Unexpected SQLException", e ); - } - } - }; - - LobCreator lobCreator = JdbcSupportLoader.loadJdbcSupport( connection ).getLobCreator( lobCreationContext ); - assertTrue( lobCreator instanceof NonContextualLobCreator ); - - Blob blob = lobCreator.createBlob( new byte[] {} ); - assertTrue( blob instanceof BlobImplementer ); - blob = lobCreator.wrap( blob ); - assertTrue( blob instanceof WrappedBlob ); - - Clob clob = lobCreator.createClob( "Hi" ); - assertTrue( clob instanceof ClobImplementer ); - clob = lobCreator.wrap( clob ); - assertTrue( clob instanceof WrappedClob ); - - Clob nclob = lobCreator.createNClob( "Hi" ); - assertTrue( nclob instanceof ClobImplementer ); - assertTrue( nclob instanceof NClobImplementer ); - nclob = lobCreator.wrap( nclob ); - assertTrue( nclob instanceof WrappedClob ); - - blob.free(); - clob.free(); - nclob.free(); - connection.close(); - } - public void testLegacyLobCreator() throws SQLException { - LobCreator lobCreator = JdbcSupportLoader.loadJdbcSupport( null ).getLobCreator(); + LobCreator lobCreator = jdbcSupport.getLobCreator(); Blob blob = lobCreator.createBlob( new byte[] {} ); assertTrue( blob instanceof BlobImplementer ); diff --git a/entitymanager/build.xml b/entitymanager/build.xml index c8acf9a860..1209061f59 100644 --- a/entitymanager/build.xml +++ b/entitymanager/build.xml @@ -12,7 +12,6 @@ destdir="${target.dir}" failonerror="false" fork="true" - executable="${jdk16_home}/bin/javac" target="1.5" classpath="${classpath}"> diff --git a/entitymanager/pom.xml b/entitymanager/pom.xml index 3341100370..063ac30d59 100644 --- a/entitymanager/pom.xml +++ b/entitymanager/pom.xml @@ -122,7 +122,6 @@ - @@ -143,14 +142,6 @@ - - org.apache.maven.plugins - maven-compiler-plugin - - 1.5 - 1.5 - - org.apache.maven.plugins maven-surefire-plugin diff --git a/envers/pom.xml b/envers/pom.xml index 931e38b802..a76494a260 100644 --- a/envers/pom.xml +++ b/envers/pom.xml @@ -19,15 +19,6 @@ - - org.apache.maven.plugins - maven-compiler-plugin - - 1.5 - 1.5 - - - org.apache.maven.plugins maven-surefire-plugin diff --git a/jdbc3-testing/pom.xml b/jdbc3-testing/pom.xml deleted file mode 100644 index a8042aa74f..0000000000 --- a/jdbc3-testing/pom.xml +++ /dev/null @@ -1,54 +0,0 @@ - - - - 4.0.0 - - - org.hibernate - hibernate-parent - 3.6.0-SNAPSHOT - ../parent/pom.xml - - - hibernate-jdbc3-testing - jar - - Hibernate JDBC3-JdbcSupport Testing - Test support of JDBC3 through JdbcSupport - - - - true - - - - - ${project.groupId} - hibernate-core - ${project.version} - - - - diff --git a/jdbc3-testing/src/test/java/org/hibernate/engine/jdbc/jdbc3/JdbcSupportTest.java b/jdbc3-testing/src/test/java/org/hibernate/engine/jdbc/jdbc3/JdbcSupportTest.java deleted file mode 100644 index 58f9554f1f..0000000000 --- a/jdbc3-testing/src/test/java/org/hibernate/engine/jdbc/jdbc3/JdbcSupportTest.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * Copyright (c) 2009 by Red Hat Inc and/or its affiliates or by - * third-party contributors as indicated by either @author tags or express - * copyright attribution statements applied by the authors. All - * third-party contributions are distributed under license by Red Hat Inc. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License, as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package org.hibernate.engine.jdbc.jdbc3; - -import java.sql.SQLException; -import java.sql.Blob; -import java.sql.Clob; - -import junit.framework.TestCase; - -import org.hibernate.engine.jdbc.LobCreationContext; -import org.hibernate.engine.jdbc.LobCreator; -import org.hibernate.engine.jdbc.JdbcSupportLoader; -import org.hibernate.engine.jdbc.BlobImplementer; -import org.hibernate.engine.jdbc.WrappedBlob; -import org.hibernate.engine.jdbc.WrappedClob; -import org.hibernate.engine.jdbc.ClobImplementer; -import org.hibernate.engine.jdbc.NClobImplementer; - - -/** - * TODO : javadoc - * - * @author Steve Ebersole - */ -public class JdbcSupportTest extends TestCase { - private static class LobCreationContextImpl implements LobCreationContext { - public Object execute(Callback callback) { - fail( "Unexpected call to getConnection" ); - return null; - } - } - - private LobCreationContextImpl lobCreationContext = new LobCreationContextImpl(); - - public void testLobCreator() throws ClassNotFoundException, SQLException { - LobCreator lobCreator = JdbcSupportLoader.loadJdbcSupport( null ).getLobCreator( lobCreationContext ); - - Blob blob = lobCreator.createBlob( new byte[] {} ); - assertTrue( blob instanceof BlobImplementer ); - blob = lobCreator.wrap( blob ); - assertTrue( blob instanceof WrappedBlob ); - - Clob clob = lobCreator.createClob( "Hi" ); - assertTrue( clob instanceof ClobImplementer ); - clob = lobCreator.wrap( clob ); - assertTrue( clob instanceof WrappedClob ); - - Clob nclob = lobCreator.createNClob( "Hi" ); - assertTrue( nclob instanceof NClobImplementer ); - nclob = lobCreator.wrap( nclob ); - assertTrue( nclob instanceof WrappedClob ); - } - - public void testLobAccess() throws SQLException { - LobCreator lobCreator = JdbcSupportLoader.loadJdbcSupport( null ).getLobCreator( lobCreationContext ); - - Blob blob = lobCreator.createBlob( "Hi".getBytes() ); - assertEquals( 2, blob.length() ); - assertEquals( 2, blob.getBytes( 1, 5 ).length ); - blob.getBinaryStream(); - - Clob clob = lobCreator.createClob( "Hi" ); - assertEquals( 2, clob.length() ); - assertEquals( 2, clob.getSubString( 1, 5 ).length() ); - clob.getCharacterStream(); - clob.getAsciiStream(); - } -} diff --git a/jdbc3-testing/src/test/resources/log4j.properties b/jdbc3-testing/src/test/resources/log4j.properties deleted file mode 100644 index f7a06c9807..0000000000 --- a/jdbc3-testing/src/test/resources/log4j.properties +++ /dev/null @@ -1,30 +0,0 @@ -# -# Hibernate, Relational Persistence for Idiomatic Java -# -# Copyright (c) 2009 by Red Hat Inc and/or its affiliates or by -# third-party contributors as indicated by either @author tags or express -# copyright attribution statements applied by the authors. All -# third-party contributions are distributed under license by Red Hat Inc. -# -# This copyrighted material is made available to anyone wishing to use, modify, -# copy, or redistribute it subject to the terms and conditions of the GNU -# Lesser General Public License, as published by the Free Software Foundation. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License -# for more details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with this distribution; if not, write to: -# Free Software Foundation, Inc. -# 51 Franklin Street, Fifth Floor -# Boston, MA 02110-1301 USA -# -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.Target=System.out -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n - - -log4j.rootLogger=info, stdout diff --git a/jdbc4-testing/pom.xml b/jdbc4-testing/pom.xml deleted file mode 100644 index 8a9ff77fcc..0000000000 --- a/jdbc4-testing/pom.xml +++ /dev/null @@ -1,76 +0,0 @@ - - - - 4.0.0 - - - org.hibernate - hibernate-parent - 3.6.0-SNAPSHOT - ../parent/pom.xml - - - hibernate-jdbc4-testing - Hibernate JDBC4-JdbcSupport Testing - Test support of JDBC4 through JdbcSupport - - - - true - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - 1.6 - 1.6 - 1.6 - ${jdk16_home}/bin/javac - true - true - - - - org.apache.maven.plugins - maven-surefire-plugin - - ${jdk16_home}/bin/java - - - - - - - - ${project.groupId} - hibernate-core - ${project.version} - - - - diff --git a/jdbc4-testing/src/test/resources/log4j.properties b/jdbc4-testing/src/test/resources/log4j.properties deleted file mode 100644 index f1b0a55562..0000000000 --- a/jdbc4-testing/src/test/resources/log4j.properties +++ /dev/null @@ -1,7 +0,0 @@ -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.Target=System.out -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n - - -log4j.rootLogger=info, stdout diff --git a/parent/pom.xml b/parent/pom.xml index 2a2c134f57..92aa70756b 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -116,28 +116,6 @@ org.jboss.maven.plugins maven-jdocbook-style-plugin true - - - org.codehaus.groovy.maven - gmaven-plugin - 1.0 - - - deploy - - execute - - - - - - - org.apache.maven.plugins @@ -153,8 +131,8 @@ - - [1.5,) + + [1.6,) @@ -164,13 +142,12 @@ - org.apache.maven.plugins maven-compiler-plugin - 1.5 - 1.5 + 1.6 + 1.6 diff --git a/pom.xml b/pom.xml index c48550757e..ec0d17e6e6 100644 --- a/pom.xml +++ b/pom.xml @@ -27,14 +27,14 @@ core testing testsuite + entitymanager + envers cache-ehcache cache-jbosscache cache-oscache cache-swarmcache connection-c3p0 connection-proxool - envers - jdbc3-testing cache-infinispan