net.sf.oval.configuration.annotation
Class JPAAnnotationsConfigurer
java.lang.Object
net.sf.oval.configuration.annotation.JPAAnnotationsConfigurer
- All Implemented Interfaces:
- Configurer
public class JPAAnnotationsConfigurer
- extends Object
- implements Configurer
Constraints configurer that interprets certain EJB3 JPA annotations:
* javax.persistence.Basic(optional=false) => net.sf.oval.constraint.NotNullCheck
* javax.persistence.OneToOne(optional=false) => net.sf.oval.constraint.NotNullCheck, net.sf.oval.constraint.AssertValidCheck (if addAssertValidConstraints=true)
* javax.persistence.ManyToOne(optional=false) => net.sf.oval.constraint.NotNullCheck, net.sf.oval.constraint.AssertValidCheck (if addAssertValidConstraints=true)
* javax.persistence.ManyToMany => net.sf.oval.constraint.AssertValidCheck (if addAssertValidConstraints=true)
* javax.persistence.Column(nullable=false) => net.sf.oval.constraint.NotNullCheck
* javax.persistence.Column(length=5) => net.sf.oval.constraint.LengthCheck
* javax.persistence.Column(precision>0) => net.sf.oval.constraint.RangeCheck (for Numbers only)
Important: by default AssertValidChecks are added for n-m relationships. This may be a problem when using lazy loading. Read this post for more details.
To avoid this override the method addAssertValidCheckIfRequired(Annotation, Collection, AccessibleObject) with an empty method body, for example
JPAAnnotationsConfigurer configurer = new JPAAnnotationsConfigurer() {
protected void addAssertValidCheckIfRequired(Annotation constraintAnnotation, Collection checks, AccessibleObject fieldOrMethod)
{
// do nothing
}
};
- Author:
- Sebastian Thomschke
|
Method Summary |
protected void |
addAssertValidCheckIfRequired(Annotation constraintAnnotation,
Collection<Check> checks,
AccessibleObject fieldOrMethod)
|
protected boolean |
containsCheckOfType(Collection<Check> checks,
Class<? extends Check> checkClass)
|
Boolean |
getApplyFieldConstraintsToConstructors()
|
ClassConfiguration |
getClassConfiguration(Class<?> clazz)
Returns the constraint configurations for the given class. |
ConstraintSetConfiguration |
getConstraintSetConfiguration(String constraintSetId)
Returns the constraint configuration for the constraint set with the
given Id. |
protected void |
initializeChecks(javax.persistence.Basic annotation,
Collection<Check> checks)
|
protected void |
initializeChecks(javax.persistence.Column annotation,
Collection<Check> checks,
AccessibleObject fieldOrMethod)
|
protected void |
initializeChecks(javax.persistence.ManyToMany annotation,
Collection<Check> checks)
|
protected void |
initializeChecks(javax.persistence.ManyToOne annotation,
Collection<Check> checks)
|
protected void |
initializeChecks(javax.persistence.OneToMany annotation,
Collection<Check> checks)
|
protected void |
initializeChecks(javax.persistence.OneToOne annotation,
Collection<Check> checks)
|
Boolean |
isApplyFieldConstraintsToSetter()
|
void |
setApplyFieldConstraintsToConstructors(Boolean applyFieldConstraintsToConstructors)
|
void |
setApplyFieldConstraintsToSetters(Boolean applyFieldConstraintsToSetters)
|
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
applyFieldConstraintsToSetters
protected Boolean applyFieldConstraintsToSetters
applyFieldConstraintsToConstructors
protected Boolean applyFieldConstraintsToConstructors
JPAAnnotationsConfigurer
public JPAAnnotationsConfigurer()
addAssertValidCheckIfRequired
protected void addAssertValidCheckIfRequired(Annotation constraintAnnotation,
Collection<Check> checks,
AccessibleObject fieldOrMethod)
containsCheckOfType
protected boolean containsCheckOfType(Collection<Check> checks,
Class<? extends Check> checkClass)
getApplyFieldConstraintsToConstructors
public Boolean getApplyFieldConstraintsToConstructors()
getClassConfiguration
public ClassConfiguration getClassConfiguration(Class<?> clazz)
- Description copied from interface:
Configurer
- Returns the constraint configurations for the given class. This method
is invoked only once by the Validator, the very first time an object
of the given class needs to be validated. The constraint configuration
is then translated into an Validator internal format and cached.
- Specified by:
getClassConfiguration in interface Configurer
- Parameters:
clazz - the class to get the configuration for
- Returns:
- The constraint configurations for the given class.
getConstraintSetConfiguration
public ConstraintSetConfiguration getConstraintSetConfiguration(String constraintSetId)
- Description copied from interface:
Configurer
- Returns the constraint configuration for the constraint set with the
given Id.
- Specified by:
getConstraintSetConfiguration in interface Configurer
- Parameters:
constraintSetId - the ID of the constraint set
- Returns:
- The constraint configuration for the constraint set with the given Id.
initializeChecks
protected void initializeChecks(javax.persistence.Basic annotation,
Collection<Check> checks)
initializeChecks
protected void initializeChecks(javax.persistence.Column annotation,
Collection<Check> checks,
AccessibleObject fieldOrMethod)
initializeChecks
protected void initializeChecks(javax.persistence.ManyToMany annotation,
Collection<Check> checks)
initializeChecks
protected void initializeChecks(javax.persistence.ManyToOne annotation,
Collection<Check> checks)
initializeChecks
protected void initializeChecks(javax.persistence.OneToMany annotation,
Collection<Check> checks)
initializeChecks
protected void initializeChecks(javax.persistence.OneToOne annotation,
Collection<Check> checks)
isApplyFieldConstraintsToSetter
public Boolean isApplyFieldConstraintsToSetter()
setApplyFieldConstraintsToConstructors
public void setApplyFieldConstraintsToConstructors(Boolean applyFieldConstraintsToConstructors)
setApplyFieldConstraintsToSetters
public void setApplyFieldConstraintsToSetters(Boolean applyFieldConstraintsToSetters)
Copyright © 2005–2013 The OVal Development Team. All rights reserved.