-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: [Validator] Any plan on constraint DSL or OCL support?
PostPosted: Fri Dec 20, 2013 5:01 pm 
Newbie

Joined: Fri Dec 20, 2013 4:41 pm
Posts: 4
Hi,

Everything is in the title. Hibernate validator seems a really nice project to validate constraints however, I haven't seen any ways to express constraints using a language. It would be great to have a language support such as the OCL standard for instance.

Just wondering if it has been discussed or considered already.

Thanks,
BQ.


Top
 Profile  
 
 Post subject: Re: [Validator] Any plan on constraint DSL or OCL support?
PostPosted: Thu Jan 02, 2014 5:25 am 
Hibernate Team
Hibernate Team

Joined: Sat Jan 24, 2009 12:46 pm
Posts: 388
Hi bquenin,

Sorry for the late reply, we were all in year's end holiday mode :)

Hibernate Validator provides an API for programmatic constraint declaration (http://docs.jboss.org/hibernate/stable/validator/reference/en-US/html_single/#section-programmatic-api) which allows to declare constraints using Java ("internal DSL") like this:

Code:
ConstraintMapping constraintMapping = ...;

constraintMapping
    .type( Car.class )
        .property( "manufacturer", FIELD )
            .constraint( new NotNullDef() )
        .property( "licensePlate", FIELD )
            .ignoreAnnotations()
            .constraint( new NotNullDef() )
            .constraint( new SizeDef().min( 2 ).max( 14 ) )
    .type( RentalCar.class )
        .property( "rentalStation", METHOD )
                .constraint( new NotNullDef() );

//... bootstrap validator using mapping


There is no support for external constraint languages such as OCL (besides the XML descriptors), but it should be possible to implement an OCL parser based on the programmatic API. Personally I feel this shouldn't be part of HV core as its quite specific and would probably not be used by many people.

Out of interest, what is your use case for using OCL instead of the means of constraint declaration provided by Bean Validation and HV (annotations, XML and API)?

--Gunnar

_________________
Visit my blog at http://musingsofaprogrammingaddict.blogspot.com/


Top
 Profile  
 
 Post subject: Re: [Validator] Any plan on constraint DSL or OCL support?
PostPosted: Wed Jan 08, 2014 10:39 am 
Newbie

Joined: Fri Dec 20, 2013 4:41 pm
Posts: 4
Hi Gunnar,

And thanks for your answer. I think you're right, it is definitely possible to implement an OCL parser using HV as a "resolver".

The need here is to be able to express constraints as a language, but not Java code, as a user would use it. Also, the dynamic aspect of the constraint (constraint can change over time, typically initiated by a user) is something I was looking for.

Using Java code to achieve this seems inadequate.

API could be a way, but contraints are not easily "buildable" without a dedicated language (again I speak of a user).

If you think I'm wrong, please feel free to tell me why :)

Regards,
BQ.


Top
 Profile  
 
 Post subject: Re: [Validator] Any plan on constraint DSL or OCL support?
PostPosted: Thu Jan 09, 2014 11:28 am 
Hibernate Team
Hibernate Team

Joined: Sat Jan 24, 2009 12:46 pm
Posts: 388
Hey,

I don't think there is a wrong or right answer here. It really depends on the exact use case and its circumstances.

My point is, the Java API allows to implement all sorts of "front ends" for declaring constraints on a given model in a dynamic manner. You could build an OCL parser using the API as back end, you could create a small DSL in a language such as JRuby based on top of it etc.

If you decide to implement something along these lines on your side, I'd be very interested in any insights and findings you get, i.e. does the API satisfy all the needs, where could it be improved etc.

--Gunnar

_________________
Visit my blog at http://musingsofaprogrammingaddict.blogspot.com/


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.