Examples of CollectionDescriptorDef


Examples of xdoclet.modules.ojb.model.CollectionDescriptorDef

        {
            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);
                }
                else
                {   
View Full Code Here

Examples of xdoclet.modules.ojb.model.CollectionDescriptorDef

            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
                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 = findRemoteCollection(origDef);

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

Examples of xdoclet.modules.ojb.model.CollectionDescriptorDef

        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))))
            {
                return remoteCollDef;
            }
        }
        return null;
View Full Code Here

Examples of xdoclet.modules.ojb.model.CollectionDescriptorDef

    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

Examples of xdoclet.modules.ojb.model.CollectionDescriptorDef

     *                             ain't any subtypes
     */
    private void ensureReferencedKeys(ModelDef modelDef, String checkLevel) throws ConstraintException
    {
        ClassDescriptorDef      classDef;
        CollectionDescriptorDef collDef;
        ReferenceDescriptorDef  refDef;

        for (Iterator it = modelDef.getClasses(); it.hasNext();)
        {
            classDef = (ClassDescriptorDef)it.next();
            for (Iterator refIt = classDef.getReferences(); refIt.hasNext();)
            {
                refDef = (ReferenceDescriptorDef)refIt.next();
                if (!refDef.getBooleanProperty(PropertyHelper.OJB_PROPERTY_IGNORE, false))
                {
                    ensureReferencedPKs(modelDef, refDef);
                }
            }
            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))
                    {
                        ensureReferencedPKs(modelDef, collDef);
                    }
                    else
                    {
View Full Code Here

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

Examples of xdoclet.modules.ojb.model.CollectionDescriptorDef

        {
            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

Examples of xdoclet.modules.ojb.model.CollectionDescriptorDef

        // 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
        String                  elementClassName = collDef.getProperty(PropertyHelper.OJB_PROPERTY_ELEMENT_CLASS_REF);
        ClassDescriptorDef      elementClass     = modelDef.getClass(elementClassName);
        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);
            }
        }

        // issue a warning if the foreignkey and remote-foreignkey columns are the same (issue OJB-67)
        String remoteForeignkey = collDef.getProperty(PropertyHelper.OJB_PROPERTY_REMOTE_FOREIGNKEY);

        if (CommaListIterator.sameLists(foreignkey, remoteForeignkey))
        {
            LogHelper.warn(true,
                           getClass(),
                           "checkIndirectionTable",
                           "The remote foreignkey ("+remoteForeignkey+") for the collection "+collDef.getName()+" in class "+collDef.getOwner().getName()+" is identical (ignoring case) to the foreign key ("+foreignkey+").");
        }

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

Examples of xdoclet.modules.ojb.model.CollectionDescriptorDef

    {
        ClassDescriptorDef      ownerClass     = (ClassDescriptorDef)fieldDef.getOwner();
        String                  ownerClassName = ownerClass.getQualifiedName();
        String                  name           = fieldDef.getName();
        ClassDescriptorDef      classDef;
        CollectionDescriptorDef collDef;
        String                  elementClassName;

        for (Iterator classIt = modelDef.getClasses(); classIt.hasNext();)
        {
            classDef = (ClassDescriptorDef)classIt.next();
            for (Iterator collIt = classDef.getCollections(); collIt.hasNext();)
            {
                collDef          = (CollectionDescriptorDef)collIt.next();
                elementClassName = collDef.getProperty(PropertyHelper.OJB_PROPERTY_ELEMENT_CLASS_REF).replace('$', '.');
                // 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 (ownerClassName.equals(elementClassName))
                {
                    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

Examples of xdoclet.modules.ojb.model.CollectionDescriptorDef

     *                             ain't any subtypes
     */
    private void ensureReferencedKeys(ModelDef modelDef, String checkLevel) throws ConstraintException
    {
        ClassDescriptorDef      classDef;
        CollectionDescriptorDef collDef;
        ReferenceDescriptorDef  refDef;

        for (Iterator it = modelDef.getClasses(); it.hasNext();)
        {
            classDef = (ClassDescriptorDef)it.next();
            for (Iterator refIt = classDef.getReferences(); refIt.hasNext();)
            {
                refDef = (ReferenceDescriptorDef)refIt.next();
                if (!refDef.getBooleanProperty(PropertyHelper.OJB_PROPERTY_IGNORE, false))
                {
                    ensureReferencedPKs(modelDef, refDef);
                }
            }
            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))
                    {
                        ensureReferencedPKs(modelDef, collDef);
                    }
                    else
                    {
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.