From a8cf8165ae228eb7ad1ad79287f322a503521316 Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Thu, 3 Jun 2021 13:26:44 +0200 Subject: [PATCH] Add version to logic evaluating @SkipForDialect and @RequiresDialect --- .../orm/test/id/QuotedIdentifierTest.java | 2 +- .../orm/test/id/array/ByteArrayIdTest.java | 4 +- .../id/array/PrimitiveByteArrayIdTest.java | 4 +- .../PostgreSQLIdentitySequenceTest.java | 2 +- .../hibernate/orm/test/rowid/RowIdTest.java | 2 +- .../orm/junit/DialectFilterExtension.java | 52 +++++++++++++++---- 6 files changed, 48 insertions(+), 18 deletions(-) diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/id/QuotedIdentifierTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/id/QuotedIdentifierTest.java index 6f1023f6f3..53c6d8d866 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/id/QuotedIdentifierTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/id/QuotedIdentifierTest.java @@ -29,7 +29,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; * @author Vlad Mihalcea */ @RequiresDialectFeature(feature = SupportsIdentityColumns.class, jiraKey = "HHH-9271") -@SkipForDialect(dialectClass = OracleDialect.class, version = 12, matchSubTypes = true, reason = "Oracle and identity column: java.sql.Connection#prepareStatement(String sql, int columnIndexes[]) does not work with quoted table names and/or quoted columnIndexes") +@SkipForDialect(dialectClass = OracleDialect.class, version = 1200, matchSubTypes = true, reason = "Oracle and identity column: java.sql.Connection#prepareStatement(String sql, int columnIndexes[]) does not work with quoted table names and/or quoted columnIndexes") @DomainModel( annotatedClasses = { QuotedIdentifierTest.QuotedIdentifier.class diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/id/array/ByteArrayIdTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/id/array/ByteArrayIdTest.java index 0e351a9709..09a31b6c32 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/id/array/ByteArrayIdTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/id/array/ByteArrayIdTest.java @@ -33,8 +33,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue; * @author Piotr Krauzowicz * @author Gail Badner */ -@SkipForDialect(dialectClass = MySQLDialect.class, version = 5, matchSubTypes = true, reason = "BLOB/TEXT column 'id' used in key specification without a key length") -@SkipForDialect(dialectClass = OracleDialect.class, version = 9, matchSubTypes = true, reason = "ORA-02329: column of datatype LOB cannot be unique or a primary key") +@SkipForDialect(dialectClass = MySQLDialect.class, version = 500, matchSubTypes = true, reason = "BLOB/TEXT column 'id' used in key specification without a key length") +@SkipForDialect(dialectClass = OracleDialect.class, version = 900, matchSubTypes = true, reason = "ORA-02329: column of datatype LOB cannot be unique or a primary key") @DomainModel( annotatedClasses = ByteArrayIdTest.DemoEntity.class ) diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/id/array/PrimitiveByteArrayIdTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/id/array/PrimitiveByteArrayIdTest.java index 9b5aba2075..a0bc56ec13 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/id/array/PrimitiveByteArrayIdTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/id/array/PrimitiveByteArrayIdTest.java @@ -33,8 +33,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue; * @author Piotr Krauzowicz * @author Gail Badner */ -@SkipForDialect(dialectClass = MySQLDialect.class, version = 5, reason = "BLOB/TEXT column 'id' used in key specification without a key length") -@SkipForDialect(dialectClass = OracleDialect.class, version = 9, matchSubTypes = true, reason = "ORA-02329: column of datatype LOB cannot be unique or a primary key") +@SkipForDialect(dialectClass = MySQLDialect.class, version = 500, reason = "BLOB/TEXT column 'id' used in key specification without a key length") +@SkipForDialect(dialectClass = OracleDialect.class, version = 900, matchSubTypes = true, reason = "ORA-02329: column of datatype LOB cannot be unique or a primary key") @DomainModel( annotatedClasses = PrimitiveByteArrayIdTest.DemoEntity.class ) diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/id/sequence/PostgreSQLIdentitySequenceTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/id/sequence/PostgreSQLIdentitySequenceTest.java index 7a3f323731..38ebd258bb 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/id/sequence/PostgreSQLIdentitySequenceTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/id/sequence/PostgreSQLIdentitySequenceTest.java @@ -35,7 +35,7 @@ import static org.junit.jupiter.api.Assertions.fail; * @author Vlad Mhalcea */ @TestForIssue(jiraKey = "HHH-13106") -@RequiresDialect(value = PostgreSQLDialect.class, version = 10) +@RequiresDialect(value = PostgreSQLDialect.class, version = 1000) @Jpa( annotatedClasses = PostgreSQLIdentitySequenceTest.Role.class ) diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/rowid/RowIdTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/rowid/RowIdTest.java index ce9ce16329..d948882b95 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/rowid/RowIdTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/rowid/RowIdTest.java @@ -33,7 +33,7 @@ import static org.junit.Assert.assertThat; */ @DomainModel( annotatedClasses = RowIdTest.Product.class ) @SessionFactory(statementInspectorClass = SQLStatementInspector.class) -@RequiresDialect( value = OracleDialect.class, version = 9) +@RequiresDialect( value = OracleDialect.class, version = 900) public class RowIdTest { @BeforeEach diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/DialectFilterExtension.java b/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/DialectFilterExtension.java index 0dba8cbf76..45e69152ac 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/DialectFilterExtension.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/DialectFilterExtension.java @@ -46,14 +46,30 @@ public class DialectFilterExtension implements ExecutionCondition { for ( RequiresDialect requiresDialect : effectiveRequiresDialects ) { requiredDialects.append(requiresDialect.value() ); requiredDialects.append( " " ); - if ( requiresDialect.matchSubTypes() ) { + final int requiredVersion = requiresDialect.version(); + if ( requiredVersion > -1 ) { + requiredDialects.append( ", version = " ); + requiredDialects.append( requiredVersion ); + requiredDialects.append( " " ); if ( requiresDialect.value().isInstance( dialect ) ) { - return ConditionEvaluationResult.enabled( "Matched @RequiresDialect" ); + if ( requiredVersion == dialect.getVersion() ) { + return ConditionEvaluationResult.enabled( "Matched @RequiresDialect" ); + } + if ( requiresDialect.matchSubTypes() && dialect.getVersion() > requiredVersion ) { + return ConditionEvaluationResult.enabled( "Matched @RequiresDialect" ); + } } } else { - if ( requiresDialect.value().equals( dialect.getClass() ) ) { - return ConditionEvaluationResult.enabled( "Matched @RequiresDialect" ); + if ( requiresDialect.matchSubTypes() ) { + if ( requiresDialect.value().isInstance( dialect ) ) { + return ConditionEvaluationResult.enabled( "Matched @RequiresDialect" ); + } + } + else { + if ( requiresDialect.value().equals( dialect.getClass() ) ) { + return ConditionEvaluationResult.enabled( "Matched @RequiresDialect" ); + } } } } @@ -61,9 +77,10 @@ public class DialectFilterExtension implements ExecutionCondition { return ConditionEvaluationResult.disabled( String.format( Locale.ROOT, - "Failed @RequiresDialect(dialect=%s) check - found %s]", - requiredDialects.toString(), - dialect.getClass().getName() + "Failed @RequiresDialect(dialect=%s) check - found %s version %s]", + requiredDialects, + dialect.getClass().getName(), + dialect.getVersion() ) ); } @@ -75,14 +92,27 @@ public class DialectFilterExtension implements ExecutionCondition { ); for ( SkipForDialect effectiveSkipForDialect : effectiveSkips ) { - if ( effectiveSkipForDialect.matchSubTypes() ) { + final int skipForVersion = effectiveSkipForDialect.version(); + if ( skipForVersion > -1 ) { if ( effectiveSkipForDialect.dialectClass().isInstance( dialect ) ) { - return ConditionEvaluationResult.disabled( "Matched @SkipForDialect(group)" ); + if ( skipForVersion == dialect.getVersion() ) { + return ConditionEvaluationResult.disabled( "Matched @SkipForDialect(group)" ); + } + if ( effectiveSkipForDialect.matchSubTypes() && dialect.getVersion() > skipForVersion ) { + return ConditionEvaluationResult.disabled( "Matched @SkipForDialect(group)" ); + } } } else { - if ( effectiveSkipForDialect.dialectClass().equals( dialect.getClass() ) ) { - return ConditionEvaluationResult.disabled( "Matched @SkipForDialect" ); + if ( effectiveSkipForDialect.matchSubTypes() ) { + if ( effectiveSkipForDialect.dialectClass().isInstance( dialect ) ) { + return ConditionEvaluationResult.disabled( "Matched @SkipForDialect(group)" ); + } + } + else { + if ( effectiveSkipForDialect.dialectClass().equals( dialect.getClass() ) ) { + return ConditionEvaluationResult.disabled( "Matched @SkipForDialect" ); + } } } }