Examples of FieldDescriptorDef


Examples of xdoclet.modules.ojb.model.FieldDescriptorDef

            return;
        }

        ClassDescriptorDef ownerClass       = (ClassDescriptorDef)collDef.getOwner();
        ClassDescriptorDef elementClass     = ((ModelDef)ownerClass.getOwner()).getClass(collDef.getProperty(PropertyHelper.OJB_PROPERTY_ELEMENT_CLASS_REF));
        FieldDescriptorDef fieldDef;
        String             token;
        String             fieldName;
        String             ordering;
        int                pos;
View Full Code Here

Examples of xdoclet.modules.ojb.model.FieldDescriptorDef

        ClassDescriptorDef ownerClass = (ClassDescriptorDef)collDef.getOwner();
        ArrayList          primFields = ownerClass.getPrimaryKeys();
        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(collDef.getProperty(PropertyHelper.OJB_PROPERTY_ELEMENT_CLASS_REF)));
        while (!queue.isEmpty())
        {
            elementClass = (ClassDescriptorDef)queue.get(0);
            queue.remove(0);

            for (Iterator it = elementClass.getExtentClasses(); it.hasNext();)
            {
                queue.add(it.next());
            }
            if (!elementClass.canBeInstantiated())
            {
                // we don't check abstract classes/interfaces
                continue;
            }
            try
            {
                keyFields = elementClass.getFields(foreignkey);
            }
            catch (NoSuchFieldException ex)
            {
                throw new ConstraintException("The collection "+collDef.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()+" 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 the 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 the 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());
                }
            }
        }
    }
View Full Code Here

Examples of xdoclet.modules.ojb.model.FieldDescriptorDef

        }

        // we know that the class is present because the reference constraints have been checked already
        ClassDescriptorDef ownerClass = (ClassDescriptorDef)refDef.getOwner();
        ArrayList          keyFields;
        FieldDescriptorDef keyField;
       
        try
        {
            keyFields = ownerClass.getFields(foreignkey);
        }
        catch (NoSuchFieldException ex)
        {
            throw new ConstraintException("The reference "+refDef.getName()+" specifies a foreignkey "+ex.getMessage()+" that is not a persistent field in 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 reference "+refDef.getName()+" in the class "+ownerClass.getName()+" uses the field "+keyField.getName()+" as foreignkey although this field is ignored in this class");
            }
        }
           
        // for the referenced class and any subtype that is instantiable (i.e. not an interface or abstract class)
        // there must be the same number of primary keys and the jdbc types of the primary keys must
        // match the jdbc types of the foreignkeys (in the correct order)
        ArrayList          queue = new ArrayList();
        ClassDescriptorDef referencedClass;
        ArrayList          primFields;
        FieldDescriptorDef primField;
        String             primType;
        String             keyType;
       
        queue.add(modelDef.getClass(refDef.getProperty(PropertyHelper.OJB_PROPERTY_CLASS_REF)));

        while (!queue.isEmpty())
        {
            referencedClass = (ClassDescriptorDef)queue.get(0);
            queue.remove(0);

            for (Iterator it = referencedClass.getExtentClasses(); it.hasNext();)
            {
                queue.add(it.next());
            }
            if (!referencedClass.canBeInstantiated())
            {
                // we don't check abstract classes/interfaces
                continue;
            }
            primFields = referencedClass.getPrimaryKeys();
            if (primFields.size() != keyFields.size())
            {
                throw new ConstraintException("The number of foreignkeys ("+keyFields.size()+") of the reference "+refDef.getName()+" doesn't match the number of primarykeys ("+primFields.size()+") of the referenced class (or its subclass) "+referencedClass.getName());
            }
            for (int idx = 0; idx < primFields.size(); idx++)
            {
                keyField  = (FieldDescriptorDef)keyFields.get(idx);
                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()+" of the reference "+refDef.getName()+" doesn't match the jdbc-type of the corresponding primarykey "+primField.getName()+" of the referenced class (or its subclass) "+referencedClass.getName());
                }
            }
        }
    }
View Full Code Here

