|
24 | 24 | import org.hibernate.validator.internal.engine.constraintvalidation.ConstraintValidatorManager;
|
25 | 25 | import org.hibernate.validator.internal.engine.constraintvalidation.ConstraintViolationCreationContext;
|
26 | 26 | import org.hibernate.validator.internal.engine.path.ModifiablePath;
|
27 |
| -import org.hibernate.validator.internal.engine.path.NodeImpl; |
28 | 27 | import org.hibernate.validator.internal.engine.valuecontext.ValueContext;
|
29 | 28 | import org.hibernate.validator.internal.metadata.aggregated.BeanMetaData;
|
30 | 29 | import org.hibernate.validator.internal.metadata.core.MetaConstraint;
|
@@ -96,12 +95,6 @@ abstract class AbstractValidationContext<T> implements BaseBeanValidationContext
|
96 | 95 | */
|
97 | 96 | private final boolean processedBeanTrackingEnabled;
|
98 | 97 |
|
99 |
| - /** |
100 |
| - * The set of already processed meta constraints per bean - path ({@link BeanPathMetaConstraintProcessedUnit}). |
101 |
| - */ |
102 |
| - @Lazy |
103 |
| - private Set<BeanPathMetaConstraintProcessedUnit> processedPathUnits; |
104 |
| - |
105 | 98 | /**
|
106 | 99 | * Contains all failing constraints so far.
|
107 | 100 | */
|
@@ -248,25 +241,25 @@ protected abstract ConstraintViolation<T> createConstraintViolation(
|
248 | 241 | ConstraintViolationCreationContext constraintViolationCreationContext);
|
249 | 242 |
|
250 | 243 | @Override
|
251 |
| - public boolean hasMetaConstraintBeenProcessed(Object bean, ModifiablePath path, MetaConstraint<?> metaConstraint) { |
| 244 | + public boolean hasMetaConstraintBeenProcessed(ValueContext<?, ?> valueContext, MetaConstraint<?> metaConstraint) { |
252 | 245 | // this is only useful if the constraint is defined for more than 1 group as in the case it's only
|
253 | 246 | // defined for one group, there is no chance it's going to be called twice.
|
254 | 247 | if ( metaConstraint.isDefinedForOneGroupOnly() ) {
|
255 | 248 | return false;
|
256 | 249 | }
|
257 | 250 |
|
258 |
| - return getInitializedProcessedPathUnits().contains( new BeanPathMetaConstraintProcessedUnit( bean, path, metaConstraint ) ); |
| 251 | + return valueContext.hasMetaConstraintBeenProcessed( metaConstraint ); |
259 | 252 | }
|
260 | 253 |
|
261 | 254 | @Override
|
262 |
| - public void markConstraintProcessed(Object bean, ModifiablePath path, MetaConstraint<?> metaConstraint) { |
| 255 | + public void markConstraintProcessed(ValueContext<?, ?> valueContext, MetaConstraint<?> metaConstraint) { |
263 | 256 | // this is only useful if the constraint is defined for more than 1 group as in the case it's only
|
264 | 257 | // defined for one group, there is no chance it's going to be called twice.
|
265 | 258 | if ( metaConstraint.isDefinedForOneGroupOnly() ) {
|
266 | 259 | return;
|
267 | 260 | }
|
268 | 261 |
|
269 |
| - getInitializedProcessedPathUnits().add( new BeanPathMetaConstraintProcessedUnit( bean, path, metaConstraint ) ); |
| 262 | + valueContext.markConstraintProcessed( metaConstraint ); |
270 | 263 | }
|
271 | 264 |
|
272 | 265 | @Override
|
@@ -318,69 +311,11 @@ private String interpolate(
|
318 | 311 | }
|
319 | 312 | }
|
320 | 313 |
|
321 |
| - private Set<BeanPathMetaConstraintProcessedUnit> getInitializedProcessedPathUnits() { |
322 |
| - if ( processedPathUnits == null ) { |
323 |
| - processedPathUnits = new HashSet<>(); |
324 |
| - } |
325 |
| - return processedPathUnits; |
326 |
| - } |
327 |
| - |
328 | 314 | private Set<ConstraintViolation<T>> getInitializedFailingConstraintViolations() {
|
329 | 315 | if ( failingConstraintViolations == null ) {
|
330 | 316 | failingConstraintViolations = new HashSet<>();
|
331 | 317 | }
|
332 | 318 | return failingConstraintViolations;
|
333 | 319 | }
|
334 | 320 |
|
335 |
| - private static final class BeanPathMetaConstraintProcessedUnit { |
336 |
| - |
337 |
| - // these fields are final but we don't mark them as final as an optimization |
338 |
| - private Object bean; |
339 |
| - private NodeImpl pathLeaf; |
340 |
| - private MetaConstraint<?> metaConstraint; |
341 |
| - private int hashCode; |
342 |
| - |
343 |
| - BeanPathMetaConstraintProcessedUnit(Object bean, ModifiablePath path, MetaConstraint<?> metaConstraint) { |
344 |
| - this.bean = bean; |
345 |
| - this.pathLeaf = path.getLeafNode(); // because the leaf represent the entire path. |
346 |
| - this.metaConstraint = metaConstraint; |
347 |
| - this.hashCode = createHashCode(); |
348 |
| - } |
349 |
| - |
350 |
| - @Override |
351 |
| - public boolean equals(Object o) { |
352 |
| - // null check intentionally left out |
353 |
| - if ( this == o ) { |
354 |
| - return true; |
355 |
| - } |
356 |
| - |
357 |
| - // No need to check if the class matches because of how this class is used in the set. |
358 |
| - BeanPathMetaConstraintProcessedUnit that = (BeanPathMetaConstraintProcessedUnit) o; |
359 |
| - |
360 |
| - if ( bean != that.bean ) { // instance equality |
361 |
| - return false; |
362 |
| - } |
363 |
| - if ( metaConstraint != that.metaConstraint ) { |
364 |
| - return false; |
365 |
| - } |
366 |
| - if ( !pathLeaf.equals( that.pathLeaf ) ) { |
367 |
| - return false; |
368 |
| - } |
369 |
| - |
370 |
| - return true; |
371 |
| - } |
372 |
| - |
373 |
| - @Override |
374 |
| - public int hashCode() { |
375 |
| - return hashCode; |
376 |
| - } |
377 |
| - |
378 |
| - private int createHashCode() { |
379 |
| - int result = System.identityHashCode( bean ); |
380 |
| - result = 31 * result + pathLeaf.hashCode(); |
381 |
| - result = 31 * result + System.identityHashCode( metaConstraint ); |
382 |
| - return result; |
383 |
| - } |
384 |
| - } |
385 |
| - |
386 | 321 | }
|
0 commit comments