Package org.apache.ojb.broker.metadata

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



    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


    }

    void changeActorCollectionDescriptorTo(boolean autoRetrieve, int autoUpdate, int autoDelete, boolean proxy)
    {
        ClassDescriptor cld = broker.getClassDescriptor(Actor.class);
        CollectionDescriptor cod = (CollectionDescriptor) cld.getCollectionDescriptors().get(0);
        cod.setLazy(proxy);
        cod.setCascadeRetrieve(autoRetrieve);
        cod.setCascadingStore(autoUpdate);
        cod.setCascadingDelete(autoDelete);
    }
View Full Code Here

    }

    void changeActorCollectionDescriptorTo(boolean autoRetrieve, boolean autoUpdate, boolean autoDelete, boolean proxy)
    {
        ClassDescriptor cld = broker.getClassDescriptor(Actor.class);
        CollectionDescriptor cod = (CollectionDescriptor) cld.getCollectionDescriptors().get(0);
        cod.setLazy(proxy);
        cod.setCascadeRetrieve(autoRetrieve);
        cod.setCascadeStore(autoUpdate);
        cod.setCascadeDelete(autoDelete);
    }
View Full Code Here

    }

    void changeMovieCollectionDescriptorTo(boolean autoRetrieve, int autoUpdate, int autoDelete, boolean proxy)
    {
        ClassDescriptor cld = broker.getClassDescriptor(MovieImpl.class);
        CollectionDescriptor cod = (CollectionDescriptor) cld.getCollectionDescriptors().get(0);
        cod.setLazy(proxy);
        cod.setCascadeRetrieve(autoRetrieve);
        cod.setCascadingStore(autoUpdate);
        cod.setCascadingDelete(autoDelete);
    }
View Full Code Here

            }
        }

        // 1:N relations
        Iterator collections = mif.getCollectionDescriptors().iterator();
        CollectionDescriptor collectionDescriptor;

        while (collections.hasNext())
        {
            collectionDescriptor = (CollectionDescriptor) collections.next();
            field = collectionDescriptor.getPersistentField();
            if (Collection.class.isAssignableFrom(field.getType()))
            {
                Collection newCol;
                Collection oldCol;
View Full Code Here

    }

    void changeRelationMetadata(String field, boolean autoRetrieve, int autoUpdate, int autoDelete, boolean proxy)
    {
        ClassDescriptor cld = broker.getClassDescriptor(Node.class);
        CollectionDescriptor cod = cld.getCollectionDescriptorByName(field);
        cod.setLazy(proxy);
        cod.setCascadeRetrieve(autoRetrieve);
        cod.setCascadingStore(autoUpdate);
        cod.setCascadingDelete(autoDelete);
    }
View Full Code Here

            }

            List codList = desc.getCollectionDescriptors();
            for (Iterator it2 = codList.iterator(); it2.hasNext();)
            {
                CollectionDescriptor cod = (CollectionDescriptor) it2.next();
                ClassDescriptor manyDesc = repos.getDescriptorFor(cod.getItemClass());
                if (cod.isMtoNRelation())
                {
                    HashSet fkTables = getFKTablesFor(cod.getIndirectionTable());
                    fkTables.addAll(getFullTableNames(desc, repos));
                    fkTables.addAll(getFullTableNames(manyDesc, repos));
                }
                else
                {
View Full Code Here

//
      // Add collection descriptors
      java.util.Iterator it = cld.getCollectionDescriptors().iterator();
      while (it.hasNext())
      {
        CollectionDescriptor collDesc = (CollectionDescriptor)it.next();
        newChildren.add(new OjbMetaCollectionDescriptorNode(
          this.getOjbMetaTreeModel().getRepository(),
          this.getOjbMetaTreeModel(),
          this,
          collDesc));
View Full Code Here

     * Store m-side and intermediary
     */
    public void testStoringWithAutoUpdateFalse1()
    {
        ClassDescriptor cld = broker.getClassDescriptor(Paper.class);
        CollectionDescriptor cod = cld.getCollectionDescriptorByName("qualifiers");
        int autoUpdate = cod.getCascadingStore();

        cod.setCascadingStore(ObjectReferenceDescriptor.CASCADE_LINK);

        try
        {
            String now = new Date().toString();
            Paper paper = new Paper();
            paper.setAuthor("Jonny Myers");
            paper.setDate(now);
            Qualifier qual = new Topic();
            qual.setName("qual " + now);
            paper.setQualifiers(Arrays.asList(new Qualifier[] { qual }));
            broker.beginTransaction();
            // TODO: use constraint in DB and fix test
            // store paper and set indirection table, ignore new Qualifier
            // object. Will cause Key Constraint Exception when constraint are set
            broker.store(paper);
            Identity paperId = new Identity(paper, broker);
            broker.commitTransaction();

            broker.clearCache();
            broker.beginTransaction();
            Paper retPaper = (Paper) broker.getObjectByIdentity(paperId);
            assertEquals(0, retPaper.getQualifiers().size());
            broker.commitTransaction();
        }
        finally
        {
            cod.setCascadingStore(autoUpdate);
        }
    }
View Full Code Here

     * n-side forced by using broker.store()
     */
    public void testStoringWithAutoUpdateFalse2()
    {
        ClassDescriptor cld = broker.getClassDescriptor(Paper.class);
        CollectionDescriptor cod = cld.getCollectionDescriptorByName("qualifiers");
        int autoUpdate = cod.getCascadingStore();

        cod.setCascadingStore(ObjectReferenceDescriptor.CASCADE_LINK);

        try
        {
            String now = new Date().toString();
            Paper paper = new Paper();
            paper.setAuthor("Jonny Myers");
            paper.setDate(now);
            Qualifier qual = new Topic();
            qual.setName("qual " + now);
            paper.setQualifiers(Arrays.asList(new Qualifier[] { qual }));
            broker.beginTransaction();
            broker.store(qual);         // store Qualifier
            broker.store(paper);        // store Paper and intermediary table only
            Identity paperId = broker.serviceIdentity().buildIdentity(paper);
            broker.commitTransaction();

            broker.clearCache();
            broker.beginTransaction();
            Paper retPaper = (Paper) broker.getObjectByIdentity(paperId);
            assertEquals(1, retPaper.getQualifiers().size());
            broker.commitTransaction();
        }
        finally
        {
            cod.setCascadingStore(autoUpdate);
        }
    }
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.