You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-dev@db.apache.org by he...@apache.org on 2003/01/09 14:25:03 UTC

cvs commit: jakarta-turbine-torque/src/java/org/apache/torque/dsfactory AbstractDataSourceFactory.java TorqueDataSourceFactory.java

henning     2003/01/09 05:25:03

  Modified:    src/java/org/apache/torque/dsfactory
                        AbstractDataSourceFactory.java
                        TorqueDataSourceFactory.java
  Log:
  - Add some meaningful debugging to AbstractDataFactory
  - Factor out some common code in the TorqueDataSource Factory
  
  Both changes together make it possible to debug all parameters which
  for the Pool and the Connection.
  
  Revision  Changes    Path
  1.5       +20 -1     jakarta-turbine-torque/src/java/org/apache/torque/dsfactory/AbstractDataSourceFactory.java
  
  Index: AbstractDataSourceFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-torque/src/java/org/apache/torque/dsfactory/AbstractDataSourceFactory.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- AbstractDataSourceFactory.java	13 Sep 2002 05:06:38 -0000	1.4
  +++ AbstractDataSourceFactory.java	9 Jan 2003 13:25:03 -0000	1.5
  @@ -110,6 +110,16 @@
                       Object value = ConvertUtils.convert(propVal, propertyType);
                       PropertyUtils
                           .setMappedProperty(ds, property, subProp, value);
  +
  +                    if (category.isDebugEnabled())
  +                    {
  +                        category.debug("setMappedProperty(" 
  +                                       + ds + ", "
  +                                       + property + ", "
  +                                       + subProp + ", "
  +                                       + value 
  +                                       + ")");
  +                    }
                   }
               }
               else
  @@ -119,6 +129,15 @@
                   Object value =
                       ConvertUtils.convert(c.getString(property), propertyType);
                   PropertyUtils.setSimpleProperty(ds, property, value);
  +
  +                if (category.isDebugEnabled())
  +                {
  +                    category.debug("setSimpleProperty(" 
  +                                   + ds + ", "
  +                                   + property + ", "
  +                                   + value 
  +                                   + ")");
  +                }
               }
           }
           catch (Exception e)
  
  
  
  1.6       +40 -30    jakarta-turbine-torque/src/java/org/apache/torque/dsfactory/TorqueDataSourceFactory.java
  
  Index: TorqueDataSourceFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-torque/src/java/org/apache/torque/dsfactory/TorqueDataSourceFactory.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- TorqueDataSourceFactory.java	27 Nov 2002 11:43:15 -0000	1.5
  +++ TorqueDataSourceFactory.java	9 Jan 2003 13:25:03 -0000	1.6
  @@ -123,22 +123,10 @@
       {
           category.debug("Starting initCPDS");
           ConnectionPoolDataSource cpds = new DriverAdapterCPDS();
  -        Configuration c = configuration.subset("connection");
  -        try
  -        {
  -            Iterator i = c.getKeys();
  -            while (i.hasNext())
  -            {
  -                String key = (String) i.next();
  -                category.debug("Setting datasource property: " + key);
  -                setProperty(key, c, cpds);
  -            }
  -        }
  -        catch (Exception e)
  -        {
  -            category.error("", e);
  -            throw new TorqueException(e);
  -        }
  +        Configuration c = null;
  +
  +        c = configuration.subset("connection");
  +        applyConfiguration(c, cpds);
           return cpds;
       }
   
  @@ -155,22 +143,44 @@
       {
           category.debug("Starting initTorqueClassic");
           TorqueClassicDataSource ds = new TorqueClassicDataSource();
  -        Configuration c = configuration.subset("pool");
  -        try
  +
  +        Configuration c = null;
  +
  +        c = configuration.subset("pool");
  +        applyConfiguration(c, ds);
  +        return ds;
  +    }
  +
  +
  +    /**
  +     * Iterate over a Configuration subset and apply all
  +     * properties to a passed object which must contain Bean
  +     * setter and getter
  +     *
  +     * @param c The configuration subset
  +     * @param o The object to apply the properties to
  +     * @throws TorqueException if a property set fails
  +     */
  +    private void applyConfiguration(Configuration c, Object o)
  +        throws TorqueException
  +    {
  +        category.debug("applyConfiguration(" + c + ", " + o + ")");
  +        
  +        if(c != null)
           {
  -            Iterator i = c.getKeys();
  -            while (i.hasNext())
  +            try
               {
  -                String key = (String) i.next();
  -                category.debug("Setting datasource property: " + key);
  -                setProperty(key, c, ds);
  +                for (Iterator i = c.getKeys(); i.hasNext();)
  +                {
  +                    String key = (String) i.next();
  +                    setProperty(key, c, o);
  +                }
  +            }
  +            catch (Exception e)
  +            {
  +                category.error(e);
  +                throw new TorqueException(e);
               }
           }
  -        catch (Exception e)
  -        {
  -            category.error("", e);
  -            throw new TorqueException(e);
  -        }
  -        return ds;
       }
   }