Package xdoclet.modules.ojb.model

Examples of xdoclet.modules.ojb.model.CollectionDescriptorDef


            ClassDescriptorDef subTypeDef = (ClassDescriptorDef)it.next();

            // find the collection in the element class that has the same indirection table
            for (Iterator collIt = subTypeDef.getCollections(); collIt.hasNext();)
            {
                CollectionDescriptorDef curCollDef = (CollectionDescriptorDef)collIt.next();

                if (indirTable.equals(curCollDef.getProperty(PropertyHelper.OJB_PROPERTY_INDIRECTION_TABLE)) &&
                    (collDef != curCollDef) &&
                    (!hasRemoteKey || CommaListIterator.sameLists(remoteKey, curCollDef.getProperty(PropertyHelper.OJB_PROPERTY_FOREIGNKEY))) &&
                    (!curCollDef.hasProperty(PropertyHelper.OJB_PROPERTY_REMOTE_FOREIGNKEY) ||
                         CommaListIterator.sameLists(localKey, curCollDef.getProperty(PropertyHelper.OJB_PROPERTY_REMOTE_FOREIGNKEY))))
                {
                    fittingCollections.add(curCollDef);
                }
            }
        }
        if (!fittingCollections.isEmpty())
        {
            // if there is more than one, check that they match, i.e. that they all have the same foreignkeys
            if (!hasRemoteKey && (fittingCollections.size() > 1))
            {
                CollectionDescriptorDef firstCollDef = (CollectionDescriptorDef)fittingCollections.get(0);
                String                  foreignKey   = firstCollDef.getProperty(PropertyHelper.OJB_PROPERTY_FOREIGNKEY);

                for (int idx = 1; idx < fittingCollections.size(); idx++)
                {
                    CollectionDescriptorDef curCollDef = (CollectionDescriptorDef)fittingCollections.get(idx);

                    if (!CommaListIterator.sameLists(foreignKey, curCollDef.getProperty(PropertyHelper.OJB_PROPERTY_FOREIGNKEY)))
                    {
                        throw new ConstraintException("Cannot determine the element-side collection that corresponds to the collection "+
                                                      collDef.getName()+" in type "+collDef.getOwner().getName()+
                                                      " because there are at least two different collections that would fit."+
                                                      " Specifying remote-foreignkey in the original collection "+collDef.getName()+
                                                      " will perhaps help");
                    }
                }
                // store the found keys at the collections
                collDef.setProperty(PropertyHelper.OJB_PROPERTY_REMOTE_FOREIGNKEY, foreignKey);
                for (int idx = 0; idx < fittingCollections.size(); idx++)
                {
                    CollectionDescriptorDef curCollDef = (CollectionDescriptorDef)fittingCollections.get(idx);

                    curCollDef.setProperty(PropertyHelper.OJB_PROPERTY_REMOTE_FOREIGNKEY, localKey);
                }
            }
        }

        // copy subclass pk fields into target class (if not already present)
View Full Code Here


        {
            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
                    {   
View Full Code Here

        // we know that the class is present because the collection constraints have been checked already
        // TODO: we must check whether there is a collection at the other side; if the type does not map to a
        // table then we have to check its subtypes
        ClassDescriptorDef      elementClass  = modelDef.getClass(collDef.getProperty(PropertyHelper.OJB_PROPERTY_ELEMENT_CLASS_REF));
        CollectionDescriptorDef remoteCollDef = collDef.getRemoteCollection();

        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 (!CommaListIterator.sameLists(remoteKeys1, 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
                collDef.setProperty(PropertyHelper.OJB_PROPERTY_REMOTE_FOREIGNKEY, remoteKeys2);
            }
        }
        // for torque we generate names for the m:n relation that are unique across inheritance
        // but only if we don't have inherited collections
        if (collDef.getOriginal() != null)
        {
            CollectionDescriptorDef origDef       = (CollectionDescriptorDef)collDef.getOriginal();
            CollectionDescriptorDef origRemoteDef = origDef.getRemoteCollection();

            // we're removing any torque relation name properties from the base collection
            origDef.setProperty(PropertyHelper.TORQUE_PROPERTY_RELATION_NAME, null);
            origDef.setProperty(PropertyHelper.TORQUE_PROPERTY_INV_RELATION_NAME, null);
            if (origRemoteDef != null)
            {
                origRemoteDef.setProperty(PropertyHelper.TORQUE_PROPERTY_RELATION_NAME, null);
                origRemoteDef.setProperty(PropertyHelper.TORQUE_PROPERTY_INV_RELATION_NAME, null);
            }
        }
        else if (!collDef.hasProperty(PropertyHelper.TORQUE_PROPERTY_RELATION_NAME))
        {
            if (remoteCollDef == null)
View Full Code Here

    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)))
                {
                    if (collDef.hasProperty(PropertyHelper.OJB_PROPERTY_INDIRECTION_TABLE))
                    {
                        if (elementClassSuffices)
                        {
                            return collDef;
                        }
                    }
                    else if (new CommaListIterator(collDef.getProperty(PropertyHelper.OJB_PROPERTY_FOREIGNKEY)).contains(name))
                    {
                        // if the field is a foreignkey of this normal 1:n collection
                        return collDef;
                    }
                }
View Full Code Here

TOP

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

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.