HHH-13225 Fix minorVersionToMatch comparison in BasicDialectResolver
This commit is contained in:
parent
103629ee87
commit
5fde418a0d
|
@ -51,7 +51,11 @@ public class BasicDialectResolver implements DialectResolver {
|
||||||
* @param majorVersionToMatch The version of the driver to match on
|
* @param majorVersionToMatch The version of the driver to match on
|
||||||
* @param dialectClass The Dialect class to use on match
|
* @param dialectClass The Dialect class to use on match
|
||||||
*/
|
*/
|
||||||
public BasicDialectResolver(String nameToMatch, int majorVersionToMatch, int minorVersionToMatch, Class dialectClass) {
|
public BasicDialectResolver(
|
||||||
|
String nameToMatch,
|
||||||
|
int majorVersionToMatch,
|
||||||
|
int minorVersionToMatch,
|
||||||
|
Class<? extends Dialect> dialectClass) {
|
||||||
this.nameToMatch = nameToMatch;
|
this.nameToMatch = nameToMatch;
|
||||||
this.majorVersionToMatch = majorVersionToMatch;
|
this.majorVersionToMatch = majorVersionToMatch;
|
||||||
this.minorVersionToMatch = minorVersionToMatch;
|
this.minorVersionToMatch = minorVersionToMatch;
|
||||||
|
@ -66,15 +70,15 @@ public class BasicDialectResolver implements DialectResolver {
|
||||||
|
|
||||||
if ( nameToMatch.equalsIgnoreCase( databaseName )
|
if ( nameToMatch.equalsIgnoreCase( databaseName )
|
||||||
&& ( majorVersionToMatch == NO_VERSION || majorVersionToMatch == databaseMajorVersion )
|
&& ( majorVersionToMatch == NO_VERSION || majorVersionToMatch == databaseMajorVersion )
|
||||||
&& ( minorVersionToMatch == NO_VERSION || majorVersionToMatch == databaseMinorVersion ) ) {
|
&& ( minorVersionToMatch == NO_VERSION || minorVersionToMatch == databaseMinorVersion ) ) {
|
||||||
try {
|
try {
|
||||||
return (Dialect) dialectClass.newInstance();
|
return (Dialect) dialectClass.newInstance();
|
||||||
}
|
}
|
||||||
catch ( HibernateException e ) {
|
catch (HibernateException e) {
|
||||||
// conceivable that the dialect ctor could throw HibernateExceptions, so don't re-wrap
|
// conceivable that the dialect ctor could throw HibernateExceptions, so don't re-wrap
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
catch ( Throwable t ) {
|
catch (Throwable t) {
|
||||||
throw new HibernateException(
|
throw new HibernateException(
|
||||||
"Could not instantiate specified Dialect class [" + dialectClass.getName() + "]",
|
"Could not instantiate specified Dialect class [" + dialectClass.getName() + "]",
|
||||||
t
|
t
|
||||||
|
|
|
@ -24,6 +24,12 @@ public class TestingDialects {
|
||||||
public static class MyDialect22 extends Dialect {
|
public static class MyDialect22 extends Dialect {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class MyDialect311 extends Dialect {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class MyDialect312 extends Dialect {
|
||||||
|
}
|
||||||
|
|
||||||
public static class MySpecialDB2Dialect extends Dialect {
|
public static class MySpecialDB2Dialect extends Dialect {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,21 +6,18 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.dialect.resolver;
|
package org.hibernate.dialect.resolver;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
|
|
||||||
import org.hibernate.dialect.Dialect;
|
import org.hibernate.dialect.Dialect;
|
||||||
import org.hibernate.dialect.TestingDialects;
|
import org.hibernate.dialect.TestingDialects;
|
||||||
import org.hibernate.engine.jdbc.dialect.internal.DialectResolverSet;
|
import org.hibernate.engine.jdbc.dialect.internal.DialectResolverSet;
|
||||||
import org.hibernate.engine.jdbc.dialect.spi.BasicDialectResolver;
|
import org.hibernate.engine.jdbc.dialect.spi.BasicDialectResolver;
|
||||||
|
import org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo;
|
||||||
import org.hibernate.engine.jdbc.dialect.spi.DialectResolver;
|
import org.hibernate.engine.jdbc.dialect.spi.DialectResolver;
|
||||||
import org.hibernate.exception.JDBCConnectionException;
|
import org.hibernate.testing.TestForIssue;
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||||
|
import org.junit.Test;
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.fail;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
|
@ -46,6 +43,7 @@ public class DialectResolverTest extends BaseUnitTestCase {
|
||||||
@Test
|
@Test
|
||||||
public void testErrorAndOrder() throws Exception {
|
public void testErrorAndOrder() throws Exception {
|
||||||
DialectResolverSet resolvers = new DialectResolverSet();
|
DialectResolverSet resolvers = new DialectResolverSet();
|
||||||
|
|
||||||
resolvers.addResolverAtFirst( new TestingDialects.MyDialectResolver1() );
|
resolvers.addResolverAtFirst( new TestingDialects.MyDialectResolver1() );
|
||||||
resolvers.addResolver( new TestingDialects.MyDialectResolver2() );
|
resolvers.addResolver( new TestingDialects.MyDialectResolver2() );
|
||||||
|
|
||||||
|
@ -62,25 +60,56 @@ public class DialectResolverTest extends BaseUnitTestCase {
|
||||||
resolvers.addResolver( new BasicDialectResolver( "MyDatabase1", TestingDialects.MyDialect1.class ) );
|
resolvers.addResolver( new BasicDialectResolver( "MyDatabase1", TestingDialects.MyDialect1.class ) );
|
||||||
resolvers.addResolver( new BasicDialectResolver( "MyDatabase2", 1, TestingDialects.MyDialect21.class ) );
|
resolvers.addResolver( new BasicDialectResolver( "MyDatabase2", 1, TestingDialects.MyDialect21.class ) );
|
||||||
resolvers.addResolver( new BasicDialectResolver( "MyDatabase2", 2, TestingDialects.MyDialect22.class ) );
|
resolvers.addResolver( new BasicDialectResolver( "MyDatabase2", 2, TestingDialects.MyDialect22.class ) );
|
||||||
resolvers.addResolver( new BasicDialectResolver( "ErrorDatabase1", Object.class ) );
|
resolvers.addResolver( new BasicDialectResolver( "ErrorDatabase1", Dialect.class ) );
|
||||||
testDetermination( resolvers, "MyDatabase1", 1, TestingDialects.MyDialect1.class );
|
|
||||||
|
|
||||||
|
testDetermination( resolvers, "MyDatabase1", 1, TestingDialects.MyDialect1.class );
|
||||||
testDetermination( resolvers, "MyDatabase1", 2, TestingDialects.MyDialect1.class );
|
testDetermination( resolvers, "MyDatabase1", 2, TestingDialects.MyDialect1.class );
|
||||||
|
|
||||||
testDetermination( resolvers, "MyDatabase2", 0, null );
|
testDetermination( resolvers, "MyDatabase2", 0, null );
|
||||||
testDetermination( resolvers, "MyDatabase2", 1, TestingDialects.MyDialect21.class );
|
testDetermination( resolvers, "MyDatabase2", 1, TestingDialects.MyDialect21.class );
|
||||||
testDetermination( resolvers, "MyDatabase2", 2, TestingDialects.MyDialect22.class );
|
testDetermination( resolvers, "MyDatabase2", 2, TestingDialects.MyDialect22.class );
|
||||||
|
|
||||||
testDetermination( resolvers, "ErrorDatabase1", 0, null );
|
testDetermination( resolvers, "ErrorDatabase1", 0, null );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestForIssue(jiraKey = "HHH-13225")
|
||||||
|
public void testMinorVersion() {
|
||||||
|
DialectResolverSet resolvers = new DialectResolverSet();
|
||||||
|
resolvers.addResolver( new BasicDialectResolver( "MyDatabase1", TestingDialects.MyDialect1.class ) );
|
||||||
|
resolvers.addResolver( new BasicDialectResolver( "MyDatabase2", 1, TestingDialects.MyDialect21.class ) );
|
||||||
|
resolvers.addResolver( new BasicDialectResolver( "MyDatabase2", 2, TestingDialects.MyDialect22.class ) );
|
||||||
|
resolvers.addResolver( new BasicDialectResolver( "MyDatabase3", 1, 1, TestingDialects.MyDialect311.class ) );
|
||||||
|
resolvers.addResolver( new BasicDialectResolver( "MyDatabase3", 1, 2, TestingDialects.MyDialect312.class ) );
|
||||||
|
resolvers.addResolver( new BasicDialectResolver( "ErrorDatabase1", Dialect.class ) );
|
||||||
|
|
||||||
|
testDetermination( resolvers, "MyDatabase1", 1, 1, TestingDialects.MyDialect1.class );
|
||||||
|
|
||||||
|
testDetermination( resolvers, "MyDatabase3", 1, null );
|
||||||
|
testDetermination( resolvers, "MyDatabase3", 1, 1, TestingDialects.MyDialect311.class );
|
||||||
|
testDetermination( resolvers, "MyDatabase3", 1, 2, TestingDialects.MyDialect312.class );
|
||||||
|
testDetermination( resolvers, "MyDatabase3", 1, 3, null );
|
||||||
|
}
|
||||||
|
|
||||||
private void testDetermination(
|
private void testDetermination(
|
||||||
DialectResolver resolver,
|
DialectResolver resolver,
|
||||||
String databaseName,
|
String databaseName,
|
||||||
int version,
|
int majorVersion,
|
||||||
Class dialectClass) throws SQLException {
|
Class<? extends Dialect> dialectClass) {
|
||||||
Dialect dialect = resolver.resolveDialect( TestingDialectResolutionInfo.forDatabaseInfo( databaseName, version ) );
|
testDetermination( resolver, databaseName, majorVersion, DialectResolutionInfo.NO_VERSION, dialectClass );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void testDetermination(
|
||||||
|
DialectResolver resolver,
|
||||||
|
String databaseName,
|
||||||
|
int majorVersion,
|
||||||
|
int minorVersion,
|
||||||
|
Class<? extends Dialect> dialectClass) {
|
||||||
|
Dialect dialect = resolver.resolveDialect(
|
||||||
|
TestingDialectResolutionInfo.forDatabaseInfo( databaseName, majorVersion, minorVersion )
|
||||||
|
);
|
||||||
if ( dialectClass == null ) {
|
if ( dialectClass == null ) {
|
||||||
assertEquals( null, dialect );
|
assertNull( dialect );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
assertEquals( dialectClass, dialect.getClass() );
|
assertEquals( dialectClass, dialect.getClass() );
|
||||||
|
|
Loading…
Reference in New Issue