You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by cr...@apache.org on 2002/12/16 02:53:20 UTC

cvs commit: jakarta-commons/beanutils/src/java/org/apache/commons/beanutils ResultSetDynaClass.java

craigmcc    2002/12/15 17:53:20

  Modified:    beanutils/src/java/org/apache/commons/beanutils
                        ResultSetDynaClass.java
  Log:
  Make it possible to select an operational mode where column names are
  *not* lower cased when being converted into DynaBean property names.  Because
  different JDBC drivers behave differently with regards to the case of the
  column names they return, using this mode will make your application
  dependent upon the behavior of your particular JDBC driver.  However, there
  are some circumstances when consciously selecting such dependence is
  necessary.
  
  PR: Bugzilla #14796
  Submitted by:	Ken Fitzpatrick <kenfitzpatrick at yahoo.com>
  
  Revision  Changes    Path
  1.7       +56 -7     jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/ResultSetDynaClass.java
  
  Index: ResultSetDynaClass.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/ResultSetDynaClass.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ResultSetDynaClass.java	7 Dec 2002 23:34:40 -0000	1.6
  +++ ResultSetDynaClass.java	16 Dec 2002 01:53:20 -0000	1.7
  @@ -136,7 +136,8 @@
   
       /**
        * <p>Construct a new ResultSetDynaClass for the specified
  -     * <code>ResultSet</code>.</p>
  +     * <code>ResultSet</code>.  The property names corresponding
  +     * to column names in the result set will be lower cased.</p>
        *
        * @param resultSet The result set to be wrapped
        *
  @@ -147,10 +148,40 @@
        */
       public ResultSetDynaClass(ResultSet resultSet) throws SQLException {
   
  +        this(resultSet, true);
  +
  +    }
  +
  +
  +    /**
  +     * <p>Construct a new ResultSetDynaClass for the specified
  +     * <code>ResultSet</code>.  The property names corresponding
  +     * to the column names in the result set will be lower cased or not,
  +     * depending on the specified <code>lowerCase</code> value.</p>
  +     *
  +     * <p><strong>WARNING</strong> - If you specify <code>false</code>
  +     * for <code>lowerCase</code>, the returned property names will
  +     * exactly match the column names returned by your JDBC driver.
  +     * Because different drivers might return column names in different
  +     * cases, the property names seen by your application will vary
  +     * depending on which JDBC driver you are using.</p>
  +     *
  +     * @param resultSet The result set to be wrapped
  +     * @param lowerCase Should property names be lower cased?
  +     *
  +     * @exception NullPointerException if <code>resultSet</code>
  +     *  is <code>false</code>
  +     * @exception SQLException if the metadata for this result set
  +     *  cannot be introspected
  +     */
  +    public ResultSetDynaClass(ResultSet resultSet, boolean lowerCase)
  +        throws SQLException {
  +
           if (resultSet == null) {
               throw new NullPointerException();
           }
           this.resultSet = resultSet;
  +        this.lowerCase = lowerCase;
           introspect();
   
       }
  @@ -160,6 +191,13 @@
   
   
       /**
  +     * Flag defining whether column names should be lower cased when
  +     * converted to property names.
  +     */
  +    protected boolean lowerCase = true;
  +
  +
  +    /**
        * The set of dynamic properties that are part of this DynaClass.
        */
       protected DynaProperty properties[] = null;
  @@ -316,6 +354,7 @@
   
       }
   
  +
       /**
        * <p>Factory method to create a new DynaProperty for the given index
        * into the result set metadata.</p>
  @@ -325,8 +364,13 @@
        * @return the newly created DynaProperty instance
        */
       protected DynaProperty createDynaProperty(ResultSetMetaData metadata, int i) throws SQLException {
  -        String name = metadata.getColumnName(i).toLowerCase();
  -        
  +
  +        String name = null;
  +        if (lowerCase) {
  +            name = metadata.getColumnName(i).toLowerCase();
  +        } else {
  +            name = metadata.getColumnName(i);
  +        }
           String className = null;
           try {
               className = metadata.getColumnClassName(i);
  @@ -341,8 +385,10 @@
               clazz = loadClass(className);
           }
           return new DynaProperty(name, clazz);
  +
       }
   
  +
       /**
        * <p>Loads the class of the given name which by default uses the class loader used 
        * to load this library.
  @@ -351,6 +397,7 @@
        * </p>
        */        
       protected Class loadClass(String className) throws SQLException {
  +
           try {
               return getClass().getClassLoader().loadClass(className);
           } 
  @@ -358,6 +405,8 @@
               throw new SQLException("Cannot load column class '" +
                                      className + "': " + e);
           }
  +
       }
  +
   
   }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>