Skip to content

Commit 6d1b9c4

Browse files
committed
HHH-18802 Add XML aggregate support for SQL Server
1 parent 1077b6f commit 6d1b9c4

File tree

5 files changed

+352
-49
lines changed

5 files changed

+352
-49
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,10 @@
5252
import org.hibernate.exception.spi.ViolatedConstraintNameExtractor;
5353
import org.hibernate.internal.util.JdbcExceptionHelper;
5454
import org.hibernate.internal.util.StringHelper;
55+
import org.hibernate.mapping.AggregateColumn;
5556
import org.hibernate.mapping.CheckConstraint;
5657
import org.hibernate.mapping.Column;
58+
import org.hibernate.mapping.Table;
5759
import org.hibernate.query.sqm.CastType;
5860
import org.hibernate.query.common.FetchClauseType;
5961
import org.hibernate.query.sqm.IntervalType;
@@ -68,6 +70,7 @@
6870
import org.hibernate.sql.ast.tree.Statement;
6971
import org.hibernate.sql.exec.spi.JdbcOperation;
7072
import org.hibernate.tool.schema.internal.StandardSequenceExporter;
73+
import org.hibernate.tool.schema.internal.StandardTableExporter;
7174
import org.hibernate.tool.schema.spi.Exporter;
7275
import org.hibernate.type.BasicType;
7376
import org.hibernate.type.BasicTypeRegistry;
@@ -142,6 +145,17 @@ public Size resolveSize(
142145
}
143146
}
144147
};
148+
private final StandardTableExporter sqlServerTableExporter = new StandardTableExporter( this ) {
149+
@Override
150+
protected void applyAggregateColumnCheck(StringBuilder buf, AggregateColumn aggregateColumn) {
151+
final JdbcType jdbcType = aggregateColumn.getType().getJdbcType();
152+
if ( jdbcType.isXml() ) {
153+
// XML columns can't have check constraints
154+
return;
155+
}
156+
super.applyAggregateColumnCheck( buf, aggregateColumn );
157+
}
158+
};
145159

146160

147161
public SQLServerLegacyDialect() {
@@ -1165,6 +1179,11 @@ public UniqueDelegate getUniqueDelegate() {
11651179
return uniqueDelegate;
11661180
}
11671181

1182+
@Override
1183+
public Exporter<Table> getTableExporter() {
1184+
return this.sqlServerTableExporter;
1185+
}
1186+
11681187
@Override
11691188
public Exporter<Sequence> getSequenceExporter() {
11701189
if ( exporter == null ) {

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,10 @@
5454
import org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtractor;
5555
import org.hibernate.exception.spi.ViolatedConstraintNameExtractor;
5656
import org.hibernate.internal.util.config.ConfigurationHelper;
57+
import org.hibernate.mapping.AggregateColumn;
5758
import org.hibernate.mapping.CheckConstraint;
5859
import org.hibernate.mapping.Column;
60+
import org.hibernate.mapping.Table;
5961
import org.hibernate.persister.entity.mutation.EntityMutationTarget;
6062
import org.hibernate.procedure.internal.SQLServerCallableStatementSupport;
6163
import org.hibernate.procedure.spi.CallableStatementSupport;
@@ -75,6 +77,7 @@
7577
import org.hibernate.sql.model.MutationOperation;
7678
import org.hibernate.sql.model.internal.OptionalTableUpdate;
7779
import org.hibernate.tool.schema.internal.StandardSequenceExporter;
80+
import org.hibernate.tool.schema.internal.StandardTableExporter;
7881
import org.hibernate.tool.schema.spi.Exporter;
7982
import org.hibernate.type.BasicType;
8083
import org.hibernate.type.BasicTypeRegistry;
@@ -161,6 +164,17 @@ public Size resolveSize(
161164
};
162165
}
163166
};
167+
private final StandardTableExporter sqlServerTableExporter = new StandardTableExporter( this ) {
168+
@Override
169+
protected void applyAggregateColumnCheck(StringBuilder buf, AggregateColumn aggregateColumn) {
170+
final JdbcType jdbcType = aggregateColumn.getType().getJdbcType();
171+
if ( jdbcType.isXml() ) {
172+
// XML columns can't have check constraints
173+
return;
174+
}
175+
super.applyAggregateColumnCheck( buf, aggregateColumn );
176+
}
177+
};
164178

165179
public SQLServerDialect() {
166180
this( MINIMUM_VERSION );
@@ -1109,6 +1123,11 @@ public UniqueDelegate getUniqueDelegate() {
11091123
return uniqueDelegate;
11101124
}
11111125

1126+
@Override
1127+
public Exporter<Table> getTableExporter() {
1128+
return this.sqlServerTableExporter;
1129+
}
1130+
11121131
@Override
11131132
public Exporter<Sequence> getSequenceExporter() {
11141133
return exporter == null ? super.getSequenceExporter() : exporter;

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,11 @@ public static <X> X fromString(
271271
String string,
272272
boolean returnEmbeddable,
273273
WrapperOptions options) throws SQLException {
274+
if ( NULL_TAG.equals( string ) ) {
275+
return null;
276+
}
274277
if ( !string.startsWith( START_TAG ) || !string.endsWith( END_TAG ) ) {
275-
throw new IllegalArgumentException( "Illegal XML for struct: " + string );
278+
throw new IllegalArgumentException( "XML not properly formatted: " + string );
276279
}
277280
int end;
278281
final Object[] array;

0 commit comments

Comments
 (0)