You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ddlutils-dev@db.apache.org by to...@apache.org on 2006/01/01 21:23:21 UTC
svn commit: r360540 - in
/db/ddlutils/trunk/src/java/org/apache/ddlutils/model: ForeignKey.java
Index.java IndexColumn.java NonUniqueIndex.java Reference.java
Author: tomdz
Date: Sun Jan 1 12:23:16 2006
New Revision: 360540
URL: http://svn.apache.org/viewcvs?rev=360540&view=rev
Log:
Added support for the sequence number/ordinal position in foreign keys/indices
Modified:
db/ddlutils/trunk/src/java/org/apache/ddlutils/model/ForeignKey.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Index.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/model/IndexColumn.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/model/NonUniqueIndex.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Reference.java
Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/model/ForeignKey.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/model/ForeignKey.java?rev=360540&r1=360539&r2=360540&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/model/ForeignKey.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/model/ForeignKey.java Sun Jan 1 12:23:16 2006
@@ -30,8 +30,6 @@
*/
public class ForeignKey implements Cloneable
{
- // TODO: Make the create/alter/drop functionality respect the name property
-
/** The name of the foreign key, may be <code>null</code>. */
private String _name;
/** The target table. */
@@ -177,22 +175,17 @@
{
if (reference != null)
{
+ for (int idx = 0; idx < _references.size(); idx++)
+ {
+ Reference curRef = getReference(idx);
+
+ if (curRef.getSequenceValue() > reference.getSequenceValue())
+ {
+ _references.add(idx, reference);
+ return;
+ }
+ }
_references.add(reference);
- }
- }
-
- /**
- * Adds a reference, ie. a mapping between a local column (in the table that owns this foreign key)
- * and a remote column, at the specified place.
- *
- * @param idx The index to add the reference at
- * @param reference The reference to add
- */
- public void addReference(int idx, Reference reference)
- {
- if (reference != null)
- {
- _references.add(idx, reference);
}
}
Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Index.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Index.java?rev=360540&r1=360539&r2=360540&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Index.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Index.java Sun Jan 1 12:23:16 2006
@@ -77,14 +77,6 @@
public void addColumn(IndexColumn column);
/**
- * Adds a column that makes up this index at the specified position.
- *
- * @param idx The position to add the index colum at
- * @param column The column to add
- */
- public void addColumn(int idx, IndexColumn column);
-
- /**
* Removes the given index column from this index.
*
* @param column The column to remove
Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/model/IndexColumn.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/model/IndexColumn.java?rev=360540&r1=360539&r2=360540&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/model/IndexColumn.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/model/IndexColumn.java Sun Jan 1 12:23:16 2006
@@ -32,6 +32,8 @@
/** Unique ID for serialization purposes. */
private static final long serialVersionUID = -5009366896427504739L;
+ /** The position within the owning index. */
+ private int _ordinalPosition;
/** The name of the column. */
protected String _name;
/** The size of the column in the index. */
@@ -55,7 +57,28 @@
{
_name = columnName;
}
-
+
+ /**
+ * Returns the position within the owning index.
+ *
+ * @return The position
+ */
+ public int getOrdinalPosition()
+ {
+ return _ordinalPosition;
+ }
+
+ /**
+ * Sets the position within the owning index. Please note that you should not
+ * change the value once the column has been added to a index.
+ *
+ * @param position The position
+ */
+ public void setOrdinalPosition(int position)
+ {
+ _ordinalPosition = position;
+ }
+
/**
* Returns the name of the column.
*
Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/model/NonUniqueIndex.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/model/NonUniqueIndex.java?rev=360540&r1=360539&r2=360540&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/model/NonUniqueIndex.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/model/NonUniqueIndex.java Sun Jan 1 12:23:16 2006
@@ -92,18 +92,17 @@
{
if (column != null)
{
- _columns.add(column);
- }
- }
+ for (int idx = 0; idx < _columns.size(); idx++)
+ {
+ IndexColumn curColumn = getColumn(idx);
- /**
- * {@inheritDoc}
- */
- public void addColumn(int idx, IndexColumn column)
- {
- if (column != null)
- {
- _columns.add(idx, column);
+ if (curColumn.getOrdinalPosition() > column.getOrdinalPosition())
+ {
+ _columns.add(idx, column);
+ return;
+ }
+ }
+ _columns.add(column);
}
}
Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Reference.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Reference.java?rev=360540&r1=360539&r2=360540&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Reference.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Reference.java Sun Jan 1 12:23:16 2006
@@ -1,8 +1,5 @@
package org.apache.ddlutils.model;
-import org.apache.commons.lang.builder.EqualsBuilder;
-import org.apache.commons.lang.builder.HashCodeBuilder;
-
/*
* Copyright 1999-2005 The Apache Software Foundation.
*
@@ -19,14 +16,24 @@
* limitations under the License.
*/
+import java.io.Serializable;
+
+import org.apache.commons.lang.builder.EqualsBuilder;
+import org.apache.commons.lang.builder.HashCodeBuilder;
+
/**
* Represents a reference between a column in the local table and a column in another table.
*
* @author Thomas Dudziak
* @version $Revision$
*/
-public class Reference implements Cloneable
+public class Reference implements Cloneable, Serializable
{
+ /** Unique ID for serialization purposes. */
+ private static final long serialVersionUID = 6062467640266171664L;
+
+ /** The sequence value within the key. */
+ private int _sequenceValue;
/** The local column. */
private Column _localColumn;
/** The foreign column. */
@@ -52,6 +59,28 @@
{
setLocalColumn(localColumn);
setForeignColumn(foreignColumn);
+ }
+
+ /**
+ * Returns the sequence value within the owning key.
+ *
+ * @return The sequence value
+ */
+ public int getSequenceValue()
+ {
+ return _sequenceValue;
+ }
+
+ /**
+ * Sets the sequence value within the owning key. Please note
+ * that you should not change the value once the reference has
+ * been added to a key.
+ *
+ * @param sequenceValue The sequence value
+ */
+ public void setSequenceValue(int sequenceValue)
+ {
+ _sequenceValue = sequenceValue;
}
/**