[hibernate-issues] [Hibernate-JIRA] Commented: (HV-274) Write a programmatic mapping API for constraint declarations

Hardy Ferentschik (JIRA) noreply at atlassian.com
Tue May 11 09:17:24 EDT 2010


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

Hardy Ferentschik commented on HV-274:
--------------------------------------

Here is a first draft on how this could look like. Entry point would be {{HibernateValidatorConfiguration}}

{noformat}
public void testProgrammaticApi() {
	HibernateValidatorConfiguration config = ( HibernateValidatorConfiguration ) TestUtil.getConfiguration();

	// class constraint
	config.addConstraint( ShoppingCartConstraint.class )
			.forGroups( Group1.class )
			.onType( ShoppingCart.class );

	// field constraint
	config.addConstraint( Size.class )
			.withMessage( "foo" )
			.andPayload( DummyPayload.class )
			.andParameter( "min", 0 )
			.andParameter( "max", 10 )
			.onField( "items" )
			.ofType( ShoppingCart.class );

	// getter constraint
	config.addConstraint( Pattern.class )
			.withParameter( "regexp", "[0-9]{10}" )
			.onGetter( "cartNo" )
			.ofType( ShoppingCart.class );
}

public interface Group1 {
}

public class DummyPayload implements Payload {
}
{noformat}

Maybe it would be worth to define a {{ConstraintParameter}} class (basically a key/value pair wrapper) and then have a {{withParameters(ConstraintParameter... parameters)}} vararg method.

This is not a 100% type safe approach. To get type-safety one would need meta classes listing the properties of each class similar to the JPA 2 typesafe criteria query. I think we should aim for a simple first version though (which does not require any additional metadata generators)

> Write a programmatic mapping API for constraint declarations
> ------------------------------------------------------------
>
>                 Key: HV-274
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HV-274
>             Project: Hibernate Validator
>          Issue Type: New Feature
>          Components: engine
>    Affects Versions: 4.0.2.GA
>            Reporter: Emmanuel Bernard
>            Assignee: Hardy Ferentschik
>             Fix For: 4.1.0
>
>


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