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