You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by ar...@apache.org on 2004/01/18 17:47:36 UTC

cvs commit: db-ojb/src/java/org/apache/ojb/broker/accesslayer ConnectionManagerImpl.java

arminw      2004/01/18 08:47:35

  Modified:    src/test/org/apache/ojb/broker PersistenceBrokerTest.java
               src/java/org/apache/ojb/broker/accesslayer
                        ConnectionManagerImpl.java
  Log:
  fix bug,
  set batch mode false by default in constructor of ConnectionManager, otherwise
  batch-mode was true the first time ConnectionManager was used (if batch-mode is enabled in
  repository file and DB supports batch update) regardsless user do a CM.setBatchMode(true) call.
  This could leed in unexpected behaviour.
  
  See test PersistenceBrokerTest#testUncommittedRead, new added test for fix
  
  Revision  Changes    Path
  1.38      +31 -5     db-ojb/src/test/org/apache/ojb/broker/PersistenceBrokerTest.java
  
  Index: PersistenceBrokerTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/PersistenceBrokerTest.java,v
  retrieving revision 1.37
  retrieving revision 1.38
  diff -u -r1.37 -r1.38
  --- PersistenceBrokerTest.java	11 Jan 2004 01:30:46 -0000	1.37
  +++ PersistenceBrokerTest.java	18 Jan 2004 16:47:35 -0000	1.38
  @@ -72,6 +72,35 @@
           }
       }
   
  +    public void testReadUncommitedDataWithinSamePB() throws Exception
  +    {
  +        String name = "testReadUncommitedDataWithinSamePB" + System.currentTimeMillis();
  +        ObjectRepository.Component comp = new ObjectRepository.Component();
  +        comp.setName(name);
  +
  +        broker.beginTransaction();
  +        // store data
  +        broker.store(comp, ObjectModificationDefaultImpl.INSERT);
  +        Query query = new QueryByCriteria(ObjectRepository.Component.class, null);
  +        // now we try to read the uncommitted data
  +        Collection all = broker.getCollectionByQuery(query);
  +        Iterator iter = all.iterator();
  +        ObjectRepository.Component temp;
  +        boolean result = false;
  +        while (iter.hasNext())
  +        {
  +            temp = (ObjectRepository.Component) iter.next();
  +            // System.out.println(temp.getName());
  +            if(name.equals(temp.getName()))
  +            {
  +                result = true;
  +                break;
  +            }
  +        }
  +        broker.commitTransaction();
  +        assertTrue("Can't read uncommitted data within same PB instance", result);
  +    }
  +
       /**
        * PK fields with primitive data types interpret '0' value as
        * 'null' by default. But if we don't use primitive data types and read
  @@ -135,7 +164,6 @@
           Class objClass = ObjectRepository.E.class;
           ClassDescriptor cld = broker.getClassDescriptor(objClass);
           Integer someOtherValue = new Integer(1111111111);
  -        String insert = "INSERT INTO TABLE_E VALUES(0,"+someOtherValue.intValue()+")";
           String delete = "DELETE FROM TABLE_E WHERE ID=0";
   
           try
  @@ -1507,12 +1535,11 @@
           OJBIterator ojbIter;
           Criteria crit;
           QueryByCriteria query;
  -        int fullSize;
   
           // All Articles index in range
           crit = new Criteria();
           query = QueryFactory.newQuery(Article.class, crit);
  -        fullSize = broker.getCollectionByQuery(query).size();
  +        int fullSize = broker.getCollectionByQuery(query).size();
   
           query.setStartAtIndex(10);
           query.setEndAtIndex(14);
  @@ -1564,13 +1591,12 @@
           OJBIterator ojbIter;
           Criteria crit;
           QueryByCriteria query;
  -        int fullSize;
   
           // looking for inexistent Article
           crit = new Criteria();
           crit.addEqualTo("articleId",new Integer(-777));
           query = QueryFactory.newQuery(Article.class, crit);
  -        fullSize = broker.getCollectionByQuery(query).size();
  +        int fullSize = broker.getCollectionByQuery(query).size();
   
           query.setStartAtIndex(10);
           query.setEndAtIndex(14);
  
  
  
  1.10      +9 -2      db-ojb/src/java/org/apache/ojb/broker/accesslayer/ConnectionManagerImpl.java
  
  Index: ConnectionManagerImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/ConnectionManagerImpl.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- ConnectionManagerImpl.java	2 Nov 2003 13:21:08 -0000	1.9
  +++ ConnectionManagerImpl.java	18 Jan 2004 16:47:35 -0000	1.10
  @@ -101,7 +101,14 @@
           this.jcd = MetadataManager.getInstance().connectionRepository().getDescriptor(pbKey);
           this.connectionFactory = ConnectionFactoryFactory.getInstance().createConnectionFactory();
           this.platform = PlatformFactory.getPlatformFor(jcd);
  -        setBatchMode(this.jcd.getBatchMode());
  +        /*
  +        by default batch mode is not enabled and after use of a PB
  +        instance, before instance was returned to pool, batch mode
  +        was set to false again (PB implementation close method)
  +        Be carefully in modify this behaviour, changes could cause
  +        unexpected behaviour
  +        */
  +        setBatchMode(false);
       }
   
       /**
  
  
  

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