From edf1fa9fbcc8346b15459a7ed49915df1a3a048c Mon Sep 17 00:00:00 2001 From: Brett Meyer Date: Sun, 23 Jun 2013 13:17:05 -0400 Subject: [PATCH] HHH-8331 Create PostgreSQL9Dialect --- .../internal/StrategySelectorBuilder.java | 4 ++- .../hibernate/dialect/PostgreSQL9Dialect.java | 36 +++++++++++++++++++ .../StandardDatabaseInfoDialectResolver.java | 11 +++--- .../dialect/resolver/DialectFactoryTest.java | 14 ++++---- ...rdDatabaseMetaDataDialectResolverTest.java | 7 ++-- 5 files changed, 56 insertions(+), 16 deletions(-) create mode 100644 hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL9Dialect.java diff --git a/hibernate-core/src/main/java/org/hibernate/boot/registry/selector/internal/StrategySelectorBuilder.java b/hibernate-core/src/main/java/org/hibernate/boot/registry/selector/internal/StrategySelectorBuilder.java index 2a9f1c56f7..57a16987ea 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/registry/selector/internal/StrategySelectorBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/registry/selector/internal/StrategySelectorBuilder.java @@ -27,9 +27,9 @@ import java.util.ArrayList; import java.util.List; import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; +import org.hibernate.boot.registry.selector.SimpleStrategyRegistrationImpl; import org.hibernate.boot.registry.selector.StrategyRegistration; import org.hibernate.boot.registry.selector.StrategyRegistrationProvider; -import org.hibernate.boot.registry.selector.SimpleStrategyRegistrationImpl; import org.hibernate.boot.registry.selector.spi.StrategySelectionException; import org.hibernate.boot.registry.selector.spi.StrategySelector; import org.hibernate.dialect.CUBRIDDialect; @@ -61,6 +61,7 @@ import org.hibernate.dialect.Oracle9iDialect; import org.hibernate.dialect.PointbaseDialect; import org.hibernate.dialect.PostgreSQL81Dialect; import org.hibernate.dialect.PostgreSQL82Dialect; +import org.hibernate.dialect.PostgreSQL9Dialect; import org.hibernate.dialect.PostgresPlusDialect; import org.hibernate.dialect.ProgressDialect; import org.hibernate.dialect.SAPDBDialect; @@ -219,6 +220,7 @@ public class StrategySelectorBuilder { addDialect( strategySelector, PostgresPlusDialect.class ); addDialect( strategySelector, PostgreSQL81Dialect.class ); addDialect( strategySelector, PostgreSQL82Dialect.class ); + addDialect( strategySelector, PostgreSQL9Dialect.class ); addDialect( strategySelector, ProgressDialect.class ); addDialect( strategySelector, SAPDBDialect.class ); addDialect( strategySelector, SQLServerDialect.class ); diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL9Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL9Dialect.java new file mode 100644 index 0000000000..d1908e96fb --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL9Dialect.java @@ -0,0 +1,36 @@ +/* + * 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; + +/** + * An SQL dialect for Postgres 9 and later. Adds support for "if exists" when dropping constraints + * + * @author edalquist + */ +public class PostgreSQL9Dialect extends PostgreSQL81Dialect { + @Override + public boolean supportsIfExistsBeforeConstraintName() { + return true; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/dialect/internal/StandardDatabaseInfoDialectResolver.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/dialect/internal/StandardDatabaseInfoDialectResolver.java index 6b70e520b3..60bf5c1e02 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/dialect/internal/StandardDatabaseInfoDialectResolver.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/dialect/internal/StandardDatabaseInfoDialectResolver.java @@ -23,8 +23,6 @@ */ package org.hibernate.engine.jdbc.dialect.internal; -import org.jboss.logging.Logger; - import org.hibernate.dialect.CUBRIDDialect; import org.hibernate.dialect.DB2400Dialect; import org.hibernate.dialect.DB2Dialect; @@ -45,6 +43,7 @@ import org.hibernate.dialect.Oracle8iDialect; import org.hibernate.dialect.Oracle9iDialect; import org.hibernate.dialect.PostgreSQL81Dialect; import org.hibernate.dialect.PostgreSQL82Dialect; +import org.hibernate.dialect.PostgreSQL9Dialect; import org.hibernate.dialect.SQLServer2005Dialect; import org.hibernate.dialect.SQLServer2008Dialect; import org.hibernate.dialect.SQLServerDialect; @@ -52,6 +51,7 @@ import org.hibernate.dialect.SybaseASE15Dialect; import org.hibernate.dialect.SybaseAnywhereDialect; import org.hibernate.engine.jdbc.dialect.spi.DatabaseInfoDialectResolver; import org.hibernate.internal.CoreMessageLogger; +import org.jboss.logging.Logger; /** * The standard DatabaseInfoDialectResolver implementation @@ -93,10 +93,11 @@ public class StandardDatabaseInfoDialectResolver implements DatabaseInfoDialectR final int majorVersion = databaseInfo.getDatabaseMajorVersion(); final int minorVersion = databaseInfo.getDatabaseMinorVersion(); - if ( majorVersion > 8 || ( majorVersion == 8 && minorVersion >= 2 ) ) { - return new PostgreSQL82Dialect(); + if ( majorVersion == 8 ) { + return minorVersion >= 2 ? new PostgreSQL82Dialect() : new PostgreSQL81Dialect(); } - return new PostgreSQL81Dialect(); + + return new PostgreSQL9Dialect(); } if ( "Apache Derby".equals( databaseName ) ) { 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 71a937875e..4cab9a4017 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 @@ -23,6 +23,10 @@ */ package org.hibernate.dialect.resolver; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; + import java.sql.Connection; import java.util.Collections; import java.util.HashMap; @@ -51,6 +55,7 @@ import org.hibernate.dialect.Oracle8iDialect; import org.hibernate.dialect.Oracle9iDialect; import org.hibernate.dialect.PostgreSQL81Dialect; import org.hibernate.dialect.PostgreSQL82Dialect; +import org.hibernate.dialect.PostgreSQL9Dialect; import org.hibernate.dialect.SQLServerDialect; import org.hibernate.dialect.SybaseASE15Dialect; import org.hibernate.dialect.SybaseAnywhereDialect; @@ -60,16 +65,10 @@ import org.hibernate.engine.jdbc.dialect.internal.DialectResolverSet; import org.hibernate.engine.jdbc.dialect.internal.StandardDatabaseInfoDialectResolver; import org.hibernate.engine.jdbc.dialect.internal.StandardDatabaseMetaDataDialectResolver; import org.hibernate.engine.jdbc.dialect.spi.DialectResolver; - +import org.hibernate.testing.junit4.BaseUnitTestCase; import org.junit.Before; import org.junit.Test; -import org.hibernate.testing.junit4.BaseUnitTestCase; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.fail; - /** * @author Steve Ebersole */ @@ -148,6 +147,7 @@ public class DialectFactoryTest extends BaseUnitTestCase { testDetermination( "MySQL", MySQLDialect.class, resolver ); testDetermination( "PostgreSQL", PostgreSQL81Dialect.class, resolver ); testDetermination( "PostgreSQL", 8, 2, PostgreSQL82Dialect.class, resolver ); + testDetermination( "PostgreSQL", 9, 0, PostgreSQL9Dialect.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 ); diff --git a/hibernate-core/src/test/java/org/hibernate/engine/jdbc/dialect/internal/StandardDatabaseMetaDataDialectResolverTest.java b/hibernate-core/src/test/java/org/hibernate/engine/jdbc/dialect/internal/StandardDatabaseMetaDataDialectResolverTest.java index 12f711da00..6d918518ab 100644 --- a/hibernate-core/src/test/java/org/hibernate/engine/jdbc/dialect/internal/StandardDatabaseMetaDataDialectResolverTest.java +++ b/hibernate-core/src/test/java/org/hibernate/engine/jdbc/dialect/internal/StandardDatabaseMetaDataDialectResolverTest.java @@ -35,6 +35,7 @@ import java.sql.SQLException; import org.hibernate.dialect.Dialect; import org.hibernate.dialect.PostgreSQL81Dialect; import org.hibernate.dialect.PostgreSQL82Dialect; +import org.hibernate.dialect.PostgreSQL9Dialect; import org.hibernate.dialect.SQLServer2005Dialect; import org.hibernate.dialect.SQLServer2008Dialect; import org.hibernate.dialect.SQLServerDialect; @@ -102,17 +103,17 @@ public class StandardDatabaseMetaDataDialectResolverTest extends BaseUnitTestCas @Test public void testResolveDialectInternalForPostgres9() throws SQLException { - runPostgresDialectTest( 9, 0, PostgreSQL82Dialect.class ); + runPostgresDialectTest( 9, 0, PostgreSQL9Dialect.class ); } @Test public void testResolveDialectInternalForPostgres91() throws SQLException { - runPostgresDialectTest( 9, 1, PostgreSQL82Dialect.class ); + runPostgresDialectTest( 9, 1, PostgreSQL9Dialect.class ); } @Test public void testResolveDialectInternalForPostgres92() throws SQLException { - runPostgresDialectTest( 9, 2, PostgreSQL82Dialect.class ); + runPostgresDialectTest( 9, 2, PostgreSQL9Dialect.class ); } private static void runSQLServerDialectTest(