Author: jgbutler
Date: Sat May 3 09:59:04 2008
New Revision: 653096
URL: http://svn.apache.org/viewvc?rev=653096&view=rev
Log:
ibator: Changes for IBATIS-505 - add support for runtime catalog and schema
Modified:
ibatis/trunk/java/tools/ibator/core/build/version.properties
ibatis/trunk/java/tools/ibator/core/doc/ReleaseNotes.txt
ibatis/trunk/java/tools/ibator/core/htmldoc/configreference/table.html
ibatis/trunk/java/tools/ibator/core/htmldoc/whatsNew.html
ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/FullyQualifiedTable.java
ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/config/PropertyRegistry.java
ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/internal/db/DatabaseIntrospector.java
Modified: ibatis/trunk/java/tools/ibator/core/build/version.properties
URL:
http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/build/version.properties?rev=653096&r1=653095&r2=653096&view=diff
==============================================================================
--- ibatis/trunk/java/tools/ibator/core/build/version.properties (original)
+++ ibatis/trunk/java/tools/ibator/core/build/version.properties Sat May 3
09:59:04 2008
@@ -1,4 +1,4 @@
#ibator build version info
-#Wed Apr 30 11:34:49 CDT 2008
+#Sat May 03 11:54:30 CDT 2008
version=1.2.0
-buildNum=537
+buildNum=538
Modified: ibatis/trunk/java/tools/ibator/core/doc/ReleaseNotes.txt
URL:
http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/doc/ReleaseNotes.txt?rev=653096&r1=653095&r2=653096&view=diff
==============================================================================
--- ibatis/trunk/java/tools/ibator/core/doc/ReleaseNotes.txt (original)
+++ ibatis/trunk/java/tools/ibator/core/doc/ReleaseNotes.txt Sat May 3
09:59:04 2008
@@ -12,6 +12,9 @@
ibator's built-in generators. Plugins are now the preferred method for
extending ibator and we recommend that you do not extend ibator's
built in generators unless absolutely necessary.
+2. Added support for runtimeCatalog and runtimeSchema properties to the
+ table configuration. Thanks to Dan Turkenkopf for the idea and the
+ patch!
Changes:
Modified: ibatis/trunk/java/tools/ibator/core/htmldoc/configreference/table.html
URL:
http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/htmldoc/configreference/table.html?rev=653096&r1=653095&r2=653096&view=diff
==============================================================================
--- ibatis/trunk/java/tools/ibator/core/htmldoc/configreference/table.html
(original)
+++ ibatis/trunk/java/tools/ibator/core/htmldoc/configreference/table.html Sat
May 3 09:59:04 2008
@@ -44,10 +44,10 @@
You can specify unlimited table elements.</p>
<h2>Database Identifiers</h2>
-<p>ibator tries to deal with the case sensitivity of database identifiers
automatically.
+<p>Ibator tries to deal with the case sensitivity of database identifiers
automatically.
In most cases, ibator is able to find tables regardless of what you
specify for <code>catalog</code>, <code>schema</code>, and
<code>tableName</code>
-attributes. ibator's process follows these steps:</p>
+attributes. Ibator's process follows these steps:</p>
<ol>
<li>If either of the <code>catalog</code>, <code>schema</code>, or
<code>tableName</code> attributes contain a space, then ibator will
@@ -321,6 +321,22 @@
interface name (like com.mycompany.MyRootInterface).</p></td>
</tr>
<tr>
+ <td valign="top">runtimeCatalog</td>
+ <td>If you specify a value for this property, than ibator will use that
+ value as the catalog in the generated SQL rather than the
<code>catalog</code>
+ as configured above.
+ This is useful if you want to generate code against one catalog, but
+ want to use a different catalog at runtime.</td>
+ </tr>
+ <tr>
+ <td valign="top">runtimeSchema</td>
+ <td>If you specify a value for this property, than ibator will use that
+ value as the schema in the generated SQL rather than the
<code>schema</code>
+ as configured above.
+ This is useful if you want to generate code against one schema, but
+ want to use a different schema at runtime.</td>
+ </tr>
+ <tr>
<td valign="top">runtimeTableName</td>
<td>If you specify a value for this property, than ibator will use that
value as the table name in the generated SQL rather than the
<code>tableName</code>
Modified: ibatis/trunk/java/tools/ibator/core/htmldoc/whatsNew.html
URL:
http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/htmldoc/whatsNew.html?rev=653096&r1=653095&r2=653096&view=diff
==============================================================================
--- ibatis/trunk/java/tools/ibator/core/htmldoc/whatsNew.html (original)
+++ ibatis/trunk/java/tools/ibator/core/htmldoc/whatsNew.html Sat May 3
09:59:04 2008
@@ -37,6 +37,10 @@
strongly suggest that you move to a plugin. See the
<a href="configreference/ibatorPlugin.html"><ibatorPlugin></a> page
for detailed information.</li>
+ <li>Added support for "runtimeCatalog" and "runtimeSchema" properties to the
+ <a href="configreference/table.html"><table></a>
+ configuration element. Thanks to Dan Turkenkopf for the idea and the
+ patch!</li>
</ul>
<h3>Changes from Abator</h3>
Modified:
ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/FullyQualifiedTable.java
URL:
http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/FullyQualifiedTable.java?rev=653096&r1=653095&r2=653096&view=diff
==============================================================================
---
ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/FullyQualifiedTable.java
(original)
+++
ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/FullyQualifiedTable.java
Sat May 3 09:59:04 2008
@@ -26,12 +26,16 @@
*/
public class FullyQualifiedTable {
- private String catalog;
+ private String introspectedCatalog;
- private String schema;
+ private String introspectedSchema;
- private String tableName;
+ private String introspectedTableName;
+ private String runtimeCatalog;
+
+ private String runtimeSchema;
+
private String runtimeTableName;
private String domainObjectName;
@@ -49,17 +53,17 @@
* This object is used to hold information related to the table itself,
* not the columns in the table.
*
- * @param catalog the actual catalog of the table as returned from
+ * @param introspectedCatalog the actual catalog of the table as returned
from
* DatabaseMetaData. This value should only be set if the user
* configured a catalog. Otherwise the DatabaseMetaData is reporting
* some database default that we don't want in the generated code.
*
- * @param schema the actual schema of the table as returned from
+ * @param introspectedSchema the actual schema of the table as returned
from
* DatabaseMetaData. This value should only be set if the user
* configured a schema. Otherwise the DatabaseMetaData is reporting
* some database default that we don't want in the generated code.
*
- * @param tableName the actual table name as returned from DatabaseMetaData
+ * @param introspectedTableName the actual table name as returned from
DatabaseMetaData
*
* @param domainObjectName the configred domain object name for this table.
* If nothing is configured, we'll build the domain object named based
@@ -74,8 +78,16 @@
* to specify a specific schema for generating code but does not want
* the schema in the generated SQL
*
+ * @param runtimeCatalog this is used to "rename" the catalog in the
+ * generated SQL. This is useful, for example, when generating code
+ * against one catalog that should run with a different catalog.
+ *
+ * @param runtimeSchema this is used to "rename" the schema in the
+ * generated SQL. This is useful, for example, when generating code
+ * against one schema that should run with a different schema.
+ *
* @param runtimeTableName this is used to "rename" the table in the
- * generated SQL. This is usefule, for example, when generating code
+ * generated SQL. This is useful, for example, when generating code
* to run with an Oracle synonym. The user would have to specify
* the actual table name and schema for generation, but would want to
* use the synonym name in the generated SQL
@@ -84,15 +96,25 @@
* delimited at runtime. The delimiter characters are obtained
* from the IbatorContext.
*/
- public FullyQualifiedTable(String catalog, String schema, String
tableName,
- String domainObjectName, String alias, boolean
ignoreQualifiersAtRuntime,
- String runtimeTableName, boolean delimitIdentifiers, IbatorContext
ibatorContext) {
+ public FullyQualifiedTable(String introspectedCatalog,
+ String introspectedSchema,
+ String introspectedTableName,
+ String domainObjectName,
+ String alias,
+ boolean ignoreQualifiersAtRuntime,
+ String runtimeCatalog,
+ String runtimeSchema,
+ String runtimeTableName,
+ boolean delimitIdentifiers,
+ IbatorContext ibatorContext) {
super();
- this.catalog = catalog;
- this.schema = schema;
- this.tableName = tableName;
+ this.introspectedCatalog = introspectedCatalog;
+ this.introspectedSchema = introspectedSchema;
+ this.introspectedTableName = introspectedTableName;
this.domainObjectName = domainObjectName;
this.ignoreQualifiersAtRuntime = ignoreQualifiersAtRuntime;
+ this.runtimeCatalog = runtimeCatalog;
+ this.runtimeSchema = runtimeSchema;
this.runtimeTableName = runtimeTableName;
if (alias == null) {
@@ -105,45 +127,55 @@
endingDelimiter = delimitIdentifiers ?
ibatorContext.getEndingDelimiter() : ""; //$NON-NLS-1$
}
- public String getCatalog() {
- return catalog;
+ public String getIntrospectedCatalog() {
+ return introspectedCatalog;
}
- public String getSchema() {
- return schema;
+ public String getIntrospectedSchema() {
+ return introspectedSchema;
}
- public String getTableName() {
- return tableName;
+ public String getIntrospectedTableName() {
+ return introspectedTableName;
}
public String getFullyQualifiedTableNameAtRuntime() {
- String localCatalog;
- String localSchema;
- String localTableName;
-
- if (StringUtility.stringHasValue(catalog) &&
!ignoreQualifiersAtRuntime) {
- localCatalog = beginningDelimiter + catalog + endingDelimiter;
- } else {
- localCatalog = null;
+ StringBuffer localCatalog = new StringBuffer();
+ if (!ignoreQualifiersAtRuntime) {
+ if (StringUtility.stringHasValue(runtimeCatalog)) {
+ localCatalog.append(runtimeCatalog);
+ } else if (StringUtility.stringHasValue(introspectedCatalog)) {
+ localCatalog.append(introspectedCatalog);
+ }
+ }
+ if (localCatalog.length() > 0) {
+ addDelimiters(localCatalog);
}
- if (StringUtility.stringHasValue(schema) &&
!ignoreQualifiersAtRuntime) {
- localSchema = beginningDelimiter + schema + endingDelimiter;
- } else {
- localSchema = null;
+ StringBuffer localSchema = new StringBuffer();
+ if (!ignoreQualifiersAtRuntime) {
+ if (StringUtility.stringHasValue(runtimeSchema)) {
+ localSchema.append(runtimeSchema);
+ } else if (StringUtility.stringHasValue(introspectedSchema)) {
+ localSchema.append(introspectedSchema);
+ }
+ }
+ if (localSchema.length() > 0) {
+ addDelimiters(localSchema);
}
+ StringBuffer localTableName = new StringBuffer();
if (StringUtility.stringHasValue(runtimeTableName)) {
- localTableName = beginningDelimiter + runtimeTableName +
endingDelimiter;
+ localTableName.append(runtimeTableName);
} else {
- localTableName = beginningDelimiter + tableName + endingDelimiter;
+ localTableName.append(introspectedTableName);
}
+ addDelimiters(localTableName);
return StringUtility.composeFullyQualifiedTableName(
- localCatalog,
- localSchema,
- localTableName,
+ localCatalog.toString(),
+ localSchema.toString(),
+ localTableName.toString(),
'.');
}
@@ -162,14 +194,21 @@
/**
* This method returns a string that is the fully qualified table name,
with
- * underscores as the seperator. This String should be
+ * underscores as the seperator.
* @return
*/
public String getSqlMapNamespace() {
+ String localCatalog =
+ StringUtility.stringHasValue(runtimeCatalog) ? runtimeCatalog :
introspectedCatalog;
+ String localSchema =
+ StringUtility.stringHasValue(runtimeSchema) ? runtimeSchema :
introspectedSchema;
+ String localTable =
+ StringUtility.stringHasValue(runtimeTableName) ? runtimeTableName
: introspectedTableName;
+
return StringUtility.composeFullyQualifiedTableName(
- ignoreQualifiersAtRuntime ? null : catalog,
- ignoreQualifiersAtRuntime ? null : schema,
- StringUtility.stringHasValue(runtimeTableName) ?
runtimeTableName : tableName,
+ ignoreQualifiersAtRuntime ? null : localCatalog,
+ ignoreQualifiersAtRuntime ? null : localSchema,
+ localTable,
'_');
}
@@ -179,7 +218,7 @@
} else if (StringUtility.stringHasValue(runtimeTableName)) {
return JavaBeansUtil.getCamelCaseString(runtimeTableName, true);
} else {
- return JavaBeansUtil.getCamelCaseString(tableName,
true);
+ return
JavaBeansUtil.getCamelCaseString(introspectedTableName, true);
}
}
@@ -195,17 +234,17 @@
FullyQualifiedTable other = (FullyQualifiedTable) obj;
- return EqualsUtil.areEqual(this.tableName, other.tableName)
- && EqualsUtil.areEqual(this.catalog, other.catalog)
- && EqualsUtil.areEqual(this.schema,
other.schema);
+ return EqualsUtil.areEqual(this.introspectedTableName,
other.introspectedTableName)
+ && EqualsUtil.areEqual(this.introspectedCatalog,
other.introspectedCatalog)
+ && EqualsUtil.areEqual(this.introspectedSchema,
other.introspectedSchema);
}
@Override
public int hashCode() {
int result = HashCodeUtil.SEED;
- result = HashCodeUtil.hash(result, tableName);
- result = HashCodeUtil.hash(result, catalog);
- result = HashCodeUtil.hash(result, schema);
+ result = HashCodeUtil.hash(result, introspectedTableName);
+ result = HashCodeUtil.hash(result, introspectedCatalog);
+ result = HashCodeUtil.hash(result, introspectedSchema);
return result;
}
@@ -213,7 +252,7 @@
@Override
public String toString() {
return StringUtility.composeFullyQualifiedTableName(
- catalog, schema, tableName, '.');
+ introspectedCatalog, introspectedSchema,
introspectedTableName, '.');
}
public String getAlias() {
@@ -230,17 +269,35 @@
public String getSubPackage() {
StringBuffer sb = new StringBuffer();
if (!ignoreQualifiersAtRuntime) {
- if (StringUtility.stringHasValue(catalog)) {
+ if (StringUtility.stringHasValue(runtimeCatalog)) {
sb.append('.');
- sb.append(catalog.toLowerCase());
+ sb.append(runtimeCatalog.toLowerCase());
+ } else if (StringUtility.stringHasValue(introspectedCatalog)) {
+ sb.append('.');
+ sb.append(introspectedCatalog.toLowerCase());
}
- if (StringUtility.stringHasValue(schema)) {
+ if (StringUtility.stringHasValue(runtimeSchema)) {
+ sb.append('.');
+ sb.append(runtimeSchema.toLowerCase());
+ } else if (StringUtility.stringHasValue(introspectedSchema)) {
sb.append('.');
- sb.append(schema.toLowerCase());
+ sb.append(introspectedSchema.toLowerCase());
}
}
+
+ // TODO - strip characters that are not valid in pacckage names
return sb.toString();
}
+
+ private void addDelimiters(StringBuffer sb) {
+ if (StringUtility.stringHasValue(beginningDelimiter)) {
+ sb.insert(0, beginningDelimiter);
+ }
+
+ if (StringUtility.stringHasValue(endingDelimiter)) {
+ sb.append(endingDelimiter);
+ }
+ }
}
Modified:
ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/config/PropertyRegistry.java
URL:
http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/config/PropertyRegistry.java?rev=653096&r1=653095&r2=653096&view=diff
==============================================================================
---
ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/config/PropertyRegistry.java
(original)
+++
ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/config/PropertyRegistry.java
Sat May 3 09:59:04 2008
@@ -41,6 +41,8 @@
public static final String TABLE_USE_COLUMN_INDEXES = "useColumnIndexes";
//$NON-NLS-1$
public static final String TABLE_USE_ACTUAL_COLUMN_NAMES =
"useActualColumnNames"; //$NON-NLS-1$
public static final String TABLE_IGNORE_QUALIFIERS_AT_RUNTIME =
"ignoreQualifiersAtRuntime"; //$NON-NLS-1$
+ public static final String TABLE_RUNTIME_CATALOG = "runtimeCatalog";
//$NON-NLS-1$
+ public static final String TABLE_RUNTIME_SCHEMA = "runtimeSchema";
//$NON-NLS-1$
public static final String TABLE_RUNTIME_TABLE_NAME = "runtimeTableName";
//$NON-NLS-1$
public static final String CONTEXT_SUPPRESS_TYPE_WARNINGS =
"suppressTypeWarnings"; //$NON-NLS-1$
Modified:
ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/internal/db/DatabaseIntrospector.java
URL:
http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/internal/db/DatabaseIntrospector.java?rev=653096&r1=653095&r2=653096&view=diff
==============================================================================
---
ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/internal/db/DatabaseIntrospector.java
(original)
+++
ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/internal/db/DatabaseIntrospector.java
Sat May 3 09:59:04 2008
@@ -65,9 +65,9 @@
ResultSet rs = null;
try {
- rs =
databaseMetaData.getPrimaryKeys(introspectedTable.getTable().getCatalog(),
- introspectedTable.getTable().getSchema(),
- introspectedTable.getTable().getTableName());
+ rs =
databaseMetaData.getPrimaryKeys(introspectedTable.getTable().getIntrospectedCatalog(),
+ introspectedTable.getTable().getIntrospectedSchema(),
+ introspectedTable.getTable().getIntrospectedTableName());
} catch (SQLException e) {
closeResultSet(rs);
warnings.add(Messages.getString("Warning.15")); //$NON-NLS-1$
@@ -452,6 +452,8 @@
tc.getDomainObjectName(),
tc.getAlias(),
"true".equalsIgnoreCase(tc.getProperty(PropertyRegistry.TABLE_IGNORE_QUALIFIERS_AT_RUNTIME)),
//$NON-NLS-1$
+ tc.getProperty(PropertyRegistry.TABLE_RUNTIME_CATALOG),
+ tc.getProperty(PropertyRegistry.TABLE_RUNTIME_SCHEMA),
tc.getProperty(PropertyRegistry.TABLE_RUNTIME_TABLE_NAME),
delimitIdentifiers,
ibatorContext);