Constraint that ensures that the field has precision and scale settings if the jdbc type requires it.

@param fieldDef   The field descriptor
@param checkLevel The current check level (this constraint is checked in all levels)
4305
private void ensurePrecisionAndScale(FieldDescriptorDef fieldDef, String checkLevel)
    {
        fieldDef.setProperty(PropertyHelper.OJB_PROPERTY_DEFAULT_PRECISION, null);
        fieldDef.setProperty(PropertyHelper.OJB_PROPERTY_DEFAULT_SCALE, null);
        if (!fieldDef.hasProperty(PropertyHelper.OJB_PROPERTY_PRECISION))
        {
            String defaultPrecision = JdbcTypeHelper.getDefaultPrecisionFor(fieldDef.getProperty(PropertyHelper.OJB_PROPERTY_JDBC_TYPE));

            if (defaultPrecision != null)
            {
                LogHelper.warn(true,
                               FieldDescriptorConstraints.class,
                               "ensureLength",
                               "The field "+fieldDef.getName()+" in class "+fieldDef.getOwner().getName()+" has no precision setting though its jdbc type requires it (in most databases); using default precision of "+defaultPrecision);
                fieldDef.setProperty(PropertyHelper.OJB_PROPERTY_DEFAULT_PRECISION, defaultPrecision);
            }
            else if (fieldDef.hasProperty(PropertyHelper.OJB_PROPERTY_SCALE))
            {
                fieldDef.setProperty(PropertyHelper.OJB_PROPERTY_DEFAULT_PRECISION, "1");
            }
        }
        if (!fieldDef.hasProperty(PropertyHelper.OJB_PROPERTY_SCALE))
         {
            String defaultScale = JdbcTypeHelper.getDefaultScaleFor(fieldDef.getProperty(PropertyHelper.OJB_PROPERTY_JDBC_TYPE));

            if (defaultScale != null)
            {
                LogHelper.warn(true,
                               FieldDescriptorConstraints.class,
                               "ensureLength",
                               "The field "+fieldDef.getName()+" in class "+fieldDef.getOwner().getName()+" has no scale setting though its jdbc type requires it (in most databases); using default scale of "+defaultScale);
                fieldDef.setProperty(PropertyHelper.OJB_PROPERTY_DEFAULT_SCALE, defaultScale);
            }
            else if (fieldDef.hasProperty(PropertyHelper.OJB_PROPERTY_PRECISION) || fieldDef.hasProperty(PropertyHelper.OJB_PROPERTY_DEFAULT_PRECISION))
            {
                fieldDef.setProperty(PropertyHelper.OJB_PROPERTY_DEFAULT_SCALE, "0");
            }
        }
    }
613973
private void ensureLength(FieldDescriptorDef fieldDef, String checkLevel)
    {
        if (!fieldDef.hasProperty(PropertyHelper.OJB_PROPERTY_LENGTH))
        {
            String defaultLength = JdbcTypeHelper.getDefaultLengthFor(fieldDef.getProperty(PropertyHelper.OJB_PROPERTY_JDBC_TYPE));

            if (defaultLength != null)
            {
                LogHelper.warn(true,
                               FieldDescriptorConstraints.class,
                               "ensureLength",
                               "The field "+fieldDef.getName()+" in class "+fieldDef.getOwner().getName()+" has no length setting though its jdbc type requires it (in most databases); using default length of "+defaultLength);
                fieldDef.setProperty(PropertyHelper.OJB_PROPERTY_LENGTH, defaultLength);
            }
        }
    }
