From d35e29dc29d7bf1e85c0dbcc2ef49349914fd57b Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Wed, 13 Jan 2016 16:13:14 +0000 Subject: [PATCH] HHH-10433 - Fix hbm2ddl utils has a problem - release jdbc connection --- .../java/org/hibernate/tool/hbm2ddl/SchemaUpdate.java | 7 ++++++- .../org/hibernate/tool/hbm2ddl/SchemaValidator.java | 10 +++++++--- .../extract/internal/DatabaseInformationImpl.java | 5 +++++ .../schema/extract/internal/ExtractionContextImpl.java | 1 + .../tool/schema/extract/spi/DatabaseInformation.java | 2 ++ .../tool/schema/extract/spi/ExtractionContext.java | 2 ++ 6 files changed, 23 insertions(+), 4 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/tool/hbm2ddl/SchemaUpdate.java b/hibernate-core/src/main/java/org/hibernate/tool/hbm2ddl/SchemaUpdate.java index 90e40ef05d..7d505c1bfe 100644 --- a/hibernate-core/src/main/java/org/hibernate/tool/hbm2ddl/SchemaUpdate.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/hbm2ddl/SchemaUpdate.java @@ -130,7 +130,12 @@ public class SchemaUpdate { ); } - schemaMigrator.doMigration( metadata, databaseInformation, true, toolTargets ); + try { + schemaMigrator.doMigration( metadata, databaseInformation, true, toolTargets ); + } + finally { + databaseInformation.cleanup(); + } } private List buildToolTargets(Target target) { diff --git a/hibernate-core/src/main/java/org/hibernate/tool/hbm2ddl/SchemaValidator.java b/hibernate-core/src/main/java/org/hibernate/tool/hbm2ddl/SchemaValidator.java index e995fbce96..9973423e4a 100755 --- a/hibernate-core/src/main/java/org/hibernate/tool/hbm2ddl/SchemaValidator.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/hbm2ddl/SchemaValidator.java @@ -86,9 +86,13 @@ public class SchemaValidator { "Error creating DatabaseInformation for schema validation" ); } - - serviceRegistry.getService( SchemaManagementTool.class ).getSchemaValidator( cfgService.getSettings() ) - .doValidation( metadata, databaseInformation ); + try { + serviceRegistry.getService( SchemaManagementTool.class ).getSchemaValidator( cfgService.getSettings() ) + .doValidation( metadata, databaseInformation ); + } + finally { + databaseInformation.cleanup(); + } } public static void main(String[] args) { diff --git a/hibernate-core/src/main/java/org/hibernate/tool/schema/extract/internal/DatabaseInformationImpl.java b/hibernate-core/src/main/java/org/hibernate/tool/schema/extract/internal/DatabaseInformationImpl.java index 446157a6c6..1dab55e267 100644 --- a/hibernate-core/src/main/java/org/hibernate/tool/schema/extract/internal/DatabaseInformationImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/schema/extract/internal/DatabaseInformationImpl.java @@ -152,4 +152,9 @@ public class DatabaseInformationImpl implements DatabaseInformation, ExtractionC return sequenceInformationMap.get( sequenceName ); } + + @Override + public void cleanup() { + extractionContext.cleanup(); + } } diff --git a/hibernate-core/src/main/java/org/hibernate/tool/schema/extract/internal/ExtractionContextImpl.java b/hibernate-core/src/main/java/org/hibernate/tool/schema/extract/internal/ExtractionContextImpl.java index 6fcb66fd7a..9da18060d2 100644 --- a/hibernate-core/src/main/java/org/hibernate/tool/schema/extract/internal/ExtractionContextImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/schema/extract/internal/ExtractionContextImpl.java @@ -96,6 +96,7 @@ public class ExtractionContextImpl implements ExtractionContext { return registeredTableAccess; } + @Override public void cleanup() { if ( jdbcDatabaseMetaData != null ) { jdbcDatabaseMetaData = null; diff --git a/hibernate-core/src/main/java/org/hibernate/tool/schema/extract/spi/DatabaseInformation.java b/hibernate-core/src/main/java/org/hibernate/tool/schema/extract/spi/DatabaseInformation.java index 338538d679..7a9e5154d8 100644 --- a/hibernate-core/src/main/java/org/hibernate/tool/schema/extract/spi/DatabaseInformation.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/schema/extract/spi/DatabaseInformation.java @@ -101,4 +101,6 @@ public interface DatabaseInformation { * @return {@code true} indicates a catalog with the given name already exists */ boolean catalogExists(Identifier catalog); + + void cleanup(); } diff --git a/hibernate-core/src/main/java/org/hibernate/tool/schema/extract/spi/ExtractionContext.java b/hibernate-core/src/main/java/org/hibernate/tool/schema/extract/spi/ExtractionContext.java index 8a9d3a9a90..afdf6f97c2 100644 --- a/hibernate-core/src/main/java/org/hibernate/tool/schema/extract/spi/ExtractionContext.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/schema/extract/spi/ExtractionContext.java @@ -40,4 +40,6 @@ public interface ExtractionContext { } DatabaseObjectAccess getDatabaseObjectAccess(); + + void cleanup(); }