Examples of xdoclet.modules.ojb.model.FieldDescriptorDef

        {
            return;
        }

        ClassDescriptorDef classDef;
        FieldDescriptorDef fieldDef;

        // we check for every inherited field
        for (Iterator classIt = modelDef.getClasses(); classIt.hasNext();)
        {
            classDef = (ClassDescriptorDef)classIt.next();
            for (Iterator fieldIt = classDef.getFields(); fieldIt.hasNext();)
            {
                fieldDef = (FieldDescriptorDef)fieldIt.next();
                if (fieldDef.isInherited())
                {
                    checkKeyModifications(modelDef, fieldDef);
                }
            }
        }
View Full Code Here

Examples of xdoclet.modules.ojb.model.FieldDescriptorDef

     * @throws ConstraintException If the field has invalid modifications
     */
    private void checkKeyModifications(ModelDef modelDef, FieldDescriptorDef keyDef) throws ConstraintException
    {
        // we check the field if it changes the primarykey-status or the jdbc-type
        FieldDescriptorDef baseFieldDef    = (FieldDescriptorDef)keyDef.getOriginal();
        boolean            isIgnored       = keyDef.getBooleanProperty(PropertyHelper.OJB_PROPERTY_IGNORE, false);
        boolean            changesJdbcType = !baseFieldDef.getProperty(PropertyHelper.OJB_PROPERTY_JDBC_TYPE).equals(keyDef.getProperty(PropertyHelper.OJB_PROPERTY_JDBC_TYPE));
        boolean            changesPrimary  = baseFieldDef.getBooleanProperty(PropertyHelper.OJB_PROPERTY_PRIMARYKEY, false) !=
                                             keyDef.getBooleanProperty(PropertyHelper.OJB_PROPERTY_PRIMARYKEY, false) ;

        if (isIgnored || changesJdbcType || changesPrimary)
        {
            FeatureDescriptorDef usingFeature = null;

            do
            {   
                usingFeature = usedByReference(modelDef, baseFieldDef);
                if (usingFeature != null)
                {
                    if (isIgnored)
                    {
                        throw new ConstraintException("Cannot ignore field "+keyDef.getName()+" in class "+keyDef.getOwner().getName()+
                                                      " because it is used in class "+baseFieldDef.getOwner().getName()+
                                                      " by the reference "+usingFeature.getName()+" from class "+
                                                      usingFeature.getOwner().getName());
                    }
                    else if (changesJdbcType)
                    {   
                        throw new ConstraintException("Modification of the jdbc-type for the field "+keyDef.getName()+" in class "+
                                                      keyDef.getOwner().getName()+" is not allowed because it is used in class "+
                                                      baseFieldDef.getOwner().getName()+" by the reference "+usingFeature.getName()+
                                                      " from class "+usingFeature.getOwner().getName());
                    }
                    else
                    {
                        throw new ConstraintException("Cannot change the primarykey status of field "+keyDef.getName()+" in class "+
                                                      keyDef.getOwner().getName()+" as primarykeys are used in class "+
                                                      baseFieldDef.getOwner().getName()+" by the reference "+usingFeature.getName()+
                                                      " from class "+usingFeature.getOwner().getName());
                    }
                }

                usingFeature = usedByCollection(modelDef, baseFieldDef, changesPrimary);
                if (usingFeature != null)
                {
                    if (isIgnored)
                    {
                        throw new ConstraintException("Cannot ignore field "+keyDef.getName()+" in class "+keyDef.getOwner().getName()+
                                                      " because it is used in class "+baseFieldDef.getOwner().getName()+
                                                      " as a foreignkey of the collection "+usingFeature.getName()+" from class "+
                                                      usingFeature.getOwner().getName());
                    }
                    else if (changesJdbcType)
                    {   
                        throw new ConstraintException("Modification of the jdbc-type for the field "+keyDef.getName()+" in class "+
                                                      keyDef.getOwner().getName()+" is not allowed because it is used in class "+
                                                      baseFieldDef.getOwner().getName()+" as a foreignkey of the collecton "+
                                                      usingFeature.getName()+" from class "+usingFeature.getOwner().getName());
                    }
                    else
                    {   
                        throw new ConstraintException("Cannot change the primarykey status of field "+keyDef.getName()+" in class "+
                                                      keyDef.getOwner().getName()+" as primarykeys are used in class "+
                                                      baseFieldDef.getOwner().getName()+" by the collection "+usingFeature.getName()+
                                                      " from class "+usingFeature.getOwner().getName());
                    }
                }

                baseFieldDef = (FieldDescriptorDef)baseFieldDef.getOriginal();
            }
            while (baseFieldDef != null);
        }
    }
