db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject cvs commit: db-ojb/src/ejb/org/apache/ojb/ejb/pb PersonArticleClient.java PersonArticleManagerPBBean.java
Date Mon, 05 Jul 2004 11:45:53 GMT
arminw      2004/07/05 04:45:53

  Modified:    src/ejb/org/apache/ojb/ejb/pb PersonArticleClient.java
                        PersonArticleManagerPBBean.java
  Log:
  add new test to show problem of nested PB instances with JBoss
  
  Revision  Changes    Path
  1.6       +32 -17    db-ojb/src/ejb/org/apache/ojb/ejb/pb/PersonArticleClient.java
  
  Index: PersonArticleClient.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/ejb/org/apache/ojb/ejb/pb/PersonArticleClient.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- PersonArticleClient.java	9 Jun 2004 00:49:29 -0000	1.5
  +++ PersonArticleClient.java	5 Jul 2004 11:45:53 -0000	1.6
  @@ -46,12 +46,41 @@
   
       public static void main(String[] args)
       {
  -//        PersonArticleClient client = new PersonArticleClient();
  -//        client.start();
           String[] arr = {PersonArticleClient.class.getName()};
           junit.textui.TestRunner.main(arr);
       }
   
  +    public void testNestedBrokerStore() throws Exception
  +    {
  +        int personsBefore = bean.personCount();
  +        int articlesBefore = bean.articleCount();
  +
  +        List articleList = VOHelper.createNewArticleList(6);
  +        List personList = VOHelper.createNewPersonList(4);
  +        bean.storeUsingNestedPB(articleList, personList);
  +
  +        int personsAfterStore = bean.personCount();
  +        int articlesAfterStore = bean.articleCount();
  +        assertEquals("wrong number of articles after store", articlesBefore + 6, articlesAfterStore);
  +        assertEquals("wrong number of persons after store", personsBefore + 4, personsAfterStore);
  +    }
  +
  +    public void testNestedBeans() throws Exception
  +    {
  +        int personsBefore = bean.personCount();
  +        int articlesBefore = bean.articleCount();
  +
  +        List articleList = VOHelper.createNewArticleList(6);
  +        List personList = VOHelper.createNewPersonList(4);
  +        // storing objects
  +        bean.storeUsingSubBeans(articleList, personList);
  +
  +        int personsAfterStore = bean.personCount();
  +        int articlesAfterStore = bean.articleCount();
  +        assertEquals("wrong number of articles after store", articlesBefore + 6, articlesAfterStore);
  +        assertEquals("wrong number of persons after store", personsBefore + 4, personsAfterStore);
  +    }
  +
       public void testNestedRollback() throws Exception
       {
           int articlesBefore = bean.articleCount();
  @@ -141,20 +170,6 @@
   
           int articlesAfterDelete = bean.articleCount();
           assertEquals("wrong number of articles after delete", articlesBefore, articlesAfterDelete);
  -    }
  -
  -    // only used when running outside junit
  -    public void start()
  -    {
  -        try
  -        {
  -            init();
  -            testNestedStoreDelete();
  -        }
  -        catch (Exception e)
  -        {
  -            e.printStackTrace();
  -        }
       }
   
       protected void setUp() throws Exception
  
  
  
  1.6       +67 -1     db-ojb/src/ejb/org/apache/ojb/ejb/pb/PersonArticleManagerPBBean.java
  
  Index: PersonArticleManagerPBBean.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/ejb/org/apache/ojb/ejb/pb/PersonArticleManagerPBBean.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- PersonArticleManagerPBBean.java	9 Jun 2004 00:49:29 -0000	1.5
  +++ PersonArticleManagerPBBean.java	5 Jul 2004 11:45:53 -0000	1.6
  @@ -22,11 +22,19 @@
   import javax.naming.InitialContext;
   import javax.naming.NamingException;
   import java.util.ArrayList;
  +import java.util.Collection;
  +import java.util.Iterator;
   import java.util.List;
   
  +import org.apache.ojb.broker.PersistenceBroker;
  +import org.apache.ojb.broker.core.PersistenceBrokerFactoryFactory;
  +import org.apache.ojb.broker.core.PersistenceBrokerFactoryIF;
  +import org.apache.ojb.broker.query.Query;
  +import org.apache.ojb.broker.query.QueryByCriteria;
   import org.apache.ojb.broker.util.logging.Logger;
   import org.apache.ojb.broker.util.logging.LoggerFactory;
   import org.apache.ojb.ejb.ArticleVO;
  +import org.apache.ojb.ejb.PersonVO;
   import org.apache.ojb.ejb.SessionBeanImpl;
   
   /**
  @@ -78,6 +86,7 @@
       private Logger log = LoggerFactory.getLogger(PersonArticleManagerPBBean.class);
       private ArticleManagerPBLocal am;
       private PersonManagerPBLocal pm;
  +    private PersistenceBrokerFactoryIF pbf;
   
       public PersonArticleManagerPBBean()
       {
  @@ -85,9 +94,66 @@
   
       public void ejbCreate()
       {
  +        pbf = PersistenceBrokerFactoryFactory.instance();
  +    }
   
  +    /**
  +     * Stores article and persons using other beans.
  +     *
  +     * @ejb:interface-method
  +     */
  +    public void storeUsingNestedPB(List articles, List persons)
  +    {
  +        PersistenceBroker broker = pbf.defaultPersistenceBroker();
  +        try
  +        {
  +            // do something with broker
  +            Query q = new QueryByCriteria(PersonVO.class, null);
  +            broker.getCollectionByQuery(q);
  +            // System.out.println("## broker1: con=" + broker.serviceConnectionManager().getConnection());
  +            //now use nested bean call
  +            // System.out.println("####### DO nested bean call");
  +            ArticleManagerPBLocal am = getArticleManager();
  +            am.storeArticles(articles);
  +            // System.out.println("####### END nested bean call");
  +            // do more with broker
  +            // System.out.println("## broker1: now store objects");
  +            storeObjects(broker, persons);
  +            // System.out.println("## broker1: end store, con=" + broker.serviceConnectionManager().getConnection());
  +        }
  +//        catch(LookupException e)
  +//        {
  +//            throw new EJBException(e);
  +//        }
  +        finally
  +        {
  +            // System.out.println("## close broker1 now");
  +            if(broker != null) broker.close();
  +        }
       }
   
  +    private Collection storeObjects(PersistenceBroker broker, Collection objects)
  +    {
  +        for (Iterator it = objects.iterator(); it.hasNext();)
  +        {
  +            broker.store(it.next());
  +        }
  +        return objects;
  +    }
  +
  +    /**
  +     * Stores article and persons using other beans.
  +     *
  +     * @ejb:interface-method
  +     */
  +    public void storeUsingSubBeans(List articles, List persons)
  +    {
  +        //store all objects
  +        ArticleManagerPBLocal am = getArticleManager();
  +        PersonManagerPBLocal pm = getPersonManager();
  +        am.storeArticles(articles);
  +        pm.storePersons(persons);
  +    }
   
       /**
        * First stores all articles, persons form
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message