You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ni...@apache.org on 2009/08/05 01:35:53 UTC

svn commit: r801021 - /commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/JDBCDynaClass.java

Author: niallp
Date: Tue Aug  4 23:35:52 2009
New Revision: 801021

URL: http://svn.apache.org/viewvc?rev=801021&view=rev
Log:
BEANUTILS-344 Provide configurable option to use the column label rather than column name

Modified:
    commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/JDBCDynaClass.java

Modified: commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/JDBCDynaClass.java
URL: http://svn.apache.org/viewvc/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/JDBCDynaClass.java?rev=801021&r1=801020&r2=801021&view=diff
==============================================================================
--- commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/JDBCDynaClass.java (original)
+++ commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/JDBCDynaClass.java Tue Aug  4 23:35:52 2009
@@ -47,6 +47,11 @@
     protected boolean lowerCase = true;
 
     /**
+     * <p>Flag defining whether column names or labels should be used.
+     */
+    private boolean useColumnLabel;
+
+    /**
      * <p>The set of dynamic properties that are part of this
      * {@link DynaClass}.</p>
      */
@@ -128,6 +133,15 @@
     }
 
     /**
+     * Set whether the column label or name should be used for the property name.
+     *
+     * @param useColumnLabel true if the column label should be used, otherwise false
+     */
+    public void setUseColumnLabel(boolean useColumnLabel) {
+        this.useColumnLabel = useColumnLabel;
+    }
+
+    /**
      * <p>Loads and returns the <code>Class</code> of the given name.
      * By default, a load from the thread context class loader is attempted.
      * If there is no such class loader, the class loader used to load this
@@ -167,7 +181,13 @@
                                     int i)
                                     throws SQLException {
 
-        String columnName = metadata.getColumnName(i);
+        String columnName = null;
+        if (useColumnLabel) {
+            columnName = metadata.getColumnLabel(i);
+        }
+        if (columnName == null || columnName.trim().length() == 0) {
+            columnName = metadata.getColumnName(i);
+        }
         String name = lowerCase ? columnName.toLowerCase() : columnName;
         if (!name.equals(columnName)) {
             if (columnNameXref == null) {