197148
public boolean fieldsToCheck(Field destination, Field source){
		destinationName = destination.getName();
		sourceName = source.getName();
		if(!xml.conversionsLoad().isEmpty()){
			configurationType = XML;
			if(config == DESTINATION){
				if(existsXmlConversion(destinationClass)) { membership = Membership.DESTINATION;  return true;}
				if(existsXmlConversion(sourceClass))      { membership = Membership.SOURCE;       return true;}}
			else{
				if(existsXmlConversion(sourceClass))      { membership = Membership.SOURCE;       return true;}
				if(existsXmlConversion(destinationClass)) { membership = Membership.DESTINATION;  return true;}}
		}
		configurationType = ANNOTATION;
		if(config == DESTINATION){
			if(existsAnnotatedConversion(destinationClass)) { membership = Membership.DESTINATION;  return true;}
			if(existsAnnotatedConversion(sourceClass))      { membership = Membership.SOURCE;       return true;}}
		else{
			if(existsAnnotatedConversion(sourceClass))      { membership = Membership.SOURCE;       return true;}
			if(existsAnnotatedConversion(destinationClass)) { membership = Membership.DESTINATION;  return true;}}
		return false;
	}
674239
private void initResetCheckbox(CheckBox box, final CmsDateField field) {

        box.addValueChangeListener(new ValueChangeListener() {

            private static final long serialVersionUID = 1L;

            public void valueChange(ValueChangeEvent event) {

                Boolean value = (Boolean)(event.getProperty().getValue());
                if (value.booleanValue()) {
                    field.clear();
                    field.setEnabled(false);
                } else {
                    field.setEnabled(true);
                }
            }
        });
    }
129597
private void ensureTableIfNecessary(ClassDescriptorDef classDef, String checkLevel)
    {
        if (classDef.getBooleanProperty(PropertyHelper.OJB_PROPERTY_OJB_PERSISTENT, false))
        {
            if (!classDef.hasProperty(PropertyHelper.OJB_PROPERTY_TABLE))
            {
                classDef.setProperty(PropertyHelper.OJB_PROPERTY_TABLE, classDef.getDefaultTableName());
            }
        }
    }
590049
private void checkTypeDepth(Feature feature, Class<?> current)
    {
        for (final Class<?> type : current.getInterfaces())
        {
            if (type.isAnnotationPresent(FeatureInterface.class))
            {
                final Feature old;
                // CHECKSTYLE IGNORE LINE: InnerAssignment
                if ((old = typeToFeature.put(type.asSubclass(Feature.class), feature)) != null)
                {
                    throw new LionEngineException(ERROR_FEATURE_EXISTS
                                                  + feature.getClass()
                                                  + AS
                                                  + type
                                                  + WITH
                                                  + old.getClass());
                }
                checkTypeDepth(feature, type);
            }
        }
        final Class<?> parent = current.getSuperclass();
        if (parent != null)
        {
            checkTypeDepth(feature, parent);
        }
    }
