Package org.apache.ojb.broker.metadata

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


        }

        count = 0;
        for (Iterator it = colDescs.iterator(); it.hasNext(); count++)
        {
            CollectionDescriptor cds = (CollectionDescriptor) it.next();
            PersistentField f = cds.getPersistentField();
            Class type = f.getType();
            Object col = f.get(obj);

            if ((col != null) && (col instanceof CollectionProxyDefaultImpl)
                    && !((CollectionProxyDefaultImpl) col).isLoaded())
View Full Code Here


        }

        count = 0;
        for (Iterator it = colDescs.iterator(); it.hasNext(); count++)
        {
            CollectionDescriptor cds = (CollectionDescriptor) it.next();
            PersistentField f = cds.getPersistentField();
            ArrayList list = collections[count];
            ArrayList newCol;

            if (list == null)
            {
View Full Code Here

        ArrayList newObjects = new ArrayList();
        int count = 0;

        for (Iterator it = colDescs.iterator(); it.hasNext(); count++)
        {
            CollectionDescriptor cds = (CollectionDescriptor) it.next();

            if (cds.getOtmDependent())
            {
                ArrayList origList = (origCollections == null ? null
                                        : (ArrayList) origCollections[count]);
                ArrayList newList = (ArrayList) newCollections[count];
View Full Code Here

            }
        }

        for (Iterator it = colDescs.iterator(); it.hasNext(); )
        {
            CollectionDescriptor cds = (CollectionDescriptor) it.next();

            if (cds.getOtmDependent())
            {
                PersistentField f = cds.getPersistentField();
                Class type = f.getType();
                Object col = f.get(obj);

                if (col != null)
                {
View Full Code Here

         * MBAIRD
         * 3. now let's register the collection descriptors
         * How do we handle proxied collections and collections of proxies
         */
        Iterator collections = mif.getCollectionDescriptors().iterator();
        CollectionDescriptor cds = null;
        while(collections.hasNext())
        {
            cds = (CollectionDescriptor) collections.next();
            Object collectionOrArray = cds.getPersistentField().get(myObj);
            EqualsColHelper ech = new EqualsColHelper(cds, collectionOrArray);
            fieldValues.put(cds, ech);
        }
        return fieldValues;
    }
View Full Code Here

            // we have to search for XXXDescriptor
            if(entry.getKey() instanceof ObjectReferenceDescriptor)
            {
                if (entry.getKey() instanceof CollectionDescriptor)
                {
                    CollectionDescriptor cds = (CollectionDescriptor) entry.getKey();
                    EqualsColHelper oldEch = (EqualsColHelper) oldImage.get(cds);
                    EqualsColHelper newEch = (EqualsColHelper) entry.getValue();
//System.out.println("");
//System.out.println("mark-oldEch: " + oldEch);
//System.out.println("mark-newEch: " + newEch);
View Full Code Here

  }

  public void testStoringWithAutoUpdateFalse() throws Exception
  {
    ClassDescriptor cld = _conn.getDescriptorFor(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}));
      Transaction trans = _kit.getTransaction(_conn);
      trans.begin();
      _conn.makePersistent(paper);        // store Paper and intermediary table only
      Identity paperId = _conn.getIdentity(paper);
      trans.commit();

    //  broker.clearCache();
      trans = _kit.getTransaction(_conn);
      trans.begin();
      Paper retPaper = (Paper) _conn.getObjectByIdentity(paperId);
      assertEquals(0, retPaper.getQualifiers().size());
      trans.commit();
      ;
    }
    finally
    {
      cod.setCascadeStore(autoUpdate);
    }
  }
View Full Code Here

  }

  public void testStoringWithAutoUpdateTrue() throws Exception
  {
    ClassDescriptor cld = _conn.getDescriptorFor(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}));
      Transaction trans = _kit.getTransaction(_conn);
      trans.begin();
      _conn.makePersistent(paper);        // store Paper, intermediary and Qualifier
      Identity paperId = _conn.getIdentity(paper);
      trans.commit();
      //broker.clearCache();
      trans = _kit.getTransaction(_conn);
      trans.begin();
      Paper retPaper = (Paper) _conn.getObjectByIdentity(paperId);
      assertEquals(1, retPaper.getQualifiers().size());
      trans.commit();
      ;
    }
    finally
    {
      cod.setCascadeStore(autoUpdate);
    }
  }
View Full Code Here

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

    cod.setCollectionClass(ManageableArrayList.class);

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

      // remove first object
      qualifiers.remove(0);
      Transaction trans = _kit.getTransaction(_conn);
      trans.begin();
      _conn.makePersistent(paper);
      trans.commit();
      ;

      //broker.clearCache();
      trans = _kit.getTransaction(_conn);
      trans.begin();
      Paper retPaper = (Paper) _conn.getObjectByIdentity(paperId);
      assertEquals(1, retPaper.getQualifiers().size());
      // target object qual1 should NOT be deleted
      Qualifier retQual1 = (Qualifier) _conn.getObjectByIdentity(_conn.getIdentity(qual1));
      Qualifier retQual2 = (Qualifier) _conn.getObjectByIdentity(_conn.getIdentity(qual2));

      assertNotNull(retQual1);
      assertNotNull(retQual2);

      trans.commit();
      ;
    }
    finally
    {
      cod.setCollectionClass(collectionClass);
    }

  }
View Full Code Here

  // delete from intermediary AND target-table when collection removal aware
  public void testDelete_RemovalAware() throws Exception
  {
    ClassDescriptor cld = _conn.getDescriptorFor(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 = _conn.getIdentity(paper);

      // remove first object
      qualifiers.remove(0);
      Transaction trans = _kit.getTransaction(_conn);
      trans.begin();
      _conn.makePersistent(paper);
      trans.commit();
      ;

    //  broker.clearCache();
      trans = _kit.getTransaction(_conn);
      trans.begin();
      Paper retPaper = (Paper) _conn.getObjectByIdentity(paperId);
      assertEquals(1, retPaper.getQualifiers().size());

      // target object qual1 should be deleted
      Qualifier retQual1 = (Qualifier) _conn.getObjectByIdentity(_conn.getIdentity(qual1));
      Qualifier retQual2 = (Qualifier) _conn.getObjectByIdentity(_conn.getIdentity(qual2));

      assertNull(retQual1);
      assertNotNull(retQual2);

      trans.commit();
      ;
    }
    finally
    {
      cod.setCollectionClass(collectionClass);
    }
  }
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.