Author: jgbutler Date: Mon Jan 28 13:50:30 2008 New Revision: 616068 URL: http://svn.apache.org/viewvc?rev=616068&view=rev Log: Abator: Further changes for IBATIS-468, change the way that columnRenamingRule interacts with useActualColumnNames
Modified: ibatis/trunk/java/mapper/mapper2/tools/abator/core/build/version.properties ibatis/trunk/java/mapper/mapper2/tools/abator/core/htmldoc/configreference/columnRenamingRule.html ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/db/DatabaseIntrospector.java Modified: ibatis/trunk/java/mapper/mapper2/tools/abator/core/build/version.properties URL: http://svn.apache.org/viewvc/ibatis/trunk/java/mapper/mapper2/tools/abator/core/build/version.properties?rev=616068&r1=616067&r2=616068&view=diff ============================================================================== --- ibatis/trunk/java/mapper/mapper2/tools/abator/core/build/version.properties (original) +++ ibatis/trunk/java/mapper/mapper2/tools/abator/core/build/version.properties Mon Jan 28 13:50:30 2008 @@ -1,4 +1,4 @@ #Abator build version info -#Tue Nov 20 23:15:11 CST 2007 +#Mon Jan 28 13:05:36 CST 2008 version=1.1.0 -buildNum=397 +buildNum=401 Modified: ibatis/trunk/java/mapper/mapper2/tools/abator/core/htmldoc/configreference/columnRenamingRule.html URL: http://svn.apache.org/viewvc/ibatis/trunk/java/mapper/mapper2/tools/abator/core/htmldoc/configreference/columnRenamingRule.html?rev=616068&r1=616067&r2=616068&view=diff ============================================================================== --- ibatis/trunk/java/mapper/mapper2/tools/abator/core/htmldoc/configreference/columnRenamingRule.html (original) +++ ibatis/trunk/java/mapper/mapper2/tools/abator/core/htmldoc/configreference/columnRenamingRule.html Mon Jan 28 13:50:30 2008 @@ -16,28 +16,63 @@ calculating the property name. For example, suppose a table contains the following columns:</p> <ul> - <li>CUST_NAME</li> - <li>CUST_ADDRESS</li> + <li>CUST_BUSINESS_NAME</li> + <li>CUST_STREET_ADDRESS</li> <li>CUST_CITY</li> <li>CUST_STATE</li> </ul> <p>It might be annoying to have the generated properties all containing the CUST prefix. The prefix can be removed by specifying a renimg rule like this:</p> - + <p><code><columnRenamingRule searchString="^CUST_" replaceString="" /></code></p> -<p>Note that, internally, Abator uses the +<p>Note that, internally, Abator uses the <code>java.util.regex.Matcher.replaceAll</code> method for this function. See the documentation for that method and class for examples of the regular expression language used in Java.</p> -<p>This element will be ignored if the "useActualColumnNames" property - is set to "true" on the corresponding <table> element. - Further, if a <columnOverride> element matches a column, - it will take precedence over this renaming rule.</p> - +<p>This element will be ignored for any column where a <columnOverride> element + matches a column - the <columnOverride> + will take precedence over the renaming rule.</p> + +<p>If specified, the renaming rule in this element will rename the column + before the property name is calculated. The calculated property name + may be different depending on the value of the + "useActualColumnNames" property on the corresponding <table> element. + The following table shows the different values that will result if + the column renaming rule shown above is applied to the field set + shown above:</p> + +<table border="1" cellspacing="0" cellpadding="5"> + <tr> + <th>Column Name</th> + <th>Property if useActualColumnNames="true"</th> + <th>Property if useActualColumnNames="false"</th> + </tr> + <tr> + <td>CUST_BUSINESS_NAME</td> + <td>BUSINESS_NAME</td> + <td>businessName</td> + </tr> + <tr> + <td>CUST_STREET_ADDRESS</td> + <td>STREET_ADDRESS</td> + <td>streetAddress</td> + </tr> + <tr> + <td>CUST_CITY</td> + <td>CITY</td> + <td>city</td> + </tr> + <tr> + <td>CUST_STATE</td> + <td>STATE</td> + <td>state</td> + </tr> +</table> + <p>This element is an optional child element of the <a href="table.html"><table></a> element.</p> Modified: ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/db/DatabaseIntrospector.java URL: http://svn.apache.org/viewvc/ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/db/DatabaseIntrospector.java?rev=616068&r1=616067&r2=616068&view=diff ============================================================================== --- ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/db/DatabaseIntrospector.java (original) +++ ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/db/DatabaseIntrospector.java Mon Jan 28 13:50:30 2008 @@ -216,6 +216,14 @@ } private void calculateExtraColumnInformation(TableConfiguration tc, Map columns) { + Pattern pattern = null; + String replaceString = null; + if (tc.getColumnRenamingRule() != null) { + pattern = Pattern.compile(tc.getColumnRenamingRule().getSearchString()); + replaceString = tc.getColumnRenamingRule().getReplaceString(); + replaceString = replaceString == null ? "" : replaceString;//$NON-NLS-1$ + } + Iterator entries = columns.entrySet().iterator(); while (entries.hasNext()) { Map.Entry entry = (Map.Entry) entries.next(); @@ -223,28 +231,18 @@ while (tableColumns.hasNext()) { ColumnDefinition cd = (ColumnDefinition) tableColumns.next(); - Pattern pattern = null; - String replaceString = null; - if (tc.getColumnRenamingRule() != null) { - pattern = Pattern.compile(tc.getColumnRenamingRule().getSearchString()); - - replaceString = tc.getColumnRenamingRule().getReplaceString(); - replaceString = replaceString == null ? "" : replaceString;//$NON-NLS-1$ + String calculatedColumnName; + if (pattern == null) { + calculatedColumnName = cd.getActualColumnName(); + } else { + Matcher matcher = pattern.matcher(cd.getActualColumnName()); + calculatedColumnName = matcher.replaceAll(replaceString); } if ("true".equalsIgnoreCase(tc.getProperty(PropertyRegistry.TABLE_USE_ACTUAL_COLUMN_NAMES))) { //$NON-NLS-1$ - cd.setJavaProperty(JavaBeansUtil.getValidPropertyName(cd - .getActualColumnName())); + cd.setJavaProperty(JavaBeansUtil.getValidPropertyName(calculatedColumnName)); } else { - if (pattern != null) { - Matcher matcher = pattern.matcher(cd.getActualColumnName()); - String renamedColumn = matcher.replaceAll(replaceString); - cd.setJavaProperty(JavaBeansUtil.getCamelCaseString(renamedColumn, - false)); - } else { - cd.setJavaProperty(JavaBeansUtil.getCamelCaseString(cd - .getActualColumnName(), false)); - } + cd.setJavaProperty(JavaBeansUtil.getCamelCaseString(calculatedColumnName, false)); } try {