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 "Clute, Andrew" <An...@osn.state.oh.us> on 2004/02/18 20:11:09 UTC

Fix for PersistenceBrokerSyncFactory bug (WAS: Pluggable IndirectionHandler)

I have created what I think is an appropriate fix for this issue (PBSync
not releasing connection when not in a JTA-tx).

The patch contents are below. Let me know what think, and if it works,
can someone commit it to CVS?

-Andrew

Index:
src/java/org/apache/ojb/broker/core/PersistenceBrokerFactorySyncImpl.jav
a
===================================================================
retrieving revision 1.1
diff -u -r1.1 PersistenceBrokerFactorySyncImpl.java
---
src/java/org/apache/ojb/broker/core/PersistenceBrokerFactorySyncImpl.jav
a	9 Jan 2004 19:29:37 -0000	1.1
+++
src/java/org/apache/ojb/broker/core/PersistenceBrokerFactorySyncImpl.jav
a	18 Feb 2004 19:09:49 -0000
@@ -164,7 +164,8 @@
     public static class PersistenceBrokerSync extends
PoolablePersistenceBroker implements Synchronization
     {
         private Logger log =
LoggerFactory.getLogger(PersistenceBrokerSync.class);
-
+        private boolean bInsideJTATransaction = false;
+        
         public PersistenceBrokerSync(PersistenceBroker broker,
KeyedObjectPool pool)
         {
             super(broker, pool);
@@ -208,6 +209,7 @@
         private void internBegin()
         {
             super.beginTransaction();
+            bInsideJTATransaction = true;
         }
 
         private void internCommit()
@@ -223,6 +225,7 @@
         private void doRealClose()
         {
             if (log.isDebugEnabled()) log.debug("Now do real close of
PB instance");
+            bInsideJTATransaction = false;
             super.close();
         }
 
@@ -230,9 +233,12 @@
         {
             if (log.isDebugEnabled()) log.debug("PB close was called,
but do not real close PB instance");
             /*
-            don't really close (return to pool) the underlying PB
instance. As recently
-            as the JTA was completed we can return PB instance to pool
+            don't really close (return to pool) the underlying PB
instance, unless
+            it was never inside a JTA-tx to being with. If it was, as
soon
+            as the JTA is completed we can return PB instance to pool
             */
+            if (!bInsideJTATransaction)
+            	doRealClose();
             return true;
         }

-----Original Message-----
From: Armin Waibel [mailto:arminw@apache.org] 
Sent: Friday, February 13, 2004 7:27 PM
To: Clute, Andrew
Subject: Re: Pluggable IndirectionHandler

Hi Andrew,

Clute, Andrew wrote:

> Armin,
> 
> I don't mean to be a pest about this, I just wanted to make sure you 
> got this code, and get your thoughts on it.

you will never be a pest, I await eagerly your next proposals ;-)

<snip from your previous mail>
 > With a normal method on an EJB and using CM-tx, when the EJB method
is  > finished, the EJB container calls commit and  >
PersistenceBrokerFactorSyncImpl is called, and that is the change that
> OJB has to wrap up it's work, and physically close the database  >
connection.
</snip>

I think you found a bug. If no tx (cm-tx or bm-tx) the PB.close() call
should be passed to the PersistenceBrokerImpl class and on this level
ConnectionManager was called to close the underlying Connection.

Currently the PersistenceBrokerSync implementation prevent the
delegation of the PB.close() call. Only when
Synchronzation#beforeCompletion() was called OJB was forced to close the
connection by calling ConnectionManager#releaseConnection().

Think when PB instance was not in a JTA-tx, the Connection should be
released on PB.close().
What do you think?

> 
> I am starting to base architectural decision on the concept that both 
> COllectionProxy and IndirectionHandler are extensible and plugable, 
> and I don't want to get too far ahead if that assumption is false.

I touched many classes till now, but I never work on the Proxy classes,
that's the reason why I don't barge in ;-) AFAIK Andy Malakov made a
similar proposal http://news.gmane.org/gmane.comp.jakarta.ojb.devel

If you don't get response on dev-list pest (oh, I mean) post again ;-)


regards,
Armin


> 
> Thanks
> 
> -Andrew
> 
> -----Original Message-----
> From: Clute, Andrew
> Sent: Thursday, February 12, 2004 5:43 PM
> To: 'arminw@apache.org'
> Subject: RE: New Feature Proposal (WAS: ManagedConnections not being
> released)
> 
> In case you do want this, the patch file is attached with the changes.
> 
> Let me know what you think
> 
> -Andrew
> 
>  
> 
> 
> -----Original Message-----
> From: Clute, Andrew [mailto:Andrew.Clute@osn.state.oh.us]
> Sent: Thursday, February 12, 2004 4:34 PM
> To: OJB Developers List
> Subject: New Feature Proposal (WAS: ManagedConnections not being
> released)
> 
>  I can confirm that my theory down below was the cause of my problem. 
> My creating my own CollectionProxy that was aware of how to walk back 
> across the wire, inside a CM-tx, to my dataset worked fine.
> 
> Now, that left open the fact that for 1:1 Proxy's, IndirectionHandler 
> was the only implementation.
> 
> I have coded a change that will allow for IndirectionHandler to 
> configured, exactly like CollectionProxy. If no entry is defined, then

> it defaults back to IndirectionHandler. The coding style is the exact 
> same as that for Collection proxy.
> 
> If this is perceived as being valuable, I would like to contribute the

> code back. Who should I send the diff files to?
> 
> -Andrew
> 
> 
> 
> -----Original Message-----
> From: Clute, Andrew [mailto:Andrew.Clute@osn.state.oh.us]
> Sent: Thursday, February 12, 2004 3:06 PM
> To: OJB Developers List
> Subject: RE: ManagedConnections not being released
> 
> Armin,
> 
> After further investigation, I can confirm it is related to the use of

> Proxy's.
> 
> Now, I have theory, and I want to see if this could be possible:
> 
> With a normal method on an EJB and using CM-tx, when the EJB method is

> finished, the EJB container calls commit and 
> PersistenceBrokerFactorSyncImpl is called, and that is the change that

> OJB has to wrap up it's work, and physically close the database 
> connection.
> 
> However, when using a proxy (even when both client and EJB are in the 
> same VM), it's access to the data is through a new instance of a 
> PersistenceBroker. That is causing a new connection to be opened up, 
> but because it is not inside a method call to an EJB, there is no
'Commit'
> phase that happens, and so PBFSync is never called and allowed to 
> close the database connection.
> 
> Do think this is accurate?
> 
> So, the solution to this is for me to create my own collection proxy 
> that can call an EJB to get the data from OJB -- that will mean that 
> the call for that will be inside an EJB transaction. I am assuming I 
> also going to have to write a custom IndirectionHandler to handle the 
> 1:1 proxy's (but that doesn't seem to be pluggable in the 
> OJB.properities
> file)
> 
> Thoughts
> 
> -Andrew
> 
> -----Original Message-----
> From: Armin Waibel [mailto:arminw@apache.org]
> Sent: Thursday, February 12, 2004 1:05 PM
> To: OJB Developers List
> Subject: Re: ManagedConnections not being released
> 
> Hi,
> 
> Clute, Andrew wrote:
> 
> 
>>I have the latest from head. I am using Jboss 3.2.3, with CM-tx for my
> 
> 
>>EJB's. I have my connection pool set to a maximum of 30 connections, 
>>but it fills up real quick. I am closing the PersistenceBroker, and I 
>>have debuged, and I do see the _conn.close() being called on the Jboss
> 
> 
>>WrappedConnection, but I look and all 30 connections are used.
>>
>>
> 
> 
> hmm, I assume you are using proxy? This is problematic in a 3-tier 
> environment, because how should the proxy be materialized on the 
> client side? (by the way, try to set useAutoCommit="0") But I don't 
> know what's the reason for your exhausted con-pool, maybe a 
> side-effect of the proxy use?
> 
> regards,
> Armin
> 
> 
>>Thoughts? I apologize in advance if this is a stupid configuration 
>>issue.
>>
>>-Andrew
>>
>>Here is my OJB repository datasource description:
>>
>><jdbc-connection-descriptor
>>	jcd-alias="devsql"
>>	default-connection="true"
>>   	platform="MsSQLServer"
>>   	jdbc-level="3.0"
>>   	jndi-datasource-name="java:MsSqlDevDS"
>>   	useAutoCommit="2"
>>   	>
>>   	<object-cache
>>class="org.apache.ojb.broker.cache.ObjectCacheDefaultImpl">
>>            <attribute attribute-name="timeout"
> 
> attribute-value="900"/>
> 
>>            <attribute attribute-name="autoSync"
>>attribute-value="true"/>
>>       </object-cache>
>>   		
>>   	<sequence-manager
>> 
>>className="org.apache.ojb.broker.util.sequence.SequenceManagerMSSQLGui
>>dI
>>mpl" />
>>
>></jdbc-connection-descriptor>
>>
>>Here is my jBoss Datasource descriptor:
>>
>><datasources>
>>  <local-tx-datasource>
>>    <jndi-name>MsSqlDevDS</jndi-name>
>> 
>><connection-url>jdbc:inetdae7:192.168.2.30:1433?<removed></connection-
>>ur
>>l>
>>    <driver-class>com.inet.tds.TdsDriver</driver-class>
>>    <min-pool-size>5</min-pool-size>
>>    <max-pool-size>30</max-pool-size>
>>    <idle-timeout-minutes>1</idle-timeout-minutes>
>>    <check-valid-connection-sql>select 1</check-valid-connection-sql>
>>  </local-tx-datasource>
>></datasources>
>>
>>And here is the error stack:
>>
>>12:29:49,906 ERROR [org.jboss.web.localhost.Engine]
>>StandardWrapperValve[org.osn.webapp.jcore.doclib.docview_jsp]:
>>Servlet.service() for servlet org.osn.webapp.jcore.doclib.docview_jsp
>>threw exception
>>org.apache.ojb.broker.PersistenceBrokerException:
>>org.apache.ojb.broker.PersistenceBrokerException:
>>org.apache.ojb.broker.PersistenceBrokerException: Used 
>>ConnectionManager instance could not obtain a connection
>>	at
>>org.apache.ojb.broker.accesslayer.CollectionProxy.loadData(CollectionP
>>ro
>>xy.java:158)
>>	at
>>
> 
> org.apache.ojb.broker.accesslayer.ListProxy.loadData(ListProxy.java:18
> 7)
> 
>>	at
>>org.apache.ojb.broker.accesslayer.CollectionProxy.getData(CollectionPr
>>ox
>>y.java:401)
>>	at
>>org.apache.ojb.broker.accesslayer.CollectionProxy.iterator(CollectionP
>>ro
>>xy.java:230)
>>	at
>>org.osn.bom.Document.getCurrentDocumentVersion(Document.java:274)
>>Caused by: org.apache.ojb.broker.PersistenceBrokerException:
>>org.apache.ojb.broker.PersistenceBrokerException: Used 
>>ConnectionManager instance could not obtain a connection
>>	at
>>org.apache.ojb.broker.core.QueryReferenceBroker.getCollectionByQuery(Q
>>ue
>>ryReferenceBroker.java:250)
>>	at
>>org.apache.ojb.broker.core.PersistenceBrokerImpl.getCollectionByQuery(
>>Pe
>>rsistenceBrokerImpl.java:1012)
>>	at
>>org.apache.ojb.broker.core.DelegatingPersistenceBroker.getCollectionBy
>>Qu
>>ery(DelegatingPersistenceBroker.java:312)
>>	at
>>org.apache.ojb.broker.core.DelegatingPersistenceBroker.getCollectionBy
>>Qu
>>ery(DelegatingPersistenceBroker.java:312)
>>	at
>>org.apache.ojb.broker.accesslayer.CollectionProxy.loadData(CollectionP
>>ro
>>xy.java:148)
>>	... 51 more
>>Caused by: org.apache.ojb.broker.PersistenceBrokerException: Used 
>>ConnectionManager instance could not obtain a connection
>>	at
>>org.apache.ojb.broker.accesslayer.StatementManager.getPreparedStatemen
>>t(
>>StatementManager.java:680)
>>	at
>>org.apache.ojb.broker.accesslayer.JdbcAccessImpl.executeQuery(JdbcAcce
>>ss
>>Impl.java:315)
>>	at
>>org.apache.ojb.broker.accesslayer.RsQueryObject.performQuery(RsQueryOb
>>je
>>ct.java:113)
>>	at
>>
> 
> org.apache.ojb.broker.accesslayer.RsIterator.<init>(RsIterator.java:21
> 1)
> 
>>	at
>>org.apache.ojb.broker.core.RsIteratorFactoryImpl.createRsIterator(RsIt
>>er
>>atorFactoryImpl.java:97)
>>	at
>>org.apache.ojb.broker.core.PersistenceBrokerImpl.getRsIteratorFromQuer
>>y(
>>PersistenceBrokerImpl.java:1631)
>>	at
>>org.apache.ojb.broker.core.PersistenceBrokerImpl.getIteratorFromQuery(
>>Pe
>>rsistenceBrokerImpl.java:1136)
>>	at
>>org.apache.ojb.broker.core.QueryReferenceBroker.getCollectionByQuery(Q
>>ue
>>ryReferenceBroker.java:143)
>>	at
>>org.apache.ojb.broker.core.QueryReferenceBroker.getCollectionByQuery(Q
>>ue
>>ryReferenceBroker.java:242)
>>	... 55 more
>>Caused by: org.apache.ojb.broker.accesslayer.LookupException:
>>SQLException thrown while trying to get Connection from Datasource
>>(java:MsSqlDevDS)
>>	at
>>org.apache.ojb.broker.accesslayer.ConnectionFactoryAbstractImpl.newCon
>>ne
>>ctionFromDataSource(ConnectionFactoryAbstractImpl.java:200)
>>	at
>>org.apache.ojb.broker.accesslayer.ConnectionFactoryAbstractImpl.lookup
>>Co
>>nnection(ConnectionFactoryAbstractImpl.java:97)
>>	at
>>org.apache.ojb.broker.accesslayer.ConnectionFactoryManagedImpl.lookupC
>>on
>>nection(ConnectionFactoryManagedImpl.java:18)
>>	at
>>org.apache.ojb.broker.accesslayer.ConnectionManagerImpl.getConnection(
>>Co
>>nnectionManagerImpl.java:144)
>>	at
>>org.apache.ojb.broker.accesslayer.StatementManager.getPreparedStatemen
>>t(
>>StatementManager.java:676)
>>	... 63 more
>>Caused by: org.jboss.util.NestedSQLException: No ManagedConnections 
>>available within configured blocking timeout ( 5000 [ms] ); - nested
>>throwable: (javax.resource.ResourceException: No ManagedConnections 
>>available within configured blocking timeout ( 5000 [ms] ))
>>	at
>>org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(Wrappe
>>rD
>>ataSource.java:106)
>>	at
>>org.apache.ojb.broker.accesslayer.ConnectionFactoryAbstractImpl.newCon
>>ne
>>ctionFromDataSource(ConnectionFactoryAbstractImpl.java:189)
>>	... 67 more
>>Caused by: javax.resource.ResourceException: No ManagedConnections 
>>available within configured blocking timeout ( 5000 [ms] )
>>	at
>>org.jboss.resource.connectionmanager.InternalManagedConnectionPool.get
>>Co
>>nnection(InternalManagedConnectionPool.java:250)
>>	at
>>org.jboss.resource.connectionmanager.JBossManagedConnectionPool$BasePo
>>ol
>>.getConnection(JBossManagedConnectionPool.java:496)
>>	at
>>org.jboss.resource.connectionmanager.BaseConnectionManager2.getManaged
>>Co
>>nnection(BaseConnectionManager2.java:425)
>>	at
>>org.jboss.resource.connectionmanager.TxConnectionManager.getManagedCon
>>ne
>>ction(TxConnectionManager.java:318)
>>	at
>>org.jboss.resource.connectionmanager.BaseConnectionManager2.allocateCo
>>nn
>>ection(BaseConnectionManager2.java:477)
>>	at
>>org.jboss.resource.connectionmanager.BaseConnectionManager2$Connection
>>Ma
>>nagerProxy.allocateConnection(BaseConnectionManager2.java:814)
>>	at
>>org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(Wrappe
>>rD
>>ataSource.java:102)
>>	... 68 more
>>
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org For 
>>additional commands, e-mail: ojb-dev-help@db.apache.org
>>
>>
>>
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org For 
> additional commands, e-mail: ojb-dev-help@db.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org For 
> additional commands, e-mail: ojb-dev-help@db.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org For 
> additional commands, e-mail: ojb-dev-help@db.apache.org
> 
> 
> 
> ----------------------------------------------------------------------
> --
> 
> Index: src/java/org/apache/ojb/broker/VirtualProxy.java
> ===================================================================
> retrieving revision 1.10
> diff -u -r1.10 VirtualProxy.java
> --- src/java/org/apache/ojb/broker/VirtualProxy.java	7 Jan 2004
11:41:20 -0000	1.10
> +++ src/java/org/apache/ojb/broker/VirtualProxy.java	12 Feb 2004
22:18:28 -0000
> @@ -57,6 +57,7 @@
>  
>  
>  import org.apache.ojb.broker.accesslayer.IndirectionHandler;
> +import org.apache.ojb.broker.util.ProxyHelper;
>  
>  import java.lang.reflect.Constructor;  //#ifdef JDK13 @@ -130,7 
> +131,8 @@
>          try
>          {
>              // the invocation handler manages all delegation stuff
> -            InvocationHandler handler = new IndirectionHandler(key,
realSubjectsIdentity);
> +            //InvocationHandler handler = new IndirectionHandler(key,
realSubjectsIdentity);
> +        	InvocationHandler handler = 
> + ProxyHelper.createIndirectionHandler(key,realSubjectsIdentity);
>  
>              // the proxy simply provides the interface of the real
subject
>              Constructor constructor = 
> proxyClass.getDeclaredConstructor(new Class[]{ InvocationHandler.class

> });
> 
> Index: src/java/org/apache/ojb/broker/accesslayer/CollectionProxy.java
> ===================================================================
> retrieving revision 1.25
> diff -u -r1.25 CollectionProxy.java
> --- src/java/org/apache/ojb/broker/accesslayer/CollectionProxy.java
14 Jan 2004 00:09:32 -0000	1.25
> +++ src/java/org/apache/ojb/broker/accesslayer/CollectionProxy.java
12 Feb 2004 22:18:58 -0000
> @@ -82,9 +82,9 @@
>      private transient PersistenceBroker m_broker;
>      private PBKey m_brokerKey;
>      private Query m_query;
> -    private Collection m_data;
> +    protected Collection m_data;
>      private Class m_collectionClass;
> -    private int m_size = -1;
> +    protected int m_size = -1;
>      /*
>      arminw
>      fix a bug, caused by closing PB instances
> 
> Index: 
> src/java/org/apache/ojb/broker/accesslayer/IndirectionHandler.java
> ===================================================================
> retrieving revision 1.23
> diff -u -r1.23 IndirectionHandler.java
> --- src/java/org/apache/ojb/broker/accesslayer/IndirectionHandler.java
7 Jan 2004 11:41:20 -0000	1.23
> +++ src/java/org/apache/ojb/broker/accesslayer/IndirectionHandler.java
12 Feb 2004 22:19:19 -0000
> @@ -92,13 +92,13 @@
>      /**
>       * the real subject which this is hidden by the proxy
>       */
> -    private Object realSubject = null;
> +    protected Object realSubject = null;
>      /**
>       * represents the identity of the real subject.
>       * when the real subject is not yet materialized,
>       * it can be loaded from the underlying db by this identity
object.
>       */
> -    private Identity id = null;
> +    protected Identity id = null;
>      private transient ArrayList listeners;
>      /*
>      arminw:
> @@ -325,7 +325,7 @@
>      /**
>       * retrieve the real subject from the underlying RDBMS
>       */
> -    private synchronized void materializeSubject() throws
PersistenceBrokerException
> +    protected synchronized void materializeSubject() throws 
> + PersistenceBrokerException
>      {
>          try
>          {
> 
>          
> 
> Index: 
> src/java/org/apache/ojb/broker/core/PersistenceBrokerConfiguration.jav
> a ===================================================================
> retrieving revision 1.1
> diff -u -r1.1 PersistenceBrokerConfiguration.java
> ---
src/java/org/apache/ojb/broker/core/PersistenceBrokerConfiguration.java
26 Apr 2003 23:18:25 -0000	1.1
> +++
src/java/org/apache/ojb/broker/core/PersistenceBrokerConfiguration.java
12 Feb 2004 22:19:33 -0000
> @@ -87,4 +87,10 @@
>       * @return Class
>       */
>      public Class getCollectionProxyClass();
> +    
> +    /**
> +     * Answer the class to be used for IndirectionHandler
> +     * @return Class
> +     */
> +    public Class getIndirectionHandlerClass();
>  }
> 
> Index: src/java/org/apache/ojb/broker/util/ProxyHelper.java
> ===================================================================
> retrieving revision 1.22
> diff -u -r1.22 ProxyHelper.java
> --- src/java/org/apache/ojb/broker/util/ProxyHelper.java	8 Feb
2004 13:19:47 -0000	1.22
> +++ src/java/org/apache/ojb/broker/util/ProxyHelper.java	12 Feb
2004 22:19:48 -0000
> @@ -65,6 +65,7 @@
>  import java.util.List;
>  import java.util.Set;
>  
> +import org.apache.ojb.broker.Identity;
>  import org.apache.ojb.broker.ManageableCollection;
>  import org.apache.ojb.broker.PBKey;
>  import org.apache.ojb.broker.PersistenceBroker;
> @@ -94,6 +95,9 @@
>  	private static final Constructor setProxyConstructor;
>  	private static final Constructor collectionProxyConstructor;
>  	private static Constructor
collectionProxyConstructorUserDefined;
> +	
> +	private static final Constructor indirectionHandlerConstructor;
> +	private static Constructor
indirectionHandlerConstructorUserDefined;
>  
>      static
>  	{
> @@ -126,6 +130,36 @@
>              throw new PersistenceBrokerException("Could not build
constructor for collectionProxy class ["+
>                      collectionProxyClass+"] defined in
configuration", e);
>          }
> +        
> +        /*Custom Indirection Handler*/
> +        paramType = new Class[]{PBKey.class, Identity.class};
> +        try
> +		{
> +        	indirectionHandlerConstructor =
IndirectionHandler.class.getConstructor(paramType);
> +        }
> +        catch (Throwable t)
> +		{
> +        	throw new PersistenceBrokerException("Error accessing
constructor for indirection handler class.", t);
> +        }
> +
> +        Class indirectionHandlerClass = null;
> +        try
> +		{
> +        	PersistenceBrokerConfiguration config =
> +        		(PersistenceBrokerConfiguration) 
> +OjbConfigurator.getInstance().getConfigurationFor(null);
> +
> +        	indirectionHandlerClass =
config.getIndirectionHandlerClass();
> +        	if(indirectionHandlerClass != null)
> +        	{
> +        		indirectionHandlerConstructorUserDefined =
indirectionHandlerClass.getConstructor(paramType);
> +        	}
> +        }
> +        catch (Exception e)
> +		{
> +        	throw new PersistenceBrokerException("Could not build
constructor for indirectionHandler class ["+
> +        			collectionProxyClass+"] defined in
configuration", e);
> +        }
> +        
>      }
>  
>      /**
> @@ -318,6 +352,38 @@
>              throw new PersistenceBrokerException(e);
>          }
>      }
> +    
> +    /**
> +     * Create a IndirectionHandler for a given query
> +     * @param key
> +     * @param id
> +     * @return the IndirectionHandler
> +     */
> +    
> +    public static final IndirectionHandler
createIndirectionHandler(PBKey key, Identity id)
> +	{
> +
> +    	Object param[] = {key,id };
> +    	
> +        Constructor indirectionConstructor =
indirectionHandlerConstructorUserDefined;
> +    	if (indirectionConstructor == null)
> +    	{
> +
> +    		indirectionConstructor = indirectionHandlerConstructor;
> +    	}
> +    	
> +    	try
> +		{
> +    		
> +    		return (IndirectionHandler)
indirectionConstructor.newInstance(param);
> +    	}
> +    	catch (Throwable e)
> +		{
> +    		throw new PersistenceBrokerException(e);
> +    	}
> +    }
> + 
> +    
>  
>      /**
>       * Answer the class to be used for CollectionProxy
>       
>      
> Index: 
> src/java/org/apache/ojb/broker/util/configuration/impl/OjbConfiguratio
> n.java 
> ===================================================================
> retrieving revision 1.31
> diff -u -r1.31 OjbConfiguration.java
> ---
src/java/org/apache/ojb/broker/util/configuration/impl/OjbConfiguration.
java	17 Jan 2004 16:57:34 -0000	1.31
> +++
src/java/org/apache/ojb/broker/util/configuration/impl/OjbConfiguration.
java	12 Feb 2004 22:20:08 -0000
> @@ -104,6 +104,7 @@
>      private String loggerConfigFile;
>      private Class persistenceBrokerClass;
>      private Class collectionProxyClass;
> +    private Class indirectionHandlerClass;
>      // limit for number of values in SQL IN Statement
>      private int sqlInLimit;
>  
> @@ -300,6 +301,9 @@
>  
>          // load CollectionProxy Class
>          collectionProxyClass = getClass("CollectionProxyClass", 
> null);
> +        
> +        // load CollectionProxy Class
> +        indirectionHandlerClass = getClass("IndirectionHandlerClass",

> + null);
>  
>          // load Locking Timeout
>          AbstractLockStrategy.DEFAULT_LOCK_TIMEOUT = 
> getInteger("LockTimeout", 60000); @@ -373,5 +377,10 @@
>  	{
>  		return collectionProxyClass;
>      }
> +	
> +	public Class getIndirectionHandlerClass()
> +	{
> +		return indirectionHandlerClass;
> +	}
>  
>  }

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


Re: Fix for PersistenceBrokerSyncFactory bug (WAS: Pluggable IndirectionHandler)

Posted by Armin Waibel <ar...@apache.org>.
Hi Andrew,

supposed I have send you a patch some days ago - seems I'm grow too old 
for that job ;-)
Currently I checked in a similar patch for the problem. Does this 
version pass your test?

regards,
Armin

Clute, Andrew wrote:

> I have created what I think is an appropriate fix for this issue (PBSync
> not releasing connection when not in a JTA-tx).
> 
> The patch contents are below. Let me know what think, and if it works,
> can someone commit it to CVS?
> 
> -Andrew
> 
> Index:
> src/java/org/apache/ojb/broker/core/PersistenceBrokerFactorySyncImpl.jav
> a
> ===================================================================
> retrieving revision 1.1
> diff -u -r1.1 PersistenceBrokerFactorySyncImpl.java
> ---
> src/java/org/apache/ojb/broker/core/PersistenceBrokerFactorySyncImpl.jav
> a	9 Jan 2004 19:29:37 -0000	1.1
> +++
> src/java/org/apache/ojb/broker/core/PersistenceBrokerFactorySyncImpl.jav
> a	18 Feb 2004 19:09:49 -0000
> @@ -164,7 +164,8 @@
>      public static class PersistenceBrokerSync extends
> PoolablePersistenceBroker implements Synchronization
>      {
>          private Logger log =
> LoggerFactory.getLogger(PersistenceBrokerSync.class);
> -
> +        private boolean bInsideJTATransaction = false;
> +        
>          public PersistenceBrokerSync(PersistenceBroker broker,
> KeyedObjectPool pool)
>          {
>              super(broker, pool);
> @@ -208,6 +209,7 @@
>          private void internBegin()
>          {
>              super.beginTransaction();
> +            bInsideJTATransaction = true;
>          }
>  
>          private void internCommit()
> @@ -223,6 +225,7 @@
>          private void doRealClose()
>          {
>              if (log.isDebugEnabled()) log.debug("Now do real close of
> PB instance");
> +            bInsideJTATransaction = false;
>              super.close();
>          }
>  
> @@ -230,9 +233,12 @@
>          {
>              if (log.isDebugEnabled()) log.debug("PB close was called,
> but do not real close PB instance");
>              /*
> -            don't really close (return to pool) the underlying PB
> instance. As recently
> -            as the JTA was completed we can return PB instance to pool
> +            don't really close (return to pool) the underlying PB
> instance, unless
> +            it was never inside a JTA-tx to being with. If it was, as
> soon
> +            as the JTA is completed we can return PB instance to pool
>              */
> +            if (!bInsideJTATransaction)
> +            	doRealClose();
>              return true;
>          }
> 
> -----Original Message-----
> From: Armin Waibel [mailto:arminw@apache.org] 
> Sent: Friday, February 13, 2004 7:27 PM
> To: Clute, Andrew
> Subject: Re: Pluggable IndirectionHandler
> 
> Hi Andrew,
> 
> Clute, Andrew wrote:
> 
> 
>>Armin,
>>
>>I don't mean to be a pest about this, I just wanted to make sure you 
>>got this code, and get your thoughts on it.
> 
> 
> you will never be a pest, I await eagerly your next proposals ;-)
> 
> <snip from your previous mail>
>  > With a normal method on an EJB and using CM-tx, when the EJB method
> is  > finished, the EJB container calls commit and  >
> PersistenceBrokerFactorSyncImpl is called, and that is the change that
> 
>>OJB has to wrap up it's work, and physically close the database  >
> 
> connection.
> </snip>
> 
> I think you found a bug. If no tx (cm-tx or bm-tx) the PB.close() call
> should be passed to the PersistenceBrokerImpl class and on this level
> ConnectionManager was called to close the underlying Connection.
> 
> Currently the PersistenceBrokerSync implementation prevent the
> delegation of the PB.close() call. Only when
> Synchronzation#beforeCompletion() was called OJB was forced to close the
> connection by calling ConnectionManager#releaseConnection().
> 
> Think when PB instance was not in a JTA-tx, the Connection should be
> released on PB.close().
> What do you think?
> 
> 
>>I am starting to base architectural decision on the concept that both 
>>COllectionProxy and IndirectionHandler are extensible and plugable, 
>>and I don't want to get too far ahead if that assumption is false.
> 
> 
> I touched many classes till now, but I never work on the Proxy classes,
> that's the reason why I don't barge in ;-) AFAIK Andy Malakov made a
> similar proposal http://news.gmane.org/gmane.comp.jakarta.ojb.devel
> 
> If you don't get response on dev-list pest (oh, I mean) post again ;-)
> 
> 
> regards,
> Armin
> 
> 
> 
>>Thanks
>>
>>-Andrew
>>
>>-----Original Message-----
>>From: Clute, Andrew
>>Sent: Thursday, February 12, 2004 5:43 PM
>>To: 'arminw@apache.org'
>>Subject: RE: New Feature Proposal (WAS: ManagedConnections not being
>>released)
>>
>>In case you do want this, the patch file is attached with the changes.
>>
>>Let me know what you think
>>
>>-Andrew
>>
>> 
>>
>>
>>-----Original Message-----
>>From: Clute, Andrew [mailto:Andrew.Clute@osn.state.oh.us]
>>Sent: Thursday, February 12, 2004 4:34 PM
>>To: OJB Developers List
>>Subject: New Feature Proposal (WAS: ManagedConnections not being
>>released)
>>
>> I can confirm that my theory down below was the cause of my problem. 
>>My creating my own CollectionProxy that was aware of how to walk back 
>>across the wire, inside a CM-tx, to my dataset worked fine.
>>
>>Now, that left open the fact that for 1:1 Proxy's, IndirectionHandler 
>>was the only implementation.
>>
>>I have coded a change that will allow for IndirectionHandler to 
>>configured, exactly like CollectionProxy. If no entry is defined, then
> 
> 
>>it defaults back to IndirectionHandler. The coding style is the exact 
>>same as that for Collection proxy.
>>
>>If this is perceived as being valuable, I would like to contribute the
> 
> 
>>code back. Who should I send the diff files to?
>>
>>-Andrew
>>
>>
>>
>>-----Original Message-----
>>From: Clute, Andrew [mailto:Andrew.Clute@osn.state.oh.us]
>>Sent: Thursday, February 12, 2004 3:06 PM
>>To: OJB Developers List
>>Subject: RE: ManagedConnections not being released
>>
>>Armin,
>>
>>After further investigation, I can confirm it is related to the use of
> 
> 
>>Proxy's.
>>
>>Now, I have theory, and I want to see if this could be possible:
>>
>>With a normal method on an EJB and using CM-tx, when the EJB method is
> 
> 
>>finished, the EJB container calls commit and 
>>PersistenceBrokerFactorSyncImpl is called, and that is the change that
> 
> 
>>OJB has to wrap up it's work, and physically close the database 
>>connection.
>>
>>However, when using a proxy (even when both client and EJB are in the 
>>same VM), it's access to the data is through a new instance of a 
>>PersistenceBroker. That is causing a new connection to be opened up, 
>>but because it is not inside a method call to an EJB, there is no
> 
> 'Commit'
> 
>>phase that happens, and so PBFSync is never called and allowed to 
>>close the database connection.
>>
>>Do think this is accurate?
>>
>>So, the solution to this is for me to create my own collection proxy 
>>that can call an EJB to get the data from OJB -- that will mean that 
>>the call for that will be inside an EJB transaction. I am assuming I 
>>also going to have to write a custom IndirectionHandler to handle the 
>>1:1 proxy's (but that doesn't seem to be pluggable in the 
>>OJB.properities
>>file)
>>
>>Thoughts
>>
>>-Andrew
>>
>>-----Original Message-----
>>From: Armin Waibel [mailto:arminw@apache.org]
>>Sent: Thursday, February 12, 2004 1:05 PM
>>To: OJB Developers List
>>Subject: Re: ManagedConnections not being released
>>
>>Hi,
>>
>>Clute, Andrew wrote:
>>
>>
>>
>>>I have the latest from head. I am using Jboss 3.2.3, with CM-tx for my
>>
>>
>>>EJB's. I have my connection pool set to a maximum of 30 connections, 
>>>but it fills up real quick. I am closing the PersistenceBroker, and I 
>>>have debuged, and I do see the _conn.close() being called on the Jboss
>>
>>
>>>WrappedConnection, but I look and all 30 connections are used.
>>>
>>>
>>
>>
>>hmm, I assume you are using proxy? This is problematic in a 3-tier 
>>environment, because how should the proxy be materialized on the 
>>client side? (by the way, try to set useAutoCommit="0") But I don't 
>>know what's the reason for your exhausted con-pool, maybe a 
>>side-effect of the proxy use?
>>
>>regards,
>>Armin
>>
>>
>>
>>>Thoughts? I apologize in advance if this is a stupid configuration 
>>>issue.
>>>
>>>-Andrew
>>>
>>>Here is my OJB repository datasource description:
>>>
>>><jdbc-connection-descriptor
>>>	jcd-alias="devsql"
>>>	default-connection="true"
>>>  	platform="MsSQLServer"
>>>  	jdbc-level="3.0"
>>>  	jndi-datasource-name="java:MsSqlDevDS"
>>>  	useAutoCommit="2"
>>>  	>
>>>  	<object-cache
>>>class="org.apache.ojb.broker.cache.ObjectCacheDefaultImpl">
>>>           <attribute attribute-name="timeout"
>>
>>attribute-value="900"/>
>>
>>>           <attribute attribute-name="autoSync"
>>>attribute-value="true"/>
>>>      </object-cache>
>>>  		
>>>  	<sequence-manager
>>>
>>>className="org.apache.ojb.broker.util.sequence.SequenceManagerMSSQLGui
>>>dI
>>>mpl" />
>>>
>>></jdbc-connection-descriptor>
>>>
>>>Here is my jBoss Datasource descriptor:
>>>
>>><datasources>
>>> <local-tx-datasource>
>>>   <jndi-name>MsSqlDevDS</jndi-name>
>>>
>>><connection-url>jdbc:inetdae7:192.168.2.30:1433?<removed></connection-
>>>ur
>>>l>
>>>   <driver-class>com.inet.tds.TdsDriver</driver-class>
>>>   <min-pool-size>5</min-pool-size>
>>>   <max-pool-size>30</max-pool-size>
>>>   <idle-timeout-minutes>1</idle-timeout-minutes>
>>>   <check-valid-connection-sql>select 1</check-valid-connection-sql>
>>> </local-tx-datasource>
>>></datasources>
>>>
>>>And here is the error stack:
>>>
>>>12:29:49,906 ERROR [org.jboss.web.localhost.Engine]
>>>StandardWrapperValve[org.osn.webapp.jcore.doclib.docview_jsp]:
>>>Servlet.service() for servlet org.osn.webapp.jcore.doclib.docview_jsp
>>>threw exception
>>>org.apache.ojb.broker.PersistenceBrokerException:
>>>org.apache.ojb.broker.PersistenceBrokerException:
>>>org.apache.ojb.broker.PersistenceBrokerException: Used 
>>>ConnectionManager instance could not obtain a connection
>>>	at
>>>org.apache.ojb.broker.accesslayer.CollectionProxy.loadData(CollectionP
>>>ro
>>>xy.java:158)
>>>	at
>>>
>>
>>org.apache.ojb.broker.accesslayer.ListProxy.loadData(ListProxy.java:18
>>7)
>>
>>
>>>	at
>>>org.apache.ojb.broker.accesslayer.CollectionProxy.getData(CollectionPr
>>>ox
>>>y.java:401)
>>>	at
>>>org.apache.ojb.broker.accesslayer.CollectionProxy.iterator(CollectionP
>>>ro
>>>xy.java:230)
>>>	at
>>>org.osn.bom.Document.getCurrentDocumentVersion(Document.java:274)
>>>Caused by: org.apache.ojb.broker.PersistenceBrokerException:
>>>org.apache.ojb.broker.PersistenceBrokerException: Used 
>>>ConnectionManager instance could not obtain a connection
>>>	at
>>>org.apache.ojb.broker.core.QueryReferenceBroker.getCollectionByQuery(Q
>>>ue
>>>ryReferenceBroker.java:250)
>>>	at
>>>org.apache.ojb.broker.core.PersistenceBrokerImpl.getCollectionByQuery(
>>>Pe
>>>rsistenceBrokerImpl.java:1012)
>>>	at
>>>org.apache.ojb.broker.core.DelegatingPersistenceBroker.getCollectionBy
>>>Qu
>>>ery(DelegatingPersistenceBroker.java:312)
>>>	at
>>>org.apache.ojb.broker.core.DelegatingPersistenceBroker.getCollectionBy
>>>Qu
>>>ery(DelegatingPersistenceBroker.java:312)
>>>	at
>>>org.apache.ojb.broker.accesslayer.CollectionProxy.loadData(CollectionP
>>>ro
>>>xy.java:148)
>>>	... 51 more
>>>Caused by: org.apache.ojb.broker.PersistenceBrokerException: Used 
>>>ConnectionManager instance could not obtain a connection
>>>	at
>>>org.apache.ojb.broker.accesslayer.StatementManager.getPreparedStatemen
>>>t(
>>>StatementManager.java:680)
>>>	at
>>>org.apache.ojb.broker.accesslayer.JdbcAccessImpl.executeQuery(JdbcAcce
>>>ss
>>>Impl.java:315)
>>>	at
>>>org.apache.ojb.broker.accesslayer.RsQueryObject.performQuery(RsQueryOb
>>>je
>>>ct.java:113)
>>>	at
>>>
>>
>>org.apache.ojb.broker.accesslayer.RsIterator.<init>(RsIterator.java:21
>>1)
>>
>>
>>>	at
>>>org.apache.ojb.broker.core.RsIteratorFactoryImpl.createRsIterator(RsIt
>>>er
>>>atorFactoryImpl.java:97)
>>>	at
>>>org.apache.ojb.broker.core.PersistenceBrokerImpl.getRsIteratorFromQuer
>>>y(
>>>PersistenceBrokerImpl.java:1631)
>>>	at
>>>org.apache.ojb.broker.core.PersistenceBrokerImpl.getIteratorFromQuery(
>>>Pe
>>>rsistenceBrokerImpl.java:1136)
>>>	at
>>>org.apache.ojb.broker.core.QueryReferenceBroker.getCollectionByQuery(Q
>>>ue
>>>ryReferenceBroker.java:143)
>>>	at
>>>org.apache.ojb.broker.core.QueryReferenceBroker.getCollectionByQuery(Q
>>>ue
>>>ryReferenceBroker.java:242)
>>>	... 55 more
>>>Caused by: org.apache.ojb.broker.accesslayer.LookupException:
>>>SQLException thrown while trying to get Connection from Datasource
>>>(java:MsSqlDevDS)
>>>	at
>>>org.apache.ojb.broker.accesslayer.ConnectionFactoryAbstractImpl.newCon
>>>ne
>>>ctionFromDataSource(ConnectionFactoryAbstractImpl.java:200)
>>>	at
>>>org.apache.ojb.broker.accesslayer.ConnectionFactoryAbstractImpl.lookup
>>>Co
>>>nnection(ConnectionFactoryAbstractImpl.java:97)
>>>	at
>>>org.apache.ojb.broker.accesslayer.ConnectionFactoryManagedImpl.lookupC
>>>on
>>>nection(ConnectionFactoryManagedImpl.java:18)
>>>	at
>>>org.apache.ojb.broker.accesslayer.ConnectionManagerImpl.getConnection(
>>>Co
>>>nnectionManagerImpl.java:144)
>>>	at
>>>org.apache.ojb.broker.accesslayer.StatementManager.getPreparedStatemen
>>>t(
>>>StatementManager.java:676)
>>>	... 63 more
>>>Caused by: org.jboss.util.NestedSQLException: No ManagedConnections 
>>>available within configured blocking timeout ( 5000 [ms] ); - nested
>>>throwable: (javax.resource.ResourceException: No ManagedConnections 
>>>available within configured blocking timeout ( 5000 [ms] ))
>>>	at
>>>org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(Wrappe
>>>rD
>>>ataSource.java:106)
>>>	at
>>>org.apache.ojb.broker.accesslayer.ConnectionFactoryAbstractImpl.newCon
>>>ne
>>>ctionFromDataSource(ConnectionFactoryAbstractImpl.java:189)
>>>	... 67 more
>>>Caused by: javax.resource.ResourceException: No ManagedConnections 
>>>available within configured blocking timeout ( 5000 [ms] )
>>>	at
>>>org.jboss.resource.connectionmanager.InternalManagedConnectionPool.get
>>>Co
>>>nnection(InternalManagedConnectionPool.java:250)
>>>	at
>>>org.jboss.resource.connectionmanager.JBossManagedConnectionPool$BasePo
>>>ol
>>>.getConnection(JBossManagedConnectionPool.java:496)
>>>	at
>>>org.jboss.resource.connectionmanager.BaseConnectionManager2.getManaged
>>>Co
>>>nnection(BaseConnectionManager2.java:425)
>>>	at
>>>org.jboss.resource.connectionmanager.TxConnectionManager.getManagedCon
>>>ne
>>>ction(TxConnectionManager.java:318)
>>>	at
>>>org.jboss.resource.connectionmanager.BaseConnectionManager2.allocateCo
>>>nn
>>>ection(BaseConnectionManager2.java:477)
>>>	at
>>>org.jboss.resource.connectionmanager.BaseConnectionManager2$Connection
>>>Ma
>>>nagerProxy.allocateConnection(BaseConnectionManager2.java:814)
>>>	at
>>>org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(Wrappe
>>>rD
>>>ataSource.java:102)
>>>	... 68 more
>>>
>>>
>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org For 
>>>additional commands, e-mail: ojb-dev-help@db.apache.org
>>>
>>>
>>>
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org For 
>>additional commands, e-mail: ojb-dev-help@db.apache.org
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org For 
>>additional commands, e-mail: ojb-dev-help@db.apache.org
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org For 
>>additional commands, e-mail: ojb-dev-help@db.apache.org
>>
>>
>>
>>----------------------------------------------------------------------
>>--
>>
>>Index: src/java/org/apache/ojb/broker/VirtualProxy.java
>>===================================================================
>>retrieving revision 1.10
>>diff -u -r1.10 VirtualProxy.java
>>--- src/java/org/apache/ojb/broker/VirtualProxy.java	7 Jan 2004
> 
> 11:41:20 -0000	1.10
> 
>>+++ src/java/org/apache/ojb/broker/VirtualProxy.java	12 Feb 2004
> 
> 22:18:28 -0000
> 
>>@@ -57,6 +57,7 @@
>> 
>> 
>> import org.apache.ojb.broker.accesslayer.IndirectionHandler;
>>+import org.apache.ojb.broker.util.ProxyHelper;
>> 
>> import java.lang.reflect.Constructor;  //#ifdef JDK13 @@ -130,7 
>>+131,8 @@
>>         try
>>         {
>>             // the invocation handler manages all delegation stuff
>>-            InvocationHandler handler = new IndirectionHandler(key,
> 
> realSubjectsIdentity);
> 
>>+            //InvocationHandler handler = new IndirectionHandler(key,
> 
> realSubjectsIdentity);
> 
>>+        	InvocationHandler handler = 
>>+ ProxyHelper.createIndirectionHandler(key,realSubjectsIdentity);
>> 
>>             // the proxy simply provides the interface of the real
> 
> subject
> 
>>             Constructor constructor = 
>>proxyClass.getDeclaredConstructor(new Class[]{ InvocationHandler.class
> 
> 
>>});
>>
>>Index: src/java/org/apache/ojb/broker/accesslayer/CollectionProxy.java
>>===================================================================
>>retrieving revision 1.25
>>diff -u -r1.25 CollectionProxy.java
>>--- src/java/org/apache/ojb/broker/accesslayer/CollectionProxy.java
> 
> 14 Jan 2004 00:09:32 -0000	1.25
> 
>>+++ src/java/org/apache/ojb/broker/accesslayer/CollectionProxy.java
> 
> 12 Feb 2004 22:18:58 -0000
> 
>>@@ -82,9 +82,9 @@
>>     private transient PersistenceBroker m_broker;
>>     private PBKey m_brokerKey;
>>     private Query m_query;
>>-    private Collection m_data;
>>+    protected Collection m_data;
>>     private Class m_collectionClass;
>>-    private int m_size = -1;
>>+    protected int m_size = -1;
>>     /*
>>     arminw
>>     fix a bug, caused by closing PB instances
>>
>>Index: 
>>src/java/org/apache/ojb/broker/accesslayer/IndirectionHandler.java
>>===================================================================
>>retrieving revision 1.23
>>diff -u -r1.23 IndirectionHandler.java
>>--- src/java/org/apache/ojb/broker/accesslayer/IndirectionHandler.java
> 
> 7 Jan 2004 11:41:20 -0000	1.23
> 
>>+++ src/java/org/apache/ojb/broker/accesslayer/IndirectionHandler.java
> 
> 12 Feb 2004 22:19:19 -0000
> 
>>@@ -92,13 +92,13 @@
>>     /**
>>      * the real subject which this is hidden by the proxy
>>      */
>>-    private Object realSubject = null;
>>+    protected Object realSubject = null;
>>     /**
>>      * represents the identity of the real subject.
>>      * when the real subject is not yet materialized,
>>      * it can be loaded from the underlying db by this identity
> 
> object.
> 
>>      */
>>-    private Identity id = null;
>>+    protected Identity id = null;
>>     private transient ArrayList listeners;
>>     /*
>>     arminw:
>>@@ -325,7 +325,7 @@
>>     /**
>>      * retrieve the real subject from the underlying RDBMS
>>      */
>>-    private synchronized void materializeSubject() throws
> 
> PersistenceBrokerException
> 
>>+    protected synchronized void materializeSubject() throws 
>>+ PersistenceBrokerException
>>     {
>>         try
>>         {
>>
>>         
>>
>>Index: 
>>src/java/org/apache/ojb/broker/core/PersistenceBrokerConfiguration.jav
>>a ===================================================================
>>retrieving revision 1.1
>>diff -u -r1.1 PersistenceBrokerConfiguration.java
>>---
> 
> src/java/org/apache/ojb/broker/core/PersistenceBrokerConfiguration.java
> 26 Apr 2003 23:18:25 -0000	1.1
> 
>>+++
> 
> src/java/org/apache/ojb/broker/core/PersistenceBrokerConfiguration.java
> 12 Feb 2004 22:19:33 -0000
> 
>>@@ -87,4 +87,10 @@
>>      * @return Class
>>      */
>>     public Class getCollectionProxyClass();
>>+    
>>+    /**
>>+     * Answer the class to be used for IndirectionHandler
>>+     * @return Class
>>+     */
>>+    public Class getIndirectionHandlerClass();
>> }
>>
>>Index: src/java/org/apache/ojb/broker/util/ProxyHelper.java
>>===================================================================
>>retrieving revision 1.22
>>diff -u -r1.22 ProxyHelper.java
>>--- src/java/org/apache/ojb/broker/util/ProxyHelper.java	8 Feb
> 
> 2004 13:19:47 -0000	1.22
> 
>>+++ src/java/org/apache/ojb/broker/util/ProxyHelper.java	12 Feb
> 
> 2004 22:19:48 -0000
> 
>>@@ -65,6 +65,7 @@
>> import java.util.List;
>> import java.util.Set;
>> 
>>+import org.apache.ojb.broker.Identity;
>> import org.apache.ojb.broker.ManageableCollection;
>> import org.apache.ojb.broker.PBKey;
>> import org.apache.ojb.broker.PersistenceBroker;
>>@@ -94,6 +95,9 @@
>> 	private static final Constructor setProxyConstructor;
>> 	private static final Constructor collectionProxyConstructor;
>> 	private static Constructor
> 
> collectionProxyConstructorUserDefined;
> 
>>+	
>>+	private static final Constructor indirectionHandlerConstructor;
>>+	private static Constructor
> 
> indirectionHandlerConstructorUserDefined;
> 
>> 
>>     static
>> 	{
>>@@ -126,6 +130,36 @@
>>             throw new PersistenceBrokerException("Could not build
> 
> constructor for collectionProxy class ["+
> 
>>                     collectionProxyClass+"] defined in
> 
> configuration", e);
> 
>>         }
>>+        
>>+        /*Custom Indirection Handler*/
>>+        paramType = new Class[]{PBKey.class, Identity.class};
>>+        try
>>+		{
>>+        	indirectionHandlerConstructor =
> 
> IndirectionHandler.class.getConstructor(paramType);
> 
>>+        }
>>+        catch (Throwable t)
>>+		{
>>+        	throw new PersistenceBrokerException("Error accessing
> 
> constructor for indirection handler class.", t);
> 
>>+        }
>>+
>>+        Class indirectionHandlerClass = null;
>>+        try
>>+		{
>>+        	PersistenceBrokerConfiguration config =
>>+        		(PersistenceBrokerConfiguration) 
>>+OjbConfigurator.getInstance().getConfigurationFor(null);
>>+
>>+        	indirectionHandlerClass =
> 
> config.getIndirectionHandlerClass();
> 
>>+        	if(indirectionHandlerClass != null)
>>+        	{
>>+        		indirectionHandlerConstructorUserDefined =
> 
> indirectionHandlerClass.getConstructor(paramType);
> 
>>+        	}
>>+        }
>>+        catch (Exception e)
>>+		{
>>+        	throw new PersistenceBrokerException("Could not build
> 
> constructor for indirectionHandler class ["+
> 
>>+        			collectionProxyClass+"] defined in
> 
> configuration", e);
> 
>>+        }
>>+        
>>     }
>> 
>>     /**
>>@@ -318,6 +352,38 @@
>>             throw new PersistenceBrokerException(e);
>>         }
>>     }
>>+    
>>+    /**
>>+     * Create a IndirectionHandler for a given query
>>+     * @param key
>>+     * @param id
>>+     * @return the IndirectionHandler
>>+     */
>>+    
>>+    public static final IndirectionHandler
> 
> createIndirectionHandler(PBKey key, Identity id)
> 
>>+	{
>>+
>>+    	Object param[] = {key,id };
>>+    	
>>+        Constructor indirectionConstructor =
> 
> indirectionHandlerConstructorUserDefined;
> 
>>+    	if (indirectionConstructor == null)
>>+    	{
>>+
>>+    		indirectionConstructor = indirectionHandlerConstructor;
>>+    	}
>>+    	
>>+    	try
>>+		{
>>+    		
>>+    		return (IndirectionHandler)
> 
> indirectionConstructor.newInstance(param);
> 
>>+    	}
>>+    	catch (Throwable e)
>>+		{
>>+    		throw new PersistenceBrokerException(e);
>>+    	}
>>+    }
>>+ 
>>+    
>> 
>>     /**
>>      * Answer the class to be used for CollectionProxy
>>      
>>     
>>Index: 
>>src/java/org/apache/ojb/broker/util/configuration/impl/OjbConfiguratio
>>n.java 
>>===================================================================
>>retrieving revision 1.31
>>diff -u -r1.31 OjbConfiguration.java
>>---
> 
> src/java/org/apache/ojb/broker/util/configuration/impl/OjbConfiguration.
> java	17 Jan 2004 16:57:34 -0000	1.31
> 
>>+++
> 
> src/java/org/apache/ojb/broker/util/configuration/impl/OjbConfiguration.
> java	12 Feb 2004 22:20:08 -0000
> 
>>@@ -104,6 +104,7 @@
>>     private String loggerConfigFile;
>>     private Class persistenceBrokerClass;
>>     private Class collectionProxyClass;
>>+    private Class indirectionHandlerClass;
>>     // limit for number of values in SQL IN Statement
>>     private int sqlInLimit;
>> 
>>@@ -300,6 +301,9 @@
>> 
>>         // load CollectionProxy Class
>>         collectionProxyClass = getClass("CollectionProxyClass", 
>>null);
>>+        
>>+        // load CollectionProxy Class
>>+        indirectionHandlerClass = getClass("IndirectionHandlerClass",
> 
> 
>>+ null);
>> 
>>         // load Locking Timeout
>>         AbstractLockStrategy.DEFAULT_LOCK_TIMEOUT = 
>>getInteger("LockTimeout", 60000); @@ -373,5 +377,10 @@
>> 	{
>> 		return collectionProxyClass;
>>     }
>>+	
>>+	public Class getIndirectionHandlerClass()
>>+	{
>>+		return indirectionHandlerClass;
>>+	}
>> 
>> }
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-dev-help@db.apache.org
> 
> 
> 

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