Skip to content

Commit 57142a8

Browse files
committed
HHH-18800 Add XML aggregate support for PostgreSQL
1 parent eeba7ed commit 57142a8

File tree

5 files changed

+371
-10
lines changed

5 files changed

+371
-10
lines changed

hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/PostgreSQLLegacyDialect.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
import org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtractor;
5454
import org.hibernate.exception.spi.ViolatedConstraintNameExtractor;
5555
import org.hibernate.internal.util.JdbcExceptionHelper;
56+
import org.hibernate.mapping.AggregateColumn;
57+
import org.hibernate.mapping.Table;
5658
import org.hibernate.metamodel.mapping.EntityMappingType;
5759
import org.hibernate.metamodel.spi.RuntimeModelCreationContext;
5860
import org.hibernate.procedure.internal.PostgreSQLCallableStatementSupport;
@@ -76,6 +78,8 @@
7678
import org.hibernate.sql.ast.tree.Statement;
7779
import org.hibernate.sql.exec.spi.JdbcOperation;
7880
import org.hibernate.tool.schema.extract.spi.ColumnTypeInformation;
81+
import org.hibernate.tool.schema.internal.StandardTableExporter;
82+
import org.hibernate.tool.schema.spi.Exporter;
7983
import org.hibernate.type.JavaObjectType;
8084
import org.hibernate.type.descriptor.java.PrimitiveByteArrayJavaType;
8185
import org.hibernate.type.descriptor.jdbc.BlobJdbcType;
@@ -143,6 +147,17 @@ public class PostgreSQLLegacyDialect extends Dialect {
143147

144148
protected final PostgreSQLDriverKind driverKind;
145149
private final UniqueDelegate uniqueDelegate = new CreateTableUniqueDelegate(this);
150+
private final StandardTableExporter postgresqlTableExporter = new StandardTableExporter( this ) {
151+
@Override
152+
protected void applyAggregateColumnCheck(StringBuilder buf, AggregateColumn aggregateColumn) {
153+
final JdbcType jdbcType = aggregateColumn.getType().getJdbcType();
154+
if ( jdbcType.isXml() ) {
155+
// Requires the use of xmltable which is not supported in check constraints
156+
return;
157+
}
158+
super.applyAggregateColumnCheck( buf, aggregateColumn );
159+
}
160+
};
146161

147162
public PostgreSQLLegacyDialect() {
148163
this( DatabaseVersion.make( 8, 0 ) );
@@ -1536,6 +1551,11 @@ public UniqueDelegate getUniqueDelegate() {
15361551
return uniqueDelegate;
15371552
}
15381553

1554+
@Override
1555+
public Exporter<Table> getTableExporter() {
1556+
return postgresqlTableExporter;
1557+
}
1558+
15391559
/**
15401560
* @return {@code true}, but only because we can "batch" truncate
15411561
*/

hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQLDialect.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
import org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtractor;
5151
import org.hibernate.exception.spi.ViolatedConstraintNameExtractor;
5252
import org.hibernate.internal.util.JdbcExceptionHelper;
53+
import org.hibernate.mapping.AggregateColumn;
54+
import org.hibernate.mapping.Table;
5355
import org.hibernate.metamodel.mapping.EntityMappingType;
5456
import org.hibernate.metamodel.spi.RuntimeModelCreationContext;
5557
import org.hibernate.persister.entity.mutation.EntityMutationTarget;
@@ -78,6 +80,8 @@
7880
import org.hibernate.sql.model.internal.OptionalTableUpdate;
7981
import org.hibernate.sql.model.jdbc.OptionalTableUpdateOperation;
8082
import org.hibernate.tool.schema.extract.spi.ColumnTypeInformation;
83+
import org.hibernate.tool.schema.internal.StandardTableExporter;
84+
import org.hibernate.tool.schema.spi.Exporter;
8185
import org.hibernate.type.JavaObjectType;
8286
import org.hibernate.type.descriptor.java.PrimitiveByteArrayJavaType;
8387
import org.hibernate.type.descriptor.jdbc.BlobJdbcType;
@@ -145,6 +149,17 @@ public class PostgreSQLDialect extends Dialect {
145149
protected final static DatabaseVersion MINIMUM_VERSION = DatabaseVersion.make( 12 );
146150

147151
private final UniqueDelegate uniqueDelegate = new CreateTableUniqueDelegate(this);
152+
private final StandardTableExporter postgresqlTableExporter = new StandardTableExporter( this ) {
153+
@Override
154+
protected void applyAggregateColumnCheck(StringBuilder buf, AggregateColumn aggregateColumn) {
155+
final JdbcType jdbcType = aggregateColumn.getType().getJdbcType();
156+
if ( jdbcType.isXml() ) {
157+
// Requires the use of xmltable which is not supported in check constraints
158+
return;
159+
}
160+
super.applyAggregateColumnCheck( buf, aggregateColumn );
161+
}
162+
};
148163

149164
protected final PostgreSQLDriverKind driverKind;
150165
private final OptionalTableUpdateStrategy optionalTableUpdateStrategy;
@@ -1474,6 +1489,11 @@ public UniqueDelegate getUniqueDelegate() {
14741489
return uniqueDelegate;
14751490
}
14761491

1492+
@Override
1493+
public Exporter<Table> getTableExporter() {
1494+
return postgresqlTableExporter;
1495+
}
1496+
14771497
/**
14781498
* @return {@code true}, but only because we can "batch" truncate
14791499
*/

0 commit comments

Comments
 (0)