db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b..@apache.org
Subject cvs commit: db-ojb/src/java/org/apache/ojb/broker/singlevm PersistenceBrokerImpl.java
Date Thu, 17 Apr 2003 16:55:35 GMT
brj         2003/04/17 09:55:34

  Modified:    src/java/org/apache/ojb/broker/util ProxyHelper.java
               src/java/org/apache/ojb/broker/singlevm
                        PersistenceBrokerImpl.java
  Log:
  moved creation of collection proxy to proxy-helper
  
  Revision  Changes    Path
  1.5       +62 -5     db-ojb/src/java/org/apache/ojb/broker/util/ProxyHelper.java
  
  Index: ProxyHelper.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/ProxyHelper.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ProxyHelper.java	25 Dec 2002 23:26:09 -0000	1.4
  +++ ProxyHelper.java	17 Apr 2003 16:55:33 -0000	1.5
  @@ -54,14 +54,22 @@
    * <http://www.apache.org/>.
    */
   
  -import org.apache.ojb.broker.VirtualProxy;
  +import java.lang.reflect.Proxy;
  +import java.util.List;
  +import java.util.Set;
  +
  +import org.apache.ojb.broker.ManageableCollection;
  +import org.apache.ojb.broker.PBKey;
   import org.apache.ojb.broker.PersistenceBrokerException;
  +import org.apache.ojb.broker.VirtualProxy;
  +import org.apache.ojb.broker.accesslayer.CollectionProxy;
   import org.apache.ojb.broker.accesslayer.IndirectionHandler;
  +import org.apache.ojb.broker.accesslayer.ListProxy;
  +import org.apache.ojb.broker.accesslayer.SetProxy;
  +import org.apache.ojb.broker.query.Query;
  +import org.apache.ojb.broker.singlevm.PersistenceBrokerImpl;
   import org.apache.ojb.broker.util.logging.Logger;
   import org.apache.ojb.broker.util.logging.LoggerFactory;
  -
  -//#ifdef JDK13
  -import java.lang.reflect.Proxy;
   //#else
   /*
   import com.develop.java.lang.reflect.Proxy;
  @@ -231,4 +239,53 @@
               return objectOrProxy.getClass();
           }
       }
  +    
  +    /**
  +     * Create a Collection Proxy for a given query
  +     * @param broker
  +     * @param query
  +     * @param collectionClass the class to build the proxy for
  +     * @return the CollectionProxy
  +     */
  +    public static final ManageableCollection createCollectionProxy(PersistenceBrokerImpl
broker, Query query, Class collectionClass)
  +    {
  +        Class paramType[] = { PBKey.class, Class.class, Query.class };
  +        Object param[] = { broker.getPBKey(), collectionClass, query };
  +        Class proxyClass = broker.getCollectionProxyClass();
  +        
  +        if (proxyClass == null)
  +        {
  +            proxyClass = getCollectionProxyClass(collectionClass);
  +        }
  +
  +		try
  +		{
  +			return (ManageableCollection) proxyClass.getConstructor(paramType).newInstance(param);
  +		}
  +        catch (Throwable e)
  +        {
  +            throw new PersistenceBrokerException(e);
  +        }
  +    }
  +    
  +    /**
  +     * Answer the class to be used for CollectionProxy
  +     * @param collectionClass
  +     * @return Class
  +     */
  +    private static Class getCollectionProxyClass(Class collectionClass)
  +    {
  +        if (List.class.isAssignableFrom(collectionClass))
  +        {
  +            return ListProxy.class;
  +        }
  +
  +        if (Set.class.isAssignableFrom(collectionClass))
  +        {
  +            return SetProxy.class;
  +        }
  +
  +        return CollectionProxy.class;
  +    }
  +    
   }
  
  
  
  1.155     +8 -37     db-ojb/src/java/org/apache/ojb/broker/singlevm/PersistenceBrokerImpl.java
  
  Index: PersistenceBrokerImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/singlevm/PersistenceBrokerImpl.java,v
  retrieving revision 1.154
  retrieving revision 1.155
  diff -u -r1.154 -r1.155
  --- PersistenceBrokerImpl.java	15 Apr 2003 19:18:49 -0000	1.154
  +++ PersistenceBrokerImpl.java	17 Apr 2003 16:55:34 -0000	1.155
  @@ -1402,12 +1402,8 @@
   			{
   				if (lazy)
   				{
  -					Class paramType[] = { PBKey.class, Class.class, Query.class };
  -					Object param[] = { getPBKey(), collectionClass, query };
  -					Class proxyClass = getCollectionProxyClass(collectionClass);
  -
  -					result = (ManageableCollection) proxyClass.getConstructor(paramType).newInstance(param);
  -				}
  +                    result = ProxyHelper.createCollectionProxy(this, query, collectionClass);
  +   				}
   				else
   				{
   					result = getCollectionByQuery(collectionClass, query.getSearchClass(), query);
  @@ -1423,33 +1419,15 @@
   
       /**
        * Answer the class to be used for CollectionProxy
  -     * @param collectionClass
        * @return Class
        */
  -	protected Class getCollectionProxyClass(Class collectionClass)
  +	public Class getCollectionProxyClass()
   	{
  -        if (m_collectionProxyClass != null)
  -        {
  -            return m_collectionProxyClass;
  -        }
  -
  -        if (List.class.isAssignableFrom(collectionClass))
  -		{
  -		    return ListProxy.class;
  -		}
  -
  -        if (Set.class.isAssignableFrom(collectionClass))
  -        {
  -            return SetProxy.class;
  -        }
  -
  -        return CollectionProxy.class;
  +        return m_collectionProxyClass;
   	}
   
       /**
  -     *
        * retrieve a collection of itemClass Objects matching the Query query
  -     *
        */
       public Collection getCollectionByQuery(Query query) throws PersistenceBrokerException
       {
  @@ -1457,9 +1435,7 @@
       }
   
       /**
  -     *
        * retrieve a collection of itemClass Objects matching the Query query
  -     *
        */
       public Collection getCollectionByQuery(Query query, boolean lazy) throws PersistenceBrokerException
       {
  @@ -1470,7 +1446,7 @@
       }
   
       /**
  -     * Method declaration
  +     * Retrieve an object by it's identity from the database
        *
        * @param oid
        * @return
  @@ -1631,7 +1607,7 @@
       }
   
       /**
  -     * Method declaration
  +     * Reterieve an object by it's identity
        *
        * @param id
        * @return
  @@ -1752,7 +1728,6 @@
        * This functionality is typically called from transaction managers, that
        * track which objects have to be stored. Thus this store method does not
        * use update cascading to referenced objects.
  -     *
        */
       private void store(Object obj, Identity oid, ClassDescriptor cld, boolean insert)
       {
  @@ -2125,8 +2100,7 @@
        */
       public Class getExtentClass(Class clazz) throws PersistenceBrokerException
       {
  -        //return descriptorRepository.getExtentClass(clazz);
  -        return getTopLevelClass(clazz);
  +         return getTopLevelClass(clazz);
       }
   
       public Class getTopLevelClass(Class clazz) throws PersistenceBrokerException
  @@ -2142,7 +2116,6 @@
       }
   
       /**
  -     *
        * removes the objects obj from the brokers internal cache and
        * inform other caches in OJB cluster about invalidation.
        */
  @@ -2313,8 +2286,6 @@
           PersistenceBrokerConfiguration config = (PersistenceBrokerConfiguration) pConfig;
   
           m_collectionProxyClass = config.getCollectionProxyClass();
  -        // now build db if specified in config
  -        //autoCreateDb(pConfig);
       }
   
   
  
  
  

Mime
View raw message