248922
private void checkCollectionForeignkeys(ModelDef modelDef, CollectionDescriptorDef collDef) throws ConstraintException
    {
        String foreignkey = collDef.getProperty(PropertyHelper.OJB_PROPERTY_FOREIGNKEY);

        if ((foreignkey == null) || (foreignkey.length() == 0))
        {
            throw new ConstraintException("The collection "+collDef.getName()+" in class "+collDef.getOwner().getName()+" has no foreignkeys");
        }

        String remoteForeignkey = collDef.getProperty(PropertyHelper.OJB_PROPERTY_REMOTE_FOREIGNKEY);

        if ((remoteForeignkey != null) && (remoteForeignkey.length() > 0))
        {
            // warning because a remote-foreignkey was specified for a 1:n collection (issue OJB-67)
            LogHelper.warn(true,
                           getClass(),
                           "checkCollectionForeignkeys",
                           "For the collection "+collDef.getName()+" in class "+collDef.getOwner().getName()+", a remote foreignkey was specified though it is a 1:n, not a m:n collection");
        }
        
        ClassDescriptorDef ownerClass       = (ClassDescriptorDef)collDef.getOwner();
        ArrayList          primFields       = ownerClass.getPrimaryKeys();
        String             elementClassName = collDef.getProperty(PropertyHelper.OJB_PROPERTY_ELEMENT_CLASS_REF);
        ArrayList          queue            = new ArrayList();
        ClassDescriptorDef elementClass;
        ArrayList          keyFields;
        FieldDescriptorDef keyField;
        FieldDescriptorDef primField;
        String             primType;
        String             keyType;
        
        // we know that the class is present because the collection constraints have been checked already
        queue.add(modelDef.getClass(elementClassName));
        while (!queue.isEmpty())
        {
            elementClass = (ClassDescriptorDef)queue.get(0);
            queue.remove(0);

            for (Iterator it = elementClass.getExtentClasses(); it.hasNext();)
            {
                queue.add(it.next());
            }
            if (!elementClass.getBooleanProperty(PropertyHelper.OJB_PROPERTY_GENERATE_REPOSITORY_INFO, true))
            {
                continue;
            }
            try
            {
                keyFields = elementClass.getFields(foreignkey);
            }
            catch (NoSuchFieldException ex)
            {
                throw new ConstraintException("The collection "+collDef.getName()+" in class "+collDef.getOwner().getName()+" specifies a foreignkey "+ex.getMessage()+" that is not a persistent field in the element class (or its subclass) "+elementClass.getName());
            }
            if (primFields.size() != keyFields.size())
            {
                throw new ConstraintException("The number of foreignkeys ("+keyFields.size()+") of the collection "+collDef.getName()+" in class "+collDef.getOwner().getName()+" doesn't match the number of primarykeys ("+primFields.size()+") of its owner class "+ownerClass.getName());
            }
            for (int idx = 0; idx < keyFields.size(); idx++)
            {
                keyField  = (FieldDescriptorDef)keyFields.get(idx);
                if (keyField.getBooleanProperty(PropertyHelper.OJB_PROPERTY_IGNORE, false))
                {
                    throw new ConstraintException("The collection "+collDef.getName()+" in class "+ownerClass.getName()+" uses the field "+keyField.getName()+" as foreignkey although this field is ignored in the element class (or its subclass) "+elementClass.getName());
                }
            }
            // the jdbc types of the primary keys must match the jdbc types of the foreignkeys (in the correct order)
            for (int idx = 0; idx < primFields.size(); idx++)
            {
                keyField  = (FieldDescriptorDef)keyFields.get(idx);
                if (keyField.getBooleanProperty(PropertyHelper.OJB_PROPERTY_IGNORE, false))
                {
                    throw new ConstraintException("The collection "+collDef.getName()+" in class "+ownerClass.getName()+" uses the field "+keyField.getName()+" as foreignkey although this field is ignored in the element class (or its subclass) "+elementClass.getName());
                }
                primField = (FieldDescriptorDef)primFields.get(idx);
                primType  = primField.getProperty(PropertyHelper.OJB_PROPERTY_JDBC_TYPE);
                keyType   = keyField.getProperty(PropertyHelper.OJB_PROPERTY_JDBC_TYPE);
                if (!primType.equals(keyType))
                {
                    throw new ConstraintException("The jdbc-type of foreignkey "+keyField.getName()+" in the element class (or its subclass) "+elementClass.getName()+" used by the collection "+collDef.getName()+" in class "+ownerClass.getName()+" doesn't match the jdbc-type of the corresponding primarykey "+primField.getName());
                }
            }
        }
    }
526935
void checkFields(ClassFile cf) throws ConstantPoolException {
        for (Field f : cf.fields) {
            String type = nameFromDescType(cf.constant_pool.getUTF8Value(f.descriptor.index));
            if (type != null) {
                DeprData dd = db.getTypeDeprecated(type);
                if (dd != null) {
                    printHasField(cf, f.getName(cf.constant_pool), type, dd.isForRemoval());
                }
            }
        }
    }
