db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gus Heck <gus.h...@olin.edu>
Subject PATCH for OjbStoreConnector
Date Fri, 23 Jan 2004 15:35:31 GMT
I posted this to the Users list with the subject: Re: NPE in OjbExtent 

Since it seems to have gone unnoticed, I am resubmtting it here. This 
patch fixes what I think is probably a bug in OjbStoreConnecter. 
Basically, OjbStoreConnector operates by grabbing a persistance broker 
when a transaction is begun and sticking it in the instance variable 
broker. When the transaction finnishes  broker is set to null. This  
means that  getBroker returns null if there is no transaction in 
progress, which is very likely to cause null pointer exceptions if a 
transactional action is used outside of a transaction. Unfortunately a 
null pointer exception could mean anything and in my case I temporarily 
came to the conclusion that something was broken in OJB. Only after 
putting the code down for several weeks to work on other projects did I 
notice that I hadn't started a transaction. (I noticed it because I 
finally said to my self, "Ok self, if noone else wants this fixed, I had 
better find a way to fix it and submit a patch". Once I understood how 
OjbStoreConnetor worked it became obvious that no transaction was in 

I propose org.apache.ojb.jdori.sql.OjbStoreConnector.getBroker() should 
throw a JDOUserException("No Transaction in Progress.")  rather than 
returning null. This would make the nature of the problem much clearer 
than a NullPointerException thrown when the broker instance that was 
returned as null is used.

- Gus

Index: src/jdori/org/apache/ojb/jdori/sql/OjbStoreConnector.java
RCS file: 

retrieving revision 1.1
diff -u -r1.1 OjbStoreConnector.java
--- src/jdori/org/apache/ojb/jdori/sql/OjbStoreConnector.java   24 Dec 
2002 12:06:01 -0000      1.1
+++ src/jdori/org/apache/ojb/jdori/sql/OjbStoreConnector.java   21 Jan 
2004 20:52:23 -0000
@@ -62,6 +62,8 @@

import com.sun.jdori.Connector;

+import javax.jdo.JDOUserException;
 * OjbStoreConnector represents a OJB PB connection
@@ -214,6 +216,9 @@
    public PersistenceBroker getBroker()
+        if (broker == null) {
+            throw new JDOUserException("No transaction in progress.");
+        }
        return broker;

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

View raw message