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 to...@apache.org on 2005/09/05 12:59:30 UTC

cvs commit: db-ojb/src/java/org/apache/ojb/broker/core/proxy ProxyHelper.java

tomdz       2005/09/05 03:59:30

  Modified:    src/java/org/apache/ojb/broker/core/proxy Tag:
                        OJB_1_0_RELEASE ProxyHelper.java
  Log:
  Fix that allows to use the metadata facilities without a configured broker
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.2.2.5   +19 -9     db-ojb/src/java/org/apache/ojb/broker/core/proxy/Attic/ProxyHelper.java
  
  Index: ProxyHelper.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/proxy/Attic/ProxyHelper.java,v
  retrieving revision 1.2.2.4
  retrieving revision 1.2.2.5
  diff -u -r1.2.2.4 -r1.2.2.5
  --- ProxyHelper.java	12 Aug 2005 13:49:21 -0000	1.2.2.4
  +++ ProxyHelper.java	5 Sep 2005 10:59:30 -0000	1.2.2.5
  @@ -15,10 +15,12 @@
    * limitations under the License.
    */
   
  +import org.apache.ojb.broker.PBFactoryException;
   import org.apache.ojb.broker.PersistenceBrokerFactory;
   import org.apache.ojb.broker.PersistenceBrokerInternal;
   
   import java.lang.ref.SoftReference;
  +
   /**
    * ProxyHelper used to get the real thing behind a proxy
    *
  @@ -28,19 +30,27 @@
   public class ProxyHelper {
       private static SoftReference proxyFactoryRef;
   
  -    static {
  -        proxyFactoryRef = new SoftReference(getBroker().getProxyFactory());
  -    }
  -
  -    public static ProxyFactory getProxyFactory() {
  -        if (proxyFactoryRef.get() == null) {
  -            proxyFactoryRef = new SoftReference(getBroker().getProxyFactory());
  +    public synchronized static ProxyFactory getProxyFactory()
  +    {
  +        if ((proxyFactoryRef == null) || (proxyFactoryRef.get() == null))
  +        {
  +            try
  +            {
  +                proxyFactoryRef = new SoftReference(getBroker().getProxyFactory());
  +            }
  +            catch (PBFactoryException ex)
  +            {
  +                // seems we cannot get a broker; in that case we're defaulting to the CGLib proxy factory
  +                // (which also works for older JDKs) ie. for broker-less mode (only metadata)
  +                return new ProxyFactoryCGLIBImpl();
  +            }
           }
           return (ProxyFactory)proxyFactoryRef.get();
   
       }
       
  -    private static PersistenceBrokerInternal getBroker(){
  +    private static PersistenceBrokerInternal getBroker()
  +    {
           return (PersistenceBrokerInternal)PersistenceBrokerFactory.defaultPersistenceBroker();
       }
   
  
  
  

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