106307
private void addIndex(IndexDescriptorDef indexDescDef, TableDef tableDef)
    {
        IndexDef indexDef = tableDef.getIndex(indexDescDef.getName());

        if (indexDef == null)
        {
            indexDef = new IndexDef(indexDescDef.getName(),
                                    indexDescDef.getBooleanProperty(PropertyHelper.OJB_PROPERTY_UNIQUE, false));
            tableDef.addIndex(indexDef);
        }

        try
        {
            String             fieldNames = indexDescDef.getProperty(PropertyHelper.OJB_PROPERTY_FIELDS);
            ArrayList          fields     = ((ClassDescriptorDef)indexDescDef.getOwner()).getFields(fieldNames);
            FieldDescriptorDef fieldDef;

            for (Iterator it = fields.iterator(); it.hasNext();)
            {
                fieldDef = (FieldDescriptorDef)it.next();
                indexDef.addColumn(fieldDef.getProperty(PropertyHelper.OJB_PROPERTY_COLUMN));
            }
        }
        catch (NoSuchFieldException ex)
        {
            // won't happen if we already checked the constraints
        }
    }
314092
private void checkInitializationMethod(ClassDescriptorDef classDef, String checkLevel) throws ConstraintException
    {
        if (!CHECKLEVEL_STRICT.equals(checkLevel))
        {
            return;
        }
        
        String initMethodName = classDef.getProperty(PropertyHelper.OJB_PROPERTY_INITIALIZATION_METHOD);

        if (initMethodName == null)
        {
            return;
        }

        Class  initClass;
        Method initMethod;

        try
        {
            initClass = InheritanceHelper.getClass(classDef.getName());
        }
        catch (ClassNotFoundException ex)
        {
            throw new ConstraintException("The class "+classDef.getName()+" was not found on the classpath");
        }
        try
        {
            initMethod = initClass.getDeclaredMethod(initMethodName, new Class[0]);
        }
        catch (NoSuchMethodException ex)
        {
            initMethod = null;
        }
        catch (Exception ex)
        {
            throw new ConstraintException("Exception while checking the class "+classDef.getName()+": "+ex.getMessage());
        }
        if (initMethod == null)
        {    
            try
            {
                initMethod = initClass.getMethod(initMethodName, new Class[0]);
            }
            catch (NoSuchMethodException ex)
            {
                throw new ConstraintException("No suitable initialization-method "+initMethodName+" found in class "+classDef.getName());
            }
            catch (Exception ex)
            {
                throw new ConstraintException("Exception while checking the class "+classDef.getName()+": "+ex.getMessage());
            }
        }

        // checking modifiers
        int mods = initMethod.getModifiers();

        if (Modifier.isStatic(mods) || Modifier.isAbstract(mods))
        {
            throw new ConstraintException("The initialization-method "+initMethodName+" in class "+classDef.getName()+" must be a concrete instance method");
        }
    }
1120944
@Override
    public boolean validate(Field f, Object validationObject)
    {
        boolean checkvalidation = true;

        for (Annotation annotation : f.getDeclaredAnnotations())
        {

            AttributeConstraintType eruleType = getERuleType(annotation.annotationType().getSimpleName());

            if (eruleType != null)
            {
                Object fieldValue = PropertyAccessorHelper.getObject(validationObject, f);

                switch (eruleType)
                {

                case ASSERT_FALSE:
                    checkvalidation = validateFalse(fieldValue, annotation);
                    break;
                case ASSERT_TRUE:
                    checkvalidation = validateTrue(fieldValue, annotation);
                    break;
                case DECIMAL_MAX:
                    checkvalidation = validateMaxDecimal(fieldValue, annotation);
                    break;
                case DECIMAL_MIN:
                    checkvalidation = validateMinDecimal(fieldValue, annotation);
                    break;
                case DIGITS:
                    checkvalidation = validateDigits(fieldValue, annotation);
                    break;
                case FUTURE:
                    checkvalidation = validateFuture(fieldValue, annotation);
                    break;
                case MAX:
                    checkvalidation = validateMaxValue(fieldValue, annotation);
                    break;

                case MIN:
                    checkvalidation = validateMinValue(fieldValue, annotation);
                    break;
                case NOT_NULL:
                    checkvalidation = validateNotNull(fieldValue, annotation);
                    break;
                case NULL:
                    checkvalidation = validateNull(fieldValue, annotation);
                    break;
                case PAST:
                    checkvalidation = validatePast(fieldValue, annotation);
                    break;
                case PATTERN:
                    checkvalidation = validatePattern(fieldValue, annotation);
                    break;
                case SIZE:
                    checkvalidation = validateSize(fieldValue, annotation);
                    break;

                }
            }
        }

        return checkvalidation;
    }
