From a67b6028c11f5da2b1c7fc078f5a0483713dfb79 Mon Sep 17 00:00:00 2001 From: Scott Marlow Date: Fri, 1 Apr 2011 16:10:34 -0400 Subject: [PATCH 01/15] HHH-6073 Dialects shouldn't use TCCL (revised to leave DerbyDialect alone) --- .../dialect/DerbyTenFiveDialect.java | 65 +++++++++++++++++++ .../hibernate/dialect/DerbyTenSixDialect.java | 54 +++++++++++++++ .../internal/StandardDialectResolver.java | 12 ++++ 3 files changed, 131 insertions(+) create mode 100644 hibernate-core/src/main/java/org/hibernate/dialect/DerbyTenFiveDialect.java create mode 100644 hibernate-core/src/main/java/org/hibernate/dialect/DerbyTenSixDialect.java diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/DerbyTenFiveDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/DerbyTenFiveDialect.java new file mode 100644 index 0000000000..8e6dea3c73 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/dialect/DerbyTenFiveDialect.java @@ -0,0 +1,65 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * 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 + * 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.dialect; + +import org.hibernate.HibernateLogger; +import org.hibernate.dialect.function.AnsiTrimFunction; +import org.hibernate.dialect.function.DerbyConcatFunction; +import org.jboss.logging.Logger; + + +/** + * Hibernate Dialect for Cloudscape 10 - aka Derby. This implements both an + * override for the identity column generator as well as for the case statement + * issue documented at: + * http://www.jroller.com/comments/kenlars99/Weblog/cloudscape_soon_to_be_derby + * + * @author Simon Johnston + * @author Scott Marlow + */ +public class DerbyTenFiveDialect extends DerbyDialect { + + private static final HibernateLogger LOG = Logger.getMessageLogger(HibernateLogger.class, DerbyTenFiveDialect.class.getName()); + + public DerbyTenFiveDialect() { + super(); + registerFunction( "concat", new DerbyConcatFunction() ); + registerFunction( "trim", new AnsiTrimFunction() ); + } + + @Override + public boolean supportsSequences() { + return false; + } + + @Override + public boolean supportsLimit() { + return true; + } + + @Override + public boolean supportsLimitOffset() { + return true; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/DerbyTenSixDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/DerbyTenSixDialect.java new file mode 100644 index 0000000000..05d2ebe71a --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/dialect/DerbyTenSixDialect.java @@ -0,0 +1,54 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * 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 + * 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.dialect; + +import org.hibernate.HibernateLogger; +import org.jboss.logging.Logger; + +/** + * Hibernate Dialect for Cloudscape 10 - aka Derby. This implements both an + * override for the identity column generator as well as for the case statement + * issue documented at: + * http://www.jroller.com/comments/kenlars99/Weblog/cloudscape_soon_to_be_derby + * + * @author Simon Johnston + * @author Scott Marlow + */ +public class DerbyTenSixDialect extends DerbyTenFiveDialect { + + private static final HibernateLogger LOG = Logger.getMessageLogger(HibernateLogger.class, DerbyTenSixDialect.class.getName()); + + public DerbyTenSixDialect() { + super(); + } + + private boolean isTenPointFiveReleaseOrNewer() { + return true; + } + + @Override + public boolean supportsSequences() { + return true; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/service/jdbc/dialect/internal/StandardDialectResolver.java b/hibernate-core/src/main/java/org/hibernate/service/jdbc/dialect/internal/StandardDialectResolver.java index 03050f2b3a..6cdba008ba 100644 --- a/hibernate-core/src/main/java/org/hibernate/service/jdbc/dialect/internal/StandardDialectResolver.java +++ b/hibernate-core/src/main/java/org/hibernate/service/jdbc/dialect/internal/StandardDialectResolver.java @@ -27,6 +27,8 @@ import java.sql.SQLException; import org.hibernate.HibernateLogger; import org.hibernate.dialect.DB2Dialect; import org.hibernate.dialect.DerbyDialect; +import org.hibernate.dialect.DerbyTenFiveDialect; +import org.hibernate.dialect.DerbyTenSixDialect; import org.hibernate.dialect.Dialect; import org.hibernate.dialect.H2Dialect; import org.hibernate.dialect.HSQLDialect; @@ -78,6 +80,16 @@ public class StandardDialectResolver extends AbstractDialectResolver { } if ( "Apache Derby".equals( databaseName ) ) { + int driverVersionMajor = metaData.getDriverMajorVersion(); + int driverVersionMinor = metaData.getDriverMinorVersion(); + if ( driverVersionMajor > 10 || ( driverVersionMajor == 10 && driverVersionMinor >= 5 ) ) { + if ( driverVersionMinor >= 6 ) { + return new DerbyTenSixDialect(); + } + else { + return new DerbyTenFiveDialect(); + } + } return new DerbyDialect(); } From 5e8e49d3ae8ae9d2a6ab6849f9c44ce013b87bd3 Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Tue, 5 Apr 2011 10:26:58 -0500 Subject: [PATCH 02/15] HHH-6073 --- .../main/java/org/hibernate/HibernateLogger.java | 4 ++++ .../java/org/hibernate/dialect/DerbyDialect.java | 4 ++++ .../hibernate/dialect/DerbyTenFiveDialect.java | 5 ----- .../hibernate/dialect/DerbyTenSixDialect.java | 12 +----------- .../internal/StandardDialectResolver.java | 16 ++++++++-------- 5 files changed, 17 insertions(+), 24 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/HibernateLogger.java b/hibernate-core/src/main/java/org/hibernate/HibernateLogger.java index ca1720eb0e..c8bda81379 100644 --- a/hibernate-core/src/main/java/org/hibernate/HibernateLogger.java +++ b/hibernate-core/src/main/java/org/hibernate/HibernateLogger.java @@ -1858,4 +1858,8 @@ public interface HibernateLogger extends BasicLogger { @LogMessage( level = WARN ) @Message( value = "Setting entity-identifier value binding where one already existed : %s.", id = 429 ) void entityIdentifierValueBindingExists(String name); + + @LogMessage( level = WARN ) + @Message( value = "The DerbyDialect dialect has been deprecated; use one of the version-specific dialects instead", id = 430 ) + void deprecatedDerbyDialect(); } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/DerbyDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/DerbyDialect.java index 335915cb82..1f3983d131 100755 --- a/hibernate-core/src/main/java/org/hibernate/dialect/DerbyDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/DerbyDialect.java @@ -40,7 +40,10 @@ import org.jboss.logging.Logger; * http://www.jroller.com/comments/kenlars99/Weblog/cloudscape_soon_to_be_derby * * @author Simon Johnston + * + * @deprecated HHH-6073 */ +@Deprecated public class DerbyDialect extends DB2Dialect { private static final HibernateLogger LOG = Logger.getMessageLogger(HibernateLogger.class, DerbyDialect.class.getName()); @@ -50,6 +53,7 @@ public class DerbyDialect extends DB2Dialect { public DerbyDialect() { super(); + LOG.deprecatedDerbyDialect(); registerFunction( "concat", new DerbyConcatFunction() ); registerFunction( "trim", new AnsiTrimFunction() ); determineDriverVersion(); diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/DerbyTenFiveDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/DerbyTenFiveDialect.java index 8e6dea3c73..0038f099c1 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/DerbyTenFiveDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/DerbyTenFiveDialect.java @@ -23,10 +23,8 @@ */ package org.hibernate.dialect; -import org.hibernate.HibernateLogger; import org.hibernate.dialect.function.AnsiTrimFunction; import org.hibernate.dialect.function.DerbyConcatFunction; -import org.jboss.logging.Logger; /** @@ -39,9 +37,6 @@ import org.jboss.logging.Logger; * @author Scott Marlow */ public class DerbyTenFiveDialect extends DerbyDialect { - - private static final HibernateLogger LOG = Logger.getMessageLogger(HibernateLogger.class, DerbyTenFiveDialect.class.getName()); - public DerbyTenFiveDialect() { super(); registerFunction( "concat", new DerbyConcatFunction() ); diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/DerbyTenSixDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/DerbyTenSixDialect.java index 05d2ebe71a..a498610b2c 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/DerbyTenSixDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/DerbyTenSixDialect.java @@ -23,9 +23,6 @@ */ package org.hibernate.dialect; -import org.hibernate.HibernateLogger; -import org.jboss.logging.Logger; - /** * Hibernate Dialect for Cloudscape 10 - aka Derby. This implements both an * override for the identity column generator as well as for the case statement @@ -36,19 +33,12 @@ import org.jboss.logging.Logger; * @author Scott Marlow */ public class DerbyTenSixDialect extends DerbyTenFiveDialect { - - private static final HibernateLogger LOG = Logger.getMessageLogger(HibernateLogger.class, DerbyTenSixDialect.class.getName()); - public DerbyTenSixDialect() { super(); } - private boolean isTenPointFiveReleaseOrNewer() { - return true; - } - @Override public boolean supportsSequences() { - return true; + return true; } } diff --git a/hibernate-core/src/main/java/org/hibernate/service/jdbc/dialect/internal/StandardDialectResolver.java b/hibernate-core/src/main/java/org/hibernate/service/jdbc/dialect/internal/StandardDialectResolver.java index 6cdba008ba..02d628a7a9 100644 --- a/hibernate-core/src/main/java/org/hibernate/service/jdbc/dialect/internal/StandardDialectResolver.java +++ b/hibernate-core/src/main/java/org/hibernate/service/jdbc/dialect/internal/StandardDialectResolver.java @@ -82,15 +82,15 @@ public class StandardDialectResolver extends AbstractDialectResolver { if ( "Apache Derby".equals( databaseName ) ) { int driverVersionMajor = metaData.getDriverMajorVersion(); int driverVersionMinor = metaData.getDriverMinorVersion(); - if ( driverVersionMajor > 10 || ( driverVersionMajor == 10 && driverVersionMinor >= 5 ) ) { - if ( driverVersionMinor >= 6 ) { - return new DerbyTenSixDialect(); - } - else { - return new DerbyTenFiveDialect(); - } + if ( driverVersionMajor > 10 || ( driverVersionMajor == 10 && driverVersionMinor >= 6 ) ) { + return new DerbyTenSixDialect(); + } + else if ( driverVersionMajor == 10 && driverVersionMinor == 5 ) { + return new DerbyTenFiveDialect(); + } + else { + return new DerbyDialect(); } - return new DerbyDialect(); } if ( "ingres".equalsIgnoreCase( databaseName ) ) { From bd5c483b67ac6d7873a0b2c9b8549930a1e40c00 Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Tue, 5 Apr 2011 16:08:59 -0500 Subject: [PATCH 03/15] HHH-6073 : test fix up --- .../src/test/java/org/hibernate/dialect/Mocks.java | 14 ++++++++++++-- .../dialect/resolver/DialectFactoryTest.java | 14 ++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/hibernate-core/src/test/java/org/hibernate/dialect/Mocks.java b/hibernate-core/src/test/java/org/hibernate/dialect/Mocks.java index e20357b321..7eee5abfc7 100644 --- a/hibernate-core/src/test/java/org/hibernate/dialect/Mocks.java +++ b/hibernate-core/src/test/java/org/hibernate/dialect/Mocks.java @@ -35,8 +35,12 @@ import java.sql.SQLException; @SuppressWarnings( {"UnnecessaryBoxing"}) public class Mocks { - public static Connection createConnection(String dbName, int version) { - DatabaseMetaDataHandler metadataHandler = new DatabaseMetaDataHandler( dbName, version ); + public static Connection createConnection(String databaseName, int majorVersion) { + return createConnection( databaseName, majorVersion, -9999 ); + } + + public static Connection createConnection(String databaseName, int majorVersion, int minorVersion) { + DatabaseMetaDataHandler metadataHandler = new DatabaseMetaDataHandler( databaseName, majorVersion, minorVersion ); ConnectionHandler connectionHandler = new ConnectionHandler(); DatabaseMetaData metadataProxy = ( DatabaseMetaData ) Proxy.newProxyInstance( @@ -90,6 +94,7 @@ public class Mocks { private static class DatabaseMetaDataHandler implements InvocationHandler { private final String databaseName; private final int majorVersion; + private final int minorVersion; private Connection connectionProxy; @@ -98,8 +103,13 @@ public class Mocks { } private DatabaseMetaDataHandler(String databaseName, int majorVersion) { + this( databaseName, majorVersion, -9999 ); + } + + private DatabaseMetaDataHandler(String databaseName, int majorVersion, int minorVersion) { this.databaseName = databaseName; this.majorVersion = majorVersion; + this.minorVersion = minorVersion; } public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { diff --git a/hibernate-core/src/test/java/org/hibernate/dialect/resolver/DialectFactoryTest.java b/hibernate-core/src/test/java/org/hibernate/dialect/resolver/DialectFactoryTest.java index aae0a88109..a10de842fa 100644 --- a/hibernate-core/src/test/java/org/hibernate/dialect/resolver/DialectFactoryTest.java +++ b/hibernate-core/src/test/java/org/hibernate/dialect/resolver/DialectFactoryTest.java @@ -33,6 +33,8 @@ import org.hibernate.HibernateException; import org.hibernate.cfg.Environment; import org.hibernate.dialect.DB2Dialect; import org.hibernate.dialect.DerbyDialect; +import org.hibernate.dialect.DerbyTenFiveDialect; +import org.hibernate.dialect.DerbyTenSixDialect; import org.hibernate.dialect.H2Dialect; import org.hibernate.dialect.HSQLDialect; import org.hibernate.dialect.InformixDialect; @@ -123,7 +125,10 @@ public class DialectFactoryTest extends BaseUnitTestCase { testDetermination( "H2", H2Dialect.class, resolver ); testDetermination( "MySQL", MySQLDialect.class, resolver ); testDetermination( "PostgreSQL", PostgreSQLDialect.class, resolver ); - testDetermination( "Apache Derby", DerbyDialect.class, resolver ); + testDetermination( "Apache Derby", 10, 4, DerbyDialect.class, resolver ); + testDetermination( "Apache Derby", 10, 5, DerbyTenFiveDialect.class, resolver ); + testDetermination( "Apache Derby", 10, 6, DerbyTenSixDialect.class, resolver ); + testDetermination( "Apache Derby", 11, 5, DerbyTenSixDialect.class, resolver ); testDetermination( "Ingres", IngresDialect.class, resolver ); testDetermination( "ingres", IngresDialect.class, resolver ); testDetermination( "INGRES", IngresDialect.class, resolver ); @@ -197,9 +202,14 @@ public class DialectFactoryTest extends BaseUnitTestCase { } private void testDetermination(String databaseName, int databaseMajorVersion, Class clazz, DialectResolver resolver) { + testDetermination( databaseName, databaseMajorVersion, -9999, clazz, resolver ); + } + + private void testDetermination(String databaseName, int majorVersion, int minorVersion, Class clazz, DialectResolver resolver) { dialectFactory.setDialectResolver( resolver ); Properties properties = new Properties(); - Connection conn = Mocks.createConnection( databaseName, databaseMajorVersion ); + Connection conn = Mocks.createConnection( databaseName, majorVersion, minorVersion ); assertEquals( clazz, dialectFactory.buildDialect( properties, conn ).getClass() ); } + } From aad256c63469420387edd30726715581f3cfd4d7 Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Tue, 5 Apr 2011 16:10:41 -0500 Subject: [PATCH 04/15] HHH-6081 - Finish up Integrator --- .../BeanValidationIntegrator.java | 10 +- .../LegacyHibernateValidationIntegrator.java | 155 ------------------ .../cfg/search/HibernateSearchIntegrator.java | 7 +- .../hibernate/impl/SessionFactoryImpl.java | 63 +++---- .../hibernate/{impl => spi}/Integrator.java | 11 +- .../envers/event/EnversIntegrator.java | 7 +- 6 files changed, 55 insertions(+), 198 deletions(-) delete mode 100644 hibernate-core/src/main/java/org/hibernate/cfg/beanvalidation/LegacyHibernateValidationIntegrator.java rename hibernate-core/src/main/java/org/hibernate/{impl => spi}/Integrator.java (84%) diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/beanvalidation/BeanValidationIntegrator.java b/hibernate-core/src/main/java/org/hibernate/cfg/beanvalidation/BeanValidationIntegrator.java index ad98076bbf..8630194f16 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/beanvalidation/BeanValidationIntegrator.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/beanvalidation/BeanValidationIntegrator.java @@ -37,7 +37,7 @@ import org.hibernate.HibernateLogger; import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Environment; import org.hibernate.engine.SessionFactoryImplementor; -import org.hibernate.impl.Integrator; +import org.hibernate.spi.Integrator; import org.hibernate.internal.util.config.ConfigurationHelper; import org.hibernate.service.classloading.spi.ClassLoaderService; import org.hibernate.service.event.spi.EventListenerRegistry; @@ -49,6 +49,8 @@ import org.hibernate.service.spi.SessionFactoryServiceRegistry; public class BeanValidationIntegrator implements Integrator { private static final HibernateLogger LOG = Logger.getMessageLogger(HibernateLogger.class, BeanValidationIntegrator.class.getName()); + public static final String APPLY_CONSTRAINTS = "hibernate.validator.apply_to_ddl"; + public static final String BV_CHECK_CLASS = "javax.validation.Validation"; public static final String MODE_PROPERTY = "javax.persistence.validation.mode"; @@ -149,7 +151,7 @@ public class BeanValidationIntegrator implements Integrator { boolean beanValidationAvailable, Class typeSafeActivatorClass, Configuration configuration) { - if ( ! ConfigurationHelper.getBoolean( LegacyHibernateValidationIntegrator.APPLY_CONSTRAINTS, configuration.getProperties(), true ) ){ + if ( ! ConfigurationHelper.getBoolean( APPLY_CONSTRAINTS, configuration.getProperties(), true ) ){ LOG.debug( "Skipping application of relational constraints from legacy Hibernate Validator" ); return; } @@ -287,4 +289,8 @@ public class BeanValidationIntegrator implements Integrator { } } + @Override + public void disintegrate(SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) { + // nothing to do here afaik + } } diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/beanvalidation/LegacyHibernateValidationIntegrator.java b/hibernate-core/src/main/java/org/hibernate/cfg/beanvalidation/LegacyHibernateValidationIntegrator.java deleted file mode 100644 index b1f1c12972..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/cfg/beanvalidation/LegacyHibernateValidationIntegrator.java +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * Copyright (c) 2011, 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 - * 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.cfg.beanvalidation; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Method; -import java.util.Map; -import java.util.ResourceBundle; - -import org.jboss.logging.Logger; - -import org.hibernate.AnnotationException; -import org.hibernate.HibernateLogger; -import org.hibernate.annotations.common.reflection.ReflectionManager; -import org.hibernate.cfg.Configuration; -import org.hibernate.engine.SessionFactoryImplementor; -import org.hibernate.event.EventType; -import org.hibernate.event.PreInsertEventListener; -import org.hibernate.event.PreUpdateEventListener; -import org.hibernate.impl.Integrator; -import org.hibernate.internal.util.ReflectHelper; -import org.hibernate.internal.util.StringHelper; -import org.hibernate.internal.util.config.ConfigurationHelper; -import org.hibernate.mapping.PersistentClass; -import org.hibernate.service.classloading.spi.ClassLoaderService; -import org.hibernate.service.event.spi.EventListenerRegistry; -import org.hibernate.service.spi.SessionFactoryServiceRegistry; - -/** - * @author Steve Ebersole - */ -public class LegacyHibernateValidationIntegrator implements Integrator { - private static final HibernateLogger LOG = Logger.getMessageLogger( HibernateLogger.class, LegacyHibernateValidationIntegrator.class.getName() ); - - public static final String APPLY_CONSTRAINTS = "hibernate.validator.apply_to_ddl"; - public static final String CLASS_VALIDATOR_CLASS = "org.hibernate.validator.ClassValidator"; - public static final String MSG_INTERPOLATOR_CLASS = "org.hibernate.validator.MessageInterpolator"; - - public static final String AUTO_REGISTER = "hibernate.validator.autoregister_listeners"; - public static final String LISTENER_CLASS_NAME = "org.hibernate.validator.event.ValidateEventListener"; - - // this code mostly all copied and pasted from various spots... - - @Override - public void integrate( - Configuration configuration, - SessionFactoryImplementor sessionFactory, - SessionFactoryServiceRegistry serviceRegistry) { - applyRelationalConstraints( configuration, serviceRegistry ); - applyListeners( configuration, serviceRegistry ); - } - - @SuppressWarnings( {"unchecked"}) - private void applyRelationalConstraints(Configuration configuration, SessionFactoryServiceRegistry serviceRegistry) { - if ( ! ConfigurationHelper.getBoolean( APPLY_CONSTRAINTS, configuration.getProperties(), true ) ){ - LOG.debug( "Skipping application of relational constraints from legacy Hibernate Validator" ); - return; - } - - Constructor validatorCtr = null; - Method applyMethod = null; - try { - final ClassLoaderService classLoaderService = serviceRegistry.getService( ClassLoaderService.class ); - final Class classValidator = classLoaderService.classForName( CLASS_VALIDATOR_CLASS ); - final Class messageInterpolator = classLoaderService.classForName( MSG_INTERPOLATOR_CLASS ); - validatorCtr = classValidator.getDeclaredConstructor( - Class.class, ResourceBundle.class, messageInterpolator, Map.class, ReflectionManager.class - ); - applyMethod = classValidator.getMethod( "apply", PersistentClass.class ); - } - catch ( NoSuchMethodException e ) { - throw new AnnotationException( e ); - } - catch ( Exception e ) { - LOG.debug( "Legacy Hibernate Validator classes not found, ignoring" ); - } - - if ( applyMethod != null ) { - Iterable persistentClasses = ( (Map) configuration.createMappings().getClasses() ).values(); - for ( PersistentClass persistentClass : persistentClasses ) { - // integrate the validate framework - String className = persistentClass.getClassName(); - if ( StringHelper.isNotEmpty( className ) ) { - try { - Object validator = validatorCtr.newInstance( - ReflectHelper.classForName( className ), null, null, null, configuration.getReflectionManager() - ); - applyMethod.invoke( validator, persistentClass ); - } - catch ( Exception e ) { - LOG.unableToApplyConstraints(className, e); - } - } - } - } - } - - private void applyListeners(Configuration configuration, SessionFactoryServiceRegistry serviceRegistry) { - final boolean registerListeners = ConfigurationHelper.getBoolean( AUTO_REGISTER, configuration.getProperties(), false ); - if ( !registerListeners ) { - LOG.debug( "Skipping legacy validator auto registration" ); - return; - } - - final Class listenerClass = loadListenerClass( serviceRegistry ); - if ( listenerClass == null ) { - LOG.debug( "Skipping legacy validator auto registration - could not locate listener" ); - return; - } - - final Object validateEventListener; - try { - validateEventListener = listenerClass.newInstance(); - } - catch ( Exception e ) { - throw new AnnotationException( "Unable to instantiate Validator event listener", e ); - } - - EventListenerRegistry listenerRegistry = serviceRegistry.getService( EventListenerRegistry.class ); - // todo : duplication strategy - - listenerRegistry.appendListeners( EventType.PRE_INSERT, (PreInsertEventListener) validateEventListener ); - listenerRegistry.appendListeners( EventType.PRE_UPDATE, (PreUpdateEventListener) validateEventListener ); - } - - private Class loadListenerClass(SessionFactoryServiceRegistry serviceRegistry) { - try { - return serviceRegistry.getService( ClassLoaderService.class ).classForName( LISTENER_CLASS_NAME ); - } - catch (Exception e) { - return null; - } - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/search/HibernateSearchIntegrator.java b/hibernate-core/src/main/java/org/hibernate/cfg/search/HibernateSearchIntegrator.java index 766652e5cf..a3dabdc764 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/search/HibernateSearchIntegrator.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/search/HibernateSearchIntegrator.java @@ -36,7 +36,7 @@ import org.hibernate.event.PostCollectionUpdateEventListener; import org.hibernate.event.PostDeleteEventListener; import org.hibernate.event.PostInsertEventListener; import org.hibernate.event.PostUpdateEventListener; -import org.hibernate.impl.Integrator; +import org.hibernate.spi.Integrator; import org.hibernate.internal.util.config.ConfigurationHelper; import org.hibernate.service.classloading.spi.ClassLoaderService; import org.hibernate.service.event.spi.DuplicationStrategy; @@ -126,4 +126,9 @@ public class HibernateSearchIntegrator implements Integrator { return Action.KEEP_ORIGINAL; } } + + @Override + public void disintegrate(SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) { + // nothing to do here afaik + } } diff --git a/hibernate-core/src/main/java/org/hibernate/impl/SessionFactoryImpl.java b/hibernate-core/src/main/java/org/hibernate/impl/SessionFactoryImpl.java index 6daaaf096a..acc9bf4d82 100644 --- a/hibernate-core/src/main/java/org/hibernate/impl/SessionFactoryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/impl/SessionFactoryImpl.java @@ -27,13 +27,11 @@ import javax.naming.NamingException; import javax.naming.Reference; import javax.naming.StringRefAddr; import java.io.IOException; -import java.io.InputStream; import java.io.InvalidObjectException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.ObjectStreamException; import java.io.Serializable; -import java.net.URL; import java.sql.Connection; import java.util.ArrayList; import java.util.Collections; @@ -44,6 +42,7 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Properties; +import java.util.ServiceLoader; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; @@ -82,7 +81,6 @@ import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Environment; import org.hibernate.cfg.Settings; import org.hibernate.cfg.beanvalidation.BeanValidationIntegrator; -import org.hibernate.cfg.beanvalidation.LegacyHibernateValidationIntegrator; import org.hibernate.cfg.search.HibernateSearchIntegrator; import org.hibernate.context.CurrentSessionContext; import org.hibernate.context.JTASessionContext; @@ -125,12 +123,12 @@ import org.hibernate.persister.spi.PersisterFactory; import org.hibernate.pretty.MessageHelper; import org.hibernate.proxy.EntityNotFoundDelegate; import org.hibernate.service.ServiceRegistry; -import org.hibernate.service.classloading.spi.ClassLoaderService; import org.hibernate.service.jdbc.connections.spi.ConnectionProvider; import org.hibernate.service.jta.platform.spi.JtaPlatform; import org.hibernate.service.spi.ServiceRegistryImplementor; import org.hibernate.service.spi.SessionFactoryServiceRegistry; import org.hibernate.service.spi.SessionFactoryServiceRegistryFactory; +import org.hibernate.spi.Integrator; import org.hibernate.stat.Statistics; import org.hibernate.stat.spi.StatisticsImplementor; import org.hibernate.tool.hbm2ddl.SchemaExport; @@ -245,8 +243,26 @@ public final class SessionFactoryImpl // todo : everything above here consider implementing as standard SF service. specifically: stats, caches, types, function-reg + class IntegratorObserver implements SessionFactoryObserver { + private ArrayList integrators = new ArrayList(); + + @Override + public void sessionFactoryCreated(SessionFactory factory) { + } + + @Override + public void sessionFactoryClosed(SessionFactory factory) { + for ( Integrator integrator : integrators ) { + integrator.disintegrate( SessionFactoryImpl.this, SessionFactoryImpl.this.serviceRegistry ); + } + } + } + + final IntegratorObserver integratorObserver = new IntegratorObserver(); + this.observer.addObserver( integratorObserver ); for ( Integrator integrator : locateIntegrators( this.serviceRegistry ) ) { - integrator.integrate( cfg, this, (SessionFactoryServiceRegistry) this.serviceRegistry ); + integrator.integrate( cfg, this, this.serviceRegistry ); + integratorObserver.integrators.add( integrator ); } //Generators: @@ -490,43 +506,14 @@ public final class SessionFactoryImpl private Iterable locateIntegrators(ServiceRegistryImplementor serviceRegistry) { List integrators = new ArrayList(); - // todo : Envers needs to bbe handled by discovery to be because it is in a separate project - integrators.add( new LegacyHibernateValidationIntegrator() ); + // todo : Envers needs to be handled by discovery to be because it is in a separate project integrators.add( new BeanValidationIntegrator() ); integrators.add( new HibernateSearchIntegrator() ); - final Properties properties = new Properties(); - - ClassLoaderService classLoader = serviceRegistry.getService( ClassLoaderService.class ); - List urls = classLoader.locateResources( "META-INF/hibernate/org.hibernate.impl.Integrator" ); - for ( URL url : urls ) { - try { - final InputStream propertyStream = url.openStream(); - try { - properties.clear(); - properties.load( propertyStream ); - // for now we only understand 'implClass' as key - final String implClass = properties.getProperty( "implClass" ); - Class integratorClass = classLoader.classForName( implClass ); - try { - integrators.add( (Integrator) integratorClass.newInstance() ); - } - catch (Exception e) { - throw new HibernateException( "Unable to instantiate specified Integrator class [" + implClass + "]", e ); - } - } - finally { - try { - propertyStream.close(); - } - catch (IOException ignore) { - } - } - } - catch ( IOException ioe ) { - LOG.debugf( ioe, "Unable to process Integrator service file [%s], skipping" , url.toExternalForm() ); - } + for ( Integrator integrator : ServiceLoader.load( Integrator.class ) ) { + integrators.add( integrator ); } + return integrators; } diff --git a/hibernate-core/src/main/java/org/hibernate/impl/Integrator.java b/hibernate-core/src/main/java/org/hibernate/spi/Integrator.java similarity index 84% rename from hibernate-core/src/main/java/org/hibernate/impl/Integrator.java rename to hibernate-core/src/main/java/org/hibernate/spi/Integrator.java index 8559dcc13d..b01d1dc513 100644 --- a/hibernate-core/src/main/java/org/hibernate/impl/Integrator.java +++ b/hibernate-core/src/main/java/org/hibernate/spi/Integrator.java @@ -21,7 +21,7 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.impl; +package org.hibernate.spi; import org.hibernate.cfg.Configuration; import org.hibernate.engine.SessionFactoryImplementor; @@ -40,6 +40,7 @@ import org.hibernate.service.spi.SessionFactoryServiceRegistry; * @author Steve Ebersole * @since 4.0 * @jira HHH-5562 + * @jira HHH-6081 */ public interface Integrator { /** @@ -53,4 +54,12 @@ public interface Integrator { Configuration configuration, SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry); + + /** + * Tongue-in-cheek name for a shutdown callback. + * + * @param sessionFactory The session factory being closed. + * @param serviceRegistry That session factory's service registry + */ + public void disintegrate(SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry); } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/event/EnversIntegrator.java b/hibernate-envers/src/main/java/org/hibernate/envers/event/EnversIntegrator.java index 48500c7d30..9c75de4019 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/event/EnversIntegrator.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/event/EnversIntegrator.java @@ -30,7 +30,7 @@ import org.hibernate.cfg.Configuration; import org.hibernate.engine.SessionFactoryImplementor; import org.hibernate.envers.configuration.AuditConfiguration; import org.hibernate.event.EventType; -import org.hibernate.impl.Integrator; +import org.hibernate.spi.Integrator; import org.hibernate.internal.util.config.ConfigurationHelper; import org.hibernate.service.event.spi.EventListenerRegistry; import org.hibernate.service.spi.SessionFactoryServiceRegistry; @@ -70,4 +70,9 @@ public class EnversIntegrator implements Integrator { listenerRegistry.appendListeners( EventType.PRE_COLLECTION_UPDATE, new EnversPreCollectionUpdateEventListenerImpl( enversConfiguration ) ); } } + + @Override + public void disintegrate(SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) { + // nothing to do afaik + } } From 7c4a9dac817212e5e1779b57a38ef3c9c588812e Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Wed, 6 Apr 2011 11:31:14 -0500 Subject: [PATCH 05/15] HHH-6073 - Dialects cannot use the Thread Context ClassLoader with AS7, please change to use the --- .../jdbc/dialect/internal/StandardDialectResolver.java | 7 +++---- .../src/test/java/org/hibernate/dialect/Mocks.java | 5 +++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/service/jdbc/dialect/internal/StandardDialectResolver.java b/hibernate-core/src/main/java/org/hibernate/service/jdbc/dialect/internal/StandardDialectResolver.java index 02d628a7a9..61cb4cd1d4 100644 --- a/hibernate-core/src/main/java/org/hibernate/service/jdbc/dialect/internal/StandardDialectResolver.java +++ b/hibernate-core/src/main/java/org/hibernate/service/jdbc/dialect/internal/StandardDialectResolver.java @@ -80,12 +80,11 @@ public class StandardDialectResolver extends AbstractDialectResolver { } if ( "Apache Derby".equals( databaseName ) ) { - int driverVersionMajor = metaData.getDriverMajorVersion(); - int driverVersionMinor = metaData.getDriverMinorVersion(); - if ( driverVersionMajor > 10 || ( driverVersionMajor == 10 && driverVersionMinor >= 6 ) ) { + final int databaseMinorVersion = metaData.getDatabaseMinorVersion(); + if ( databaseMajorVersion > 10 || ( databaseMajorVersion == 10 && databaseMinorVersion >= 6 ) ) { return new DerbyTenSixDialect(); } - else if ( driverVersionMajor == 10 && driverVersionMinor == 5 ) { + else if ( databaseMajorVersion == 10 && databaseMinorVersion == 5 ) { return new DerbyTenFiveDialect(); } else { diff --git a/hibernate-core/src/test/java/org/hibernate/dialect/Mocks.java b/hibernate-core/src/test/java/org/hibernate/dialect/Mocks.java index 7eee5abfc7..82730478c0 100644 --- a/hibernate-core/src/test/java/org/hibernate/dialect/Mocks.java +++ b/hibernate-core/src/test/java/org/hibernate/dialect/Mocks.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.dialect; +import javax.persistence.criteria.CriteriaBuilder; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Proxy; @@ -122,6 +123,10 @@ public class Mocks { return Integer.valueOf( majorVersion ); } + if ( "getDatabaseMinorVersion".equals( methodName ) ) { + return Integer.valueOf( minorVersion ); + } + if ( "getConnection".equals( methodName ) ) { return connectionProxy; } From 03c40093911dbfd41a85ee9929127717442417f2 Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Wed, 6 Apr 2011 11:32:57 -0500 Subject: [PATCH 06/15] HHH-6088 - Move to slf4j-log4j12 for test logging --- build.gradle | 6 ++---- .../org/hibernate/engine/jdbc/spi/SqlStatementLogger.java | 2 +- .../java/org/hibernate/hql/ast/QueryTranslatorImpl.java | 4 ++-- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/build.gradle b/build.gradle index 3c3916e85b..0646f16e94 100644 --- a/build.gradle +++ b/build.gradle @@ -71,13 +71,12 @@ libraries = [ logging: 'org.jboss.logging:jboss-logging:3.0.0.Beta5', logging_tools: 'org.jboss.logging:jboss-logging-tools:1.0.0.Beta4', slf4j_api: 'org.slf4j:slf4j-api:' + slf4jVersion, - slf4j_simple: 'org.slf4j:slf4j-simple:' + slf4jVersion, + slf4j_log4j12: 'org.slf4j:slf4j-log4j12:' + slf4jVersion, jcl_slf4j: 'org.slf4j:jcl-over-slf4j:' + slf4jVersion, jcl_api: 'commons-logging:commons-logging-api:99.0-does-not-exist', jcl: 'commons-logging:commons-logging:99.0-does-not-exist', // testing - atomikos: 'com.atomikos:transactions-jdbc:3.7.0', junit: 'junit:junit:4.8.2', jpa_modelgen: 'org.hibernate:hibernate-jpamodelgen:1.1.1.Final', shrinkwrap_api: 'org.jboss.shrinkwrap:shrinkwrap-api:1.0.0-alpha-6', @@ -121,9 +120,8 @@ subprojects { subProject -> dependencies { compile( libraries.logging ) testCompile( libraries.junit ) - testCompile( libraries.atomikos ) testRuntime( libraries.slf4j_api ) - testRuntime( libraries.slf4j_simple ) + testRuntime( libraries.slf4j_log4j12 ) testRuntime( libraries.jcl_slf4j ) testRuntime( libraries.jcl_api ) testRuntime( libraries.jcl ) diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/spi/SqlStatementLogger.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/spi/SqlStatementLogger.java index 2b6f85a8e2..89aec68f26 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/spi/SqlStatementLogger.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/spi/SqlStatementLogger.java @@ -100,7 +100,7 @@ public class SqlStatementLogger { statement = formatter.format( statement ); } } - LOG.debugf(statement); + LOG.debug( statement ); if ( logToStdout ) { System.out.println( "Hibernate: " + statement ); } diff --git a/hibernate-core/src/main/java/org/hibernate/hql/ast/QueryTranslatorImpl.java b/hibernate-core/src/main/java/org/hibernate/hql/ast/QueryTranslatorImpl.java index fbe4b527b2..c10ebd0f62 100644 --- a/hibernate-core/src/main/java/org/hibernate/hql/ast/QueryTranslatorImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/hql/ast/QueryTranslatorImpl.java @@ -249,7 +249,7 @@ public class QueryTranslatorImpl implements FilterTranslator { if (LOG.isDebugEnabled()) { ASTPrinter printer = new ASTPrinter( SqlTokenTypes.class ); - LOG.debugf(printer.showAsString(w.getAST(), "--- SQL AST ---")); + LOG.debug( printer.showAsString( w.getAST(), "--- SQL AST ---" ) ); } w.getParseErrorHandler().throwQueryException(); @@ -280,7 +280,7 @@ public class QueryTranslatorImpl implements FilterTranslator { void showHqlAst(AST hqlAst) { if (LOG.isDebugEnabled()) { ASTPrinter printer = new ASTPrinter( HqlTokenTypes.class ); - LOG.debugf(printer.showAsString(hqlAst, "--- HQL AST ---")); + LOG.debug( printer.showAsString( hqlAst, "--- HQL AST ---" ) ); } } From 154675d32270f7a9b8ac77ea0ef2b92d9ba49525 Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Wed, 6 Apr 2011 12:27:46 -0500 Subject: [PATCH 07/15] HHH-6088 - Move to slf4j-log4j12 for test logging --- hibernate-core/src/test/resources/log4j.properties | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/hibernate-core/src/test/resources/log4j.properties b/hibernate-core/src/test/resources/log4j.properties index c13e5d4f48..55c7e4968d 100644 --- a/hibernate-core/src/test/resources/log4j.properties +++ b/hibernate-core/src/test/resources/log4j.properties @@ -6,15 +6,5 @@ log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n log4j.rootLogger=info, stdout -log4j.logger.org.hibernate.test=info log4j.logger.org.hibernate.tool.hbm2ddl=debug -log4j.logger.org.hibernate.engine.jdbc.internal=trace -log4j.logger.org.hibernate.engine.jdbc.internal.proxy=trace -log4j.logger.org.hibernate.engine.jdbc.batch.internal=trace -log4j.logger.org.hibernate.hql.ast.QueryTranslatorImpl=trace -log4j.logger.org.hibernate.hql.ast.HqlSqlWalker=trace -log4j.logger.org.hibernate.hql.ast.SqlGenerator=trace -log4j.logger.org.hibernate.hql.ast.AST=trace -log4j.logger.org.hibernate.type.descriptor.sql.BasicBinder=trace -log4j.logger.org.hibernate.type.BasicTypeRegistry=trace From 7b4998d1ce2491fe08313e0ee542e2c5d34908af Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Wed, 6 Apr 2011 12:28:00 -0500 Subject: [PATCH 08/15] HHH-5244 - Flesh out H2Dialect temp table support --- .../java/org/hibernate/HibernateLogger.java | 4 +++ .../java/org/hibernate/dialect/H2Dialect.java | 33 +++++++++++++------ 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/HibernateLogger.java b/hibernate-core/src/main/java/org/hibernate/HibernateLogger.java index c8bda81379..af81d38a71 100644 --- a/hibernate-core/src/main/java/org/hibernate/HibernateLogger.java +++ b/hibernate-core/src/main/java/org/hibernate/HibernateLogger.java @@ -1862,4 +1862,8 @@ public interface HibernateLogger extends BasicLogger { @LogMessage( level = WARN ) @Message( value = "The DerbyDialect dialect has been deprecated; use one of the version-specific dialects instead", id = 430 ) void deprecatedDerbyDialect(); + + @LogMessage( level = WARN ) + @Message( value = "Unable to determine H2 database version, certain features may not work", id = 431 ) + void undeterminedH2Version(); } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/H2Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/H2Dialect.java index c79ca410ff..0bfda11376 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/H2Dialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/H2Dialect.java @@ -46,29 +46,33 @@ public class H2Dialect extends Dialect { private static final HibernateLogger LOG = Logger.getMessageLogger(HibernateLogger.class, H2Dialect.class.getName()); - private String querySequenceString; + private final String querySequenceString; public H2Dialect() { super(); - querySequenceString = "select sequence_name from information_schema.sequences"; + String querySequenceString = "select sequence_name from information_schema.sequences"; try { // HHH-2300 - final Class constants = ReflectHelper.classForName( "org.h2.engine.Constants" ); - final int majorVersion = ( Integer ) constants.getDeclaredField( "VERSION_MAJOR" ).get( null ); - final int minorVersion = ( Integer ) constants.getDeclaredField( "VERSION_MINOR" ).get( null ); - final int buildId = ( Integer ) constants.getDeclaredField( "BUILD_ID" ).get( null ); + final Class h2ConstantsClass = ReflectHelper.classForName( "org.h2.engine.Constants" ); + final int majorVersion = ( Integer ) h2ConstantsClass.getDeclaredField( "VERSION_MAJOR" ).get( null ); + final int minorVersion = ( Integer ) h2ConstantsClass.getDeclaredField( "VERSION_MINOR" ).get( null ); + final int buildId = ( Integer ) h2ConstantsClass.getDeclaredField( "BUILD_ID" ).get( null ); if ( buildId < 32 ) { querySequenceString = "select name from information_schema.sequences"; } - if (!(majorVersion > 1 || minorVersion > 2 || buildId >= 139)) LOG.unsupportedMultiTableBulkHqlJpaql(majorVersion, - minorVersion, - buildId); + if ( ! ( majorVersion > 1 || minorVersion > 2 || buildId >= 139 ) ) { + LOG.unsupportedMultiTableBulkHqlJpaql( majorVersion, minorVersion, buildId ); + } } catch ( Exception e ) { - // ignore (probably H2 not in the classpath) + // probably H2 not in the classpath, though in certain app server environments it might just mean we are + // not using the correct classloader + LOG.undeterminedH2Version(); } + this.querySequenceString = querySequenceString; + registerColumnType( Types.BOOLEAN, "boolean" ); registerColumnType( Types.BIGINT, "bigint" ); registerColumnType( Types.BINARY, "binary" ); @@ -297,8 +301,17 @@ public class H2Dialect extends Dialect { return "create local temporary table if not exists"; } + @Override + public String getCreateTemporaryTablePostfix() { + // actually 2 different options are specified here: + // 1) [on commit drop] - says to drop the table on transaction commit + // 2) [transactional] - says to not perform an implicit commit of any current transaction + return "on commit drop transactional"; + } + @Override public Boolean performTemporaryTableDDLInIsolation() { + // explicitly create the table using the same connection and transaction return Boolean.FALSE; } From de38d784c7138a6c93a2b46f2354189e82a8018e Mon Sep 17 00:00:00 2001 From: Strong Liu Date: Thu, 7 Apr 2011 01:59:56 +0800 Subject: [PATCH 09/15] HHH-6076 - query with setFirstResult throws Exception on derby --- .../java/org/hibernate/loader/Loader.java | 34 +++++++++++++------ .../test/pagination/PaginationTest.java | 17 ++++++++++ 2 files changed, 40 insertions(+), 11 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/loader/Loader.java b/hibernate-core/src/main/java/org/hibernate/loader/Loader.java index 3f44629eee..a919f1230c 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/Loader.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/Loader.java @@ -1685,6 +1685,19 @@ public abstract class Loader { return dialect.supportsLimit() && hasMaxRows( selection ); } + private ScrollMode getScrollMode(boolean scroll, QueryParameters queryParameters, boolean hasFirstRow, boolean useLimitOffSet) { + final boolean canScroll = getFactory().getSettings().isScrollableResultSetsEnabled(); + if ( !canScroll ) { + return null; + } + if ( scroll ) { + return queryParameters.getScrollMode(); + } + if ( hasFirstRow && !useLimitOffSet ) { + return ScrollMode.SCROLL_INSENSITIVE; + } + return null; + } /** * Obtain a PreparedStatement with all parameters pre-bound. * Bind JDBC-style ? parameters, named parameters, and @@ -1701,24 +1714,23 @@ public abstract class Loader { final RowSelection selection = queryParameters.getRowSelection(); boolean useLimit = useLimit( selection, dialect ); boolean hasFirstRow = getFirstRow( selection ) > 0; - boolean useOffset = hasFirstRow && useLimit && dialect.supportsLimitOffset(); + boolean useLimitOffset = hasFirstRow && useLimit && dialect.supportsLimitOffset(); boolean callable = queryParameters.isCallable(); final boolean canScroll = getFactory().getSettings().isScrollableResultSetsEnabled(); final boolean useScrollableResultSetToSkip = hasFirstRow && - !useOffset && - getFactory().getSettings().isScrollableResultSetsEnabled(); - final ScrollMode scrollMode = - canScroll - ? scroll || useScrollableResultSetToSkip - ? queryParameters.getScrollMode() - : ScrollMode.SCROLL_INSENSITIVE - : null; - + !useLimitOffset && canScroll; + ScrollMode scrollMode = getScrollMode(scroll,queryParameters,hasFirstRow,useLimit); +// +// if(canScroll && ( scroll || useScrollableResultSetToSkip )){ +// scrollMode = scroll ? queryParameters.getScrollMode() : ScrollMode.SCROLL_INSENSITIVE; +// }else{ +// scrollMode = null; +// } if ( useLimit ) { sql = dialect.getLimitString( sql.trim(), //use of trim() here is ugly? - useOffset ? getFirstRow(selection) : 0, + useLimitOffset ? getFirstRow(selection) : 0, getMaxOrLimit(selection, dialect) ); } diff --git a/hibernate-core/src/test/java/org/hibernate/test/pagination/PaginationTest.java b/hibernate-core/src/test/java/org/hibernate/test/pagination/PaginationTest.java index bac6e72836..eb0ef1d031 100755 --- a/hibernate-core/src/test/java/org/hibernate/test/pagination/PaginationTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/pagination/PaginationTest.java @@ -91,6 +91,23 @@ public class PaginationTest extends BaseCoreFunctionalTestCase { cleanupTestData(); } + @Test + public void testOffset(){ + prepareTestData(); + Session session = openSession(); + session.beginTransaction(); + List result; + + result = generateBaseHQLQuery( session ) + .setFirstResult( 3 ) + .list(); + result = generateBaseCriteria( session ) + .setFirstResult( 3 ) + .list(); + session.getTransaction().commit(); + session.close(); + cleanupTestData(); + } @Test @RequiresDialectFeature( From ef35cd7be3a2a81e6b53635f2f54bce2d94b3916 Mon Sep 17 00:00:00 2001 From: Strong Liu Date: Thu, 7 Apr 2011 02:03:48 +0800 Subject: [PATCH 10/15] HHH-6076 - query with setFirstResult throws Exception on derby --- .../java/org/hibernate/loader/Loader.java | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/loader/Loader.java b/hibernate-core/src/main/java/org/hibernate/loader/Loader.java index a919f1230c..3372e54eca 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/Loader.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/Loader.java @@ -1685,16 +1685,15 @@ public abstract class Loader { return dialect.supportsLimit() && hasMaxRows( selection ); } - private ScrollMode getScrollMode(boolean scroll, QueryParameters queryParameters, boolean hasFirstRow, boolean useLimitOffSet) { + private ScrollMode getScrollMode(boolean scroll, boolean hasFirstRow, boolean useLimitOffSet, QueryParameters queryParameters) { final boolean canScroll = getFactory().getSettings().isScrollableResultSetsEnabled(); - if ( !canScroll ) { - return null; - } - if ( scroll ) { - return queryParameters.getScrollMode(); - } - if ( hasFirstRow && !useLimitOffSet ) { - return ScrollMode.SCROLL_INSENSITIVE; + if ( canScroll ) { + if ( scroll ) { + return queryParameters.getScrollMode(); + } + if ( hasFirstRow && !useLimitOffSet ) { + return ScrollMode.SCROLL_INSENSITIVE; + } } return null; } @@ -1720,7 +1719,7 @@ public abstract class Loader { final boolean canScroll = getFactory().getSettings().isScrollableResultSetsEnabled(); final boolean useScrollableResultSetToSkip = hasFirstRow && !useLimitOffset && canScroll; - ScrollMode scrollMode = getScrollMode(scroll,queryParameters,hasFirstRow,useLimit); + final ScrollMode scrollMode = getScrollMode( scroll, hasFirstRow, useLimit, queryParameters ); // // if(canScroll && ( scroll || useScrollableResultSetToSkip )){ // scrollMode = scroll ? queryParameters.getScrollMode() : ScrollMode.SCROLL_INSENSITIVE; From 9a81587505a864a2915b328c5a9777fe8ff779eb Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Wed, 6 Apr 2011 13:54:03 -0500 Subject: [PATCH 11/15] HHH-6081 - Finish up Integrator --- .../resources/META-INF/hibernate/org.hibernate.impl.Integrator | 1 - .../resources/META-INF/services/org.hibernate.spi.Integrator | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) delete mode 100644 hibernate-envers/src/main/resources/META-INF/hibernate/org.hibernate.impl.Integrator create mode 100644 hibernate-envers/src/main/resources/META-INF/services/org.hibernate.spi.Integrator diff --git a/hibernate-envers/src/main/resources/META-INF/hibernate/org.hibernate.impl.Integrator b/hibernate-envers/src/main/resources/META-INF/hibernate/org.hibernate.impl.Integrator deleted file mode 100644 index 1a519c9225..0000000000 --- a/hibernate-envers/src/main/resources/META-INF/hibernate/org.hibernate.impl.Integrator +++ /dev/null @@ -1 +0,0 @@ -implClass = org.hibernate.envers.event.EnversIntegrator \ No newline at end of file diff --git a/hibernate-envers/src/main/resources/META-INF/services/org.hibernate.spi.Integrator b/hibernate-envers/src/main/resources/META-INF/services/org.hibernate.spi.Integrator new file mode 100644 index 0000000000..dac1b598b9 --- /dev/null +++ b/hibernate-envers/src/main/resources/META-INF/services/org.hibernate.spi.Integrator @@ -0,0 +1 @@ +org.hibernate.envers.event.EnversIntegrator \ No newline at end of file From 2a8c81790b4b1313bcb1ba032274fea23300ca4c Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Wed, 6 Apr 2011 14:44:46 -0500 Subject: [PATCH 12/15] HHH-6094 - Test failures in hibernate-infinispan dealing with query caching --- hibernate-infinispan/hibernate-infinispan.gradle | 3 --- .../infinispan/functional/BasicTransactionalTestCase.java | 4 ++++ 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/hibernate-infinispan/hibernate-infinispan.gradle b/hibernate-infinispan/hibernate-infinispan.gradle index b7d14c98b8..95e428fd88 100644 --- a/hibernate-infinispan/hibernate-infinispan.gradle +++ b/hibernate-infinispan/hibernate-infinispan.gradle @@ -49,8 +49,5 @@ test { systemProperties['jgroups.bind_addr'] = 'localhost' // systemProperties['log4j.configuration'] = 'file:/log4j/log4j-infinispan.xml' enabled = true - afterTest { desc, result -> - println "Executing test ${desc.name} [${desc.className}] with result: ${result.resultType}" - } } diff --git a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/BasicTransactionalTestCase.java b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/BasicTransactionalTestCase.java index c2ca0f0b06..916b8c5bde 100644 --- a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/BasicTransactionalTestCase.java +++ b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/BasicTransactionalTestCase.java @@ -38,6 +38,8 @@ import org.hibernate.stat.Statistics; import org.junit.Test; +import org.hibernate.testing.FailureExpected; + import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -318,6 +320,7 @@ public class BasicTransactionalTestCase extends SingleNodeTestCase { } @Test + @FailureExpected( jiraKey = "HHH-6094" ) public void testQueryCache() throws Exception { Statistics stats = sessionFactory().getStatistics(); stats.clear(); @@ -375,6 +378,7 @@ public class BasicTransactionalTestCase extends SingleNodeTestCase { } @Test + @FailureExpected( jiraKey = "HHH-6094" ) public void testQueryCacheHitInSameTransaction() throws Exception { Statistics stats = sessionFactory().getStatistics(); stats.clear(); From 691712fcbbfd47d9bb119c499cc84d894f1aab2d Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Wed, 6 Apr 2011 16:10:02 -0500 Subject: [PATCH 13/15] prepare 4.0.0.Alpha2 release --- build.gradle | 2 +- changelog.txt | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 0646f16e94..716ad71278 100644 --- a/build.gradle +++ b/build.gradle @@ -91,7 +91,7 @@ subprojects { subProject -> defaultTasks 'build' group = 'org.hibernate' - version = '4.0.0-SNAPSHOT' + version = '4.0.0.Alpha2' // minimize changes, at least for now (gradle uses 'build' by default).. buildDir = "target" diff --git a/changelog.txt b/changelog.txt index 52474ae45b..0fc28e8fac 100644 --- a/changelog.txt +++ b/changelog.txt @@ -5,6 +5,67 @@ match the actual issue resolution (i.e. a bug might not be a bug). Please refer to the particular case on JIRA using the issue tracking number to learn more about each case. +Changes in version 4.0.0.Alpha2 (2011.04.06) +------------------------------------------------------------------------------------------------------------------------ + +** Bug + * [HHH-4999] - createSQLQuery(query).list() result screw up when when columns in different tables have same name + * [HHH-5803] - Better handling of implicit literal numeric expression typing + * [HHH-5940] - @MapKeyJoinColumns always throws an exception + * [HHH-5989] - Add tests of JPA-style transaction joining + * [HHH-5996] - Wire in JdbcServices into SchemaUpdateTask, SchemaExportTask, SchemaValidatorTask, HibernateService.dropSchema(), HibernateService.createSchema() + * [HHH-6001] - Add a top-level directory inside the release bundle archives + * [HHH-6002] - Use today's year when building copyright footer for aggregated javadocs + * [HHH-6028] - Remove o.h.classic stuff + * [HHH-6057] - hibernate.cfg.xml references wrong hbm.xml files and doesn't include reference to DTD file + * [HHH-6058] - Error in mapping file in Event.hbm.xml file for documentation in download + * [HHH-6061] - ValidatoryFactory type checking + * [HHH-6076] - query with setFirstResult throws Exception on derby + +** Improvement + * [HHH-2680] - Blobs not updated on Session.merge() for detached instances + * [HHH-2860] - Consolidate Session creation options/parameters + * [HHH-4362] - @RowId + * [HHH-5244] - Flesh out H2Dialect temp table support + * [HHH-5284] - Allow Type to dictate the default length/scale/precision + * [HHH-5562] - Introduce a locator pattern for integrators to be able to leverage to more easily integrate with Hibernate + * [HHH-5947] - Improve error message, documentation and tests on @UniqueConstraint + * [HHH-5993] - Expose SessionFactoryObserver to Hibernate EntityManager configuration + * [HHH-6053] - Create an interface for centralizing the contract that is shared between Session and StatelessSession + +** New Feature + * [HHH-5697] - Support for multi-tenancy + +** Patch + * [HHH-3646] - implement Criteria API querying of collection-of-component (David Mansfield) + * [HHH-5348] - support for TypedQuery jpaql/hql "scalar" queries + +** Task + * [HHH-5650] - Pull documentation building into 'release' module + * [HHH-5682] - Modify service infrastructure to leverage CDI annotations + * [HHH-5683] - Create Weld-specific ServiceRegistry + * [HHH-5913] - Implement set of event listeners as a service + * [HHH-5942] - Migrate to JUnit 4 + * [HHH-5966] - Finish up loose ends for overriding a SqlTypeDescriptor + * [HHH-6010] - Remove duplication in code involving Work and ReturningWork + * [HHH-6013] - Consolidate on single JTA impl for testing + * [HHH-6015] - Investigate hibernate-infinispan test failures since migration to JUnit4 + * [HHH-6016] - Migrate version injection plugin to Gradle + * [HHH-6025] - Remove cglib dependencies + * [HHH-6026] - Migrate bytecode provider integrations to api/spi/internal split + * [HHH-6027] - Migrate o.h.action pakcage to api/spi/internal split + * [HHH-6033] - Migrate stats to api/spi/internal split + * [HHH-6036] - integration documentation generation + * [HHH-6038] - Migrate to use newly separated gradle-upload-auth-plugin + * [HHH-6047] - allow nesting of ServiceRegistry + * [HHH-6050] - Remove direct compile-time dependencies to slf4j from build + * [HHH-6051] - Create a SessionFactory scoped ServiceRegistry + * [HHH-6052] - Make statistics a service + * [HHH-6073] - Dialects cannot use the Thread Context ClassLoader with AS7, please change to use the + * [HHH-6081] - Finish up Integrator + * [HHH-6088] - Move to slf4j-log4j12 for test logging + + Changes in version 4.0.0.Alpha1 (2011.03.09) ------------------------------------------------------------------------------------------------------------------------ http://opensource.atlassian.com/projects/hibernate/browse/HHH/fixforversion/11161 From 484d5e2fbba09c75d30c9a1c15861451b5eeb763 Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Wed, 6 Apr 2011 16:28:39 -0500 Subject: [PATCH 14/15] prepare 4.0.0.Alpha2 release --- .../org/hibernate/testing/junit4/CustomRunner.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/junit4/CustomRunner.java b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/CustomRunner.java index 7f16dd3c39..a698e3345b 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/junit4/CustomRunner.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/CustomRunner.java @@ -165,7 +165,17 @@ public class CustomRunner extends BlockJUnit4ClassRunner { } } - private static Dialect dialect = Dialect.getDialect(); + private static Dialect dialect = determineDialect(); + + private static Dialect determineDialect() { + try { + return Dialect.getDialect(); + } + catch( Exception e ) { + return new Dialect() { + }; + } + } protected Ignore convertSkipToIgnore(FrameworkMethod frameworkMethod) { // @Skip From 5408dac36bdbce25f580827140bedbc3c3ba7f65 Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Wed, 6 Apr 2011 17:36:47 -0500 Subject: [PATCH 15/15] prepare for 4.0.0.Alpha3 development --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 716ad71278..0646f16e94 100644 --- a/build.gradle +++ b/build.gradle @@ -91,7 +91,7 @@ subprojects { subProject -> defaultTasks 'build' group = 'org.hibernate' - version = '4.0.0.Alpha2' + version = '4.0.0-SNAPSHOT' // minimize changes, at least for now (gradle uses 'build' by default).. buildDir = "target"