[hibernate-issues] [Hibernate-JIRA] Issue Comment Edited: (BVAL-232) Support Method-Level constraint declaration

Gunnar Morling (JIRA) noreply at atlassian.com
Fri Jul 8 16:42:53 EDT 2011


    [ http://opensource.atlassian.com/projects/hibernate/browse/BVAL-232?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=42826#action_42826 ] 

Gunnar Morling edited comment on BVAL-232 at 7/8/11 3:41 PM:
-------------------------------------------------------------

Approach #2a:
Use dedicated constraints/validators:

{code:java}
@DateParameterCheck
void bookHotel(@NotNull @Valid Customer customer, Date from, Date to);
{code}

The validator for the constraint would get passed the parameter values as array/list, maybe one would have a new interface {{MethodConstraintValidator}} for this:

{code:java}
public class DateParameterCheckValidator implements MethodConstraintValidator<DateParameterCheck> {

   @Override
   public void initialize(DateParameterCheck constraint) {}

   @Override
   public boolean isValid(Object[] parameterValues, ConstraintValidatorContext context) {
       return ((Date)parameterValues[1]).before((Date)parameterValues[2]);
   }
}
{code}

      was (Author: gunnar.morling):
    Approach #2a:
Use dedicated constraints/validators:

{code:java}
@DateParameterCheck
void bookHotel(@NotNull @Valid Customer customer, Date from, Date to);
{code}

The validator for the constraint would get passed the parameter values as array/list, maybe one would have a new interface {{MethodConstraintValidator}} for this:

{code:java}
public class DateParameterCheckValidator implements MethodConstraintValidator<DateParameterCheck> {

   public void initialize(DateParameterCheck constraint) {}

   public boolean isValid(Object[] parameterValues, ConstraintValidatorContext context) {
       return ((Date)parameterValues[1]).before((Date)parameterValues[2]);
   }
}
{code}
  
> Support Method-Level constraint declaration
> -------------------------------------------
>
>                 Key: BVAL-232
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/BVAL-232
>             Project: Bean Validation
>          Issue Type: New Feature
>          Components: spec-general
>            Reporter: Emmanuel Bernard
>             Fix For: 1.1
>
>
> Do you think we should support the following?
> {code}@DateInOrder
> void bookHotel(@NotNull @Valid Customer customer, Date from, Date to);{code}
> ie like we have properly level and class level constraints, we could get method level constraints receiving all the parameters and raising constraints violations if necessary.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list