Package org.apache.ojb.broker.metadata

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


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

        cod.setCascadingStore(ObjectReferenceDescriptor.CASCADE_OBJECT);

        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.setCascadingStore(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

        {
            // never returns null, thus we can direct call iterator
            Iterator descriptors = cld.getCollectionDescriptors().iterator();
            while (descriptors.hasNext())
            {
                CollectionDescriptor cod = (CollectionDescriptor) descriptors.next();
                linkOrUnlinkXToMany(doLink, obj, cod, insert);
            }
        }
    }
View Full Code Here

            linkOrUnlinkOneToOne(true, obj, ord, insert);
            match = true;
        }
        else
        {
            CollectionDescriptor cod = cld.getCollectionDescriptorByName(attributeName);
            if (cod != null)
            {
                linkOrUnlinkXToMany(true, obj, cod, insert);
                match = true;
            }
View Full Code Here

            linkOrUnlinkOneToOne(doLink, obj, ord, insert);
            match = true;
        }
        else
        {
            CollectionDescriptor cod = cld.getCollectionDescriptorByName(attributeName);
            if (cod != null)
            {
                linkOrUnlinkXToMany(doLink, obj, cod, insert);
                match = true;
            }
View Full Code Here

        {
            ClassDescriptor classDesc = (ClassDescriptor)classDescIt.next();

            for (Iterator collDescIt = classDesc.getCollectionDescriptors().iterator(); collDescIt.hasNext();)
            {
                CollectionDescriptor collDesc   = (CollectionDescriptor)collDescIt.next();
                String               indirTable = collDesc.getIndirectionTable();

                if ((indirTable != null) && (indirTable.length() > 0))
                {
                    Set columns = (Set)indirectionTables.get(indirTable);

                    if (columns == null)
                    {
                        columns = new HashSet();
                        indirectionTables.put(indirTable, columns);
                    }
                    columns.addAll(Arrays.asList(collDesc.getFksToThisClass()));
                    columns.addAll(Arrays.asList(collDesc.getFksToItemClass()));
                }
            }
        }
        if (indirectionTables.isEmpty())
        {
View Full Code Here

     * Test deprecated auto Settings
     */
    public void testAutoUpdateDeleteSettings()
    {
        ojbChangeReferenceSetting(Actor.class, "movies", false, false, false, false);
        CollectionDescriptor ord = broker.getClassDescriptor(Actor.class)
                .getCollectionDescriptorByName("movies");
        assertEquals(LINK, ord.getCascadingStore());
        assertEquals(LINK, ord.getCascadingDelete());
        assertEquals(false, ord.getCascadeStore());
        assertEquals(false, ord.getCascadeDelete());

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

    public void setUp() throws Exception
    {
        super.setUp();
        ClassDescriptor cld = MetadataManager.getInstance().getRepository().getDescriptorFor(ProductGroup.class);
        CollectionDescriptor cod = cld.getCollectionDescriptorByName("allArticlesInGroup");
        oldValue = cod.getCascadingStore();
        // odmg-api need false
        cod.setCascadeStore(false);
    }
View Full Code Here

    {
        ClassDescriptor cldProductGroup = broker.getClassDescriptor(ProductGroup.class);
        ClassDescriptor cldArticle = broker.getClassDescriptor(Article.class);
        Class productGroupProxy = cldProductGroup.getProxyClass();
        Class articleProxy = cldArticle.getProxyClass();
        CollectionDescriptor cds = cldProductGroup.getCollectionDescriptorByName("allArticlesInGroup");

        //
        // use ProductGroup and Articles with disabled Proxy
        //
        cldProductGroup.setProxyClass(null);
        cldProductGroup.setProxyClassName(null);
        cldArticle.setProxyClass(null);
        cldArticle.setProxyClassName(null);
        broker.getDescriptorRepository().setClassDescriptor(cldProductGroup);
        broker.getDescriptorRepository().setClassDescriptor(cldArticle);
       
        //
        // orderby articleId, ASC
        //
        broker.clearCache();
        cds.getOrderBy().clear();
        cds.addOrderBy("articleId", true);
        
        Criteria crit = new Criteria();
        crit.addLessOrEqualThan("groupId", new Integer(5));
        QueryByCriteria q = QueryFactory.newQuery(ProductGroup.class, crit);
        q.addOrderByDescending("groupId");
        q.addPrefetchedRelationship("allArticlesInGroup");

        Collection results = broker.getCollectionByQuery(q);
        assertNotNull(results);
        assertTrue(results.size() == 5);
        InterfaceProductGroup pg = (InterfaceProductGroup) results.toArray()[1];
        assertNotNull(pg.getAllArticles());
        Object articles[] = pg.getAllArticles().toArray();
        int articleSize = articles.length;
        assertTrue(articleSize == 10);
        Article a1 = (Article) articles[0];
        Article a2 = (Article) articles[9];
        assertTrue(a1.getArticleId().intValue() < a2.getArticleId().intValue());

        //
        // orderby articleId, DESC
        //
        broker.clearCache();
        cds.getOrderBy().clear();
        cds.addOrderBy("articleId", false);

        results = broker.getCollectionByQuery(q);
        assertNotNull(results);
        assertTrue(results.size() == 5);
        pg = (InterfaceProductGroup) results.toArray()[1];
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.