Package dev.morphia.query.validation
Class OperationValidator
- java.lang.Object
-
- dev.morphia.query.validation.OperationValidator
-
- All Implemented Interfaces:
Validator
- Direct Known Subclasses:
AllOperationValidator
,ExistsOperationValidator
,GeoWithinOperationValidator
,InOperationValidator
,ModOperationValidator
,NotInOperationValidator
,SizeOperationValidator
public abstract class OperationValidator extends java.lang.Object implements Validator
Extend this abstract class to provide a way of validating part of a query that contains aFilterOperator
. Currently all subclasses of this are final and singletons so this isn't the root of a massive class hierarchy.
-
-
Constructor Summary
Constructors Constructor Description OperationValidator()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description boolean
apply(MappedField mappedField, FilterOperator operator, java.lang.Object value, java.util.List<ValidationFailure> validationFailures)
Apply validation for the given operator.protected abstract FilterOperator
getOperator()
This method is called by theapply
method to determine whether to validate the query.protected abstract void
validate(MappedField mappedField, java.lang.Object value, java.util.List<ValidationFailure> validationFailures)
Performs the actual validation, and assumesappliesTo
has returned true
-
-
-
Method Detail
-
apply
public boolean apply(MappedField mappedField, FilterOperator operator, java.lang.Object value, java.util.List<ValidationFailure> validationFailures)
Apply validation for the given operator. If the operator does not match the operator required by the implementing class, then this method will return false to show validation was not applied. If the operator is the one being validated, this method will return true, and any failures in validation will be added to the list ofvalidationFailures
.- Parameters:
mappedField
- the field being queriedoperator
- any FilterOperator for a queryvalue
- the query value, to apply the operator tovalidationFailures
- the list to add any failures to. If validation passes orappliesTo
returned false, this list will not change.- Returns:
- true if validation was applied, false if this validation doesn't apply to this operator.
-
getOperator
protected abstract FilterOperator getOperator()
This method is called by theapply
method to determine whether to validate the query. The validator will only work for a single FilterOperator, and this will be returned by this method- Returns:
- the FilterOperator this validator cares about.
-
validate
protected abstract void validate(MappedField mappedField, java.lang.Object value, java.util.List<ValidationFailure> validationFailures)
Performs the actual validation, and assumesappliesTo
has returned true- Parameters:
mappedField
- the field being queriedvalue
- the query value, to apply the operator to. This should not be null.validationFailures
- the list to add any newValidationFailures
to. If validation passed this list will not change.
-
-