Package xdoclet.modules.ojb.model

Examples of xdoclet.modules.ojb.model.ClassDescriptorDef


        }

        // now checking the element type
        ModelDef           model            = (ModelDef)collDef.getOwner().getOwner();
        String             elementClassName = collDef.getProperty(PropertyHelper.OJB_PROPERTY_ELEMENT_CLASS_REF);
        ClassDescriptorDef elementClassDef  = model.getClass(elementClassName);

        if (elementClassDef == null)
        {
            throw new ConstraintException("Collection "+collDef.getName()+" in class "+collDef.getOwner().getName()+" references an unknown class "+elementClassName);
        }
        if (!elementClassDef.getBooleanProperty(PropertyHelper.OJB_PROPERTY_OJB_PERSISTENT, false))
        {
            throw new ConstraintException("The element class "+elementClassName+" of the collection "+collDef.getName()+" in class "+collDef.getOwner().getName()+" is not persistent");
        }
        if (CHECKLEVEL_STRICT.equals(checkLevel) && (arrayElementClassName != null))
        {
View Full Code Here


        if ((orderbySpec == null) || (orderbySpec.length() == 0))
        {
            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;

        for (CommaListIterator it = new CommaListIterator(orderbySpec); it.hasNext();)
        {
            token = it.getNext();
            pos   = token.indexOf('=');
            if (pos == -1)
            {
                fieldName = token;
                ordering  = null;
            }
            else
            {
                fieldName = token.substring(0, pos);
                ordering  = token.substring(pos + 1);
            }
            fieldDef = elementClass.getField(fieldName);
            if (fieldDef == null)
            {
                throw new ConstraintException("The field "+fieldName+" specified in the orderby attribute of the collection "+collDef.getName()+" in class "+ownerClass.getName()+" hasn't been found in the element class "+elementClass.getName());
            }
            if ((ordering != null) && (ordering.length() > 0) &&
                !"ASC".equals(ordering) && !"DESC".equals(ordering))
            {
                throw new ConstraintException("The ordering "+ordering+" specified in the orderby attribute of the collection "+collDef.getName()+" in class "+ownerClass.getName()+" is invalid");
View Full Code Here

        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.hasProperty(PropertyHelper.OJB_PROPERTY_INDIRECTION_TABLE))
                {
                    checkIndirectionTable(modelDef, collDef);
View Full Code Here

        {
            throw new ConstraintException("The collection "+collDef.getName()+" has no foreignkeys");
        }

        // we know that the class is present because the collection constraints have been checked already
        ClassDescriptorDef      elementClass  = modelDef.getClass(collDef.getProperty(PropertyHelper.OJB_PROPERTY_ELEMENT_CLASS_REF));
        CollectionDescriptorDef remoteCollDef = findRemoteCollection(collDef);

        if (remoteCollDef == null)
        {
            // error if there is none and we don't have remote-foreignkey specified
            if (!collDef.hasProperty(PropertyHelper.OJB_PROPERTY_REMOTE_FOREIGNKEY))
            {
                throw new ConstraintException("The collection "+collDef.getName()+" in class "+collDef.getOwner().getName()+" must specify remote-foreignkeys as the class on the other side of the m:n association has no corresponding collection");
            }
        }
        else
        {   
            String remoteKeys2 = remoteCollDef.getProperty(PropertyHelper.OJB_PROPERTY_FOREIGNKEY);

            if (collDef.hasProperty(PropertyHelper.OJB_PROPERTY_REMOTE_FOREIGNKEY))
            {
                // check that the specified remote-foreignkey equals the remote foreignkey setting
                String remoteKeys1 = collDef.getProperty(PropertyHelper.OJB_PROPERTY_REMOTE_FOREIGNKEY);

                if (!remoteKeys1.equals(remoteKeys2))
                {
                    throw new ConstraintException("The remote-foreignkey property specified for collection "+collDef.getName()+" in class "+collDef.getOwner().getName()+" doesn't match the foreignkey property of the corresponding collection "+remoteCollDef.getName()+" in class "+elementClass.getName());
                }
            }
            else
            {
                // ensure the remote-foreignkey setting
View Full Code Here

     * @return The corresponding remote collection
     */
    private CollectionDescriptorDef findRemoteCollection(CollectionDescriptorDef collDef)
    {
        ModelDef                modelDef      = (ModelDef)collDef.getOwner().getOwner();
        ClassDescriptorDef      elementClass  = modelDef.getClass(collDef.getProperty(PropertyHelper.OJB_PROPERTY_ELEMENT_CLASS_REF));
        String                  indirTable    = collDef.getProperty(PropertyHelper.OJB_PROPERTY_INDIRECTION_TABLE);
        boolean                 hasRemoteKey  = collDef.hasProperty(PropertyHelper.OJB_PROPERTY_REMOTE_FOREIGNKEY);
        String                  remoteKey     = collDef.getProperty(PropertyHelper.OJB_PROPERTY_REMOTE_FOREIGNKEY);
        CollectionDescriptorDef remoteCollDef = null;

        // find the collection in the element class that has the same indirection table
        for (Iterator it = elementClass.getCollections(); it.hasNext();)
        {
            remoteCollDef = (CollectionDescriptorDef)it.next();
            if (indirTable.equals(remoteCollDef.getProperty(PropertyHelper.OJB_PROPERTY_INDIRECTION_TABLE)) &&
                (collDef != remoteCollDef) &&
                (!hasRemoteKey || remoteKey.equals(remoteCollDef.getProperty(PropertyHelper.OJB_PROPERTY_FOREIGNKEY))))
View Full Code Here

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

        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

        if (CHECKLEVEL_NONE.equals(checkLevel))
        {
            return;
        }

        ClassDescriptorDef classDef;

        for (Iterator it = modelDef.getClasses(); it.hasNext();)
        {
            classDef = (ClassDescriptorDef)it.next();
            for (Iterator refIt = classDef.getReferences(); refIt.hasNext();)
            {
                checkReferenceForeignkeys(modelDef, (ReferenceDescriptorDef)refIt.next());
            }
        }
    }
View Full Code Here

        {
            throw new ConstraintException("The reference "+refDef.getName()+" has no foreignkeys");
        }

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

        if (CHECKLEVEL_NONE.equals(checkLevel))
        {
            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

     * @return The collection that uses the field or <code>null</code> if the field is not
     *         used in this way
     */
    private CollectionDescriptorDef usedByCollection(ModelDef modelDef, FieldDescriptorDef fieldDef, boolean elementClassSuffices)
    {
        ClassDescriptorDef      ownerClass = (ClassDescriptorDef)fieldDef.getOwner();
        String                  name       = fieldDef.getName();
        ClassDescriptorDef      classDef;
        CollectionDescriptorDef collDef;

        for (Iterator classIt = modelDef.getClasses(); classIt.hasNext();)
        {
            classDef = (ClassDescriptorDef)classIt.next();
            for (Iterator collIt = classDef.getCollections(); collIt.hasNext();)
            {
                collDef = (CollectionDescriptorDef)collIt.next();
                // if the owner class of the field is the element class of a normal collection
                // and the field is a foreignkey of this collection
                if (ownerClass.getName().equals(collDef.getProperty(PropertyHelper.OJB_PROPERTY_ELEMENT_CLASS_REF)))
View Full Code Here

TOP

Related Classes of xdoclet.modules.ojb.model.ClassDescriptorDef

Copyright © 2018 www.massapicom. 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.