jon 01/05/10 16:03:23
Modified: src/java/org/apache/turbine/torque/engine/database/model
Database.java ForeignKey.java Table.java
Log:
dtd related cleanup
support for abstract tables
makes sure that the toString() methods work properly
code cleanup
Revision Changes Path
1.6 +8 -5
jakarta-turbine/src/java/org/apache/turbine/torque/engine/database/model/Database.java
Index: Database.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine/src/java/org/apache/turbine/torque/engine/database/model/Database.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- Database.java 2001/05/05 13:19:12 1.5
+++ Database.java 2001/05/10 23:03:21 1.6
@@ -66,11 +66,10 @@
*
* @author <a href="mailto:[EMAIL PROTECTED]>Leon Messerschmidt</a>
* @author <a href="mailto:[EMAIL PROTECTED]>John McNally</a>
- * @version $Id: Database.java,v 1.5 2001/05/05 13:19:12 jvanzyl Exp $
+ * @version $Id: Database.java,v 1.6 2001/05/10 23:03:21 jon Exp $
*/
public class Database
{
-
private List tableList = new ArrayList(100);
private Column curColumn;
private String name;
@@ -103,7 +102,6 @@
basePeer = attrib.getValue("basePeer");
}
-
/**
* Get the name of the Database
*/
@@ -188,7 +186,6 @@
return tbls;
}
-
/**
* Return the table with the specified name.
* @return A Table object. If it does not exist it returns null
@@ -255,11 +252,17 @@
{
StringBuffer result = new StringBuffer();
- result.append ("<database>\n");
+ result.append ("<database name=\"" + getName());
+ result.append (" package=\"" + getPackage() + "\"");
+ result.append (" baseClass=\"" + getBaseClass() + "\"");
+ result.append (" basePeer=\"" + getBasePeer() + "\"");
+ result.append(">\n");
+
for (Iterator i = tableList.iterator() ; i.hasNext() ;)
{
result.append (i.next());
}
+
result.append ("</database>");
return result.toString();
}
1.6 +2 -125
jakarta-turbine/src/java/org/apache/turbine/torque/engine/database/model/ForeignKey.java
Index: ForeignKey.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine/src/java/org/apache/turbine/torque/engine/database/model/ForeignKey.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ForeignKey.java 2001/05/05 13:19:12 1.5
+++ ForeignKey.java 2001/05/10 23:03:21 1.6
@@ -63,23 +63,15 @@
* A Class for information about foreign keys of a table
*
* @author <a href="mailto:[EMAIL PROTECTED]">Fedor</a>
- * @version $Id: ForeignKey.java,v 1.5 2001/05/05 13:19:12 jvanzyl Exp $
+ * @version $Id: ForeignKey.java,v 1.6 2001/05/10 23:03:21 jon Exp $
*/
public class ForeignKey
{
- public static final int NONE = 0;
- public static final int SET_NULL = 1;
- public static final int CASCADE = 2;
- public static final int RESTRICT = 3;
-
private String foreignTableName;
private Table parentTable;
private List localColumns = new ArrayList(3);
private List foreignColumns = new ArrayList(3);
- private int onupdate;
- private int ondelete;
-
/**
* Default Constructor
*/
@@ -93,28 +85,8 @@
public void loadFromXML (Attributes attrib)
{
foreignTableName = attrib.getValue("foreignTable");
-
- // FIXME!! the dtd does not contain attributes onupdate and ondelete
- onupdate = NONE;
- ondelete = NONE;
-
- String tmp = attrib.getValue("onupdate");
- if (tmp != null)
- {
- if (tmp.equals ("restrict")) onupdate = RESTRICT;
- else if (tmp.equals ("cascade")) onupdate = CASCADE;
- else if (tmp.equals ("set null")) onupdate = SET_NULL;
- }
-
- tmp = attrib.getValue("ondelete");
- if (tmp != null)
- {
- if (tmp.equals ("restrict")) ondelete = RESTRICT;
- else if (tmp.equals ("cascade")) ondelete = CASCADE;
- else if (tmp.equals ("set null")) ondelete = SET_NULL;
- }
-
}
+
/**
* Get the foreignTableName of the FK
*
@@ -226,7 +198,6 @@
return h;
}
-
/**
* Return the vector of local columns. You should not edit
* this vector.
@@ -252,7 +223,6 @@
return h;
}
-
/**
* String representation of the foreign key. This
* is an xml representation.
@@ -263,16 +233,6 @@
result.append(" <foreign-key foreignTable=\"")
.append(foreignTableName)
.append("\"");
-
- if (getOnUpdate() != NONE)
- {
- result.append(" onupdate=\""+getOnUpdateString()+"\"");
- }
- if (getOnDelete() != NONE)
- {
- result.append(" ondelete=\""+getOnDeleteString()+"\"");
- }
-
result.append(">\n");
for (int i=0; i<localColumns.size(); i++)
@@ -284,89 +244,6 @@
result.append(" </foreign-key>\n");
return result.toString();
}
-
-
- /**
- * A utility to convert foreign integer properties
- * to string values
- */
- private String foreignString (int on)
- {
- if (on == CASCADE) return "cascade";
- if (on == RESTRICT) return "restrict";
- if (on == SET_NULL) return "set null";
- return null;
- }
-
- /**
- * Returns the onUpdate value
- */
- public int getOnUpdate()
- {
- return onupdate;
- }
-
-
- /**
- * Get ON UPDATE for a foreign key as a string
- */
- public String getOnUpdateString()
- {
- return foreignString (onupdate);
- }
-
- /**
- * Set ON UPDATE for a foreign key
- */
- public void setOnUpdate (int u)
- {
- onupdate = u;
- }
-
- /**
- * Returns the onDelete value
- */
- public int getOnDelete()
- {
- return ondelete;
- }
-
- /**
- * Get ON DELETE for a foreign key
- */
- public String getOnDeleteString()
- {
- return foreignString (ondelete);
- }
-
- /**
- * Set ON DELETE for a foreign key
- */
- public void setOnDelete (int d)
- {
- ondelete = d;
- }
-
- /**
- * Utility method for easier code generation
- */
- public String printOnDelete()
- {
- if (ondelete == NONE) return "";
-
- return "ON UPDATE "+getOnDeleteString().toUpperCase();
- }
-
- /**
- * Utility method for easier code generation
- */
- public String printOnUpdate()
- {
- if (onupdate == NONE) return "";
-
- return "ON UPDATE "+getOnUpdateString().toUpperCase();
- }
-
}
1.13 +59 -12
jakarta-turbine/src/java/org/apache/turbine/torque/engine/database/model/Table.java
Index: Table.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine/src/java/org/apache/turbine/torque/engine/database/model/Table.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- Table.java 2001/05/05 13:19:13 1.12
+++ Table.java 2001/05/10 23:03:22 1.13
@@ -66,7 +66,7 @@
*
* @author <a href="mailto:[EMAIL PROTECTED]">Leon Messerschmidt</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
- * @version $Id: Table.java,v 1.12 2001/05/05 13:19:13 jvanzyl Exp $
+ * @version $Id: Table.java,v 1.13 2001/05/10 23:03:22 jon Exp $
*/
public class Table
{
@@ -86,6 +86,7 @@
private boolean containsForeignPK;
private Column inheritanceColumn;
private boolean skipSql;
+ private boolean abstractValue;
// private String pkg;
private String baseClass;
private String basePeer;
@@ -122,6 +123,7 @@
idMethod = attrib.getValue("idMethod");
skipSql = "true".equals(attrib.getValue("skipSql"));
// pkg = attrib.getValue("package");
+ abstractValue = "true".equals(attrib.getValue("abstract"));
baseClass = attrib.getValue("baseClass");
basePeer = attrib.getValue("basePeer");
}
@@ -185,7 +187,6 @@
Column col = new Column();
col.loadFromXML (attrib);
addColumn(col);
-
return col;
}
@@ -215,7 +216,6 @@
ForeignKey fk = new ForeignKey();
fk.loadFromXML (attrib);
addForeignKey (fk);
-
return fk;
}
@@ -241,7 +241,6 @@
{
names.add( ((Inheritance)children.get(i)).getClassName() );
}
-
return names;
}
@@ -321,7 +320,6 @@
IdMethodParameter imp = new IdMethodParameter();
imp.loadFromXML (attrib);
addIdMethodParameter (imp);
-
return imp;
}
@@ -358,7 +356,6 @@
Index index = new Index();
index.loadFromXML (attrib);
addIndex (index);
-
return index;
}
@@ -380,7 +377,6 @@
{
Unique unique = new Unique();
addUnique (unique);
-
return unique;
}
@@ -467,6 +463,34 @@
{
this.skipSql = v;
}
+
+ /**
+ * When a table is abstract, it marks the business object
+ * class that is generated as being abstract. if you have a
+ * table called "FOO", then the Foo BO will be
+ * public abstract class Foo
+ * This helps support class hierarchies
+ *
+ * @return value of abstractValue.
+ */
+ public boolean isAbstract()
+ {
+ return abstractValue;
+ }
+
+ /**
+ * When a table is abstract, it marks the business object
+ * class that is generated as being abstract. if you have a
+ * table called "FOO", then the Foo BO will be
+ * public abstract class Foo
+ * This helps support class hierarchies
+ *
+ * @param v Value to assign to abstractValue.
+ */
+ public void setAbstract(boolean v)
+ {
+ this.abstractValue = v;
+ }
/**
* Returns an Array containing all the columns in the table
@@ -531,7 +555,6 @@
.getValue();
}
}
-
return result;
}
@@ -563,7 +586,6 @@
return tbls;
}
-
/**
* Returns a specified column.
* @return Return a Column object or null if it does not exist.
@@ -601,7 +623,6 @@
return null;
}
-
/**
* Returns true if the table contains a spesified column
*/
@@ -660,6 +681,34 @@
.append('\"');
}
+ if (skipSql)
+ {
+ result.append(" skipSql=\"")
+ .append(new Boolean(skipSql))
+ .append('\"');
+ }
+
+ if (abstractValue)
+ {
+ result.append(" abstract=\"")
+ .append(new Boolean(abstractValue))
+ .append('\"');
+ }
+
+ if (baseClass != null)
+ {
+ result.append(" baseClass=\"")
+ .append(baseClass)
+ .append('\"');
+ }
+
+ if (basePeer != null)
+ {
+ result.append(" basePeer=\"")
+ .append(basePeer)
+ .append('\"');
+ }
+
result.append(">\n");
if (columnList != null)
@@ -686,7 +735,6 @@
result.append(iter.next());
}
}
-
result.append ("</table>\n");
@@ -712,7 +760,6 @@
pk.add(col);
}
}
-
return pk;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]