diff --git a/hibernate-core/src/main/java/org/hibernate/hql/internal/ast/ErrorCounter.java b/hibernate-core/src/main/java/org/hibernate/hql/internal/ast/ErrorCounter.java index bee855397e..9a28c8e3dd 100644 --- a/hibernate-core/src/main/java/org/hibernate/hql/internal/ast/ErrorCounter.java +++ b/hibernate-core/src/main/java/org/hibernate/hql/internal/ast/ErrorCounter.java @@ -40,9 +40,9 @@ public class ErrorCounter implements ParseErrorHandler { private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class, ErrorCounter.class.getName()); - private List errorList = new ArrayList(); - private List warningList = new ArrayList(); - private List recognitionExceptions = new ArrayList(); + private List errorList = new ArrayList(); + private List warningList = new ArrayList(); + private List recognitionExceptions = new ArrayList(); public void reportError(RecognitionException e) { reportError( e.toString() ); @@ -66,8 +66,8 @@ public class ErrorCounter implements ParseErrorHandler { private String getErrorString() { StringBuilder buf = new StringBuilder(); - for ( Iterator iterator = errorList.iterator(); iterator.hasNext(); ) { - buf.append( ( String ) iterator.next() ); + for ( Iterator iterator = errorList.iterator(); iterator.hasNext(); ) { + buf.append( iterator.next() ); if ( iterator.hasNext() ) buf.append( "\n" ); } @@ -76,7 +76,7 @@ public class ErrorCounter implements ParseErrorHandler { public void throwQueryException() throws QueryException { if ( getErrorCount() > 0 ) { - if (recognitionExceptions.size() > 0) throw QuerySyntaxException.convert((RecognitionException)recognitionExceptions.get(0)); + if (recognitionExceptions.size() > 0) throw QuerySyntaxException.convert(recognitionExceptions.get(0)); throw new QueryException(getErrorString()); } LOG.debug("throwQueryException() : no errors"); diff --git a/hibernate-core/src/test/java/org/hibernate/id/SequenceHiLoGeneratorNoIncrementTest.java b/hibernate-core/src/test/java/org/hibernate/id/SequenceHiLoGeneratorNoIncrementTest.java index fe81d34d56..97fd6f959e 100644 --- a/hibernate-core/src/test/java/org/hibernate/id/SequenceHiLoGeneratorNoIncrementTest.java +++ b/hibernate-core/src/test/java/org/hibernate/id/SequenceHiLoGeneratorNoIncrementTest.java @@ -32,7 +32,7 @@ import java.sql.SQLException; import java.util.Properties; import org.hibernate.Session; -import org.hibernate.TestingDatabaseInfo; +import org.hibernate.testing.env.TestingDatabaseInfo; import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Environment; import org.hibernate.cfg.NamingStrategy; @@ -88,7 +88,7 @@ public class SequenceHiLoGeneratorNoIncrementTest extends BaseUnitTestCase { } ); - Dialect dialect = new H2Dialect(); + Dialect dialect = TestingDatabaseInfo.DIALECT; generator = new SequenceHiLoGenerator(); generator.configure( StandardBasicTypes.LONG, properties, dialect ); diff --git a/hibernate-core/src/test/java/org/hibernate/id/SequenceHiLoGeneratorTest.java b/hibernate-core/src/test/java/org/hibernate/id/SequenceHiLoGeneratorTest.java index 6fe9ff8064..7239297ff7 100644 --- a/hibernate-core/src/test/java/org/hibernate/id/SequenceHiLoGeneratorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/id/SequenceHiLoGeneratorTest.java @@ -32,7 +32,7 @@ import java.sql.SQLException; import java.util.Properties; import org.hibernate.Session; -import org.hibernate.TestingDatabaseInfo; +import org.hibernate.testing.env.TestingDatabaseInfo; import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Environment; import org.hibernate.cfg.NamingStrategy; @@ -84,7 +84,7 @@ public class SequenceHiLoGeneratorTest extends BaseUnitTestCase { } } ); - Dialect dialect = new H2Dialect(); + Dialect dialect = TestingDatabaseInfo.DIALECT; generator = new SequenceHiLoGenerator(); generator.configure( StandardBasicTypes.LONG, properties, dialect ); diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/relational/ObjectNameTests.java b/hibernate-core/src/test/java/org/hibernate/metamodel/relational/ObjectNameTests.java index 30b2f2d10d..d974b8d942 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/relational/ObjectNameTests.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/relational/ObjectNameTests.java @@ -27,6 +27,7 @@ import org.junit.Test; import org.hibernate.dialect.Dialect; import org.hibernate.dialect.H2Dialect; +import org.hibernate.testing.env.TestingDatabaseInfo; import org.hibernate.testing.junit4.BaseUnitTestCase; import static org.junit.Assert.assertEquals; @@ -55,7 +56,7 @@ public class ObjectNameTests extends BaseUnitTestCase { @Test public void testIdentifierBuilding() { - Dialect dialect = new H2Dialect(); + Dialect dialect = TestingDatabaseInfo.DIALECT; ObjectName on = new ObjectName( "schema", "catalog", "name" ); assertEquals( "schema.catalog.name", on.toText() ); on = new ObjectName( "schema", null, "name" ); diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/relational/TableManipulationTests.java b/hibernate-core/src/test/java/org/hibernate/metamodel/relational/TableManipulationTests.java index 6974fff0e2..69fdc683b4 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/relational/TableManipulationTests.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/relational/TableManipulationTests.java @@ -29,6 +29,7 @@ import org.junit.Test; import org.hibernate.dialect.Dialect; import org.hibernate.dialect.H2Dialect; +import org.hibernate.testing.env.TestingDatabaseInfo; import org.hibernate.testing.junit4.BaseUnitTestCase; import static org.junit.Assert.assertEquals; @@ -133,7 +134,7 @@ public class TableManipulationTests extends BaseUnitTestCase { @Test public void testQualifiedName() { - Dialect dialect = new H2Dialect(); + Dialect dialect = TestingDatabaseInfo.DIALECT; Schema schema = new Schema( Identifier.toIdentifier( "schema" ), Identifier.toIdentifier( "`catalog`" ) ); Table table = schema.createTable( Identifier.toIdentifier( "my_table" ) ); assertEquals( "my_table", table.getTableName().getName() ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/backquotes/BackquoteTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/backquotes/BackquoteTest.java index a3eb378aee..d048ea4591 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/backquotes/BackquoteTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/backquotes/BackquoteTest.java @@ -59,6 +59,12 @@ public class BackquoteTest extends BaseUnitTestCase { log.debug(writer.toString()); fail(e.getMessage()); } + finally { + if ( sessionFactory != null ) { + sessionFactory.close(); + sessionFactory = null; + } + } } /** @@ -87,6 +93,11 @@ public class BackquoteTest extends BaseUnitTestCase { e.printStackTrace(new PrintWriter(writer)); log.debug(writer.toString()); fail(e.getMessage()); - } + } finally { + if(sessionFactory!=null){ + sessionFactory.close(); + sessionFactory = null; + } + } } } diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/onetoone/primarykey/NullablePrimaryKeyTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/onetoone/primarykey/NullablePrimaryKeyTest.java index 27325d900b..be6ce4e9e7 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/onetoone/primarykey/NullablePrimaryKeyTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/onetoone/primarykey/NullablePrimaryKeyTest.java @@ -5,6 +5,7 @@ import org.jboss.logging.Logger; import org.junit.Assert; import org.junit.Test; +import org.hibernate.SessionFactory; import org.hibernate.cfg.AnnotationConfiguration; import org.hibernate.cfg.Environment; import org.hibernate.dialect.SQLServerDialect; @@ -23,12 +24,13 @@ public class NullablePrimaryKeyTest { public void testGeneratedSql() { ServiceRegistry serviceRegistry = null; + SessionFactory sf = null; try { AnnotationConfiguration config = new AnnotationConfiguration(); config.addAnnotatedClass(Address.class); config.addAnnotatedClass(Person.class); serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( Environment.getProperties() ); - config.buildSessionFactory( serviceRegistry ); + sf = config.buildSessionFactory( serviceRegistry ); String[] schema = config .generateSchemaCreationScript(new SQLServerDialect()); for (String s : schema) { @@ -41,9 +43,13 @@ public class NullablePrimaryKeyTest { Assert.fail(e.getMessage()); } finally { + if ( sf != null ) { + sf.close(); + } if ( serviceRegistry != null ) { ServiceRegistryBuilder.destroy( serviceRegistry ); } + } } } diff --git a/hibernate-core/src/test/java/org/hibernate/test/instrument/cases/AbstractExecutable.java b/hibernate-core/src/test/java/org/hibernate/test/instrument/cases/AbstractExecutable.java index 0c3d0f7e35..4bb9df9a91 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/instrument/cases/AbstractExecutable.java +++ b/hibernate-core/src/test/java/org/hibernate/test/instrument/cases/AbstractExecutable.java @@ -30,8 +30,10 @@ public abstract class AbstractExecutable implements Executable { } finally { factory.close(); + factory = null; if ( serviceRegistry != null ) { ServiceRegistryBuilder.destroy( serviceRegistry ); + serviceRegistry = null; } } } diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/env/ConnectionProviderBuilder.java b/hibernate-testing/src/main/java/org/hibernate/testing/env/ConnectionProviderBuilder.java index e7aef85b82..e236e88c9b 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/env/ConnectionProviderBuilder.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/env/ConnectionProviderBuilder.java @@ -77,6 +77,6 @@ public class ConnectionProviderBuilder { } public static Dialect getCorrespondingDialect() { - return new H2Dialect(); + return TestingDatabaseInfo.DIALECT; } } diff --git a/hibernate-core/src/test/java/org/hibernate/TestingDatabaseInfo.java b/hibernate-testing/src/main/java/org/hibernate/testing/env/TestingDatabaseInfo.java similarity index 98% rename from hibernate-core/src/test/java/org/hibernate/TestingDatabaseInfo.java rename to hibernate-testing/src/main/java/org/hibernate/testing/env/TestingDatabaseInfo.java index 8102fbeef5..7ce98e701f 100644 --- a/hibernate-core/src/test/java/org/hibernate/TestingDatabaseInfo.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/env/TestingDatabaseInfo.java @@ -21,7 +21,7 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate; +package org.hibernate.testing.env; import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Environment;