Fix several tests failing on Oracle 11 and some others on older dbs
This commit is contained in:
parent
2c1ee27038
commit
4e9a643346
|
@ -433,12 +433,47 @@ public class OracleLegacySqlAstTranslator<T extends JdbcOperation> extends Abstr
|
||||||
rhs.accept( this );
|
rhs.accept( this );
|
||||||
appendSql( ')' );
|
appendSql( ')' );
|
||||||
break;
|
break;
|
||||||
|
case SqlTypes.ARRAY:
|
||||||
|
switch ( operator ) {
|
||||||
|
case DISTINCT_FROM:
|
||||||
|
appendSql( "decode(" );
|
||||||
|
arrayToString( lhs );
|
||||||
|
appendSql( ',' );
|
||||||
|
arrayToString( rhs );
|
||||||
|
appendSql( ",0,1)=1" );
|
||||||
|
break;
|
||||||
|
case NOT_DISTINCT_FROM:
|
||||||
|
appendSql( "decode(" );
|
||||||
|
arrayToString( lhs );
|
||||||
|
appendSql( ',' );
|
||||||
|
arrayToString( rhs );
|
||||||
|
appendSql( ",0,1)=0" );
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
arrayToString( lhs );
|
||||||
|
appendSql( operator.sqlText() );
|
||||||
|
arrayToString( rhs );
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
renderComparisonEmulateDecode( lhs, operator, rhs );
|
renderComparisonEmulateDecode( lhs, operator, rhs );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void arrayToString(Expression expression) {
|
||||||
|
appendSql("case when ");
|
||||||
|
expression.accept( this );
|
||||||
|
appendSql(" is not null then (select listagg(column_value||',')");
|
||||||
|
if ( !getDialect().getVersion().isSameOrAfter( 18 ) ) {
|
||||||
|
// The within group clause became optional in 18
|
||||||
|
appendSql(" within group(order by rownum)");
|
||||||
|
}
|
||||||
|
appendSql("||';' from table(");
|
||||||
|
expression.accept( this );
|
||||||
|
appendSql(")) else null end");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void renderSelectTupleComparison(
|
protected void renderSelectTupleComparison(
|
||||||
List<SqlSelection> lhsExpressions,
|
List<SqlSelection> lhsExpressions,
|
||||||
|
|
|
@ -34,6 +34,7 @@ import java.util.Locale;
|
||||||
|
|
||||||
import static java.sql.Types.ARRAY;
|
import static java.sql.Types.ARRAY;
|
||||||
import static java.util.Collections.emptySet;
|
import static java.util.Collections.emptySet;
|
||||||
|
import static org.hibernate.internal.util.StringHelper.truncate;
|
||||||
import static org.hibernate.internal.util.collections.ArrayHelper.EMPTY_STRING_ARRAY;
|
import static org.hibernate.internal.util.collections.ArrayHelper.EMPTY_STRING_ARRAY;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -233,8 +234,10 @@ public class OracleNestedTableJdbcType implements JdbcType {
|
||||||
final Dialect dialect = database.getDialect();
|
final Dialect dialect = database.getDialect();
|
||||||
final BasicPluralJavaType<?> pluralJavaType = (BasicPluralJavaType<?>) javaType;
|
final BasicPluralJavaType<?> pluralJavaType = (BasicPluralJavaType<?>) javaType;
|
||||||
String elementTypeName = getTypeName( pluralJavaType.getElementJavaType(), dialect );
|
String elementTypeName = getTypeName( pluralJavaType.getElementJavaType(), dialect );
|
||||||
return " nested table " + columnName
|
return " nested table " + columnName + " store as \"" + truncate(
|
||||||
+ " store as \"" + tableName + " " + columnName + " " + elementTypeName + "\"";
|
tableName + " " + columnName + " " + elementTypeName,
|
||||||
|
dialect.getMaxIdentifierLength()
|
||||||
|
) + "\"";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -470,7 +470,12 @@ public class OracleSqlAstTranslator<T extends JdbcOperation> extends SqlAstTrans
|
||||||
private void arrayToString(Expression expression) {
|
private void arrayToString(Expression expression) {
|
||||||
appendSql("case when ");
|
appendSql("case when ");
|
||||||
expression.accept( this );
|
expression.accept( this );
|
||||||
appendSql(" is not null then (select listagg(column_value||',')||';' from table(");
|
appendSql(" is not null then (select listagg(column_value||',')");
|
||||||
|
if ( !getDialect().getVersion().isSameOrAfter( 18 ) ) {
|
||||||
|
// The within group clause became optional in 18
|
||||||
|
appendSql(" within group(order by rownum)");
|
||||||
|
}
|
||||||
|
appendSql("||';' from table(");
|
||||||
expression.accept( this );
|
expression.accept( this );
|
||||||
appendSql(")) else null end");
|
appendSql(")) else null end");
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@ import java.util.List;
|
||||||
|
|
||||||
import org.hibernate.testing.TestForIssue;
|
import org.hibernate.testing.TestForIssue;
|
||||||
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
|
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
|
||||||
import org.hibernate.testing.orm.junit.JiraKey;
|
|
||||||
import org.hibernate.testing.orm.junit.Jpa;
|
import org.hibernate.testing.orm.junit.Jpa;
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
@ -18,7 +17,6 @@ import jakarta.persistence.Entity;
|
||||||
import jakarta.persistence.FetchType;
|
import jakarta.persistence.FetchType;
|
||||||
import jakarta.persistence.ForeignKey;
|
import jakarta.persistence.ForeignKey;
|
||||||
import jakarta.persistence.GeneratedValue;
|
import jakarta.persistence.GeneratedValue;
|
||||||
import jakarta.persistence.GenerationType;
|
|
||||||
import jakarta.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
import jakarta.persistence.Inheritance;
|
import jakarta.persistence.Inheritance;
|
||||||
import jakarta.persistence.InheritanceType;
|
import jakarta.persistence.InheritanceType;
|
||||||
|
@ -47,6 +45,7 @@ public class RefreshAndInheritanceTest {
|
||||||
scope.inTransaction(
|
scope.inTransaction(
|
||||||
entityManager -> {
|
entityManager -> {
|
||||||
ManufacturerCompany manufacturerCompany = new ManufacturerCompany();
|
ManufacturerCompany manufacturerCompany = new ManufacturerCompany();
|
||||||
|
manufacturerCompany.setId( 1L );
|
||||||
manufacturerCompany.setComputerSystem( new ManufacturerComputerSystem() );
|
manufacturerCompany.setComputerSystem( new ManufacturerComputerSystem() );
|
||||||
|
|
||||||
Person person = new Person();
|
Person person = new Person();
|
||||||
|
@ -85,7 +84,6 @@ public class RefreshAndInheritanceTest {
|
||||||
@DiscriminatorColumn(name = "CompanyType", discriminatorType = DiscriminatorType.INTEGER)
|
@DiscriminatorColumn(name = "CompanyType", discriminatorType = DiscriminatorType.INTEGER)
|
||||||
public static abstract class Company {
|
public static abstract class Company {
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
||||||
protected long id;
|
protected long id;
|
||||||
|
|
||||||
@OneToMany(mappedBy = "company", orphanRemoval = true, cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
@OneToMany(mappedBy = "company", orphanRemoval = true, cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||||
|
@ -99,6 +97,10 @@ public class RefreshAndInheritanceTest {
|
||||||
people.add( person );
|
people.add( person );
|
||||||
person.setCompany( this );
|
person.setCompany( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setId(long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Entity(name = "ComputerSystem")
|
@Entity(name = "ComputerSystem")
|
||||||
|
@ -106,7 +108,7 @@ public class RefreshAndInheritanceTest {
|
||||||
@DiscriminatorColumn(name = "CompanyType", discriminatorType = DiscriminatorType.INTEGER)
|
@DiscriminatorColumn(name = "CompanyType", discriminatorType = DiscriminatorType.INTEGER)
|
||||||
public static abstract class ComputerSystem {
|
public static abstract class ComputerSystem {
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue
|
||||||
private long id;
|
private long id;
|
||||||
|
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
|
@ -139,7 +141,7 @@ public class RefreshAndInheritanceTest {
|
||||||
@Entity(name = "Person")
|
@Entity(name = "Person")
|
||||||
public static class Person {
|
public static class Person {
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue
|
||||||
private long id;
|
private long id;
|
||||||
|
|
||||||
private String firstName;
|
private String firstName;
|
||||||
|
|
|
@ -52,7 +52,7 @@ import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||||
@Setting(name = AvailableSettings.FORMAT_SQL, value = "false")
|
@Setting(name = AvailableSettings.FORMAT_SQL, value = "false")
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@RequiresDialect(H2Dialect.class)
|
@RequiresDialect(value = H2Dialect.class, majorVersion = 2, comment = "H2 didn't support SQL arrays before version 2")
|
||||||
@JiraKey("HHH-16469")
|
@JiraKey("HHH-16469")
|
||||||
public class DepthOneBatchTest {
|
public class DepthOneBatchTest {
|
||||||
|
|
||||||
|
|
|
@ -1892,8 +1892,9 @@ public class FunctionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SkipForDialect(dialectClass = OracleDialect.class)
|
@SkipForDialect(dialectClass = OracleDialect.class, reason = "HHH-16576")
|
||||||
@SkipForDialect(dialectClass = MariaDBDialect.class)
|
@SkipForDialect(dialectClass = MariaDBDialect.class, reason = "HHH-16576")
|
||||||
|
@SkipForDialect(dialectClass = MySQLDialect.class, majorVersion = 5, reason = "HHH-16576")
|
||||||
public void testMaxOverUnion(SessionFactoryScope scope) {
|
public void testMaxOverUnion(SessionFactoryScope scope) {
|
||||||
scope.inTransaction(
|
scope.inTransaction(
|
||||||
session -> {
|
session -> {
|
||||||
|
|
|
@ -148,6 +148,6 @@ public class EnumSet extends BaseEnversJPAFunctionalTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void verifyMapping(JdbcMapping jdbcMapping) {
|
private void verifyMapping(JdbcMapping jdbcMapping) {
|
||||||
assertThat( jdbcMapping.getJdbcType().getJdbcTypeCode() ).isIn( Types.VARCHAR, SqlTypes.ENUM );
|
assertThat( jdbcMapping.getJdbcType().getJdbcTypeCode() ).isIn( Types.VARCHAR, Types.NVARCHAR, SqlTypes.ENUM );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue