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 PersistenceBrokerConfiguration.java PersistenceBrokerImpl.java
Date Thu, 13 Feb 2003 20:10:53 GMT
brj         2003/02/13 12:10:53

  Modified:    src/java/org/apache/ojb/broker/util/configuration/impl
                        OjbConfiguration.java
               src/java/org/apache/ojb/broker/singlevm
                        PersistenceBrokerConfiguration.java
                        PersistenceBrokerImpl.java
  Log:
  CollectionProxy class is configurable now
  
  Revision  Changes    Path
  1.20      +15 -3     db-ojb/src/java/org/apache/ojb/broker/util/configuration/impl/OjbConfiguration.java
  
  Index: OjbConfiguration.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/configuration/impl/OjbConfiguration.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- OjbConfiguration.java	9 Jan 2003 17:08:45 -0000	1.19
  +++ OjbConfiguration.java	13 Feb 2003 20:10:52 -0000	1.20
  @@ -96,8 +96,6 @@
           PersistenceBrokerConfiguration,
           PBPoolConfiguration, MetadataConfiguration
   {
  -    private static final String NULL = "null";
  -
       /** use Server or local broker*/
       private boolean serverUsed;
       /** the repository file keeping the O/R Metadata*/
  @@ -109,6 +107,7 @@
       private Class persistentFieldClass;
       private String loggerConfigFile;
       private Class persistenceBrokerClass;
  +    private Class collectionProxyClass;
       // limit for number of values in SQL IN Statement
       private int sqlInLimit;
   
  @@ -130,6 +129,7 @@
       // Metadata configuration
       private boolean useSerializedRepository;
   
  +    
   
       public OjbConfiguration()
       {
  @@ -288,6 +288,9 @@
           persistenceBrokerClass =
                   getClass("PersistenceBrokerClass", PersistenceBrokerImpl.class, PersistenceBroker.class);
   
  +        // load CollectionProxy Class
  +        collectionProxyClass = getClass("CollectionProxyClass", null);
  +
           // load Locking Timeout
           AbstractLockStrategy.DEFAULT_LOCK_TIMEOUT = getInteger("LockTimeout", 60000);
   
  @@ -352,4 +355,13 @@
       {
           return useImplicitLocking;
       }
  +    
  +	/**
  +	 * @see org.apache.ojb.broker.singlevm.PersistenceBrokerConfiguration#getCollectionProxyClass()
  +	 */
  +	public Class getCollectionProxyClass()
  +	{
  +		return collectionProxyClass;
  +    }
  +
   }
  
  
  
  1.6       +7 -1      db-ojb/src/java/org/apache/ojb/broker/singlevm/PersistenceBrokerConfiguration.java
  
  Index: PersistenceBrokerConfiguration.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/singlevm/PersistenceBrokerConfiguration.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- PersistenceBrokerConfiguration.java	19 Oct 2002 18:05:40 -0000	1.5
  +++ PersistenceBrokerConfiguration.java	13 Feb 2003 20:10:52 -0000	1.6
  @@ -77,4 +77,10 @@
   	public Class getPersistenceBrokerClass();
   
   	public int getSqlInLimit();	
  +    
  +    /**
  +     * Answer the class to be used for CollectionProxy
  +     * @return Class
  +     */
  +    public Class getCollectionProxyClass();
   }
  
  
  
  1.128     +53 -13    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.127
  retrieving revision 1.128
  diff -u -r1.127 -r1.128
  --- PersistenceBrokerImpl.java	11 Feb 2003 20:33:48 -0000	1.127
  +++ PersistenceBrokerImpl.java	13 Feb 2003 20:10:52 -0000	1.128
  @@ -55,13 +55,12 @@
    */
   
   import java.lang.reflect.Array;
  +import java.lang.reflect.Proxy;
   import java.util.ArrayList;
   import java.util.Collection;
   import java.util.Enumeration;
  -import java.util.HashMap;
   import java.util.Iterator;
   import java.util.List;
  -import java.util.Map;
   import java.util.Vector;
   
   import org.apache.ojb.broker.Identity;
  @@ -168,6 +167,12 @@
       private SqlGenerator sqlGenerator;
       private BrokerHelper brokerHelper;
       private PBKey pbKey;
  +    
  +    /**
  +     * The Class to be used for CollectionProxies
  +     * if null use either ListProxy or CollectionProxy
  +     */
  +    private Class m_collectionProxyClass = null;
   
   	/**
   	 * Lists for object registration during delete operations.
  @@ -1325,9 +1330,9 @@
       }
   
       /**
  -     *
        * retrieve a collection of type collectionClass matching the Query query
  -     *
  +     * 
  +     * @see org.apache.ojb.broker.PersistenceBroker#getCollectionByQuery(Class, Query)
        */
       public ManageableCollection getCollectionByQuery(Class collectionClass, Query query)
               throws PersistenceBrokerException
  @@ -1335,6 +1340,16 @@
           return getCollectionByQuery(collectionClass, query, false);
       }
   
  +    /**
  +     * retrieve a collection of type collectionClass matching the Query query
  +     * if lazy = true return a CollectionProxy
  +     * 
  +     * @param collectionClass
  +     * @param query
  +     * @param lazy
  +     * @return ManageableCollection
  +     * @throws PersistenceBrokerException
  +     */
       public ManageableCollection getCollectionByQuery(Class collectionClass, Query query,
boolean lazy)
               throws PersistenceBrokerException
       {
  @@ -1342,14 +1357,18 @@
   
           if (lazy)
           {
  -            if (List.class.isAssignableFrom(collectionClass))
  -            {
  -                result = new ListProxy(getPBKey(), collectionClass, query);
  -            }
  -            else
  -            {
  -                result = new CollectionProxy(getPBKey(), collectionClass, query);
  -            }
  +            Class paramType[] = {PBKey.class, Class.class, Query.class};
  +            Object param[] = {getPBKey(), collectionClass, query};
  +			Class proxyClass = getCollectionProxyClass(collectionClass);
  +
  +			try
  +			{
  +				result = (ManageableCollection)proxyClass.getConstructor(paramType).newInstance(param);
  +			}
  +			catch (Throwable e)
  +			{
  +                throw new PersistenceBrokerException(e);
  +			}
           }
           else
           {
  @@ -1360,6 +1379,26 @@
       }
   
       /**
  +     * Answer the class to be used for CollectionProxy
  +     * @param collectionClass
  +     * @return Class
  +     */
  +	protected Class getCollectionProxyClass(Class collectionClass)
  +	{ 
  +        if (m_collectionProxyClass != null)
  +        {
  +            return m_collectionProxyClass;
  +        }     
  +		
  +        if (List.class.isAssignableFrom(collectionClass))
  +		{
  +		    return ListProxy.class;
  +		}
  +		
  +        return CollectionProxy.class;
  +	}
  +
  +    /**
        *
        * retrieve a collection of itemClass Objects matching the Query query
        *
  @@ -2196,6 +2235,7 @@
   
           pool = new ServerPool(config.getServers());
           runningInServerMode = config.isRunningInServerMode();
  +        m_collectionProxyClass = config.getCollectionProxyClass();
           // now build db if specified in config
           autoCreateDb(pConfig);
       }
  
  
  

Mime
View raw message