354595
void checkSuper(ClassFile cf) throws ConstantPoolException {
        String sname = cf.getSuperclassName();
        DeprData dd = db.getTypeDeprecated(sname);
        if (dd != null) {
            printType("scan.out.extends", cf, sname, dd.isForRemoval());
        }
    }
266061
private void checkCollectionForeignkeys(ModelDef modelDef, String checkLevel) throws ConstraintException
    {
        if (CHECKLEVEL_NONE.equals(checkLevel))
        {
            return;
        }

        ClassDescriptorDef      classDef;
        CollectionDescriptorDef collDef;

        for (Iterator it = modelDef.getClasses(); it.hasNext();)
        {
            classDef = (ClassDescriptorDef)it.next();
            for (Iterator collIt = classDef.getCollections(); collIt.hasNext();)
            {
                collDef = (CollectionDescriptorDef)collIt.next();
                if (!collDef.getBooleanProperty(PropertyHelper.OJB_PROPERTY_IGNORE, false))
                {
                    if (collDef.hasProperty(PropertyHelper.OJB_PROPERTY_INDIRECTION_TABLE))
                    {
                        checkIndirectionTable(modelDef, collDef);
                    }
                    else
                    {    
                        checkCollectionForeignkeys(modelDef, collDef);
                    }
                }
            }
        }
    }
861084
@SuppressWarnings({"checkstyle:cyclomaticcomplexity", "checkstyle:npathcomplexity", "checkstyle:nestedifdepth"})
	protected void checkSuperConstructor(
			XtendTypeDeclaration container,
			EStructuralFeature feature,
			Collection<ActionParameterTypes> defaultSignatures) {
		final JvmDeclaredType jvmElement = this.associations.getInferredType(container);
		if (jvmElement != null) {
			final Map<ActionParameterTypes, JvmConstructor> superConstructors =
					CollectionLiterals.newTreeMap((Comparator<ActionParameterTypes>) null);
			final JvmTypeReference typeRef = jvmElement.getExtendedClass();
			final JvmType supertype = (typeRef == null) ? null : typeRef.getType();
			if (supertype instanceof JvmGenericType) {
				final JvmGenericType jvmSuperElement = (JvmGenericType) supertype;
				for (final JvmConstructor superConstructor : jvmSuperElement.getDeclaredConstructors()) {
					final ActionParameterTypes sig = this.sarlActionSignatures.createParameterTypesFromJvmModel(
							superConstructor.isVarArgs(), superConstructor.getParameters());
					superConstructors.put(sig, superConstructor);
				}
			}

			final ActionParameterTypes voidKey = this.sarlActionSignatures.createParameterTypesForVoid();
			//boolean hasDeclaredConstructor = false;

			for (final XtendMember member : container.getMembers()) {
				if (member instanceof SarlConstructor) {
					final SarlConstructor constructor = (SarlConstructor) member;
					//hasDeclaredConstructor = true;
					boolean invokeDefaultConstructor = true;
					final XExpression body = constructor.getExpression();
					if (body instanceof XBlockExpression) {
						final XBlockExpression block = (XBlockExpression) body;
						if (!block.getExpressions().isEmpty()) {
							final XExpression firstStatement = block.getExpressions().get(0);
							if (firstStatement instanceof XConstructorCall || isDelegateConstructorCall(firstStatement)) {
								invokeDefaultConstructor = false;
							}
						}
					} else if (body instanceof XConstructorCall || isDelegateConstructorCall(body)) {
						invokeDefaultConstructor = false;
					}
					if (invokeDefaultConstructor && !superConstructors.containsKey(voidKey)) {
						final List<String> issueData = new ArrayList<>();
						for (final ActionParameterTypes defaultSignature : defaultSignatures) {
							issueData.add(defaultSignature.toString());
						}
						error(Messages.SARLValidator_33,
								member,
								null,
								ValidationMessageAcceptor.INSIGNIFICANT_INDEX,
								MUST_INVOKE_SUPER_CONSTRUCTOR,
								toArray(issueData, String.class));
					}
				}
			}

			// The following code is no more needed because of the constructor inheritance mechanism which
			// is implemented into the JVM model inferrer.
			/*if (!hasDeclaredConstructor) {
				for (final ActionParameterTypes defaultSignature : defaultSignatures) {
					if (!superConstructors.containsKey(defaultSignature)) {
						final List<String> issueData = new ArrayList<>();
						for (final JvmConstructor superConstructor : superConstructors.values()) {
							issueData.add(EcoreUtil.getURI(superConstructor).toString());
							issueData.add(doGetReadableSignature(container.getName(), superConstructor.getParameters()));
						}
						error(Messages.SARLValidator_33,
								container, feature, MISSING_CONSTRUCTOR, toArray(issueData, String.class));
					}
				}
			}*/
		}
	}
