[hibernate-issues] [Hibernate-JIRA] Issue Comment Edited: (HV-390) Boolean composition of constraints

Hardy Ferentschik (JIRA) noreply at atlassian.com
Sun Oct 17 14:39:48 EDT 2010


    [ http://opensource.atlassian.com/projects/hibernate/browse/HV-390?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=38755#action_38755 ] 

Hardy Ferentschik edited comment on HV-390 at 10/17/10 1:39 PM:
----------------------------------------------------------------

We did think about more constraints at once, but could not come up with an elegant solution for it, due to the limitations on the possible types an annotation element can have. With the current @Bool it is of course possible to express ((Email | Address) & Phone) by first creating the annotation
containing  
{code}
@Bool(OR)
@Email
@Address
@interface Or1{}
{code}
and then 
{code}
@Bool(AND)
@Or1
@Phone
@interface OrAnd {}
{code}
As far as the name is concerned, we are open to suggestions, and @CompositionType is just fine.
I can attach a log file with the changes required, or directly the three modified files which can be just replaced in the validator. (As soon as I get access to the computer I forgot at home....)

      was (Author: federicom):
    We did think about more constraints at once, but could not come up with an elegant solution for it, due to the limitations on the possible types an annotation element can have. With the current @Bool it is of course possible to express ((Email | Address) & Phone) by first creating the annotation
containing  

@Bool(OR)
@Email
@Address
@interface Or1{}

and then 

@Bool(AND)
@Or1
@Phone
@interface OrAnd {}

As far as the name is concerned, we are open to suggestions, and @CompositionType is just fine.
I can attach a log file with the changes required, or directly the three modified files which can be just replaced in the validator. (As soon as I get access to the computer I forgot at home....)
  
> Boolean composition of constraints
> ----------------------------------
>
>                 Key: HV-390
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HV-390
>             Project: Hibernate Validator
>          Issue Type: New Feature
>          Components: engine
>            Reporter: Federico Mancini
>            Assignee: Hardy Ferentschik
>             Fix For: 4.2.0
>
>         Attachments: modified classes.zip
>
>
> By adding a built-in annotation @Bool (or some other name) with element values OR, ALLFALSE and AND (which would be the default) it would be possible to 
> compose constraints in a boolean fashion.
> For example:
> {code}
> //Specify that at least one of the patterns must match
> @Bool(OR)
> @List({@Pattern(regexp="pat1"), at Pattern(regexp="pat2"), at Pattern(regexp="pat3"), at Pattern(regexp="pat4")})
> @interface WhiteList{..}
> {code}
> {code}
> //Specify that none of the patterns must match
> @Bool(ALLFALSE)
> @List({@Pattern(regexp="pat1"), at Pattern(regexp="pat2"), at Pattern(regexp="pat3"), at Pattern(regexp="pat4")})
> @interface BlackList{..}
> {code}
> {code}
> //At least on valid contact method must match
> @Bool(OR)
> @Email
> @Address
> @Phone
> @interface ContactDetails{...}
> {code}
> This would greatly increase the type of new constraints that can be defined just by reusing some existing ones.
> Possible extensions might be for example further operators like XOR (meaning exactly one of the constraints must hold) or similar.
> It seems like it is possible to implement this feature by adding very little code to just a couple of classes, and adding the new @Bool annotation to the API.

-- 
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