HHH-16182 Fix some tests for older databases and adapt assertion for boolean function
This commit is contained in:
parent
2a017db0bc
commit
1bd0180172
|
@ -10,6 +10,8 @@ import java.sql.Types;
|
|||
|
||||
import org.hibernate.boot.model.FunctionContributions;
|
||||
import org.hibernate.boot.model.FunctionContributor;
|
||||
import org.hibernate.dialect.AbstractHANADialect;
|
||||
import org.hibernate.dialect.DB2Dialect;
|
||||
import org.hibernate.dialect.OracleDialect;
|
||||
import org.hibernate.dialect.SQLServerDialect;
|
||||
import org.hibernate.dialect.SybaseASEDialect;
|
||||
|
@ -330,16 +332,7 @@ public class BooleanMappingTests {
|
|||
return result.intValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* @implNote Skipped for dialects without support for boolean (predicate) expressions. The test
|
||||
* is really about handling the SQM function reference anyway; the actual Dialect implementation
|
||||
* is not standard.
|
||||
*/
|
||||
@Test
|
||||
@SkipForDialect(dialectClass = OracleDialect.class)
|
||||
@SkipForDialect(dialectClass = SybaseDialect.class)
|
||||
@SkipForDialect(dialectClass = SybaseASEDialect.class)
|
||||
@SkipForDialect(dialectClass = SQLServerDialect.class)
|
||||
public void testBooleanFunctionAsPredicate(SessionFactoryScope scope) {
|
||||
// Not strictly relevant to boolean mappings, but test that boolean
|
||||
// functions work *as a* predicate after HHH-16182
|
||||
|
@ -351,20 +344,20 @@ public class BooleanMappingTests {
|
|||
} );
|
||||
|
||||
assertThat( statementInspector.getSqlQueries().size(), equalTo( 1 ) );
|
||||
assertThat( statementInspector.getSqlQueries().get( 0 ), containsString( "(1=1)" ) );
|
||||
assertThat( statementInspector.getSqlQueries().get( 0 ), containsString( "(2=2)" ) );
|
||||
assertThat( statementInspector.getSqlQueries().get( 0 ), containsString( "where (1=1) or (2=2)" ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @implNote Skipped for dialects without support for boolean (predicate) expressions. The test
|
||||
* is really about handling the SQM function reference anyway; the actual Dialect implementation
|
||||
* is not standard.
|
||||
* @implNote Skipped for dialects without support for comparing a boolean predicate against a boolean expressions,
|
||||
* i.e. `(1=1)=true`. The test is really about handling the SQM function reference anyway;
|
||||
* the actual Dialect implementation is not standard.
|
||||
*/
|
||||
@Test
|
||||
@SkipForDialect(dialectClass = OracleDialect.class)
|
||||
@SkipForDialect(dialectClass = SybaseDialect.class)
|
||||
@SkipForDialect(dialectClass = SybaseASEDialect.class)
|
||||
@SkipForDialect(dialectClass = SQLServerDialect.class)
|
||||
@SkipForDialect(dialectClass = SybaseDialect.class, matchSubTypes = true)
|
||||
@SkipForDialect(dialectClass = AbstractHANADialect.class, matchSubTypes = true)
|
||||
@SkipForDialect(dialectClass = DB2Dialect.class, majorVersion = 10)
|
||||
public void testBooleanFunctionInPredicate(SessionFactoryScope scope) {
|
||||
// Not strictly relevant to boolean mappings, but test that boolean
|
||||
// functions work *in a* predicate after HHH-16182
|
||||
|
|
|
@ -7058,6 +7058,14 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
|||
@Override
|
||||
public Object visitBooleanExpressionPredicate(SqmBooleanExpressionPredicate predicate) {
|
||||
final Expression booleanExpression = (Expression) predicate.getBooleanExpression().accept( this );
|
||||
if ( booleanExpression instanceof SelfRenderingExpression ) {
|
||||
final Predicate sqlPredicate = new SelfRenderingPredicate( (SelfRenderingExpression) booleanExpression );
|
||||
if ( predicate.isNegated() ) {
|
||||
return new NegatedPredicate( sqlPredicate );
|
||||
}
|
||||
return sqlPredicate;
|
||||
}
|
||||
else {
|
||||
final JdbcMapping jdbcMapping = booleanExpression.getExpressionType().getJdbcMapping( 0 );
|
||||
if ( jdbcMapping.getValueConverter() != null ) {
|
||||
// handle converted booleans (yes-no, etc)
|
||||
|
@ -7074,6 +7082,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
|||
getBooleanType()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object visitExistsPredicate(SqmExistsPredicate predicate) {
|
||||
|
|
|
@ -23,9 +23,11 @@ import jakarta.persistence.Id;
|
|||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.OneToOne;
|
||||
import jakarta.persistence.Version;
|
||||
|
||||
import org.hibernate.annotations.Cache;
|
||||
import org.hibernate.annotations.CacheConcurrencyStrategy;
|
||||
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -57,19 +59,17 @@ public class CacheableEntityGraphTest extends BaseEntityManagerFunctionalTestCas
|
|||
EntityGraph<Product> entityGraph = em.createEntityGraph( Product.class );
|
||||
entityGraph.addAttributeNodes( "tag" );
|
||||
|
||||
em.createQuery(
|
||||
"select p from org.hibernate.orm.test.jpa.graphs.CacheableEntityGraphTest$Product p",
|
||||
Product.class)
|
||||
em.createQuery( "select p from Product p", Product.class )
|
||||
.setMaxResults( 2 )
|
||||
.setHint( "jakarta.persistence.loadgraph", entityGraph )
|
||||
.getSingleResult();
|
||||
}
|
||||
|
||||
@Entity
|
||||
@Entity(name = "Product")
|
||||
public static class Product {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@GeneratedValue
|
||||
public int id;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
|
@ -87,11 +87,11 @@ public class CacheableEntityGraphTest extends BaseEntityManagerFunctionalTestCas
|
|||
}
|
||||
}
|
||||
|
||||
@Entity
|
||||
@Entity(name = "Color")
|
||||
public static class Color {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@GeneratedValue
|
||||
public int id;
|
||||
|
||||
@OneToOne(fetch = FetchType.LAZY)
|
||||
|
@ -99,11 +99,11 @@ public class CacheableEntityGraphTest extends BaseEntityManagerFunctionalTestCas
|
|||
}
|
||||
|
||||
@Cacheable
|
||||
@Entity
|
||||
@Entity(name = "Tag")
|
||||
public static class Tag {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@GeneratedValue
|
||||
public int id;
|
||||
|
||||
@Version
|
||||
|
|
Loading…
Reference in New Issue