hasNotNull = hasNotNull || applyNotNull( property, descriptor ); applyDigits( property, descriptor ); applySize( property, descriptor, propertyDesc ); applyMin( property, descriptor, dialect ); applyMax( property, descriptor, dialect ); applyLength( property, descriptor, propertyDesc ); boolean hasNotNullFromComposingConstraints = applyConstraints( descriptor.getComposingConstraints(), property, propertyDesc, null,
Property property = findPropertyByName( persistentClass, prefix + propertyDesc.getPropertyName() ); boolean hasNotNull; if ( property != null ) { hasNotNull = applyConstraints( propertyDesc.getConstraintDescriptors(), property, propertyDesc, groups, activateNotNull, dialect ); applyDDL( prefix + propertyDesc.getPropertyName() + ".", persistentClass, componentClass, factory, groups,
@SuppressWarnings("UnusedDeclaration") public static void activate(ActivationContext activationContext) { final ValidatorFactory factory; try { factory = getValidatorFactory( activationContext ); } catch (IntegrationException e) { if ( activationContext.getValidationModes().contains( ValidationMode.CALLBACK ) ) { throw new IntegrationException( "Bean Validation provider was not available, but 'callback' validation was requested", e ); } if ( activationContext.getValidationModes().contains( ValidationMode.DDL ) ) { throw new IntegrationException( "Bean Validation provider was not available, but 'ddl' validation was requested", e ); } LOG.debug( "Unable to acquire Bean Validation ValidatorFactory, skipping activation" ); return; } applyRelationalConstraints( factory, activationContext ); applyCallbackListeners( factory, activationContext ); }
final PersistentAttributeMapping property = findPropertyByName( persistentClass, prefix + propertyDesc.getPropertyName() ); boolean hasNotNull; if ( property != null ) { hasNotNull = applyConstraints( propertyDesc.getConstraintDescriptors(), property, propertyDesc, groups, activateNotNull, dialect ); if ( isComposite( property ) && propertyDesc.isCascaded() ) { Class<?> componentClass = ( (Component) property.getValueMapping() ).getComponentClass(); applyDDL( prefix + propertyDesc.getPropertyName() + ".", persistentClass, componentClass, factory, groups,
public static void applyDDL(Collection<PersistentClass> persistentClasses, Properties properties) { ValidatorFactory factory = getValidatorFactory( properties ); Class<?>[] groupsArray = new GroupsPerOperation( properties ).get( GroupsPerOperation.Operation.DDL ); Set<Class<?>> groups = new HashSet<Class<?>>( Arrays.asList( groupsArray ) ); for ( PersistentClass persistentClass : persistentClasses ) { final String className = persistentClass.getClassName(); if ( className == null || className.length() == 0) continue; Class<?> clazz; try { clazz = ReflectHelper.classForName( className, TypeSafeActivator.class ); } catch ( ClassNotFoundException e ) { throw new AssertionFailure( "Entity class not found", e); } try { applyDDL( "", persistentClass, clazz, factory, groups, true ); } catch (Exception e) { logger.warn( "Unable to apply constraints on DDL for " + className, e ); } } }
public static void activateBeanValidation(EventListeners eventListeners, Properties properties) { ValidatorFactory factory = getValidatorFactory( properties ); BeanValidationEventListener beanValidationEventListener = new BeanValidationEventListener( factory, properties ); { PreInsertEventListener[] listeners = eventListeners.getPreInsertEventListeners(); int length = listeners.length + 1; PreInsertEventListener[] newListeners = new PreInsertEventListener[length]; System.arraycopy( listeners, 0, newListeners, 0, length - 1 ); newListeners[length - 1] = beanValidationEventListener; eventListeners.setPreInsertEventListeners( newListeners ); } { PreUpdateEventListener[] listeners = eventListeners.getPreUpdateEventListeners(); int length = listeners.length + 1; PreUpdateEventListener[] newListeners = new PreUpdateEventListener[length]; System.arraycopy( listeners, 0, newListeners, 0, length - 1 ); newListeners[length - 1] = beanValidationEventListener; eventListeners.setPreUpdateEventListeners( newListeners ); } { PreDeleteEventListener[] listeners = eventListeners.getPreDeleteEventListeners(); int length = listeners.length + 1; PreDeleteEventListener[] newListeners = new PreDeleteEventListener[length]; System.arraycopy( listeners, 0, newListeners, 0, length - 1 ); newListeners[length - 1] = beanValidationEventListener; eventListeners.setPreDeleteEventListeners( newListeners ); } }
applyDDL( "", persistentClass, clazz, factory, groups, true, dialect );
@SuppressWarnings( {"UnusedDeclaration"}) public static void applyDDL(Collection<PersistentClass> persistentClasses, Properties properties, Dialect dialect) { ValidatorFactory factory = getValidatorFactory( properties ); Class<?>[] groupsArray = new GroupsPerOperation( properties ).get( GroupsPerOperation.Operation.DDL ); Set<Class<?>> groups = new HashSet<Class<?>>( Arrays.asList( groupsArray ) ); for ( PersistentClass persistentClass : persistentClasses ) { final String className = persistentClass.getClassName(); if ( className == null || className.length() == 0 ) { continue; } Class<?> clazz; try { clazz = ReflectHelper.classForName( className, TypeSafeActivator.class ); } catch ( ClassNotFoundException e ) { throw new AssertionFailure( "Entity class not found", e ); } try { applyDDL( "", persistentClass, clazz, factory, groups, true, dialect ); } catch (Exception e) { LOG.unableToApplyConstraints( className, e ); } } }
@SuppressWarnings( {"UnusedDeclaration"}) public static void activateBeanValidation(EventListenerRegistry listenerRegistry, Configuration configuration) { final Properties properties = configuration.getProperties(); ValidatorFactory factory = getValidatorFactory( properties ); BeanValidationEventListener listener = new BeanValidationEventListener( factory, properties ); listenerRegistry.addDuplicationStrategy( DuplicationStrategyImpl.INSTANCE ); listenerRegistry.appendListeners( EventType.PRE_INSERT, listener ); listenerRegistry.appendListeners( EventType.PRE_UPDATE, listener ); listenerRegistry.appendListeners( EventType.PRE_DELETE, listener ); listener.initialize( configuration ); }
applyDDL( "", entityMapping, clazz, factory, groups, true, dialect );
private static boolean applyConstraints(Set<ConstraintDescriptor<?>> constraintDescriptors, Property property, PropertyDescriptor propertyDesc, Set<Class<?>> groups, boolean canApplyNotNull) { boolean hasNotNull = false; for (ConstraintDescriptor<?> descriptor : constraintDescriptors) { if ( groups != null && Collections.disjoint( descriptor.getGroups(), groups) ) continue; if ( canApplyNotNull ) { hasNotNull = hasNotNull || applyNotNull( property, descriptor ); } // apply bean validation specific constraints applyDigits( property, descriptor ); applySize( property, descriptor, propertyDesc ); applyMin( property, descriptor ); applyMax( property, descriptor ); // apply hibernate validator specific constraints - we cannot import any HV specific classes though! applyLength( property, descriptor, propertyDesc ); // pass an empty set as composing constraints inherit the main constraint and thus are matching already hasNotNull = hasNotNull || applyConstraints( descriptor.getComposingConstraints(), property, propertyDesc, null, canApplyNotNull ); } return hasNotNull; }
private static void applyDDL(String prefix, PersistentClass persistentClass, Class<?> clazz, ValidatorFactory factory, Set<Class<?>> groups, boolean activateNotNull) { final BeanDescriptor descriptor = factory.getValidator().getConstraintsForClass( clazz ); //no bean level constraints can be applied, go to the properties for ( PropertyDescriptor propertyDesc : descriptor.getConstrainedProperties() ) { Property property = findPropertyByName( persistentClass, prefix + propertyDesc.getPropertyName() ); boolean hasNotNull = false; if ( property != null ) { hasNotNull = applyConstraints( propertyDesc.getConstraintDescriptors(), property, propertyDesc, groups, activateNotNull ); if ( property.isComposite() && propertyDesc.isCascaded() ) { Class<?> componentClass = ( ( Component ) property.getValue() ).getComponentClass(); /* * we can apply not null if the upper component let's us activate not null * and if the property is not null. * Otherwise, all sub columns should be left nullable */ final boolean canSetNotNullOnColumns = activateNotNull && hasNotNull; applyDDL( prefix + propertyDesc.getPropertyName() + ".", persistentClass, componentClass, factory, groups, canSetNotNullOnColumns ); } //FIXME add collection of components } } }
@SuppressWarnings( {"UnusedDeclaration"}) public static void applyDDL(Collection<PersistentClass> persistentClasses, Properties properties, Dialect dialect) { ValidatorFactory factory = getValidatorFactory( properties ); Class<?>[] groupsArray = new GroupsPerOperation( properties ).get( GroupsPerOperation.Operation.DDL ); Set<Class<?>> groups = new HashSet<Class<?>>( Arrays.asList( groupsArray ) ); for ( PersistentClass persistentClass : persistentClasses ) { final String className = persistentClass.getClassName(); if ( className == null || className.length() == 0 ) { continue; } Class<?> clazz; try { clazz = ReflectHelper.classForName( className, TypeSafeActivator.class ); } catch ( ClassNotFoundException e ) { throw new AssertionFailure( "Entity class not found", e ); } try { applyDDL( "", persistentClass, clazz, factory, groups, true, dialect ); } catch (Exception e) { LOG.unableToApplyConstraints( className, e ); } } }
@SuppressWarnings("UnusedDeclaration") public static void activate(ActivationContext activationContext) { final ValidatorFactory factory; try { factory = getValidatorFactory( activationContext ); } catch (IntegrationException e) { if ( activationContext.getValidationModes().contains( ValidationMode.CALLBACK ) ) { throw new IntegrationException( "Bean Validation provider was not available, but 'callback' validation was requested", e ); } if ( activationContext.getValidationModes().contains( ValidationMode.DDL ) ) { throw new IntegrationException( "Bean Validation provider was not available, but 'ddl' validation was requested", e ); } LOG.debug( "Unable to acquire Bean Validation ValidatorFactory, skipping activation" ); return; } applyRelationalConstraints( factory, activationContext ); applyCallbackListeners( factory, activationContext ); }
@SuppressWarnings( {"UnusedDeclaration"}) public static void activateBeanValidation(EventListenerRegistry listenerRegistry, Configuration configuration) { final Properties properties = configuration.getProperties(); ValidatorFactory factory = getValidatorFactory( properties ); BeanValidationEventListener listener = new BeanValidationEventListener( factory, properties ); listenerRegistry.addDuplicationStrategy( DuplicationStrategyImpl.INSTANCE ); listenerRegistry.appendListeners( EventType.PRE_INSERT, listener ); listenerRegistry.appendListeners( EventType.PRE_UPDATE, listener ); listenerRegistry.appendListeners( EventType.PRE_DELETE, listener ); listener.initialize( configuration ); }
hasNotNull = hasNotNull || applyNotNull( property, descriptor ); applyDigits( property, descriptor ); applySize( property, descriptor, propertyDesc ); applyMin( property, descriptor, dialect ); applyMax( property, descriptor, dialect ); applyLength( property, descriptor, propertyDesc ); hasNotNull = hasNotNull || applyConstraints( descriptor.getComposingConstraints(), property, propertyDesc, null,
Property property = findPropertyByName( persistentClass, prefix + propertyDesc.getPropertyName() ); boolean hasNotNull; if ( property != null ) { hasNotNull = applyConstraints( propertyDesc.getConstraintDescriptors(), property, propertyDesc, groups, activateNotNull, dialect ); applyDDL( prefix + propertyDesc.getPropertyName() + ".", persistentClass, componentClass, factory, groups,
hasNotNull = hasNotNull || applyNotNull( property, descriptor ); applyDigits( property, descriptor ); applySize( property, descriptor, propertyDesc ); applyMin( property, descriptor, dialect ); applyMax( property, descriptor, dialect ); applyLength( property, descriptor, propertyDesc ); boolean hasNotNullFromComposingConstraints = applyConstraints( descriptor.getComposingConstraints(), property, propertyDesc, null,
Property property = findPropertyByName( persistentClass, prefix + propertyDesc.getPropertyName() ); boolean hasNotNull; if ( property != null ) { hasNotNull = applyConstraints( propertyDesc.getConstraintDescriptors(), property, propertyDesc, groups, activateNotNull, dialect ); applyDDL( prefix + propertyDesc.getPropertyName() + ".", persistentClass, componentClass, factory, groups,
hasNotNull = hasNotNull || applyNotNull( property, descriptor ); applyDigits( property, descriptor ); applySize( property, descriptor, propertyDesc ); applyMin( property, descriptor, dialect ); applyMax( property, descriptor, dialect ); applyLength( property, descriptor, propertyDesc ); hasNotNull = hasNotNull || applyConstraints( descriptor.getComposingConstraints(), property, propertyDesc, null,