1292142
public static boolean onCheckValidationConstraints(Field attribute)
    {
        // / Checks if attribute contains any validation constraint enabled
        return attribute.isAnnotationPresent(AssertFalse.class) || attribute.isAnnotationPresent(AssertTrue.class)
                || attribute.isAnnotationPresent(DecimalMax.class) || attribute.isAnnotationPresent(DecimalMin.class)
                || attribute.isAnnotationPresent(Digits.class) || attribute.isAnnotationPresent(Future.class)
                || attribute.isAnnotationPresent(Max.class) || attribute.isAnnotationPresent(Min.class)
                || attribute.isAnnotationPresent(NotNull.class) || attribute.isAnnotationPresent(Null.class)
                || attribute.isAnnotationPresent(Past.class) || attribute.isAnnotationPresent(Pattern.class)
                || attribute.isAnnotationPresent(Size.class);

    }
834262
private void checkModifications(ClassDescriptorDef classDef, String checkLevel) throws ConstraintException
    {
        if (CHECKLEVEL_NONE.equals(checkLevel))
        {
            return;
        }

        HashMap              features = new HashMap();
        FeatureDescriptorDef def;

        for (Iterator it = classDef.getFields(); it.hasNext();)
        {
            def = (FeatureDescriptorDef)it.next();
            features.put(def.getName(), def);
        }
        for (Iterator it = classDef.getReferences(); it.hasNext();)
        {
            def = (FeatureDescriptorDef)it.next();
            features.put(def.getName(), def);
        }
        for (Iterator it = classDef.getCollections(); it.hasNext();)
        {
            def = (FeatureDescriptorDef)it.next();
            features.put(def.getName(), def);
        }

        // now checking the modifications
        Properties mods;
        String     modName;
        String     propName;

        for (Iterator it = classDef.getModificationNames(); it.hasNext();)
        {
            modName = (String)it.next();
            if (!features.containsKey(modName))
            {
                throw new ConstraintException("Class "+classDef.getName()+" contains a modification for an unknown feature "+modName);
            }
            def = (FeatureDescriptorDef)features.get(modName);
            if (def.getOriginal() == null)
            {
                throw new ConstraintException("Class "+classDef.getName()+" contains a modification for a feature "+modName+" that is not inherited but defined in the same class");
            }
            // checking modification
            mods = classDef.getModification(modName);
            for (Iterator propIt = mods.keySet().iterator(); propIt.hasNext();)
            {
                propName = (String)propIt.next();
                if (!PropertyHelper.isPropertyAllowed(def.getClass(), propName))
                {
                    throw new ConstraintException("The modification of attribute "+propName+" in class "+classDef.getName()+" is not applicable to the feature "+modName);
                }
            }
        }
    }
796833
function (fieldDefinition, fieldName) {
    const fieldType = propertyHelper.getFieldType(fieldDefinition);

    if (fieldType === 'date') {
      // This field is a date field. Create the checks
      return createDateChecks(fieldDefinition, fieldName);
    }
  }