View Full Code Here

Examples of xdoclet.modules.ojb.model.FieldDescriptorDef

        }

        ClassDescriptorDef ownerClass       = (ClassDescriptorDef)collDef.getOwner();
        String             elementClassName = collDef.getProperty(PropertyHelper.OJB_PROPERTY_ELEMENT_CLASS_REF).replace('$', '.');
        ClassDescriptorDef elementClass     = ((ModelDef)ownerClass.getOwner()).getClass(elementClassName);
        FieldDescriptorDef fieldDef;
        String             token;
        String             fieldName;
        String             ordering;
        int                pos;
View Full Code Here

Examples of xdoclet.modules.ojb.model.FieldDescriptorDef

        // first we gather all field names
        for (CommaListIterator it = new CommaListIterator(fkFieldNames); it.hasNext();)
        {
            String             fieldName = (String)it.next();
            FieldDescriptorDef fieldDef  = elementClassDef.getField(fieldName);

            if (fieldDef == null)
            {
                missingFields.add(fieldName);
            }
            fkFields.put(fieldName, fieldDef);
        }

        // next we traverse all sub types and gather fields as we go
        for (Iterator it = elementClassDef.getAllExtentClasses(); it.hasNext() && !missingFields.isEmpty();)
        {
            ClassDescriptorDef subTypeDef = (ClassDescriptorDef)it.next();

            for (int idx = 0; idx < missingFields.size();)
            {
                FieldDescriptorDef fieldDef = subTypeDef.getField((String)missingFields.get(idx));

                if (fieldDef != null)
                {
                    fkFields.put(fieldDef.getName(), fieldDef);
                    missingFields.remove(idx);
                }
                else
                {
                    idx++;
View Full Code Here

Examples of xdoclet.modules.ojb.model.FieldDescriptorDef

            ArrayList subPKs = subTypeDef.getPrimaryKeys();

            // check against already present PKs
            for (Iterator pkIt = subPKs.iterator(); pkIt.hasNext();)
            {
                FieldDescriptorDef fieldDef   = (FieldDescriptorDef)pkIt.next();
                FieldDescriptorDef foundPKDef = (FieldDescriptorDef)pks.get(fieldDef.getName());

                if (foundPKDef != null)
                {
                    if (!isEqual(fieldDef, foundPKDef))
                    {
                        throw new ConstraintException("Cannot pull up the declaration of the required primary key "+fieldDef.getName()+
                                                      " because its definitions in "+fieldDef.getOwner().getName()+" and "+
                                                      foundPKDef.getOwner().getName()+" differ");
                    }
                }
                else
                {
                    pks.put(fieldDef.getName(), fieldDef);
View Full Code Here

Examples of xdoclet.modules.ojb.model.FieldDescriptorDef

    {
        boolean forceVirtual = !classDef.getBooleanProperty(PropertyHelper.OJB_PROPERTY_GENERATE_REPOSITORY_INFO, true);

        for (Iterator it = fields.iterator(); it.hasNext();)
        {
            FieldDescriptorDef fieldDef = (FieldDescriptorDef)it.next();

            // First we check whether this field is already present in the class
            FieldDescriptorDef foundFieldDef = classDef.getField(fieldDef.getName());

            if (foundFieldDef != null)
            {
                if (isEqual(fieldDef, foundFieldDef))
                {
                    if (forceVirtual)
                    {
                        foundFieldDef.setProperty(PropertyHelper.OJB_PROPERTY_VIRTUAL_FIELD, "true");
                    }
                    continue;
                }
                else
                {
View Full Code Here

Examples of xdoclet.modules.ojb.model.FieldDescriptorDef

        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());
                }
            }
        }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.