Package org.apache.ojb.broker.metadata

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


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


    }

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

    void changeActorCollectionDescriptorTo(boolean autoRetrieve, int autoUpdate, int autoDelete, boolean proxy)
    {
        PersistenceBroker broker = PersistenceBrokerFactory.defaultPersistenceBroker();
        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);
        broker.close();
    }
View Full Code Here

    void changeMovieCollectionDescriptorTo(boolean autoRetrieve, int autoUpdate, int autoDelete, boolean proxy)
    {
        PersistenceBroker broker = PersistenceBrokerFactory.defaultPersistenceBroker();
        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);
        broker.close();
    }
View Full Code Here

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

        cod.setCascadeStore(false);

        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(paper);        // store Paper and intermediary table only
            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.setCascadeStore(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");
        boolean autoUpdate = cod.getCascadeStore();

        cod.setCascadeStore(false);

        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(paper);        // store Paper and intermediary table only
            broker.store(qual);         // store Qualifier
            Identity paperId = new Identity(paper, broker);
            broker.commitTransaction();

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

     * Store m-side, intermediary and n-side
     */
    public void testStoringWithAutoUpdateTrue()
    {
        ClassDescriptor cld = broker.getClassDescriptor(Paper.class);
        CollectionDescriptor cod = cld.getCollectionDescriptorByName("qualifiers");
        boolean autoUpdate = cod.getCascadeStore();

        cod.setCascadeStore(true);

        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(paper);        // store Paper, intermediary and Qualifier
            Identity paperId = new Identity(paper, broker);
            broker.commitTransaction();

            broker.clearCache();
            broker.beginTransaction();
            Paper retPaper = (Paper) broker.getObjectByIdentity(paperId);
            assertEquals(1, retPaper.getQualifiers().size());
            broker.commitTransaction();
        }
        finally
        {
            cod.setCascadeStore(autoUpdate);
        }
    }
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()
    {
        changeAutoSetting(Project.class, "subProjects", false, false, false, false);
        CollectionDescriptor ord = broker.getClassDescriptor(Project.class)
                .getCollectionDescriptorByName("subProjects");
        assertEquals(CollectionDescriptor.CASCADE_LINK, ord.getCascadingStore());
        assertEquals(CollectionDescriptor.CASCADE_NONE, ord.getCascadingDelete());
        assertEquals(false, ord.getCascadeStore());
        assertEquals(false, ord.getCascadeDelete());

        changeAutoSetting(Project.class, "subProjects", false, true, true, false);
        ord = broker.getClassDescriptor(Project.class)
                .getCollectionDescriptorByName("subProjects");
        assertEquals(ObjectReferenceDescriptor.CASCADE_OBJECT, ord.getCascadingStore());
        assertEquals(ObjectReferenceDescriptor.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.