Please, check my attached proposition of the patch.
I don't properly update toString() in Table and ForeignKey class.
P.S. src/java/database.dtd is application/octet-stream. Is it correct?
--
Przemysław Sztoch <[EMAIL PROTECTED]>
Mobile +48 (502) 400 239, GG 569973
Index: src/java/database.dtd
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Index: src/java/mapping.xml
===================================================================
--- src/java/mapping.xml (revision 384285)
+++ src/java/mapping.xml (working copy)
@@ -13,6 +13,7 @@
<class name="org.apache.ddlutils.model.Table">
<element name="table">
<attribute name="name" property="name"/>
+ <attribute name="pkName" property="pkName"/>
<attribute name="description" property="description"/>
<element property="columns" updater="addColumn"/>
@@ -39,6 +40,8 @@
<element name="foreign-key">
<attribute name="foreignTable" property="foreignTableName"/>
<attribute name="name" property="name"/>
+ <attribute name="onUpdate" property="onUpdate"/>
+ <attribute name="onDelete" property="onDelete"/>
<element property="references" updater="addReference"/>
</element>
Index: src/java/org/apache/ddlutils/model/ForeignKey.java
===================================================================
--- src/java/org/apache/ddlutils/model/ForeignKey.java (revision 384285)
+++ src/java/org/apache/ddlutils/model/ForeignKey.java (working copy)
@@ -37,6 +37,10 @@
private Table _foreignTable;
/** The name of the foreign table. */
private String _foreignTableName;
+ /** The integrity action for update. */
+ private String _onUpdate;
+ /** The integrity action for delete. */
+ private String _onDelete;
/** The references between local and remote columns. */
private ListOrderedSet _references = new ListOrderedSet();
@@ -126,6 +130,46 @@
}
/**
+ * Returns the action for update.
+ *
+ * @return The name
+ */
+ public String getOnUpdate()
+ {
+ return _onUpdate;
+ }
+
+ /**
+ * Sets the action for update.
+ *
+ * @param name The name
+ */
+ public void setOnUpdate(String onUpdate)
+ {
+ _onUpdate = onUpdate;
+ }
+
+ /**
+ * Returns the action for update.
+ *
+ * @return The name
+ */
+ public String getOnDelete()
+ {
+ return _onDelete;
+ }
+
+ /**
+ * Sets the action for update.
+ *
+ * @param name The name
+ */
+ public void setOnDelete(String onDelete)
+ {
+ _onDelete = onDelete;
+ }
+
+ /**
* Returns the number of references.
*
* @return The number of references
@@ -223,6 +267,8 @@
result._name = _name;
result._foreignTableName = _foreignTableName;
result._references = new ListOrderedSet();
+ result._onUpdate = _onUpdate;
+ result._onDelete = _onDelete;
for (Iterator it = _references.iterator(); it.hasNext();)
{
@@ -247,6 +293,8 @@
return new EqualsBuilder().append(_name, other._name)
.append(_foreignTableName,
other._foreignTableName)
.append(_references,
other._references)
+ .append(_onUpdate,
other._onUpdate)
+ .append(_onDelete,
other._onDelete)
.isEquals();
}
else
@@ -264,7 +312,9 @@
public boolean equalsIgnoreCase(ForeignKey otherFk)
{
if (_name.equalsIgnoreCase(otherFk._name) &&
- _foreignTableName.equalsIgnoreCase(otherFk._foreignTableName))
+ _foreignTableName.equalsIgnoreCase(otherFk._foreignTableName) &&
+ _onUpdate.equalsIgnoreCase(otherFk._onUpdate) &&
+ _onDelete.equalsIgnoreCase(otherFk._onDelete))
{
HashSet otherRefs = new HashSet();
@@ -306,6 +356,8 @@
return new HashCodeBuilder(17, 37).append(_name)
.append(_foreignTableName)
.append(_references)
+ .append(_onUpdate)
+ .append(_onDelete)
.toHashCode();
}
Index: src/java/org/apache/ddlutils/model/Table.java
===================================================================
--- src/java/org/apache/ddlutils/model/Table.java (revision 384285)
+++ src/java/org/apache/ddlutils/model/Table.java (working copy)
@@ -48,6 +48,8 @@
private String _description = null;
/** The table's type as read from the database. */
private String _type = null;
+ /** The primary key name. */
+ private String _pkName = null;
/** The columns in this table. */
private ArrayList _columns = new ArrayList();
/** The foreign keys associated to this table. */
@@ -156,6 +158,26 @@
}
/**
+ * Returns the name of the primary key.
+ *
+ * @return The name
+ */
+ public String getPkName()
+ {
+ return _pkName;
+ }
+
+ /**
+ * Sets the name of the primary key.
+ *
+ * @param pkName The name
+ */
+ public void setPkName(String pkName)
+ {
+ _pkName = pkName;
+ }
+
+ /**
* Returns the number of columns in this table.
*
* @return The number of columns
@@ -669,6 +691,7 @@
result._schema = _schema;
result._name = _name;
result._type = _type;
+ result._pkName = _pkName;
result._columns = (ArrayList)_columns.clone();
result._foreignKeys = (ArrayList)_foreignKeys.clone();
result._indices = (ArrayList)_indices.clone();
@@ -688,6 +711,7 @@
// Note that this compares case sensitive
// TODO: For now we ignore catalog and schema (type should be
irrelevant anyways)
return new EqualsBuilder().append(_name,
other._name)
+ .append(_pkName,
other._pkName)
.append(_columns,
other._columns)
.append(new HashSet(_foreignKeys), new
HashSet(other._foreignKeys))
.append(new HashSet(_indices), new
HashSet(other._indices))
@@ -706,6 +730,7 @@
{
// TODO: For now we ignore catalog and schema (type should be
irrelevant anyways)
return new HashCodeBuilder(17, 37).append(_name)
+ .append(_pkName)
.append(_columns)
.append(new HashSet(_foreignKeys))
.append(new HashSet(_indices))
Index: src/java/org/apache/ddlutils/platform/postgresql/PostgreSqlPlatform.java
===================================================================
--- src/java/org/apache/ddlutils/platform/postgresql/PostgreSqlPlatform.java
(revision 384285)
+++ src/java/org/apache/ddlutils/platform/postgresql/PostgreSqlPlatform.java
(working copy)
@@ -84,6 +84,8 @@
// no support for specifying the size for these types
info.setHasSize(Types.BINARY, false);
info.setHasSize(Types.VARBINARY, false);
+ info.setHasSize(Types.TIMESTAMP, true);
+ info.setHasSize(Types.TIME, true);
setSqlBuilder(new PostgreSqlBuilder(this));
setModelReader(new PostgreSqlModelReader(this));
Index: src/java/org/apache/ddlutils/platform/SqlBuilder.java
===================================================================
--- src/java/org/apache/ddlutils/platform/SqlBuilder.java (revision
384285)
+++ src/java/org/apache/ddlutils/platform/SqlBuilder.java (working copy)
@@ -1595,6 +1595,12 @@
*/
protected void writePrimaryKeyStmt(Table table, Column[]
primaryKeyColumns) throws IOException
{
+ if (table.getPkName()!=null)
+ {
+ print("CONSTRAINT ");
+ print(table.getPkName());
+ print(" ");
+ }
print("PRIMARY KEY (");
for (int idx = 0; idx < primaryKeyColumns.length; idx++)
{
@@ -1796,7 +1802,9 @@
printIdentifier(getForeignKeyName(table, key));
print(" ");
}
- print("FOREIGN KEY (");
+ print("FOREIGN KEY");
+ writeForeignKeyOption(key);
+ print(" (");
writeLocalReferences(key);
print(") REFERENCES ");
printIdentifier(getTableName(database.findTable(key.getForeignTableName())));
@@ -1806,6 +1814,32 @@
}
}
}
+
+ protected void writeForeignKeyOption(ForeignKey key) throws IOException
+ {
+ if (key.getOnUpdate() != null && !key.getOnUpdate().equals("none"))
+ {
+ print(" ON UPDATE ");
+ if (key.getOnUpdate().equals("cascade")) {
+ print("CASCADE");
+ } else if (key.getOnUpdate().equals("setnull")) {
+ print("SET NULL");
+ } else if (key.getOnUpdate().equals("restrict")) {
+ print("RESTRICT");
+ }
+ }
+ if (key.getOnDelete() != null && !key.getOnDelete().equals("none"))
+ {
+ print(" ON DELETE ");
+ if (key.getOnDelete().equals("cascade")) {
+ print("CASCADE");
+ } else if (key.getOnDelete().equals("setnull")) {
+ print("SET NULL");
+ } else if (key.getOnDelete().equals("restrict")) {
+ print("RESTRICT");
+ }
+ }
+ }
/**
* Writes a single foreign key constraint using a alter table statement.
@@ -1826,7 +1860,9 @@
print("ADD CONSTRAINT ");
printIdentifier(getForeignKeyName(table, key));
- print(" FOREIGN KEY (");
+ print(" FOREIGN KEY");
+ writeForeignKeyOption(key);
+ print(" (");
writeLocalReferences(key);
print(") REFERENCES ");
printIdentifier(getTableName(database.findTable(key.getForeignTableName())));