public abstract class AbstractJavaTimeValidator<C extends Annotation,T extends TemporalAccessor & Comparable<? super T>> extends Object implements HibernateConstraintValidator<C,T>
java.time
package.Modifier and Type | Field and Description |
---|---|
protected Clock |
referenceClock |
Constructor and Description |
---|
AbstractJavaTimeValidator() |
Modifier and Type | Method and Description |
---|---|
protected abstract Duration |
getEffectiveTemporalValidationTolerance(Duration absoluteTemporalValidationTolerance)
Returns the temporal validation tolerance to apply.
|
protected abstract T |
getReferenceValue(Clock reference)
Returns an object of the validated type corresponding to the current time reference as provided by the
ClockProvider . |
void |
initialize(ConstraintDescriptor<C> constraintDescriptor,
HibernateConstraintValidatorInitializationContext initializationContext)
Initializes the validator in preparation for
ConstraintValidator.isValid(Object, ConstraintValidatorContext) calls. |
protected abstract boolean |
isValid(int result)
Returns whether the result of the comparison between the validated value and the time reference is considered
valid.
|
boolean |
isValid(T value,
ConstraintValidatorContext context)
Implements the validation logic.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
initialize
protected Clock referenceClock
public void initialize(ConstraintDescriptor<C> constraintDescriptor, HibernateConstraintValidatorInitializationContext initializationContext)
HibernateConstraintValidator
ConstraintValidator.isValid(Object, ConstraintValidatorContext)
calls.
It is an alternative to ConstraintValidator.initialize(Annotation)
method. Should be used if any additional information
except annotation is needed to initialize a validator.
Note, when using HibernateConstraintValidator
user should only override one of the methods, either
HibernateConstraintValidator.initialize(ConstraintDescriptor, HibernateConstraintValidatorInitializationContext)
or ConstraintValidator.initialize(Annotation)
.
Both methods will be called during initialization, starting with
HibernateConstraintValidator.initialize(ConstraintDescriptor, HibernateConstraintValidatorInitializationContext)
.initialize
in interface HibernateConstraintValidator<C extends Annotation,T extends TemporalAccessor & Comparable<? super T>>
constraintDescriptor
- a constraint descriptor for a given constraint declarationinitializationContext
- an initialization context for a current ConstraintValidatorFactory
public boolean isValid(T value, ConstraintValidatorContext context)
ConstraintValidator
value
must not be altered.
This method can be accessed concurrently, thread-safety must be ensured by the implementation.
isValid
in interface ConstraintValidator<C extends Annotation,T extends TemporalAccessor & Comparable<? super T>>
value
- object to validatecontext
- context in which the constraint is evaluatedfalse
if value
does not pass the constraintprotected abstract Duration getEffectiveTemporalValidationTolerance(Duration absoluteTemporalValidationTolerance)
protected abstract T getReferenceValue(Clock reference)
ClockProvider
.protected abstract boolean isValid(int result)
Copyright © 2021 JBoss by Red Hat. All rights reserved.