1616import org .hibernate .mapping .SoftDeletable ;
1717import org .hibernate .mapping .Table ;
1818import org .hibernate .metamodel .mapping .SoftDeletableModelPart ;
19- import org .hibernate .metamodel .mapping .SoftDeleteMapping ;
2019import org .hibernate .metamodel .mapping .internal .MappingModelCreationProcess ;
2120import org .hibernate .metamodel .mapping .internal .SoftDeleteMappingImpl ;
22- import org .hibernate .sql .ast .spi .SqlExpressionResolver ;
23- import org .hibernate .sql .ast .tree .expression .ColumnReference ;
24- import org .hibernate .sql .ast .tree .expression .Expression ;
25- import org .hibernate .sql .ast .tree .expression .JdbcLiteral ;
26- import org .hibernate .sql .ast .tree .from .TableReference ;
27- import org .hibernate .sql .ast .tree .predicate .ComparisonPredicate ;
28- import org .hibernate .sql .ast .tree .predicate .Predicate ;
29- import org .hibernate .sql .ast .tree .update .Assignment ;
3021
3122import java .time .Instant ;
3223
3324import static org .hibernate .internal .util .StringHelper .coalesce ;
3425import static org .hibernate .internal .util .StringHelper .isBlank ;
35- import static org .hibernate .query .sqm .ComparisonOperator .EQUAL ;
3626
3727/**
3828 * Helper for dealing with {@link org.hibernate.annotations.SoftDelete}
@@ -95,6 +85,9 @@ private static Column createSoftDeleteIndicatorColumn(
9585 MetadataBuildingContext context ) {
9686 final Column softDeleteColumn = new Column ();
9787
88+ softDeleteColumn .setValue ( softDeleteIndicatorValue );
89+ softDeleteIndicatorValue .addColumn ( softDeleteColumn );
90+
9891 applyColumnName ( softDeleteColumn , softDeleteConfig , context );
9992
10093 softDeleteColumn .setLength ( 1 );
@@ -108,9 +101,6 @@ private static Column createSoftDeleteIndicatorColumn(
108101 softDeleteColumn .setComment ( softDeleteConfig .comment () );
109102 }
110103
111- softDeleteColumn .setValue ( softDeleteIndicatorValue );
112- softDeleteIndicatorValue .addColumn ( softDeleteColumn );
113-
114104 return softDeleteColumn ;
115105 }
116106
@@ -120,6 +110,7 @@ private static void applyColumnName(
120110 MetadataBuildingContext context ) {
121111 final Database database = context .getMetadataCollector ().getDatabase ();
122112 final PhysicalNamingStrategy namingStrategy = context .getBuildingOptions ().getPhysicalNamingStrategy ();
113+ // NOTE : the argument order is strange here - the fallback value comes first
123114 final String logicalColumnName = coalesce (
124115 softDeleteConfig .strategy ().getDefaultColumnName (),
125116 softDeleteConfig .columnName ()
@@ -142,56 +133,4 @@ public static SoftDeleteMappingImpl resolveSoftDeleteMapping(
142133 return new SoftDeleteMappingImpl ( softDeletableModelPart , bootMapping , tableName , creationProcess );
143134 }
144135
145- /**
146- * Create a SQL AST Predicate for restricting matches to non-deleted rows
147- *
148- * @param tableReference The table reference for the table containing the soft-delete column
149- * @param softDeleteMapping The soft-delete mapping
150- */
151- public static Predicate createNonSoftDeletedRestriction (
152- TableReference tableReference ,
153- SoftDeleteMapping softDeleteMapping ) {
154- final ColumnReference softDeleteColumn = new ColumnReference ( tableReference , softDeleteMapping );
155- final JdbcLiteral <?> notDeletedLiteral = new JdbcLiteral <>(
156- softDeleteMapping .getNonDeletedLiteralValue (),
157- softDeleteMapping .getJdbcMapping ()
158- );
159- return new ComparisonPredicate ( softDeleteColumn , EQUAL , notDeletedLiteral );
160- }
161-
162- /**
163- * Create a SQL AST Predicate for restricting matches to non-deleted rows
164- *
165- * @param tableReference The table reference for the table containing the soft-delete column
166- * @param softDeleteMapping The soft-delete mapping
167- */
168- public static Predicate createNonSoftDeletedRestriction (
169- TableReference tableReference ,
170- SoftDeleteMapping softDeleteMapping ,
171- SqlExpressionResolver expressionResolver ) {
172- final Expression softDeleteColumn = expressionResolver .resolveSqlExpression ( tableReference , softDeleteMapping );
173- final JdbcLiteral <?> notDeletedLiteral = new JdbcLiteral <>(
174- softDeleteMapping .getNonDeletedLiteralValue (),
175- softDeleteMapping .getJdbcMapping ()
176- );
177- return new ComparisonPredicate ( softDeleteColumn , EQUAL , notDeletedLiteral );
178- }
179-
180- /**
181- * Create a SQL AST Assignment for setting the soft-delete column to its
182- * deleted indicate value
183- *
184- * @param tableReference The table reference for the table containing the soft-delete column
185- * @param softDeleteMapping The soft-delete mapping
186- */
187- public static Assignment createSoftDeleteAssignment (
188- TableReference tableReference ,
189- SoftDeleteMapping softDeleteMapping ) {
190- final ColumnReference softDeleteColumn = new ColumnReference ( tableReference , softDeleteMapping );
191- final JdbcLiteral <?> softDeleteIndicator = new JdbcLiteral <>(
192- softDeleteMapping .getDeletedLiteralValue (),
193- softDeleteMapping .getJdbcMapping ()
194- );
195- return new Assignment ( softDeleteColumn , softDeleteIndicator );
196- }
197136}
0 commit comments