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/proxy AbstractIndirectionHandler.java
Date Mon, 26 Sep 2005 23:57:44 GMT
arminw      2005/09/26 16:57:44

  Modified:    src/java/org/apache/ojb/broker/core/proxy Tag:
                        OJB_1_0_RELEASE AbstractIndirectionHandler.java
  Log:
  fix NPE in getBroker() method (submitted patch by Steve Clark) + minor code cleanup
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.1.2.3   +20 -23    db-ojb/src/java/org/apache/ojb/broker/core/proxy/AbstractIndirectionHandler.java
  
  Index: AbstractIndirectionHandler.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/proxy/AbstractIndirectionHandler.java,v
  retrieving revision 1.1.2.2
  retrieving revision 1.1.2.3
  diff -u -r1.1.2.2 -r1.1.2.3
  --- AbstractIndirectionHandler.java	17 Aug 2005 21:19:39 -0000	1.1.2.2
  +++ AbstractIndirectionHandler.java	26 Sep 2005 23:57:44 -0000	1.1.2.3
  @@ -22,7 +22,6 @@
   import org.apache.ojb.broker.OJBRuntimeException;
   import org.apache.ojb.broker.PBFactoryException;
   import org.apache.ojb.broker.PBKey;
  -import org.apache.ojb.broker.PersistenceBroker;
   import org.apache.ojb.broker.PersistenceBrokerException;
   import org.apache.ojb.broker.PersistenceBrokerFactory;
   import org.apache.ojb.broker.PersistenceBrokerInternal;
  @@ -49,13 +48,6 @@
       private Identity _id = null;
       /** The materialization listeners */
       private transient ArrayList _listeners;
  -    /*
  -    arminw:
  -    only close broker instance if we get it from PBF, do
  -    not close if we obtain from PBThreadMapping
  -    TODO: Find a better solution
  -    */
  -    private boolean _needsClose;
   
   	/**
   	 * Creates a new indirection handler for the indicated object.
  @@ -214,11 +206,9 @@
   			if (_broker == null)
   			{
   				_broker = (PersistenceBrokerInternal) PersistenceBrokerFactory.createPersistenceBroker(getBrokerKey());
  -				// TODO: Better way?
  -				_needsClose = true;
  -				broker = _broker;
   			}
  -		}
  +            broker = _broker;
  +        }
   		return broker;
   	}
   
  @@ -227,10 +217,14 @@
   	 */
   	protected void releaseBroker()
   	{
  -		if (_broker != null && _needsClose)
  +		/*
  +        arminw:
  +        only close broker instance if we get it from PBF, this
  +        is the case when _broker is not null
  +        */
  +        if (_broker != null)
   		{
  -			_needsClose = false;
  -			_broker.close();
  +			if(!_broker.isClosed()) _broker.close();
   			_broker = null;
   		}
   	}
  @@ -294,7 +288,7 @@
   	 */
   	public Object invoke(Object proxy, Method method, Object[] args)
   	{
  -		Object subject = null;
  +		Object subject;
   		String methodName = method.getName();
   
   		try
  @@ -358,9 +352,15 @@
   			// otherwise equals may return false.
   			if ("equals".equals(methodName) && args[0] != null)
   			{
  -				Object otherObj = getBroker().getProxyFactory().getRealObject(args[0]);
  -				args[0] = otherObj;
  -			}
  +                try
  +                {
  +                    args[0] = getBroker().getProxyFactory().getRealObject(args[0]);
  +                }
  +                finally
  +                {
  +                    releaseBroker();
  +                }
  +            }
   
   			if ("getIndirectionHandler".equals(methodName) && args[0] != null)
   			{
  @@ -417,12 +417,9 @@
   	 */
   	protected synchronized Object materializeSubject() throws PersistenceBrokerException
   	{
  -		PersistenceBroker broker = getBroker();
  -
   		try
   		{
  -			Object realSubject = broker.getObjectByIdentity(_id);
  -
  +			Object realSubject = getBroker().getObjectByIdentity(_id);
   			if (realSubject == null)
   			{
   				LoggerFactory.getLogger(IndirectionHandler.class).warn(
  
  
  

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