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/java/org/apache/ojb/broker/core PersistenceBrokerHandle.java DelegatingPersistenceBroker.java
Date Mon, 11 Aug 2003 13:43:42 GMT
arminw      2003/08/11 06:43:42

  Modified:    src/test/org/apache/ojb/broker PersistenceBrokerTest.java
               src/java/org/apache/ojb/broker/core
                        PersistenceBrokerHandle.java
                        DelegatingPersistenceBroker.java
  Log:
  fix PB.isClosed problem
  Thanks Scott Gustafson
  He wrote:
  > If I run isClosed() on a PersistenceBroker which is closed, it throws an
  > exception rather than just returning true, is this the sort of behavior that
  > is expected?
  
  Revision  Changes    Path
  1.28      +35 -7     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.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- PersistenceBrokerTest.java	12 Jul 2003 16:17:23 -0000	1.27
  +++ PersistenceBrokerTest.java	11 Aug 2003 13:43:41 -0000	1.28
  @@ -216,6 +216,33 @@
           assertNull("should be null after deletion", b);
       }
   
  +    public void testPBisClosed()
  +    {
  +        PersistenceBroker pb = PersistenceBrokerFactory.defaultPersistenceBroker();
  +
  +        pb.beginTransaction();
  +        assertTrue(pb.isInTransaction());
  +        pb.commitTransaction();
  +        assertFalse(pb.isInTransaction());
  +
  +        pb.beginTransaction();
  +        pb.abortTransaction();
  +        assertFalse(pb.isInTransaction());
  +
  +        pb.close();
  +        assertTrue(pb.isClosed());
  +
  +        try
  +        {
  +            pb.beginTransaction();
  +            fail("We expect an exception, but was not thrown");
  +        }
  +        catch (Exception e)
  +        {
  +            assertTrue(true);
  +        }
  +    }
  +
       /**
        * test the the PB deleteByQuery() method.
        */
  @@ -385,12 +412,12 @@
           }
   
           C c1 = new C();
  -        Identity iC1 = new Identity(c1, broker);
  +        // Identity iC1 = new Identity(c1, broker);
           C c2 = new C();
  -        Identity iC2 = new Identity(c2, broker);
  +        // Identity iC2 = new Identity(c2, broker);
   
           D d1 = new D();
  -        Identity iD1 = new Identity(d1, broker);
  +        // Identity iD1 = new Identity(d1, broker);
   
           broker.store(c1);
           broker.store(c2);
  @@ -775,9 +802,9 @@
       {
           // create new items for a class with autoincrement PK
           ProductGroup pg1 = new ProductGroup();
  -        Identity id1 = new Identity(pg1, broker);
  +        // Identity id1 = new Identity(pg1, broker);
           ProductGroup pg2 = new ProductGroup();
  -        Identity id2 = new Identity(pg2, broker);
  +        // Identity id2 = new Identity(pg2, broker);
           pg1.setName("AutoIncGroup1");
           pg2.setName("AutoIncGroup2");
   
  @@ -1247,6 +1274,7 @@
           person.setLastname("time_" + timestamp);
   
           broker.beginTransaction();
  +        // Identity used to assign PK of object
           Identity oid = new Identity(person, broker);
           Person serializedPerson = (Person) SerializationUtils.clone(person);
   
  @@ -1261,7 +1289,7 @@
           Query query = QueryFactory.newQuery(Person.class, crit);
           Collection result = broker.getCollectionByQuery(query);
   
  -        assertEquals("Expect to find exact 1 object", 1, result.size());
  +        assertEquals("Expect to find exact 1 object for "+oid, 1, result.size());
       }
   
       public void testDoubleDelete()
  @@ -1273,7 +1301,7 @@
           person.setLastname("time_" + timestamp);
   
           broker.beginTransaction();
  -        Identity oid = new Identity(person, broker);
  +        // Identity oid = new Identity(person, broker);
           Person serializedPerson = (Person) SerializationUtils.clone(person);
           broker.store(person);
           broker.commitTransaction();
  
  
  
  1.4       +2 -2      db-ojb/src/java/org/apache/ojb/broker/core/PersistenceBrokerHandle.java
  
  Index: PersistenceBrokerHandle.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/PersistenceBrokerHandle.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- PersistenceBrokerHandle.java	23 Jul 2003 20:06:56 -0000	1.3
  +++ PersistenceBrokerHandle.java	11 Aug 2003 13:43:42 -0000	1.4
  @@ -19,7 +19,7 @@
   
       public boolean isClosed()
       {
  -        if(getBroker() == null) return true;
  +        if(getDelegate() == null) return true;
           else return super.isClosed();
       }
   
  
  
  
  1.7       +6 -1      db-ojb/src/java/org/apache/ojb/broker/core/DelegatingPersistenceBroker.java
  
  Index: DelegatingPersistenceBroker.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/DelegatingPersistenceBroker.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- DelegatingPersistenceBroker.java	16 Jul 2003 15:53:03 -0000	1.6
  +++ DelegatingPersistenceBroker.java	11 Aug 2003 13:43:42 -0000	1.7
  @@ -53,11 +53,16 @@
   	protected PersistenceBroker getBroker()
   	{
   		if (m_broker != null)
  +        {
   			return m_broker;
  +        }
   		else
  -			throw new IllegalStateException(
  +        {
  +            throw new IllegalStateException(
                       "This PersistenceBroker instance is already closed."+
                       " It's not possible to re-use closed instance.");
  +        }
  +
   	}
   
   	/**
  
  
  

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