HHH-7692 Use Postgres82Dialect for 9 and 9.1.
This commit is contained in:
parent
0695e22d41
commit
0916baf2f8
|
@ -87,7 +87,7 @@ public class StandardDialectResolver extends AbstractDialectResolver {
|
||||||
|
|
||||||
if ( "PostgreSQL".equals( databaseName ) ) {
|
if ( "PostgreSQL".equals( databaseName ) ) {
|
||||||
final int databaseMinorVersion = metaData.getDatabaseMinorVersion();
|
final int databaseMinorVersion = metaData.getDatabaseMinorVersion();
|
||||||
if (databaseMajorVersion >= 8 && databaseMinorVersion >= 2) {
|
if ( databaseMajorVersion > 8 || ( databaseMajorVersion == 8 && databaseMinorVersion >= 2 ) ) {
|
||||||
return new PostgreSQL82Dialect();
|
return new PostgreSQL82Dialect();
|
||||||
}
|
}
|
||||||
return new PostgreSQL81Dialect();
|
return new PostgreSQL81Dialect();
|
||||||
|
@ -110,7 +110,7 @@ public class StandardDialectResolver extends AbstractDialectResolver {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( "ingres".equalsIgnoreCase( databaseName ) ) {
|
if ( "ingres".equalsIgnoreCase( databaseName ) ) {
|
||||||
switch( databaseMajorVersion ) {
|
switch ( databaseMajorVersion ) {
|
||||||
case 9:
|
case 9:
|
||||||
int databaseMinorVersion = metaData.getDatabaseMinorVersion();
|
int databaseMinorVersion = metaData.getDatabaseMinorVersion();
|
||||||
if (databaseMinorVersion > 2) {
|
if (databaseMinorVersion > 2) {
|
||||||
|
|
|
@ -33,6 +33,8 @@ import java.sql.DatabaseMetaData;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
import org.hibernate.dialect.Dialect;
|
import org.hibernate.dialect.Dialect;
|
||||||
|
import org.hibernate.dialect.PostgreSQL81Dialect;
|
||||||
|
import org.hibernate.dialect.PostgreSQL82Dialect;
|
||||||
import org.hibernate.dialect.SQLServer2005Dialect;
|
import org.hibernate.dialect.SQLServer2005Dialect;
|
||||||
import org.hibernate.dialect.SQLServer2008Dialect;
|
import org.hibernate.dialect.SQLServer2008Dialect;
|
||||||
import org.hibernate.dialect.SQLServerDialect;
|
import org.hibernate.dialect.SQLServerDialect;
|
||||||
|
@ -72,6 +74,41 @@ public class StandardDialectResolverTest extends BaseUnitTestCase {
|
||||||
runSQLServerDialectTest(7, SQLServerDialect.class);
|
runSQLServerDialectTest(7, SQLServerDialect.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testResolveDialectInternalForPostgres81() throws SQLException {
|
||||||
|
runPostgresDialectTest(8, 1, PostgreSQL81Dialect.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testResolveDialectInternalForPostgres82() throws SQLException {
|
||||||
|
runPostgresDialectTest(8, 2, PostgreSQL82Dialect.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testResolveDialectInternalForPostgres83() throws SQLException {
|
||||||
|
runPostgresDialectTest(8, 3, PostgreSQL82Dialect.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testResolveDialectInternalForPostgres84() throws SQLException {
|
||||||
|
runPostgresDialectTest(8, 4, PostgreSQL82Dialect.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testResolveDialectInternalForPostgres9() throws SQLException {
|
||||||
|
runPostgresDialectTest(9, 0, PostgreSQL82Dialect.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testResolveDialectInternalForPostgres91() throws SQLException {
|
||||||
|
runPostgresDialectTest(9, 1, PostgreSQL82Dialect.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testResolveDialectInternalForPostgres92() throws SQLException {
|
||||||
|
runPostgresDialectTest(9, 2, PostgreSQL82Dialect.class);
|
||||||
|
}
|
||||||
|
|
||||||
private static void runSQLServerDialectTest(int version, Class<? extends SQLServerDialect> expectedDialect)
|
private static void runSQLServerDialectTest(int version, Class<? extends SQLServerDialect> expectedDialect)
|
||||||
throws SQLException {
|
throws SQLException {
|
||||||
DatabaseMetaData metaData = mock(DatabaseMetaData.class);
|
DatabaseMetaData metaData = mock(DatabaseMetaData.class);
|
||||||
|
@ -83,4 +120,31 @@ public class StandardDialectResolverTest extends BaseUnitTestCase {
|
||||||
assertTrue("Dialect for SQL Server version " + version + " should be " + expectedDialect.getSimpleName(),
|
assertTrue("Dialect for SQL Server version " + version + " should be " + expectedDialect.getSimpleName(),
|
||||||
expectedDialect.isInstance(dialect));
|
expectedDialect.isInstance(dialect));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void runPostgresDialectTest(int majorVersion, int minorVersion,
|
||||||
|
Class<? extends Dialect> expectedDialect) throws SQLException {
|
||||||
|
runDialectTest("PostgreSQL", majorVersion, minorVersion, expectedDialect);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void runDialectTest(String productName, int majorVersion, int minorVersion,
|
||||||
|
Class<? extends Dialect> expectedDialect) throws SQLException {
|
||||||
|
DatabaseMetaData metaData = mock(DatabaseMetaData.class);
|
||||||
|
when(metaData.getDatabaseProductName()).thenReturn(productName);
|
||||||
|
when(metaData.getDatabaseMajorVersion()).thenReturn(majorVersion);
|
||||||
|
when(metaData.getDatabaseMinorVersion()).thenReturn(minorVersion);
|
||||||
|
|
||||||
|
Dialect dialect = new StandardDialectResolver().resolveDialect(metaData);
|
||||||
|
|
||||||
|
StringBuilder builder = new StringBuilder(productName)
|
||||||
|
.append(" ")
|
||||||
|
.append(majorVersion);
|
||||||
|
if (minorVersion > 0) {
|
||||||
|
builder.append(".").append(minorVersion);
|
||||||
|
}
|
||||||
|
String dbms = builder.toString();
|
||||||
|
|
||||||
|
assertNotNull("Dialect for " + dbms + " should not be null", dialect);
|
||||||
|
assertTrue("Dialect for " + dbms + " should be " + expectedDialect.getSimpleName(),
|
||||||
|
expectedDialect.isInstance(dialect));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue