|
26 | 26 | import org.hibernate.dialect.sequence.DB2SequenceSupport; |
27 | 27 | import org.hibernate.dialect.sequence.SequenceSupport; |
28 | 28 | import org.hibernate.dialect.sql.ast.DB2SqlAstTranslator; |
| 29 | +import org.hibernate.dialect.sql.ast.PostgreSQLSqlAstTranslator; |
29 | 30 | import org.hibernate.dialect.type.DB2StructJdbcType; |
30 | 31 | import org.hibernate.dialect.unique.AlterTableUniqueIndexDelegate; |
31 | 32 | import org.hibernate.dialect.unique.UniqueDelegate; |
|
45 | 46 | import org.hibernate.mapping.Table; |
46 | 47 | import org.hibernate.metamodel.mapping.EntityMappingType; |
47 | 48 | import org.hibernate.metamodel.spi.RuntimeModelCreationContext; |
| 49 | +import org.hibernate.persister.entity.mutation.EntityMutationTarget; |
48 | 50 | import org.hibernate.procedure.internal.DB2CallableStatementSupport; |
49 | 51 | import org.hibernate.procedure.spi.CallableStatementSupport; |
50 | 52 | import org.hibernate.query.common.TemporalUnit; |
|
63 | 65 | import org.hibernate.sql.ast.spi.StandardSqlAstTranslatorFactory; |
64 | 66 | import org.hibernate.sql.ast.tree.Statement; |
65 | 67 | import org.hibernate.sql.exec.spi.JdbcOperation; |
| 68 | +import org.hibernate.sql.model.MutationOperation; |
| 69 | +import org.hibernate.sql.model.internal.OptionalTableUpdate; |
| 70 | +import org.hibernate.sql.model.jdbc.OptionalTableUpdateOperation; |
66 | 71 | import org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorDB2DatabaseImpl; |
67 | 72 | import org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorNoOpImpl; |
68 | 73 | import org.hibernate.tool.schema.extract.spi.SequenceInformationExtractor; |
@@ -169,16 +174,20 @@ protected void applyAggregateColumnCheck(StringBuilder buf, AggregateColumn aggr |
169 | 174 | } |
170 | 175 | }; |
171 | 176 |
|
| 177 | + private final OptionalTableUpdateStrategy optionalTableUpdateStrategy; |
| 178 | + |
172 | 179 | public DB2Dialect() { |
173 | 180 | this( MINIMUM_VERSION ); |
174 | 181 | } |
175 | 182 |
|
176 | 183 | public DB2Dialect(DialectResolutionInfo info) { |
177 | | - super( info ); |
| 184 | + this( info.makeCopyOrDefault( MINIMUM_VERSION ) ); |
| 185 | + registerKeywords( info ); |
178 | 186 | } |
179 | 187 |
|
180 | 188 | public DB2Dialect(DatabaseVersion version) { |
181 | 189 | super( version ); |
| 190 | + optionalTableUpdateStrategy = DB2Dialect::usingMerge; |
182 | 191 | } |
183 | 192 |
|
184 | 193 | @Override |
@@ -253,6 +262,39 @@ protected void registerColumnTypes(TypeContributions typeContributions, ServiceR |
253 | 262 | ); |
254 | 263 | } |
255 | 264 |
|
| 265 | + @FunctionalInterface |
| 266 | + private interface OptionalTableUpdateStrategy { |
| 267 | + MutationOperation buildMutationOperation( |
| 268 | + EntityMutationTarget mutationTarget, |
| 269 | + OptionalTableUpdate optionalTableUpdate, |
| 270 | + SessionFactoryImplementor factory); |
| 271 | + } |
| 272 | + |
| 273 | + @Override |
| 274 | + public MutationOperation createOptionalTableUpdateOperation( |
| 275 | + EntityMutationTarget mutationTarget, |
| 276 | + OptionalTableUpdate optionalTableUpdate, |
| 277 | + SessionFactoryImplementor factory) { |
| 278 | + return optionalTableUpdateStrategy.buildMutationOperation( mutationTarget, optionalTableUpdate, factory ); |
| 279 | + } |
| 280 | + |
| 281 | + private static MutationOperation usingMerge( |
| 282 | + EntityMutationTarget mutationTarget, |
| 283 | + OptionalTableUpdate optionalTableUpdate, |
| 284 | + SessionFactoryImplementor factory) { |
| 285 | + final PostgreSQLSqlAstTranslator<?> translator = new PostgreSQLSqlAstTranslator<>( factory, optionalTableUpdate ); |
| 286 | + return translator.createMergeOperation( optionalTableUpdate ); |
| 287 | + } |
| 288 | + |
| 289 | + private static MutationOperation withoutMerge( |
| 290 | + EntityMutationTarget mutationTarget, |
| 291 | + OptionalTableUpdate optionalTableUpdate, |
| 292 | + SessionFactoryImplementor factory) { |
| 293 | + return new OptionalTableUpdateOperation( mutationTarget, optionalTableUpdate, factory ); |
| 294 | + } |
| 295 | + |
| 296 | + |
| 297 | + |
256 | 298 | protected UniqueDelegate createUniqueDelegate() { |
257 | 299 | return new AlterTableUniqueIndexDelegate( this ); |
258 | 300 | } |
|
0 commit comments