Package org.apache.ojb.broker.metadata

Examples of org.apache.ojb.broker.metadata.CollectionDescriptor


        // get all members of obj that are collections and delete all their elements
        Iterator i = listCds.iterator();

        while (i.hasNext())
        {
            CollectionDescriptor cds = (CollectionDescriptor) i.next();
            if(cds.getCascadingDelete() != ObjectReferenceDescriptor.CASCADE_NONE)
            {
                if(cds.isMtoNRelation())
                {
                    // if this is a m:n mapped table, remove entries from indirection table
                    mtoNBroker.deleteMtoNImplementor(cds, obj);
                }
                /*
                if cascading delete is on, delete all referenced objects.
                NOTE: User has to take care to populate all referenced objects before delete
                the main object to avoid referential constraint violation
                 */
                if (cds.getCascadingDelete() == ObjectReferenceDescriptor.CASCADE_OBJECT)
                {
                    Object col = cds.getPersistentField().get(obj);
                    if (col != null)
                    {
                        Iterator colIterator = BrokerHelper.getCollectionIterator(col);
                        while (colIterator.hasNext())
                        {
View Full Code Here


            return;
        }
        Iterator i = listCods.iterator();
        while (i.hasNext())
        {
            CollectionDescriptor cod = (CollectionDescriptor) i.next();
            /*
            if CASCADE_NONE was set, do nothing with referenced objects
            */
            if(cod.getCascadingStore() != ObjectReferenceDescriptor.CASCADE_NONE)
            {
                Object referencedObjects = cod.getPersistentField().get(obj);
                if(cod.isMtoNRelation())
                {
                    storeAndLinkMtoN(false, obj, cod, referencedObjects, insert);
                }
                else
                {
View Full Code Here

          logger.info("Retrieving reference named["+pAttributeName+"] on ["+
                      pInstance.getClass().getName()+"]");
        }
*/
        ClassDescriptor cld = getClassDescriptor(pInstance.getClass());
        CollectionDescriptor cod = cld.getCollectionDescriptorByName(pAttributeName);
        if (cod != null)
        {
            referencesBroker.retrieveCollection(pInstance, cld, cod, true);
        }
        else
View Full Code Here

     * @param cld
     */
    public void refreshRelationships(Object obj, ClassDescriptor cld)
    {
        Iterator iter;
        CollectionDescriptor cds;
        ObjectReferenceDescriptor rds;
        iter = cld.getCollectionDescriptors().iterator();
        while (iter.hasNext())
        {
            cds = (CollectionDescriptor) iter.next();
            if (cds.isRefresh())
            {
                referencesBroker.retrieveCollection(obj, cld, cds, false);
            }
        }
        //
View Full Code Here

                        }
                    }
                    Vector cds = tempCld.getCollectionDescriptors();
                    for (int i = cds.size() - 1; i >= 0; i--)
                    {
                        CollectionDescriptor cd = (CollectionDescriptor) cds.get(i);
                        v.add(cd.getPersistentField());
                    }
                    baseClass = tempCld.getBaseClass();
                }
                while ((null != baseClass) && !(baseClass.equals(OBJECT)));
                cld.setSuperPersistentFieldDescriptors(v);
View Full Code Here

         * 3. now let's register the collection descriptors
         * How do we handle proxied collections and collections of proxies
         * @see org.apache.ojb.odmg.OneToManyTest
         */
        Iterator collections = mif.getCollectionDescriptors().iterator();
        CollectionDescriptor collectionDescriptor = null;
        while(collections.hasNext())
        {
            collectionDescriptor = (CollectionDescriptor) collections.next();
            Object collectionOrArray = collectionDescriptor.getPersistentField().get(myObj);
            if(collectionOrArray != null)
            {
                int referencesId = 0;
                // no special treatment for CollectionProxies required,
                // their size() method does not materialize the elements.
View Full Code Here

     *
     */
    public void retrieveCollections(Object newObj, ClassDescriptor cld, boolean forced) throws PersistenceBrokerException
    {
        Iterator i = cld.getCollectionDescriptors().iterator();
        CollectionDescriptor cds;
        // turn off auto prefetching for related proxies
        Class saveClassToPrefetch = classToPrefetch;
        classToPrefetch = null;
        while (i.hasNext())
        {
View Full Code Here

    // delete from intermediary table only when collection NOT removal aware
    public void testDelete_NonRemovalAware()
    {
        ClassDescriptor cld = broker.getClassDescriptor(Paper.class);
        CollectionDescriptor cod = cld.getCollectionDescriptorByName("qualifiers");
        Class collectionClass = cod.getCollectionClass();

        cod.setCollectionClass(ManageableArrayList.class);

        try
        {
            Paper paper = createPaper();
            Identity paperId = new Identity(paper, broker);
            List qualifiers = paper.getQualifiers();
            Qualifier qual1 = (Qualifier) qualifiers.get(0);
            Qualifier qual2 = (Qualifier) qualifiers.get(1);

            // remove first object
            qualifiers.remove(0);
            broker.beginTransaction();
            broker.store(paper);
            broker.commitTransaction();

            broker.clearCache();
            broker.beginTransaction();
            Paper retPaper = (Paper) broker.getObjectByIdentity(paperId);
            assertEquals(1, retPaper.getQualifiers().size());

            // target object qual1 should NOT be deleted
            Qualifier retQual1 = (Qualifier) broker.getObjectByIdentity(new Identity(qual1, broker));
            Qualifier retQual2 = (Qualifier) broker.getObjectByIdentity(new Identity(qual2, broker));

            assertNotNull(retQual1);
            assertNotNull(retQual2);

            broker.commitTransaction();
        }
        finally
        {
            cod.setCollectionClass(collectionClass);
        }

    }
View Full Code Here

    // delete from intermediary AND target-table when collection removal aware
    public void testDelete_RemovalAware()
    {
        ClassDescriptor cld = broker.getClassDescriptor(Paper.class);
        CollectionDescriptor cod = cld.getCollectionDescriptorByName("qualifiers");
        Class collectionClass = cod.getCollectionClass();

        cod.setCollectionClass(RemovalAwareCollection.class);

        try
        {
            Paper paper = createPaper();
            List qualifiers = paper.getQualifiers();
            Qualifier qual1 = (Qualifier) qualifiers.get(0);
            Qualifier qual2 = (Qualifier) qualifiers.get(1);
            Identity paperId = new Identity(paper, broker);

            // remove first object
            qualifiers.remove(0);
            broker.beginTransaction();
            broker.store(paper);
            broker.commitTransaction();

            broker.clearCache();
            broker.beginTransaction();
            Paper retPaper = (Paper) broker.getObjectByIdentity(paperId);
            assertEquals(1, retPaper.getQualifiers().size());

            // target object qual1 should be deleted
            Qualifier retQual1 = (Qualifier) broker.getObjectByIdentity(new Identity(qual1, broker));
            Qualifier retQual2 = (Qualifier) broker.getObjectByIdentity(new Identity(qual2, broker));

            assertNull(retQual1);
            assertNotNull(retQual2);

            broker.commitTransaction();
        }
        finally
        {
            cod.setCollectionClass(collectionClass);
        }
    }
View Full Code Here


    public void testAutoUpdateDeleteSettings()
    {
        changeActorCollectionDescriptorTo(false, false, false, false);
        CollectionDescriptor ord = broker.getClassDescriptor(Actor.class)
                .getCollectionDescriptorByName("movies");
        assertEquals(CollectionDescriptor.CASCADE_LINK, ord.getCascadingStore());
        assertEquals(CollectionDescriptor.CASCADE_LINK, ord.getCascadingDelete());
        assertEquals(false, ord.getCascadeStore());
        assertEquals(false, ord.getCascadeDelete());

        changeActorCollectionDescriptorTo(false, true, true, false);
        ord = broker.getClassDescriptor(Actor.class)
                .getCollectionDescriptorByName("movies");
        assertEquals(CollectionDescriptor.CASCADE_OBJECT, ord.getCascadingStore());
        assertEquals(CollectionDescriptor.CASCADE_OBJECT, ord.getCascadingDelete());
        assertEquals(true, ord.getCascadeStore());
        assertEquals(true, ord.getCascadeDelete());
    }
View Full Code Here

TOP

Related Classes of org.apache.ojb.broker.metadata.CollectionDescriptor

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.