So I've been working on getting torque to play nicely with postgres.
I've had to make several changes (nothing huge), to get the following to
work:
Foreign Keys to not throw exceptions at runtime
--------------------
XMLSchemaToSQL.java
null check on properties (see eariler post)
added the file foreign_key under db/postgres
added the line in postgres/db.props
foreignKeyInsideTableDirective = true
TODO:
foreignKeyInsideTableDirective = false
does not work (it still puts them inside the table)
Drop Serial
----------
in postgres, you should drop the sequence, before you drop the table.
(only applicable for serial keys)
XMLSchemaToSQL.java
added a small section of logic for this
Each db/* now needs a template called drop_seq
(all can be empty except postgres which has)
drop sequence $table#_$seq#_seq;
which leads me to the next fix:
Utils.stringSubstitution()
I needed to add the ability to have a token separator for torque's
macro substituion
Does anyone want the patches?
mike
Here's the torque.XMLSchemaToSQL diffs:
Index: XMLSchemaToSQL.java
===================================================================
RCS file:
/products/cvs/turbine/turbine/src/java/org/apache/turbine/tools/torque/xml/XMLSchemaToSQL.java,v
retrieving revision 1.9
diff -c -u -r1.9 XMLSchemaToSQL.java
--- XMLSchemaToSQL.java 2000/10/31 10:17:40 1.9
+++ XMLSchemaToSQL.java 2000/10/31 21:22:40
@@ -119,6 +119,9 @@
*/
private String sqlTargetFile;
+ /** Drop sequence template for target database. */
+ private String dropSequenceTemplate;
+
/** Drop template for target database. */
private String dropTemplate;
@@ -146,6 +149,8 @@
/** The indent to use in the SQL generation. */
private static final String INDENT = " ";
+ private Vector autoIncrementSet = new Vector();
+
// This needs to be cleaned up.
private StringBuffer sql = new StringBuffer();
private StringBuffer table = new StringBuffer();
@@ -259,6 +264,7 @@
// Get the db.props file for the db specified in torque.props.
dbProps = Utils.loadProps(path + "db.props");
+ dropSequenceTemplate = Utils.fileContentsToString(path + "drop_seq");
dropTemplate = Utils.fileContentsToString(path + "drop");
tableTemplate = Utils.fileContentsToString(path + "table");
commentTemplate = Utils.fileContentsToString(path + "comment");
@@ -335,7 +341,20 @@
substitutions = new Hashtable();
substitutions.put("table", tableName);
-
+
+ if (dropSequenceTemplate != null) {
+ int size = autoIncrementSet.size();
+ StringBuffer prefix;
+ if (size > 0) {
+ String col = (String)autoIncrementSet.elementAt(0);
+ substitutions.put("seq", col);
+ prefix = Utils.stringSubstitution(dropSequenceTemplate,
+ substitutions, '#');
+
+ table = new StringBuffer(prefix.toString() + table.toString());
+ }
+ }
+
// Unique Indices.
if (unique.length() > 0)
{
@@ -461,6 +480,8 @@
else
chop = 2;
+
+
// Place the columns in the table directive.
substitutions.put("columns", Utils.chop(columns.toString(), chop));
table = Utils.stringSubstitution(table.toString(), substitutions);
@@ -475,6 +496,7 @@
foreignColumns = new StringBuffer();
foreignKeyList = new ArrayList();
foreignKeys = new StringBuffer();
+ autoIncrementSet.removeAllElements();
indices = new StringBuffer();
indexes = new StringBuffer();
@@ -488,6 +510,7 @@
if (attributes != null)
tableName = (String) attributes.getValue("name");
+
table.append(dropTemplate);
table.append("\n");
table.append(tableTemplate);
@@ -496,24 +519,34 @@
private boolean primaryKeyInside()
{
+ String isPkeyInside;
+ isPkeyInside =
+ dbProps.getProperty("primaryKeyInsideTableDirective");
+
return primaryKeys.length() > 0 &&
- dbProps.getProperty("primaryKeyInsideTableDirective")
- .equalsIgnoreCase("true");
+ isPkeyInside != null &&
+ isPkeyInside.equalsIgnoreCase("true");
}
private boolean foreignKeyInside()
{
+ String isFkeyInside;
+ isFkeyInside = dbProps.getProperty("foreignKeyInsideTableDirective");
+
//return foreignKeys.length() > 0 &&
return localColumns.length() > 0 &&
- dbProps.getProperty("foreignKeyInsideTableDirective")
- .equalsIgnoreCase("true");
+ isFkeyInside != null &&
+ isFkeyInside.equalsIgnoreCase("true");
}
private boolean indexInside()
{
- return indices.length() > 0 &&
- dbProps.getProperty("indexInsideTableDirective")
- .equalsIgnoreCase("true");
+ String isIndexInside;
+ isIndexInside = dbProps.getProperty("indexInsideTableDirective");
+
+ return indices.length() > 0 &&
+ isIndexInside != null &&
+ isIndexInside.equalsIgnoreCase("true");
}
/**
@@ -548,6 +581,7 @@
if (attributes.getValue("autoIncrement") != null)
{
autoIncrement = dbAutoIncrement + " ";
+ autoIncrementSet.addElement(columnName);
}
if (attributes.getValue("size") != null)
Here's the torque Utils diffs:
Index: Utils.java
===================================================================
RCS file:
/products/cvs/turbine/turbine/src/java/org/apache/turbine/tools/torque/util/Utils.java,v
retrieving revision 1.1
diff -c -r1.1 Utils.java
*** Utils.java 2000/10/27 23:17:54 1.1
--- Utils.java 2000/10/31 21:18:31
***************
*** 201,212 ****
--- 201,224 ----
public static StringBuffer stringSubstitution(String argStr,
Hashtable vars)
{
+ return stringSubstitution(argStr, vars, (char)0);
+ }
+
+ public static StringBuffer stringSubstitution(String argStr,
+ Hashtable vars,
+ char delimiter)
+ {
StringBuffer argBuf = new StringBuffer();
for (int cIdx = 0 ; cIdx < argStr.length();)
{
char ch = argStr.charAt(cIdx);
+ if (ch == delimiter) {
+ cIdx++;
+ continue;
+ }
+
switch (ch)
{
case '$':
***************
*** 214,219 ****
--- 226,236 ----
for (++cIdx ; cIdx < argStr.length(); ++cIdx)
{
ch = argStr.charAt(cIdx);
+
+ if (ch == delimiter) {
+ break;
+ }
+
if (ch == '_' || Character.isLetterOrDigit(ch))
nameBuf.append(ch);
else
------------------------------------------------------------
To subscribe: [EMAIL PROTECTED]
To unsubscribe: [EMAIL PROTECTED]
Search: <http://www.mail-archive.com/turbine%40list.working-dogs.com/>
Problems?: [EMAIL PROTECTED]