Add version to logic evaluating @SkipForDialect and @RequiresDialect

This commit is contained in:
Andrea Boriero 2021-06-03 13:26:44 +02:00
parent 39d5d344fb
commit a8cf8165ae
6 changed files with 48 additions and 18 deletions

View File

@ -29,7 +29,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
* @author Vlad Mihalcea * @author Vlad Mihalcea
*/ */
@RequiresDialectFeature(feature = SupportsIdentityColumns.class, jiraKey = "HHH-9271") @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( @DomainModel(
annotatedClasses = { annotatedClasses = {
QuotedIdentifierTest.QuotedIdentifier.class QuotedIdentifierTest.QuotedIdentifier.class

View File

@ -33,8 +33,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
* @author <a href="mailto:p.krauzowicz@visiona.pl">Piotr Krauzowicz</a> * @author <a href="mailto:p.krauzowicz@visiona.pl">Piotr Krauzowicz</a>
* @author Gail Badner * @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 = MySQLDialect.class, version = 500, 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 = OracleDialect.class, version = 900, matchSubTypes = true, reason = "ORA-02329: column of datatype LOB cannot be unique or a primary key")
@DomainModel( @DomainModel(
annotatedClasses = ByteArrayIdTest.DemoEntity.class annotatedClasses = ByteArrayIdTest.DemoEntity.class
) )

View File

@ -33,8 +33,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
* @author <a href="mailto:p.krauzowicz@visiona.pl">Piotr Krauzowicz</a> * @author <a href="mailto:p.krauzowicz@visiona.pl">Piotr Krauzowicz</a>
* @author Gail Badner * @author Gail Badner
*/ */
@SkipForDialect(dialectClass = MySQLDialect.class, version = 5, reason = "BLOB/TEXT column 'id' used in key specification without a key length") @SkipForDialect(dialectClass = MySQLDialect.class, version = 500, 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 = OracleDialect.class, version = 900, matchSubTypes = true, reason = "ORA-02329: column of datatype LOB cannot be unique or a primary key")
@DomainModel( @DomainModel(
annotatedClasses = PrimitiveByteArrayIdTest.DemoEntity.class annotatedClasses = PrimitiveByteArrayIdTest.DemoEntity.class
) )

View File

@ -35,7 +35,7 @@ import static org.junit.jupiter.api.Assertions.fail;
* @author Vlad Mhalcea * @author Vlad Mhalcea
*/ */
@TestForIssue(jiraKey = "HHH-13106") @TestForIssue(jiraKey = "HHH-13106")
@RequiresDialect(value = PostgreSQLDialect.class, version = 10) @RequiresDialect(value = PostgreSQLDialect.class, version = 1000)
@Jpa( @Jpa(
annotatedClasses = PostgreSQLIdentitySequenceTest.Role.class annotatedClasses = PostgreSQLIdentitySequenceTest.Role.class
) )

View File

@ -33,7 +33,7 @@ import static org.junit.Assert.assertThat;
*/ */
@DomainModel( annotatedClasses = RowIdTest.Product.class ) @DomainModel( annotatedClasses = RowIdTest.Product.class )
@SessionFactory(statementInspectorClass = SQLStatementInspector.class) @SessionFactory(statementInspectorClass = SQLStatementInspector.class)
@RequiresDialect( value = OracleDialect.class, version = 9) @RequiresDialect( value = OracleDialect.class, version = 900)
public class RowIdTest { public class RowIdTest {
@BeforeEach @BeforeEach

View File

@ -46,14 +46,30 @@ public class DialectFilterExtension implements ExecutionCondition {
for ( RequiresDialect requiresDialect : effectiveRequiresDialects ) { for ( RequiresDialect requiresDialect : effectiveRequiresDialects ) {
requiredDialects.append(requiresDialect.value() ); requiredDialects.append(requiresDialect.value() );
requiredDialects.append( " " ); 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 ) ) { 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 { else {
if ( requiresDialect.value().equals( dialect.getClass() ) ) { if ( requiresDialect.matchSubTypes() ) {
return ConditionEvaluationResult.enabled( "Matched @RequiresDialect" ); 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( return ConditionEvaluationResult.disabled(
String.format( String.format(
Locale.ROOT, Locale.ROOT,
"Failed @RequiresDialect(dialect=%s) check - found %s]", "Failed @RequiresDialect(dialect=%s) check - found %s version %s]",
requiredDialects.toString(), requiredDialects,
dialect.getClass().getName() dialect.getClass().getName(),
dialect.getVersion()
) )
); );
} }
@ -75,14 +92,27 @@ public class DialectFilterExtension implements ExecutionCondition {
); );
for ( SkipForDialect effectiveSkipForDialect : effectiveSkips ) { for ( SkipForDialect effectiveSkipForDialect : effectiveSkips ) {
if ( effectiveSkipForDialect.matchSubTypes() ) { final int skipForVersion = effectiveSkipForDialect.version();
if ( skipForVersion > -1 ) {
if ( effectiveSkipForDialect.dialectClass().isInstance( dialect ) ) { 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 { else {
if ( effectiveSkipForDialect.dialectClass().equals( dialect.getClass() ) ) { if ( effectiveSkipForDialect.matchSubTypes() ) {
return ConditionEvaluationResult.disabled( "Matched @SkipForDialect" ); if ( effectiveSkipForDialect.dialectClass().isInstance( dialect ) ) {
return ConditionEvaluationResult.disabled( "Matched @SkipForDialect(group)" );
}
}
else {
if ( effectiveSkipForDialect.dialectClass().equals( dialect.getClass() ) ) {
return ConditionEvaluationResult.disabled( "Matched @SkipForDialect" );
}
} }
} }
} }