Author: jgbutler
Date: Tue Nov 20 22:06:41 2007
New Revision: 596946
URL: http://svn.apache.org/viewvc?rev=596946&view=rev
Log:
Abator: Changes for IBATIS-468 - column renaming with regular expressions
Added:
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/config/ColumnRenamingRule.java
Modified:
ibatis/trunk/java/mapper/mapper2/tools/abator/core/build/version.properties
ibatis/trunk/java/mapper/mapper2/tools/abator/core/doc/ReleaseNotes.txt
ibatis/trunk/java/mapper/mapper2/tools/abator/core/htmldoc/menu.html
ibatis/trunk/java/mapper/mapper2/tools/abator/core/htmldoc/whatsNew.html
ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/config/AbatorContext.java
ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/config/JDBCConnectionConfiguration.java
ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/config/TableConfiguration.java
ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/config/xml/AbatorConfigurationParser.java
ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/config/xml/abator-config_1_0.dtd
ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/db/DatabaseIntrospector.java
ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/util/messages/messages.properties
ibatis/trunk/java/mapper/mapper2/tools/abator/core/testJava5/abatortest/CreateDB.sql
ibatis/trunk/java/mapper/mapper2/tools/abator/core/testJava5/abatortest/abatorConfig.xml
ibatis/trunk/java/mapper/mapper2/tools/abator/core/testJava5/abatortest/execute/miscellaneous/MiscellaneousTests.java
ibatis/trunk/java/mapper/mapper2/tools/abator/core/testJava5/abatortest/execute/miscellaneous/SqlMapConfig.xml
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=596946&r1=596945&r2=596946&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
Tue Nov 20 22:06:41 2007
@@ -1,4 +1,4 @@
#Abator build version info
-#Sat Nov 17 19:58:51 CST 2007
+#Tue Nov 20 23:15:11 CST 2007
version=1.1.0
-buildNum=395
+buildNum=397
Modified:
ibatis/trunk/java/mapper/mapper2/tools/abator/core/doc/ReleaseNotes.txt
URL:
http://svn.apache.org/viewvc/ibatis/trunk/java/mapper/mapper2/tools/abator/core/doc/ReleaseNotes.txt?rev=596946&r1=596945&r2=596946&view=diff
==============================================================================
--- ibatis/trunk/java/mapper/mapper2/tools/abator/core/doc/ReleaseNotes.txt
(original)
+++ ibatis/trunk/java/mapper/mapper2/tools/abator/core/doc/ReleaseNotes.txt Tue
Nov 20 22:06:41 2007
@@ -39,6 +39,7 @@
14. Added updateByExample generated method
15. Java2 is now the default generator set
16. IBATIS-470 - make legacy DAOs extendable
+17. IBATIS-468 - add <columnRenamingRule>
-------------------------------------------------------------------------------
Version 1.0.0:
Added:
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=596946&view=auto
==============================================================================
---
ibatis/trunk/java/mapper/mapper2/tools/abator/core/htmldoc/configreference/columnRenamingRule.html
(added)
+++
ibatis/trunk/java/mapper/mapper2/tools/abator/core/htmldoc/configreference/columnRenamingRule.html
Tue Nov 20 22:06:41 2007
@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3c.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+ <title>The <columnRenamingRule> Element</title>
+ <link type="text/css" rel="stylesheet" href="../abator.css"/>
+</head>
+<body>
+<h1>The <columnRenamingRule> Element</h1>
+<p>The <columnRenamingRule> element is used to tell Abator to rename
+database columns before calulating the corresponding property
+name in an introspected table. This is useful when all columns
+in a table have a common prefix that should be removed before
+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_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
+ <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 is an optional child
+element of the <a href="table.html"><table></a> element.</p>
+
+<h2>Required Attributes</h2>
+<table border="1" cellspacing="0" cellpadding="5">
+ <tr>
+ <th>Attribute</th>
+ <th>Description</th>
+ </tr>
+ <tr>
+ <td>searchString</td>
+ <td>This is a regular expression that defines the substring to be
replaced.</td>
+ </tr>
+</table>
+
+<h2>Optional Attributes</h2>
+<table border="1" cellspacing="0" cellpadding="5">
+ <tr>
+ <th>Attribute</th>
+ <th>Description</th>
+ </tr>
+ <tr>
+ <td>replaceString</td>
+ <td>This is a string to be substituted for every occurance of the
+ search string. If not specified, the empty string is used.</td>
+ </tr>
+</table>
+
+<h2>Child Elements</h2>
+<p>None</p>
+
+</body>
+</html>
Modified: ibatis/trunk/java/mapper/mapper2/tools/abator/core/htmldoc/menu.html
URL:
http://svn.apache.org/viewvc/ibatis/trunk/java/mapper/mapper2/tools/abator/core/htmldoc/menu.html?rev=596946&r1=596945&r2=596946&view=diff
==============================================================================
--- ibatis/trunk/java/mapper/mapper2/tools/abator/core/htmldoc/menu.html
(original)
+++ ibatis/trunk/java/mapper/mapper2/tools/abator/core/htmldoc/menu.html Tue
Nov 20 22:06:41 2007
@@ -21,6 +21,7 @@
<a href="configreference/abatorContext.html"
target="mainFrame"><abatorContext></a><br/>
<a href="configreference/classPathEntry.html"
target="mainFrame"><classPathEntry></a><br/>
<a href="configreference/columnOverride.html"
target="mainFrame"><columnOverride></a><br/>
+ <a href="configreference/columnRenamingRule.html"
target="mainFrame"><columnRenamingRule></a><br/>
<a href="configreference/daoGenerator.html"
target="mainFrame"><daoGenerator></a><br/>
<a href="configreference/generatedKey.html"
target="mainFrame"><generatedKey></a><br/>
<a href="configreference/ignoreColumn.html"
target="mainFrame"><ignoreColumn></a><br/>
Modified:
ibatis/trunk/java/mapper/mapper2/tools/abator/core/htmldoc/whatsNew.html
URL:
http://svn.apache.org/viewvc/ibatis/trunk/java/mapper/mapper2/tools/abator/core/htmldoc/whatsNew.html?rev=596946&r1=596945&r2=596946&view=diff
==============================================================================
--- ibatis/trunk/java/mapper/mapper2/tools/abator/core/htmldoc/whatsNew.html
(original)
+++ ibatis/trunk/java/mapper/mapper2/tools/abator/core/htmldoc/whatsNew.html
Tue Nov 20 22:06:41 2007
@@ -66,6 +66,11 @@
<li>Fixed bug - incorrect datatype mapping for JDBC BIT datatype</li>
<li>Made the generated Example and Criteria classes extendable</li>
<li>Made the legacy DAOs extendable</li>
+ <li>Added the ability to provide a renaming rule for columns. This is for
the
+ use case where columns have a common prefix that should be removed before
+ calculating the property name. See the
+ <a
href="configreference/columnRenamingRule.html"><columnRenamingRule></a>
+ reference page for more information</li>
</ul>
<h2>Version 1.0.0</h2>
Modified:
ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/config/AbatorContext.java
URL:
http://svn.apache.org/viewvc/ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/config/AbatorContext.java?rev=596946&r1=596945&r2=596946&view=diff
==============================================================================
---
ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/config/AbatorContext.java
(original)
+++
ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/config/AbatorContext.java
Tue Nov 20 22:06:41 2007
@@ -132,7 +132,12 @@
* columns exist
*/
public void validate(List errors) {
- validateJdbcConnectionConfiguration(errors);
+ if (jdbcConnectionConfiguration == null) {
+ errors.add(Messages.getString("ValidationError.10")); //$NON-NLS-1$
+ return;
+ } else {
+ jdbcConnectionConfiguration.validate(errors);
+ }
if (javaModelGeneratorConfiguration == null) {
errors.add(Messages.getString("ValidationError.8")); //$NON-NLS-1$
@@ -178,60 +183,11 @@
TableConfiguration tc = (TableConfiguration)
tableConfigurations
.get(i);
- validateTableConfiguration(tc, errors, i);
+ tc.validate(errors, i);
}
}
}
- private void validateJdbcConnectionConfiguration(List errors) {
- if (jdbcConnectionConfiguration == null) {
- errors.add(Messages.getString("ValidationError.10")); //$NON-NLS-1$
- return;
- }
-
- if (!StringUtility.stringHasValue(jdbcConnectionConfiguration
- .getDriverClass())) {
- errors.add(Messages.getString("ValidationError.4"));
//$NON-NLS-1$
- }
-
- if (!StringUtility.stringHasValue(jdbcConnectionConfiguration
- .getConnectionURL())) {
- errors.add(Messages.getString("ValidationError.5"));
//$NON-NLS-1$
- }
- }
-
- private void validateTableConfiguration(TableConfiguration tc, List
errors,
- int listPosition) {
- if (!StringUtility.stringHasValue(tc.getTableName())) {
- errors.add(Messages.getString("ValidationError.6",
Integer.toString(listPosition))); //$NON-NLS-1$
- }
-
- String tableName = StringUtility.composeFullyQualifiedTableName(
- tc.getCatalog(), tc.getSchema(), tc.getTableName(), '.');
-
- if (tc.getGeneratedKey() != null
- &&
!StringUtility.stringHasValue(tc.getGeneratedKey()
- .getRuntimeSqlStatement())) {
- errors
- .add(Messages.getString("ValidationError.7",
//$NON-NLS-1$
- tableName));
- }
-
- if
("true".equalsIgnoreCase(tc.getProperty(PropertyRegistry.TABLE_USE_COLUMN_INDEXES)))
{ //$NON-NLS-1$
- // when using column indexes, either both or neither query ids
should be set
- if (tc.isSelectByExampleStatementEnabled() &&
tc.isSelectByPrimaryKeyStatementEnabled()) {
- boolean queryId1Set =
StringUtility.stringHasValue(tc.getSelectByExampleQueryId());
- boolean queryId2Set =
StringUtility.stringHasValue(tc.getSelectByPrimaryKeyQueryId());
-
- if (queryId1Set != queryId2Set) {
- errors
- .add(Messages.getString("ValidationError.13",
//$NON-NLS-1$
- tableName));
- }
- }
- }
- }
-
/**
* Generate iBATIS artifacts based on the configuration specified in the
* constructor. This method is long running.
Added:
ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/config/ColumnRenamingRule.java
URL:
http://svn.apache.org/viewvc/ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/config/ColumnRenamingRule.java?rev=596946&view=auto
==============================================================================
---
ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/config/ColumnRenamingRule.java
(added)
+++
ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/config/ColumnRenamingRule.java
Tue Nov 20 22:06:41 2007
@@ -0,0 +1,92 @@
+/*
+ * Copyright 2007 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ibatis.abator.config;
+
+import java.util.List;
+
+import org.apache.ibatis.abator.api.dom.xml.Attribute;
+import org.apache.ibatis.abator.api.dom.xml.XmlElement;
+import org.apache.ibatis.abator.internal.util.StringUtility;
+import org.apache.ibatis.abator.internal.util.messages.Messages;
+
+/**
+ * This class is used to specify a renaming fule for columns
+ * in a table. This renaming rule will be run against all
+ * column names before calculating the corresponding property name.
+ * The most common use case is when columns in a table are all
+ * prefixed by a certain value.
+ *
+ * For example, if columns in a table are named:
+ *
+ * <ul>
+ * <li>CUST_NAME</li>
+ * <li>CUST_ADDRESS</li>
+ * <li>CUST_CITY</li>
+ * <li>CUST_STATE</li>
+ * </ul>
+ *
+ * it might be annoying to have the generated properties
+ * all containing the CUST prefix. This class can be used to
+ * remove the prefix by specifying
+ *
+ * <ul>
+ * <li>searchString = "^CUST"</li>
+ * <li>replaceString=""</li>
+ * </ul>
+ *
+ * Note that internally, Abator uses the
+ * <code>java.util.regex.Matcher.replaceAll</code> method
+ * for this function. See the documentation of that method
+ * for example of the regular expression language used in
+ * Java.
+ *
+ * @author Jeff Butler
+ *
+ */
+public class ColumnRenamingRule {
+ private String searchString;
+ private String replaceString;
+
+ public String getReplaceString() {
+ return replaceString;
+ }
+ public void setReplaceString(String replaceString) {
+ this.replaceString = replaceString;
+ }
+ public String getSearchString() {
+ return searchString;
+ }
+ public void setSearchString(String searchString) {
+ this.searchString = searchString;
+ }
+
+ public void validate(List errors) {
+ if (!StringUtility.stringHasValue(searchString)) {
+ errors.add(Messages.getString("ValidationError.14")); //$NON-NLS-1$
+ }
+ }
+
+ public XmlElement toXmlElement() {
+ XmlElement xmlElement = new XmlElement("columnRenamingRule");
//$NON-NLS-1$
+ xmlElement.addAttribute(new Attribute("searchString", searchString));
//$NON-NLS-1$
+
+ if (replaceString != null) {
+ xmlElement.addAttribute(new Attribute("replaceString",
replaceString)); //$NON-NLS-1$
+ }
+
+ return xmlElement;
+ }
+}
Modified:
ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/config/JDBCConnectionConfiguration.java
URL:
http://svn.apache.org/viewvc/ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/config/JDBCConnectionConfiguration.java?rev=596946&r1=596945&r2=596946&view=diff
==============================================================================
---
ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/config/JDBCConnectionConfiguration.java
(original)
+++
ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/config/JDBCConnectionConfiguration.java
Tue Nov 20 22:06:41 2007
@@ -22,6 +22,7 @@
import org.apache.ibatis.abator.api.dom.xml.Attribute;
import org.apache.ibatis.abator.api.dom.xml.XmlElement;
import org.apache.ibatis.abator.internal.util.StringUtility;
+import org.apache.ibatis.abator.internal.util.messages.Messages;
/**
*
@@ -111,5 +112,15 @@
addPropertyXmlElements(xmlElement);
return xmlElement;
+ }
+
+ public void validate(List errors) {
+ if (!StringUtility.stringHasValue(driverClass)) {
+ errors.add(Messages.getString("ValidationError.4")); //$NON-NLS-1$
+ }
+
+ if (!StringUtility.stringHasValue(connectionURL)) {
+ errors.add(Messages.getString("ValidationError.5")); //$NON-NLS-1$
+ }
}
}
Modified:
ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/config/TableConfiguration.java
URL:
http://svn.apache.org/viewvc/ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/config/TableConfiguration.java?rev=596946&r1=596945&r2=596946&view=diff
==============================================================================
---
ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/config/TableConfiguration.java
(original)
+++
ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/config/TableConfiguration.java
Tue Nov 20 22:06:41 2007
@@ -26,6 +26,7 @@
import org.apache.ibatis.abator.internal.util.EqualsUtil;
import org.apache.ibatis.abator.internal.util.HashCodeUtil;
import org.apache.ibatis.abator.internal.util.StringUtility;
+import org.apache.ibatis.abator.internal.util.messages.Messages;
/**
*
@@ -68,6 +69,8 @@
private String configuredModelType;
private boolean delimitIdentifiers;
+ private ColumnRenamingRule columnRenamingRule;
+
public TableConfiguration(AbatorContext abatorContext) {
super();
@@ -412,6 +415,10 @@
xmlElement.addElement(generatedKey.toXmlElement());
}
+ if (columnRenamingRule != null) {
+ xmlElement.addElement(columnRenamingRule.toXmlElement());
+ }
+
if (ignoredColumns.size() > 0) {
Iterator iter = ignoredColumns.keySet().iterator();
while (iter.hasNext()) {
@@ -459,5 +466,47 @@
public void setUpdateByExampleStatementEnabled(
boolean updateByExampleStatementEnabled) {
this.updateByExampleStatementEnabled = updateByExampleStatementEnabled;
+ }
+
+ public void validate(List errors, int listPosition) {
+ if (!StringUtility.stringHasValue(tableName)) {
+ errors.add(Messages.getString("ValidationError.6",
Integer.toString(listPosition))); //$NON-NLS-1$
+ }
+
+ String fqTableName = StringUtility.composeFullyQualifiedTableName(
+ catalog, schema, tableName, '.');
+
+ if (generatedKey != null
+ &&
!StringUtility.stringHasValue(generatedKey.getRuntimeSqlStatement())) {
+ errors
+ .add(Messages.getString("ValidationError.7", //$NON-NLS-1$
+ fqTableName));
+ }
+
+ if
("true".equalsIgnoreCase(getProperty(PropertyRegistry.TABLE_USE_COLUMN_INDEXES)))
{ //$NON-NLS-1$
+ // when using column indexes, either both or neither query ids
should be set
+ if (selectByExampleStatementEnabled &&
selectByPrimaryKeyStatementEnabled) {
+ boolean queryId1Set =
StringUtility.stringHasValue(selectByExampleQueryId);
+ boolean queryId2Set =
StringUtility.stringHasValue(selectByPrimaryKeyQueryId);
+
+ if (queryId1Set != queryId2Set) {
+ errors
+ .add(Messages.getString("ValidationError.13",
//$NON-NLS-1$
+ fqTableName));
+ }
+ }
+ }
+
+ if (columnRenamingRule != null) {
+ columnRenamingRule.validate(errors);
+ }
+ }
+
+ public ColumnRenamingRule getColumnRenamingRule() {
+ return columnRenamingRule;
+ }
+
+ public void setColumnRenamingRule(ColumnRenamingRule columnRenamingRule) {
+ this.columnRenamingRule = columnRenamingRule;
}
}
Modified:
ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/config/xml/AbatorConfigurationParser.java
URL:
http://svn.apache.org/viewvc/ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/config/xml/AbatorConfigurationParser.java?rev=596946&r1=596945&r2=596946&view=diff
==============================================================================
---
ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/config/xml/AbatorConfigurationParser.java
(original)
+++
ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/config/xml/AbatorConfigurationParser.java
Tue Nov 20 22:06:41 2007
@@ -32,6 +32,7 @@
import org.apache.ibatis.abator.config.AbatorConfiguration;
import org.apache.ibatis.abator.config.AbatorContext;
import org.apache.ibatis.abator.config.ColumnOverride;
+import org.apache.ibatis.abator.config.ColumnRenamingRule;
import org.apache.ibatis.abator.config.DAOGeneratorConfiguration;
import org.apache.ibatis.abator.config.GeneratedKey;
import org.apache.ibatis.abator.config.IgnoredColumn;
@@ -433,6 +434,8 @@
parseIgnoreColumn(tc, childNode);
} else if ("generatedKey".equals(childNode.getNodeName())) {
//$NON-NLS-1$
parseGeneratedKey(tc, childNode);
+ } else if ("columnRenamingRule".equals(childNode.getNodeName())) {
//$NON-NLS-1$
+ parseColumnRenamingRule(tc, childNode);
}
}
}
@@ -502,6 +505,22 @@
tc.addIgnoredColumn(ic);
}
+ private void parseColumnRenamingRule(TableConfiguration tc, Node node) {
+ Properties attributes = parseAttributes(node);
+ String searchString = attributes.getProperty("searchString");
//$NON-NLS-1$
+ String replaceString = attributes.getProperty("replaceString");
//$NON-NLS-1$
+
+ ColumnRenamingRule crr = new ColumnRenamingRule();
+
+ crr.setSearchString(searchString);
+
+ if (StringUtility.stringHasValue(replaceString)) {
+ crr.setReplaceString(replaceString);
+ }
+
+ tc.setColumnRenamingRule(crr);
+ }
+
private void parseJavaTypeResolver(AbatorContext abatorContext, Node node)
{
JavaTypeResolverConfiguration javaTypeResolverConfiguration = new
JavaTypeResolverConfiguration();
Modified:
ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/config/xml/abator-config_1_0.dtd
URL:
http://svn.apache.org/viewvc/ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/config/xml/abator-config_1_0.dtd?rev=596946&r1=596945&r2=596946&view=diff
==============================================================================
---
ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/config/xml/abator-config_1_0.dtd
(original)
+++
ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/config/xml/abator-config_1_0.dtd
Tue Nov 20 22:06:41 2007
@@ -133,7 +133,7 @@
The table element is used to specify a database table that will be the
source information
for a set of generated objects.
-->
-<!ELEMENT table (property*, generatedKey?, (columnOverride | ignoreColumn)*) >
+<!ELEMENT table (property*, generatedKey?, columnRenamingRule?,
(columnOverride | ignoreColumn)*) >
<!ATTLIST table
catalog CDATA #IMPLIED
schema CDATA #IMPLIED
@@ -187,4 +187,13 @@
sqlStatement CDATA #REQUIRED
identity CDATA #IMPLIED
type CDATA #IMPLIED>
+
+<!--
+ The columnRenamingRule element is used to specify a rule for renaming
+ columns before the corresponding property name is calculated
+-->
+<!ELEMENT columnRenamingRule EMPTY>
+<!ATTLIST columnRenamingRule
+ searchString CDATA #REQUIRED
+ replaceString CDATA #IMPLIED>
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=596946&r1=596945&r2=596946&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
Tue Nov 20 22:06:41 2007
@@ -24,6 +24,8 @@
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import org.apache.ibatis.abator.api.FullyQualifiedTable;
import org.apache.ibatis.abator.api.JavaTypeResolver;
@@ -220,13 +222,29 @@
Iterator tableColumns = ((List) entry.getValue()).iterator();
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$
+ }
if
("true".equalsIgnoreCase(tc.getProperty(PropertyRegistry.TABLE_USE_ACTUAL_COLUMN_NAMES)))
{ //$NON-NLS-1$
cd.setJavaProperty(JavaBeansUtil.getValidPropertyName(cd
.getActualColumnName()));
} else {
- cd.setJavaProperty(JavaBeansUtil.getCamelCaseString(cd
+ 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));
+ }
}
try {
Modified:
ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/util/messages/messages.properties
URL:
http://svn.apache.org/viewvc/ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/util/messages/messages.properties?rev=596946&r1=596945&r2=596946&view=diff
==============================================================================
---
ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/util/messages/messages.properties
(original)
+++
ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/util/messages/messages.properties
Tue Nov 20 22:06:41 2007
@@ -12,6 +12,7 @@
ValidationError.11=At least one AbatorConfiguration element is required
ValidationError.12={0} Target Package is Required for context {1}
ValidationError.13=If "useColumnIndexes" property is set, then either both or
neither query id must be set for table {0}
+ValidationError.14="searchString is required in a ColumnRenamingRule"
RuntimeError.0=configfile is a required parameter
RuntimeError.1=configfile {0} does not exist
Modified:
ibatis/trunk/java/mapper/mapper2/tools/abator/core/testJava5/abatortest/CreateDB.sql
URL:
http://svn.apache.org/viewvc/ibatis/trunk/java/mapper/mapper2/tools/abator/core/testJava5/abatortest/CreateDB.sql?rev=596946&r1=596945&r2=596946&view=diff
==============================================================================
---
ibatis/trunk/java/mapper/mapper2/tools/abator/core/testJava5/abatortest/CreateDB.sql
(original)
+++
ibatis/trunk/java/mapper/mapper2/tools/abator/core/testJava5/abatortest/CreateDB.sql
Tue Nov 20 22:06:41 2007
@@ -82,3 +82,11 @@
blob1 longvarbinary,
blob2 longvarbinary
);
+
+create table RegexRename (
+ CUST_ID integer,
+ CUST_NAME varchar(30),
+ CUST_ADDRESS varchar(30),
+ ZIP_CODE char(5),
+ primary key(CUST_ID)
+);
Modified:
ibatis/trunk/java/mapper/mapper2/tools/abator/core/testJava5/abatortest/abatorConfig.xml
URL:
http://svn.apache.org/viewvc/ibatis/trunk/java/mapper/mapper2/tools/abator/core/testJava5/abatortest/abatorConfig.xml?rev=596946&r1=596945&r2=596946&view=diff
==============================================================================
---
ibatis/trunk/java/mapper/mapper2/tools/abator/core/testJava5/abatortest/abatorConfig.xml
(original)
+++
ibatis/trunk/java/mapper/mapper2/tools/abator/core/testJava5/abatortest/abatorConfig.xml
Tue Nov 20 22:06:41 2007
@@ -383,5 +383,8 @@
<columnOverride column="timeField"
javaType="abatortest.execute.miscellaneous.MyTime"
typeHandler="abatortest.execute.miscellaneous.MyTimeTypeHandler"/>
</table>
+ <table tableName="RegexRename">
+ <columnRenamingRule searchString="^CUST" />
+ </table>
</abatorContext>
</abatorConfiguration>
Modified:
ibatis/trunk/java/mapper/mapper2/tools/abator/core/testJava5/abatortest/execute/miscellaneous/MiscellaneousTests.java
URL:
http://svn.apache.org/viewvc/ibatis/trunk/java/mapper/mapper2/tools/abator/core/testJava5/abatortest/execute/miscellaneous/MiscellaneousTests.java?rev=596946&r1=596945&r2=596946&view=diff
==============================================================================
---
ibatis/trunk/java/mapper/mapper2/tools/abator/core/testJava5/abatortest/execute/miscellaneous/MiscellaneousTests.java
(original)
+++
ibatis/trunk/java/mapper/mapper2/tools/abator/core/testJava5/abatortest/execute/miscellaneous/MiscellaneousTests.java
Tue Nov 20 22:06:41 2007
@@ -39,9 +39,12 @@
import abatortest.BaseTest;
import abatortest.generated.miscellaneous.dao.MyObjectDAO;
import abatortest.generated.miscellaneous.dao.MyObjectDAOImpl;
+import abatortest.generated.miscellaneous.dao.RegexrenameDAO;
+import abatortest.generated.miscellaneous.dao.RegexrenameDAOImpl;
import abatortest.generated.miscellaneous.model.MyObject;
import abatortest.generated.miscellaneous.model.MyObjectExample;
import abatortest.generated.miscellaneous.model.MyObjectKey;
+import abatortest.generated.miscellaneous.model.Regexrename;
import abatortest.execute.miscellaneous.FirstName;
/**
@@ -854,5 +857,29 @@
} catch (SQLException e) {
fail(e.getMessage());
}
+ }
+
+ public void testRegexRenameInsert() {
+ RegexrenameDAO dao = new RegexrenameDAOImpl(sqlMapClient);
+
+ try {
+ Regexrename record = new Regexrename();
+ record.setAddress("123 Main Street");
+ record.setId(22);
+ record.setName("Fred");
+ record.setZipCode("99999");
+
+ dao.insertRegexrename(record);
+
+ Regexrename returnedRecord = dao.selectRegexrenameByPrimaryKey(22);
+
+ assertEquals(record.getAddress(), returnedRecord.getAddress());
+ assertEquals(record.getId(), returnedRecord.getId());
+ assertEquals(record.getName(), returnedRecord.getName());
+ assertEquals(record.getZipCode(), returnedRecord.getZipCode());
+ } catch (SQLException e) {
+ fail(e.getMessage());
+ }
+
}
}
Modified:
ibatis/trunk/java/mapper/mapper2/tools/abator/core/testJava5/abatortest/execute/miscellaneous/SqlMapConfig.xml
URL:
http://svn.apache.org/viewvc/ibatis/trunk/java/mapper/mapper2/tools/abator/core/testJava5/abatortest/execute/miscellaneous/SqlMapConfig.xml?rev=596946&r1=596945&r2=596946&view=diff
==============================================================================
---
ibatis/trunk/java/mapper/mapper2/tools/abator/core/testJava5/abatortest/execute/miscellaneous/SqlMapConfig.xml
(original)
+++
ibatis/trunk/java/mapper/mapper2/tools/abator/core/testJava5/abatortest/execute/miscellaneous/SqlMapConfig.xml
Tue Nov 20 22:06:41 2007
@@ -18,5 +18,6 @@
</transactionManager>
<sqlMap
resource="abatortest/generated/miscellaneous/xml/PKFIELDS_SqlMap.xml" />
+ <sqlMap
resource="abatortest/generated/miscellaneous/xml/REGEXRENAME_SqlMap.xml" />
</sqlMapConfig>