db-ddlutils-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r240460 [2/2] - in /db/ddlutils/trunk: ./ lib/ src/java/ src/java/org/apache/ddlutils/ src/java/org/apache/ddlutils/builder/ src/java/org/apache/ddlutils/dynabean/ src/java/org/apache/ddlutils/io/ src/java/org/apache/ddlutils/model/ src/jav...
Date Sat, 27 Aug 2005 21:50:57 GMT
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=240460&r1=240459&r2=240460&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 Sat Aug 27 14:44:57 2005
@@ -16,68 +16,177 @@
  * limitations under the License.
  */
 
-
+/**
+ * Represents a reference between a column in the local table and a column in another table. 
+ */
 public class Reference implements Cloneable, Comparable
 {
-    private String local;
-    private String foreign;
-    
-    public Reference() {}
+    /** The local column */
+    private Column _localColumn;
+    /** The foreign column */
+    private Column _foreignColumn;
+    /** The name of the local column */
+    private String _localColumnName;
+    /** The name of the foreign column */
+    private String _foreignColumnName;
 
-    /* (non-Javadoc)
-     * @see java.lang.Object#clone()
+    /**
+     * Creates a new, empty reference.
      */
-    public Object clone() throws CloneNotSupportedException
+    public Reference()
+    {}
+
+    /**
+     * Creates a new reference between the two given columns.
+     * 
+     * @param localColumn   The local column
+     * @param foreignColumn The remote column
+     */
+    public Reference(Column localColumn, Column foreignColumn)
     {
-        Reference result = new Reference();
+        setLocalColumn(localColumn);
+        setForeignColumn(foreignColumn);
+    }
 
-        result.local   = local;
-        result.foreign = foreign;
-        return result;
+    /**
+     * Returns the local column.
+     *
+     * @return The local column
+     */
+    public Column getLocalColumn()
+    {
+        return _localColumn;
     }
 
-    public String getLocal()
+    /**
+     * Sets the local column.
+     *
+     * @param localColumn The local column
+     */
+    public void setLocalColumn(Column localColumn)
     {
-        return local;
+        _localColumn     = localColumn;
+        _localColumnName = (localColumn == null ? null : localColumn.getName());
     }
-    
-    public void setLocal(String local)
+
+    /**
+     * Returns the foreign column.
+     *
+     * @return The foreign column
+     */
+    public Column getForeignColumn()
     {
-        this.local = local;
+        return _foreignColumn;
     }
-    
-    public String getForeign()
+
+    /**
+     * Sets the foreign column.
+     *
+     * @param foreignColumn The foreign column
+     */
+    public void setForeignColumn(Column foreignColumn)
+    {
+        _foreignColumn     = foreignColumn;
+        _foreignColumnName = (foreignColumn == null ? null : foreignColumn.getName());
+    }
+
+    /**
+     * Returns the name of the local column.
+     * 
+     * @return The column name
+     */
+    public String getLocalColumnName()
     {
-        return foreign;
+        return _localColumnName;
+    }
+
+    /**
+     * Sets the name of the local column. Note that you should not use this method when
+     * manipulating the model manually. Rather use the {@link #setLocalColumn(Column)} method.
+     * 
+     * @param localColumnName The column name
+     */
+    public void setLocalColumnName(String localColumnName)
+    {
+        if ((_localColumn != null) && !_localColumn.getName().equals(localColumnName))
+        {
+            _localColumn = null;
+        }
+        _localColumnName = localColumnName;
     }
     
-    public void setForeign(String foreign)
+    /**
+     * Returns the name of the foreign column.
+     * 
+     * @return The column name
+     */
+    public String getForeignColumnName()
     {
-        this.foreign = foreign;
+        return _foreignColumnName;
     }
     
-    public boolean equals(Object o) {
-        boolean result = o != null && getClass().equals(o.getClass());
-        if ( result ) {
-            Reference ref = (Reference) o;
-            result = this.local.equalsIgnoreCase(ref.local) && this.foreign.equalsIgnoreCase(ref.foreign);
+    /**
+     * Sets the name of the remote column. Note that you should not use this method when
+     * manipulating the model manually. Rather use the {@link #setForeignColumn(Column)} method.
+     * 
+     * @param foreignColumnName The column name
+     */
+    public void setForeignColumnName(String foreignColumnName)
+    {
+        if ((_foreignColumn != null) && !_foreignColumn.getName().equals(foreignColumnName))
+        {
+            _foreignColumn = null;
         }
-        return result;
+        _foreignColumnName = foreignColumnName;
+    }
+
+    /* (non-Javadoc)
+     * @see java.lang.Object#clone()
+     */
+    public Object clone() throws CloneNotSupportedException
+    {
+        return new Reference(getLocalColumn(), getForeignColumn());
     }
 
     /* (non-Javadoc)
      * @see java.lang.Comparable#compareTo(java.lang.Object)
      */
-    public int compareTo(Object o) {
-        Reference ref = (Reference) o;
-        int result = this.local.compareTo(ref.local);
-        if ( result == 0 ) {
-            result = this.foreign.compareTo(ref.foreign);
+    public int compareTo(Object other)
+    {
+        Reference ref = (Reference)other;
+
+        int result = getLocalColumnName().compareTo(ref.getLocalColumnName());
+
+        if (result == 0)
+        {
+            result = getForeignColumnName().compareTo(ref.getForeignColumnName());
         }
         return result;
     }
-    
-    public String toString() {
-        return "Reference[" + this.local + " to " + this.foreign + "]";
+
+    /* (non-Javadoc)
+     * @see java.lang.Object#equals(java.lang.Object)
+     */
+    public boolean equals(Object other)
+    {
+        boolean result = (other != null) && getClass().equals(other.getClass());
+
+        if (result)
+        {
+            Reference ref = (Reference) other;
+
+            // TODO: Compare the columns, not their names
+            result = getLocalColumnName().equals(ref.getLocalColumnName()) &&
+                     getForeignColumnName().equals(ref.getForeignColumnName());
+        }
+        return result;
+    }
+
+    /* (non-Javadoc)
+     * @see java.lang.Object#toString()
+     */
+    public String toString()
+    {
+        return "Reference[" + getLocalColumnName() + " to " + getForeignColumnName() + "]";
     }
 }

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Table.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Table.java?rev=240460&r1=240459&r2=240460&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Table.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Table.java Sat Aug 27 14:44:57 2005
@@ -16,217 +16,415 @@
  * limitations under the License.
  */
 
+import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 
-/**
- * Models a table.
- *
- * @version $Id$
- * @author John Marshall/Connectria
- * @author Matthew Hawthorne
- */
-import org.apache.commons.collections.iterators.FilterIterator;
 import org.apache.commons.collections.Predicate;
+import org.apache.commons.collections.list.PredicatedList;
 
-public class Table implements Cloneable
+/**
+ * Represents a table in the database model.
+ * 
+ * @version $Revision$
+ */
+public class Table implements Serializable, Cloneable
 {
-    private static final Predicate UNIQUE_PREDICATE = new Predicate() {
-        public boolean evaluate(Object input) {
-            return ((Index)input).isUnique();
-        }
-    };
-
-    private String catalog = null;
-
-    private String name = null;
+    /** Unique ID for serialization purposes */
+    private static final long serialVersionUID = -5541154961302342608L;
 
-    private String javaName = null;
+    /** The catalog of this table as read from the database */
+    private String _catalog = null;
+    /** The table's schema */
+    private String _schema = null;
+    /** The name */
+    private String _name = null;
+    /** A desription of the table */
+    private String _description = null;
+    /** The table's type as read from the database */
+    private String _type = null;
+    /** The columns in this table */
+    private ArrayList _columns = new ArrayList();
+    /** The foreign keys associated to this table */
+    private ArrayList _foreignKeys = new ArrayList();
+    /** The indices applied to this table */
+    private ArrayList _indices = new ArrayList();
 
-    private String schema = null;
-
-    private String remarks = null;
-
-    private String type = null;
-
-    private ArrayList columns = new ArrayList();
+    /**
+     * Returns the catalog of this table as read from the database.
+     * 
+     * @return The catalog
+     */
+    public String getCatalog()
+    {
+        return _catalog;
+    }
 
-    private ArrayList foreignKeys = new ArrayList();
+    /**
+     * Sets the catalog of this table.
+     * 
+     * @param catalog The catalog
+     */
+    public void setCatalog(String catalog)
+    {
+        _catalog = catalog;
+    }
 
-    private ArrayList indexes = new ArrayList();
+    /**
+     * Returns the schema of this table as read from the database.
+     * 
+     * @return The schema
+     */
+    public String getSchema()
+    {
+        return _schema;
+    }
 
-    public Table()
+    /**
+     * Sets the schema of this table.
+     * 
+     * @param schema The schema
+     */
+    public void setSchema(String schema)
     {
+        _schema = schema;
     }
 
-    public String toString()
+    /**
+     * Returns the type of this table as read from the database.
+     * 
+     * @return The type
+     */
+    public String getType()
     {
-        return super.toString() + "[name=" + name + "]";
+        return _type;
     }
 
-    /* (non-Javadoc)
-     * @see java.lang.Object#clone()
+    /**
+     * Sets the type of this table.
+     * 
+     * @param type The type
      */
-    public Object clone() throws CloneNotSupportedException
+    public void setType(String type)
     {
-        Table result = new Table();
+        _type = type;
+    }
 
-        result.catalog     = catalog;
-        result.name        = name;
-        result.javaName    = javaName;
-        result.schema      = schema;
-        result.remarks     = remarks;
-        result.type        = type;
-        result.columns     = (ArrayList)columns.clone();
-        result.foreignKeys = (ArrayList)foreignKeys.clone();
-        result.indexes     = (ArrayList)indexes.clone();
-        return result;
+    /**
+     * Returns the name of the table.
+     * 
+     * @return The name
+     */
+    public String getName()
+    {
+        return _name;
     }
 
-    public String getCatalog()
+    /**
+     * Sets the name of the table.
+     * 
+     * @param name The name
+     */
+    public void setName(String name)
     {
-        return this.catalog;
+        _name = name;
     }
 
-    public void setCatalog(String catalog)
+    /**
+     * Returns the description of the table.
+     *
+     * @return The description
+     */
+    public String getDescription()
     {
-        this.catalog = catalog;
+        return _description;
     }
 
-    public String getRemarks()
+    /**
+     * Sets the description of the table.
+     *
+     * @param description The description
+     */
+    public void setDescription(String description)
     {
-        return this.remarks;
+        _description = description;
     }
 
-    public void setRemarks(String remarks)
+    /**
+     * Returns the number of columns in this table.
+     * 
+     * @return The number of columns
+     */
+    public int getColumnCount()
     {
-        this.remarks = remarks;
+        return _columns.size();
     }
 
-    public String getSchema()
+    /**
+     * Returns the column at the specified position.
+     * 
+     * @param idx The column index
+     * @return The column at this position
+     */
+    public Column getColumn(int idx)
     {
-        return this.schema;
+        return (Column)_columns.get(idx);
     }
 
-    public void setSchema(String schema)
+    /**
+     * Returns the columns in this table.
+     * 
+     * @return The columns
+     */
+    public Column[] getColumns()
     {
-        this.schema = schema;
+        return (Column[])_columns.toArray(new Column[_columns.size()]);
     }
 
-    public String getType()
+    /**
+     * Adds the given column.
+     * 
+     * @param column The column
+     */
+    public void addColumn(Column column)
     {
-        return (type == null) ? "(null)" : type;
+        if (column != null)
+        {
+            _columns.add(column);
+        }
     }
 
-    public void setType(String type)
+    /**
+     * Adds the given column at the specified position .
+     * 
+     * @param idx    The index where to add the column
+     * @param column The column
+     */
+    public void addColumn(int idx, Column column)
     {
-        this.type = type;
+        if (column != null)
+        {
+            _columns.add(idx, column);
+        }
     }
 
-    public String getName()
+    /**
+     * Removes the given column.
+     * 
+     * @param column The column to remove
+     */
+    public void removeColumn(Column column)
     {
-        return name;
+        if (column != null)
+        {
+            _columns.remove(column);
+        }
     }
 
-    public void setName(String name)
+    /**
+     * Removes the indicated column.
+     * 
+     * @param idx The index of the column to remove
+     */
+    public void removeColumn(int idx)
     {
-        this.name=name;
+        _columns.remove(idx);
     }
 
-    public String getJavaName()
+    /**
+     * Returns the number of foreign keys.
+     * 
+     * @return The number of foreign keys
+     */
+    public int getForeignKeyCount()
     {
-        return javaName;
+        return _foreignKeys.size();
     }
 
-    public void setJavaName(String javaName)
+    /**
+     * Returns the foreign key at the given position.
+     * 
+     * @param idx The foreign key index
+     * @return The foreign key
+     */
+    public ForeignKey getForeignKey(int idx)
     {
-        this.javaName = javaName;
+        return (ForeignKey)_foreignKeys.get(idx);
     }
 
-    public void addColumn(Column column)
+    /**
+     * Returns the foreign keys of this table.
+     * 
+     * @return The foreign keys
+     */
+    public ForeignKey[] getForeignKeys()
     {
-        columns.add(column);
+        return (ForeignKey[])_foreignKeys.toArray(new ForeignKey[_foreignKeys.size()]);
     }
 
-    public void addAll(List columns)
+    /**
+     * Adds the given foreign key.
+     * 
+     * @param foreignKey The foreign key
+     */
+    public void addForeignKey(ForeignKey foreignKey)
     {
-        if(columns != null &&
-           columns.size() > 0)
+        if (foreignKey != null)
         {
-            int columnsSize = columns.size();
-            for(int i = 0; i < columnsSize; i++)
-            {
-                Column column = (Column) columns.get(i);
-                if(column != null)
-                {
-                    this.addColumn(column);
-                }
-            }
+            _foreignKeys.add(foreignKey);
         }
     }
 
-    public List getColumns()
+    /**
+     * Adds the given foreign key at the specified position.
+     * 
+     * @param idx        The index to add the foreign key at
+     * @param foreignKey The foreign key
+     */
+    public void addForeignKey(int idx, ForeignKey foreignKey)
     {
-        return columns;
+        if (foreignKey != null)
+        {
+            _foreignKeys.add(idx, foreignKey);
+        }
     }
 
-    public void addForeignKey(ForeignKey foreignKey)
+    /**
+     * Removes the given foreign key.
+     * 
+     * @param foreignKey The foreign key to remove
+     */
+    public void removeForeignKey(ForeignKey foreignKey)
     {
-        foreignKeys.add(foreignKey);
+        if (foreignKey != null)
+        {
+            _foreignKeys.remove(foreignKey);
+        }
     }
 
-    public List getForeignKeys()
+    /**
+     * Removes the indicated foreign key.
+     * 
+     * @param idx The index of the foreign key to remove
+     */
+    public void removeForeignKey(int idx)
     {
-        return foreignKeys;
+        _foreignKeys.remove(idx);
     }
 
-    public Column getColumn(int index)
+    /**
+     * Returns the number of indices.
+     * 
+     * @return The number of indices
+     */
+    public int getIndexCount()
     {
-        return (Column) columns.get(index);
+        return _indices.size();
     }
 
-    public ForeignKey getForeignKey(int index)
+    /**
+     * Returns the index at the specified position.
+     * 
+     * @param idx The position
+     * @return The index
+     */
+    public Index getIndex(int idx)
     {
-        return (ForeignKey) foreignKeys.get(index);
+        return (Index)_indices.get(idx);
     }
 
+    /**
+     * Adds the given index.
+     * 
+     * @param index The index
+     */
     public void addIndex(Index index)
     {
-        indexes.add(index);
+        if (index != null)
+        {
+            _indices.add(index);
+        }
+    }
+
+    /**
+     * Adds the given index at the specified position.
+     * 
+     * @param idx   The position to add the index at
+     * @param index The index
+     */
+    public void addIndex(int idx, Index index)
+    {
+        if (index != null)
+        {
+            _indices.add(idx, index);
+        }
     }
 
-    public List getIndexes()
+    /**
+     * Returns the indices of this table.
+     * 
+     * @return The indices
+     */
+    public Index[] getIndices()
     {
-        return indexes;
+        return (Index[])_indices.toArray(new Index[_indices.size()]);
     }
 
-    public Index getIndex(int index)
+    /**
+     * Gets a list of non-unique indices on this table.
+     * 
+     * @return The unique indices
+     */
+    public Index[] getNonUniqueIndices()
     {
-        return (Index) indexes.get(index);
+        List nonUniqueIndices = PredicatedList.decorate(_indices, new Predicate() {
+            public boolean evaluate(Object input) {
+                return !((Index)input).isUnique();
+            }
+        });
+
+        return (Index[])nonUniqueIndices.toArray(new Index[nonUniqueIndices.size()]);
     }
 
-//take this out of Unique is annoying
-//this is in here to support <unique> in the xml
     /**
-     * Add a unique index to this table
-     * @param index The unique index
+     * Gets a list of unique indices on this table.
+     * 
+     * @return The unique indices
      */
-    public void addUnique(Unique index)
+    public Index[] getUniqueIndices()
     {
-        addIndex(index);
+        List uniqueIndices = PredicatedList.decorate(_indices, new Predicate() {
+            public boolean evaluate(Object input) {
+                return ((Index)input).isUnique();
+            }
+        });
+
+        return (Index[])uniqueIndices.toArray(new Index[uniqueIndices.size()]);
     }
 
     /**
-     * Gets a list of unique indexes on this table.
-     * @return an Iterator of Index objects where isUnique == true
+     * Removes the given index.
+     * 
+     * @param index The index to remove
      */
-    public Iterator getUniques()
+    public void removeIndex(Index index)
     {
-        return new FilterIterator( indexes.iterator(), UNIQUE_PREDICATE );
+        if (index != null)
+        {
+            _indices.remove(index);
+        }
     }
-//end unique
 
+    /**
+     * Removes the indicated index.
+     * 
+     * @param idx The position of the index to remove
+     */
+    public void removeIndex(int idx)
+    {
+        _indices.remove(idx);
+    }
 
     // Helper methods
     //-------------------------------------------------------------------------
@@ -237,10 +435,11 @@
      */
     public boolean hasPrimaryKey()
     {
-        for (Iterator iter = getColumns().iterator(); iter.hasNext(); )
+        for (Iterator it = _columns.iterator(); it.hasNext(); )
         {
-            Column column = (Column) iter.next();
-            if ( column.isPrimaryKey() )
+            Column column = (Column)it.next();
+
+            if (column.isPrimaryKey())
             {
                 return true;
             }
@@ -272,9 +471,9 @@
      */
     public Column findColumn(String name, boolean caseSensitive)
     {
-        for (Iterator iter = getColumns().iterator(); iter.hasNext(); )
+        for (Iterator it = _columns.iterator(); it.hasNext(); )
         {
-            Column column = (Column) iter.next();
+            Column column = (Column)it.next();
 
             if (caseSensitive)
             {
@@ -296,73 +495,127 @@
 
     /**
      * Finds the index with the specified name, using case insensitive matching.
-     * Note that this method is not called getIndex(String) to avoid introspection
+     * Note that this method is not called getIndex to avoid introspection
      * problems.
+     * 
+     * @param name The name of the index
+     * @return The index or <code>null</code> if there is no such index
      */
     public Index findIndex(String name)
     {
-        for (Iterator iter = getIndexes().iterator(); iter.hasNext(); )
+        return findIndex(name, false);
+    }
+
+    /**
+     * Finds the index with the specified name, using case insensitive matching.
+     * Note that this method is not called getIndex to avoid introspection
+     * problems.
+     * 
+     * @param name          The name of the index
+     * @param caseSensitive Whether case matters for the names
+     * @return The index or <code>null</code> if there is no such index
+     */
+    public Index findIndex(String name, boolean caseSensitive)
+    {
+        for (int idx = 0; idx < getIndexCount(); idx++)
         {
-            Index index = (Index) iter.next();
+            Index index = getIndex(idx);
 
-            // column names are typically case insensitive
-            if (index.getName().equalsIgnoreCase( name ))
+            if (caseSensitive)
             {
-                return index;
+                if (index.getName().equals(name))
+                {
+                    return index;
+                }
+            }
+            else
+            {
+                if (index.getName().equalsIgnoreCase(name))
+                {
+                    return index;
+                }
             }
         }
         return null;
     }
 
     /**
-     * Finds a ForeignKey within the table that matches the supplied ForeignKey
-     * exactly, meaning the foreign table and all column references are the same.
+     * Finds the foreign key in this table that is equal to the supplied foreign key.
+     * 
+     * @param key The foreign key to search for
+     * @return The found foreign key
      */
     public ForeignKey findForeignKey(ForeignKey key)
     {
-        ForeignKey result = null;
-        for (Iterator iter = getForeignKeys().iterator(); iter.hasNext(); )
+        for (int idx = 0; idx < getForeignKeyCount(); idx++)
         {
-            ForeignKey fk = (ForeignKey) iter.next();
-            if ( fk.equals(key) ) {
-                result = key;
-                break;
+            ForeignKey fk = getForeignKey(idx);
+
+            if (fk.equals(key))
+            {
+                return fk;
             }
         }
-        return result;
+        return null;
     }
 
     /**
-     * @return a List of primary key columns or an empty list if there are no
-     * primary key columns for this Table
+     * Returns the primary key columns of this table.
+     * 
+     * @return The primary key columns
      */
-    public List getPrimaryKeyColumns()
+    public Column[] getPrimaryKeyColumns()
     {
-        List answer = new ArrayList();
-        for (Iterator iter = getColumns().iterator(); iter.hasNext(); )
-        {
-            Column column = (Column) iter.next();
-            if ( column.isPrimaryKey() )
-            {
-                answer.add(column);
+        List pkColumns = PredicatedList.decorate(_columns, new Predicate() {
+            public boolean evaluate(Object input) {
+                return ((Column)input).isPrimaryKey();
             }
-        }
-        return answer;
+        });
+
+        return (Column[])pkColumns.toArray(new Column[pkColumns.size()]);
     }
 
     /**
-     * @return the auto increment column, if there is one, otherwise null is returned
+     * Returns the auto increment column in this table if there is one.
+     * 
+     * @return The column or <code>null</code> if there is none in this table
      */
     public Column getAutoIncrementColumn()
     {
-        for (Iterator iter = getColumns().iterator(); iter.hasNext(); )
+        for (int idx = 0; idx < getColumnCount(); idx++)
         {
-            Column column = (Column) iter.next();
-            if ( column.isAutoIncrement() )
+            Column column = getColumn(idx);
+
+            if (column.isAutoIncrement())
             {
                 return column;
             }
         }
         return null;
+    }
+
+    /* (non-Javadoc)
+     * @see java.lang.Object#clone()
+     */
+    public Object clone() throws CloneNotSupportedException
+    {
+        Table result = new Table();
+
+        result._catalog     = _catalog;
+        result._schema      = _schema;
+        result._name        = _name;
+        result._type        = _type;
+        result._columns     = (ArrayList)_columns.clone();
+        result._foreignKeys = (ArrayList)_foreignKeys.clone();
+        result._indices     = (ArrayList)_indices.clone();
+        return result;
+    }
+
+    /* (non-Javadoc)
+     * @see java.lang.Object#toString()
+     */
+    public String toString()
+    {
+        return "Table " + _name + " [" + _columns.size() + " columns]";
     }
 }

Copied: db/ddlutils/trunk/src/java/org/apache/ddlutils/model/UniqueIndex.java (from r226549, db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Unique.java)
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/model/UniqueIndex.java?p2=db/ddlutils/trunk/src/java/org/apache/ddlutils/model/UniqueIndex.java&p1=db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Unique.java&r1=226549&r2=240460&rev=240460&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Unique.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/model/UniqueIndex.java Sat Aug 27 14:44:57 2005
@@ -27,44 +27,73 @@
  * @author John Marshall/Connectria
  * @version $Revision$
  */
-public class Unique extends Index
+public class UniqueIndex implements Index
 {
-    public Unique() {
-        setUnique( true );
+    /** Unique ID for serialization purposes */
+    private static final long serialVersionUID = -4097003126550294993L;
+
+    /** The name of the index */
+    protected String    _name;
+    /** The columns making up the unique index */
+    protected ArrayList _columns = new ArrayList();
+
+    /* (non-Javadoc)
+     * @see org.apache.ddlutils.model.Index#isUnique()
+     */
+    public boolean isUnique()
+    {
+        return true;
     }
 
     /* (non-Javadoc)
-     * @see java.lang.Object#clone()
+     * @see org.apache.ddlutils.model.Index#getName()
      */
-    public Object clone() throws CloneNotSupportedException
+    public String getName()
     {
-        Unique result = new Unique();
+        return _name;
+    }
 
-        result.name         = name;
-        result.indexColumns = (ArrayList)indexColumns.clone();
-        result.unique       = unique;
-        return result;
+    /* (non-Javadoc)
+     * @see org.apache.ddlutils.model.Index#setName(java.lang.String)
+     */
+    public void setName(String name)
+    {
+        _name = name;
     }
 
-    public void setUnique(boolean unique) {
-        if ( unique == false ) {
-            throw new IllegalArgumentException( "Unique index cannot be made non-unique" );
-        }
-        super.setUnique(unique);
+    /* (non-Javadoc)
+     * @see org.apache.ddlutils.model.Index#addColumn(org.apache.ddlutils.model.IndexColumn)
+     */
+    public void addColumn(IndexColumn column)
+    {
+        _columns.add(column);
     }
 
-    public boolean isUnique() {
-        return true;
+    /* (non-Javadoc)
+     * @see org.apache.ddlutils.model.Index#getColumn(int)
+     */
+    public IndexColumn getColumn(int idx)
+    {
+        return (IndexColumn)_columns.get(idx);
     }
 
-    public void addUniqueColumn(UniqueColumn indexColumn)
+    /* (non-Javadoc)
+     * @see org.apache.ddlutils.model.Index#getColumns()
+     */
+    public List getColumns()
     {
-        super.addIndexColumn(indexColumn);
+        return _columns;
     }
-    
-    public List getUniqueColumns()
+
+    /* (non-Javadoc)
+     * @see java.lang.Object#clone()
+     */
+    public Object clone() throws CloneNotSupportedException
     {
-        return super.getIndexColumns();
+        UniqueIndex result = new UniqueIndex();
+
+        result._name    = _name;
+        result._columns = (ArrayList)_columns.clone();
+        return result;
     }
-    
 }

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/task/DdlToDatabaseTask.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/task/DdlToDatabaseTask.java?rev=240460&r1=240459&r2=240460&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/task/DdlToDatabaseTask.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/task/DdlToDatabaseTask.java Sat Aug 27 14:44:57 2005
@@ -16,12 +16,11 @@
  * limitations under the License.
  */
 
-import java.beans.IntrospectionException;
 import java.io.File;
 import java.util.ArrayList;
 import java.util.Iterator;
 
-import org.apache.ddlutils.io.DatabaseReader;
+import org.apache.ddlutils.io.DatabaseIO;
 import org.apache.ddlutils.model.Database;
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.DirectoryScanner;
@@ -125,17 +124,9 @@
      */
     private Database readSchemaFiles()
     {
-        DatabaseReader reader = null;
+        DatabaseIO reader = new DatabaseIO();
         Database       model  = null;
 
-        try
-        {
-            reader = new DatabaseReader();
-        }
-        catch (IntrospectionException ex)
-        {
-            throw new BuildException(ex);
-        }
         if ((_singleSchemaFile != null) && !_fileSets.isEmpty())
         {
             throw new BuildException("Please use either the schemafile attribute or the sub fileset element, but not both");
@@ -185,7 +176,7 @@
      * @param schemaFile The schema file
      * @return The model
      */
-    private Database readSingleSchemaFile(DatabaseReader reader, File schemaFile)
+    private Database readSingleSchemaFile(DatabaseIO reader, File schemaFile)
     {
         Database model = null;
 
@@ -201,7 +192,7 @@
         {
             try
             {
-                model = (Database)reader.parse(schemaFile);
+                model = reader.read(schemaFile);
                 log("Read schema file "+schemaFile.getAbsolutePath(), Project.MSG_INFO);
             }
             catch (Exception ex)

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteDataToFileCommand.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteDataToFileCommand.java?rev=240460&r1=240459&r2=240460&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteDataToFileCommand.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteDataToFileCommand.java Sat Aug 27 14:44:57 2005
@@ -18,7 +18,6 @@
 
 import java.io.File;
 import java.io.FileOutputStream;
-import java.util.Iterator;
 
 import org.apache.ddlutils.Platform;
 import org.apache.ddlutils.io.DataWriter;
@@ -70,9 +69,9 @@
             // TODO: An advanced algorithm could be employed here that writes objects
             //       related by foreign keys, in the correct order
             writer.writeDocumentStart();
-            for (Iterator tableIt = model.getTables().iterator(); tableIt.hasNext();)
+            for (int idx = 0; idx < model.getTableCount(); idx++)
             {
-                Table table = (Table)tableIt.next();
+                Table table = (Table)model.getTable(idx);
 
                 writer.write(platform.query(model, "select * from "+table.getName()));
             }

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteSchemaToFileCommand.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteSchemaToFileCommand.java?rev=240460&r1=240459&r2=240460&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteSchemaToFileCommand.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/task/WriteSchemaToFileCommand.java Sat Aug 27 14:44:57 2005
@@ -19,7 +19,7 @@
 import java.io.File;
 import java.io.FileWriter;
 
-import org.apache.ddlutils.io.DatabaseWriter;
+import org.apache.ddlutils.io.DatabaseIO;
 import org.apache.ddlutils.model.Database;
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.Project;
@@ -59,11 +59,10 @@
 
         try
         {
-            FileWriter     outputWriter = new FileWriter(_outputFile);
-            DatabaseWriter dbWriter     = new DatabaseWriter(outputWriter);
+            FileWriter outputWriter = new FileWriter(_outputFile);
+            DatabaseIO dbIO         = new DatabaseIO();
 
-            dbWriter.enablePrettyPrint();
-            dbWriter.write(model);
+            dbIO.write(model, outputWriter);
             outputWriter.close();
             task.log("Written schema to "+_outputFile.getAbsolutePath(), Project.MSG_INFO);
         }

Modified: db/ddlutils/trunk/src/test/org/apache/ddlutils/TestPlatformBase.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/test/org/apache/ddlutils/TestPlatformBase.java?rev=240460&r1=240459&r2=240460&view=diff
==============================================================================
--- db/ddlutils/trunk/src/test/org/apache/ddlutils/TestPlatformBase.java (original)
+++ db/ddlutils/trunk/src/test/org/apache/ddlutils/TestPlatformBase.java Sat Aug 27 14:44:57 2005
@@ -23,7 +23,7 @@
 
 import junit.framework.TestCase;
 
-import org.apache.ddlutils.io.DatabaseReader;
+import org.apache.ddlutils.io.DatabaseIO;
 import org.apache.ddlutils.model.Database;
 import org.xml.sax.SAXException;
 
@@ -138,11 +138,9 @@
      * @param dbDef The database XML definition
      * @return The database model
      */
-    protected Database parseDatabaseFromString(String dbDef) throws IntrospectionException, IOException, SAXException
+    protected Database parseDatabaseFromString(String dbDef)
     {
-        DatabaseReader reader = new DatabaseReader();
-
-        return (Database)reader.parse(new StringReader(dbDef));
+        return new DatabaseIO().read(new StringReader(dbDef));
     }
 
     /**

Modified: db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestDataReader.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestDataReader.java?rev=240460&r1=240459&r2=240460&view=diff
==============================================================================
--- db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestDataReader.java (original)
+++ db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestDataReader.java Sat Aug 27 14:44:57 2005
@@ -78,8 +78,8 @@
 
     public void testRead() throws Exception
     {
-        DatabaseReader  modelReader = new DatabaseReader();
-        Database        model       = (Database)modelReader.parse(new StringReader(TEST_SCHEMA));
+        DatabaseIO  modelReader = new DatabaseIO();
+        Database        model       = modelReader.read(new StringReader(TEST_SCHEMA));
         final ArrayList readObjects = new ArrayList();
         DataReader      dataReader  = new DataReader();
 

Added: db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestDatabaseIO.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestDatabaseIO.java?rev=240460&view=auto
==============================================================================
--- db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestDatabaseIO.java (added)
+++ db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestDatabaseIO.java Sat Aug 27 14:44:57 2005
@@ -0,0 +1,1211 @@
+package org.apache.ddlutils.io;
+
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.sql.Types;
+
+import junit.framework.TestCase;
+
+import org.apache.ddlutils.model.Column;
+import org.apache.ddlutils.model.Database;
+import org.apache.ddlutils.model.ForeignKey;
+import org.apache.ddlutils.model.Index;
+import org.apache.ddlutils.model.IndexColumn;
+import org.apache.ddlutils.model.ModelException;
+import org.apache.ddlutils.model.Reference;
+import org.apache.ddlutils.model.Table;
+
+/**
+ * Tests the database reading/writing via the {@link org.apache.ddlutils.io.DatabaseIO} class.
+ */
+public class TestDatabaseIO extends TestCase
+{
+    /**
+     * Reads the database model from the given string.
+     * 
+     * @param modelAsXml The database model XML
+     * @return The database model
+     */
+    private Database readModel(String modelAsXml)
+    {
+        return new DatabaseIO().read(new StringReader(modelAsXml));
+    }
+
+    /**
+     * Writes the given database model to a string.
+     * 
+     * @param model The database model
+     * @return The database model XML
+     */
+    private String writeModel(Database model)
+    {
+        StringWriter writer = new StringWriter();
+
+        new DatabaseIO().write(model, writer);
+        return writer.toString();
+    }
+
+    /**
+     * Tests a simple database model.
+     */
+    public void testSimple() throws Exception
+    {
+        Database model = readModel(
+            "<database name='test'>\n" +
+            "  <table name='SomeTable'\n" +
+            "         description='Some table'>\n" +
+            "    <column name='ID'\n" +
+            "            type='INTEGER'\n" +
+            "            primaryKey='true'\n" +
+            "            required='true'\n" +
+            "            description='The primary key'/>\n" +
+            "  </table>\n" +
+            "</database>");
+
+        assertEquals("test",
+                     model.getName());
+        assertEquals(1,
+                     model.getTableCount());
+        
+        Table table = model.getTable(0);
+
+        assertEquals("SomeTable",
+                     table.getName());
+        assertEquals("Some table",
+                     table.getDescription());
+        assertNull(table.getAutoIncrementColumn());
+        assertEquals(1,
+                     table.getColumnCount());
+        assertEquals(0,
+                     table.getForeignKeyCount());
+        assertEquals(0,
+                     table.getIndexCount());
+
+        Column column = table.getColumn(0);
+
+        assertEquals("ID",
+                     column.getName());
+        assertEquals("INTEGER",
+                     column.getType());
+        assertEquals(Types.INTEGER,
+                     column.getTypeCode());
+        assertTrue(column.isPrimaryKey());
+        assertTrue(column.isRequired());
+        assertFalse(column.isAutoIncrement());
+        assertNull(column.getDefaultValue());
+        assertEquals("The primary key",
+                     column.getDescription());
+
+        assertEquals(
+            "  <database name=\"test\">\n" +
+            "    <table name=\"SomeTable\" description=\"Some table\">\n" +
+            "      <column name=\"ID\" primaryKey=\"true\" required=\"true\" type=\"INTEGER\" autoIncrement=\"false\" description=\"The primary key\"/>\n" +
+            "    </table>\n" +
+            "  </database>\n",
+            writeModel(model));
+    }
+
+    /**
+     * Tests a database model containing a foreignkey.
+     */
+    public void testForeignkey() throws Exception
+    {
+        Database model = readModel(
+            "<database name='test'>\n" +
+            "  <table name='SomeTable'\n" +
+            "         description='Some table'>\n" +
+            "    <column name='ID'\n" +
+            "            type='VARCHAR'\n" +
+            "            size='16'\n" +
+            "            primaryKey='true'\n" +
+            "            required='true'\n" +
+            "            description='The primary key'/>\n" +
+            "  </table>\n" +
+            "  <table name='AnotherTable'\n" +
+            "         description='And another table'>\n" +
+            "    <column name='Some_ID'\n" +
+            "            type='VARCHAR'\n" +
+            "            size='16'\n" +
+            "            description='The foreign key'/>\n" +
+            "    <foreign-key foreignTable='SomeTable'>\n" +
+            "       <reference local='Some_ID' foreign='ID'/>\n" +
+            "    </foreign-key>\n" +
+            "  </table>\n" +
+            "</database>");
+
+        assertEquals("test",
+                     model.getName());
+        assertEquals(2,
+                     model.getTableCount());
+
+        Table someTable = model.getTable(0);
+
+        assertEquals("SomeTable",
+                     someTable.getName());
+        assertEquals("Some table",
+                     someTable.getDescription());
+        assertNull(someTable.getAutoIncrementColumn());
+        assertEquals(1,
+                     someTable.getColumnCount());
+        assertEquals(0,
+                     someTable.getForeignKeyCount());
+        assertEquals(0,
+                     someTable.getIndexCount());
+
+        Column pkColumn = someTable.getColumn(0);
+
+        assertEquals("ID",
+                     pkColumn.getName());
+        assertEquals("VARCHAR",
+                     pkColumn.getType());
+        assertEquals(Types.VARCHAR,
+                     pkColumn.getTypeCode());
+        assertEquals(16,
+                     pkColumn.getSizeAsInt());
+        assertTrue(pkColumn.isPrimaryKey());
+        assertTrue(pkColumn.isRequired());
+        assertFalse(pkColumn.isAutoIncrement());
+        assertNull(pkColumn.getDefaultValue());
+        assertEquals("The primary key",
+                     pkColumn.getDescription());
+
+        Table anotherTable = model.getTable(1);
+
+        assertEquals("AnotherTable",
+                     anotherTable.getName());
+        assertEquals("And another table",
+                     anotherTable.getDescription());
+        assertNull(anotherTable.getAutoIncrementColumn());
+        assertEquals(1,
+                     anotherTable.getColumnCount());
+        assertEquals(1,
+                     anotherTable.getForeignKeyCount());
+        assertEquals(0,
+                     anotherTable.getIndexCount());
+
+        Column fkColumn = anotherTable.getColumn(0);
+
+        assertEquals("Some_ID",
+                     fkColumn.getName());
+        assertEquals("VARCHAR",
+                     fkColumn.getType());
+        assertEquals(Types.VARCHAR,
+                     fkColumn.getTypeCode());
+        assertEquals(16,
+                     fkColumn.getSizeAsInt());
+        assertFalse(fkColumn.isPrimaryKey());
+        assertFalse(fkColumn.isRequired());
+        assertFalse(fkColumn.isAutoIncrement());
+        assertEquals("The foreign key",
+                     fkColumn.getDescription());
+
+        ForeignKey fk = anotherTable.getForeignKey(0);
+
+        assertNull(fk.getName());
+        assertEquals(someTable,
+                     fk.getForeignTable());
+        assertEquals(someTable.getName(),
+                     fk.getForeignTableName());
+        assertEquals(1,
+                     fk.getReferences().size());
+
+        Reference ref = fk.getFirstReference();
+
+        assertEquals(fkColumn,
+                     ref.getLocalColumn());
+        assertEquals("Some_ID",
+                     ref.getLocalColumnName());
+        assertEquals(pkColumn,
+                     ref.getForeignColumn());
+        assertEquals("ID",
+                     ref.getForeignColumnName());
+
+        assertEquals(
+            "  <database name=\"test\">\n" +
+            "    <table name=\"SomeTable\" description=\"Some table\">\n" +
+            "      <column name=\"ID\" primaryKey=\"true\" required=\"true\" type=\"VARCHAR\" size=\"16\" autoIncrement=\"false\" description=\"The primary key\"/>\n" +
+            "    </table>\n" +
+            "    <table name=\"AnotherTable\" description=\"And another table\">\n" +
+            "      <column name=\"Some_ID\" primaryKey=\"false\" required=\"false\" type=\"VARCHAR\" size=\"16\" autoIncrement=\"false\" description=\"The foreign key\"/>\n" +
+            "      <foreign-key foreignTable=\"SomeTable\">\n" +
+            "        <reference local=\"Some_ID\" foreign=\"ID\"/>\n" +
+            "      </foreign-key>\n" +
+            "    </table>\n" +
+            "  </database>\n",
+            writeModel(model));
+    }
+
+    /**
+     * Tests a database model with indices.
+     */
+    public void testIndices1() throws Exception
+    {
+        Database model = readModel(
+            "<database name='test'>\n" +
+            "  <table name='TableWidthIndex'>\n" +
+            "    <column name='id'\n" +
+            "            type='DOUBLE'\n" +
+            "            primaryKey='true'\n" +
+            "            required='true'/>\n" +
+            "    <column name='when'\n" +
+            "            type='TIMESTAMP'\n" +
+            "            required='true'/>\n" +
+            "    <column name='value'\n" +
+            "            type='SMALLINT'\n" +
+            "            default='1'/>\n" +
+            "    <index name='test index'>\n" +
+            "      <index-column name='value'/>\n" +
+            "    </index>\n" +
+            "    <index>\n" +
+            "      <index-column name='when'/>\n" +
+            "      <index-column name='id'/>\n" +
+            "    </index>\n" +
+            "  </table>\n" +
+            "</database>");
+
+        assertEquals("test",
+                     model.getName());
+        assertEquals(1,
+                     model.getTableCount());
+        
+        Table table = model.getTable(0);
+
+        assertEquals("TableWidthIndex",
+                     table.getName());
+        assertNull(table.getDescription());
+        assertNull(table.getAutoIncrementColumn());
+        assertEquals(3,
+                     table.getColumnCount());
+        assertEquals(0,
+                     table.getForeignKeyCount());
+        assertEquals(2,
+                     table.getIndexCount());
+
+        Column column = table.getColumn(0);
+
+        assertEquals("id",
+                     column.getName());
+        assertEquals("DOUBLE",
+                     column.getType());
+        assertEquals(Types.DOUBLE,
+                     column.getTypeCode());
+        assertTrue(column.isPrimaryKey());
+        assertTrue(column.isRequired());
+        assertFalse(column.isAutoIncrement());
+        assertNull(column.getDefaultValue());
+        assertNull(column.getDefaultValue());
+        assertNull(column.getDescription());
+
+        column = table.getColumn(1);
+
+        assertEquals("when",
+                     column.getName());
+        assertEquals("TIMESTAMP",
+                     column.getType());
+        assertEquals(Types.TIMESTAMP,
+                     column.getTypeCode());
+        assertFalse(column.isPrimaryKey());
+        assertTrue(column.isRequired());
+        assertFalse(column.isAutoIncrement());
+        assertNull(column.getDefaultValue());
+        assertNull(column.getDescription());
+
+        column = table.getColumn(2);
+
+        assertEquals("value",
+                     column.getName());
+        assertEquals("SMALLINT",
+                     column.getType());
+        assertEquals(Types.SMALLINT,
+                     column.getTypeCode());
+        assertFalse(column.isPrimaryKey());
+        assertFalse(column.isRequired());
+        assertFalse(column.isAutoIncrement());
+        assertEquals("1",
+                     column.getDefaultValue());
+        assertNull(column.getDescription());
+
+        Index index = table.getIndex(0);
+
+        assertEquals("test index",
+                     index.getName());
+        assertFalse(index.isUnique());
+        assertEquals(1,
+                     index.getColumns().size());
+
+        IndexColumn indexColumn = index.getColumn(0);
+
+        assertEquals("value",
+                     indexColumn.getName());
+        assertNull(indexColumn.getSize());
+
+        index = table.getIndex(1);
+
+        assertNull(index.getName());
+        assertFalse(index.isUnique());
+        assertEquals(2,
+                     index.getColumns().size());
+
+        indexColumn = index.getColumn(0);
+
+        assertEquals("when",
+                     indexColumn.getName());
+        assertNull(indexColumn.getSize());
+
+        indexColumn = index.getColumn(1);
+
+        assertEquals("id",
+                     indexColumn.getName());
+        assertNull(indexColumn.getSize());
+
+        assertEquals(
+            "  <database name=\"test\">\n" +
+            "    <table name=\"TableWidthIndex\">\n" +
+            "      <column name=\"id\" primaryKey=\"true\" required=\"true\" type=\"DOUBLE\" autoIncrement=\"false\"/>\n" +
+            "      <column name=\"when\" primaryKey=\"false\" required=\"true\" type=\"TIMESTAMP\" autoIncrement=\"false\"/>\n" +
+            "      <column name=\"value\" primaryKey=\"false\" required=\"false\" type=\"SMALLINT\" default=\"1\" autoIncrement=\"false\"/>\n" +
+            "      <index name=\"test index\">\n" +
+            "        <index-column name=\"value\"/>\n" +
+            "      </index>\n" +
+            "      <index>\n" +
+            "        <index-column name=\"when\"/>\n" +
+            "        <index-column name=\"id\"/>\n" +
+            "      </index>\n" +
+            "    </table>\n" +
+            "  </database>\n",
+            writeModel(model));
+    }
+
+    /**
+     * Tests a database model with indices, both uniques and non-uniques.
+     */
+    public void testIndices2() throws Exception
+    {
+        Database model = readModel(
+            "<database name='test'>\n" +
+            "  <table name='TableWidthIndices'>\n" +
+            "    <column name='id'\n" +
+            "            type='SMALLINT'\n" +
+            "            primaryKey='false'\n" +
+            "            required='true'\n" +
+            "            autoIncrement='true'/>\n" +
+            "    <column name='when'\n" +
+            "            type='DATE'/>\n" +
+            "    <unique name='important column'>\n" +
+            "      <unique-column name='id'/>\n" +
+            "    </unique>\n" +
+            "    <index>\n" +
+            "      <index-column name='when'/>\n" +
+            "    </index>\n" +
+            "  </table>\n" +
+            "</database>");
+
+        assertEquals("test",
+                     model.getName());
+        assertEquals(1,
+                     model.getTableCount());
+        
+        Table table = model.getTable(0);
+
+        assertEquals("TableWidthIndices",
+                     table.getName());
+        assertNull(table.getDescription());
+        assertEquals(2,
+                     table.getColumnCount());
+        assertEquals(0,
+                     table.getForeignKeyCount());
+        assertEquals(2,
+                     table.getIndexCount());
+
+        Column column = table.getColumn(0);
+
+        assertEquals("id",
+                     column.getName());
+        assertEquals("SMALLINT",
+                     column.getType());
+        assertEquals(Types.SMALLINT,
+                     column.getTypeCode());
+        assertFalse(column.isPrimaryKey());
+        assertTrue(column.isRequired());
+        assertTrue(column.isAutoIncrement());
+        assertNull(column.getDefaultValue());
+        assertNull(column.getDefaultValue());
+        assertNull(column.getDescription());
+
+        assertEquals(column,
+                     table.getAutoIncrementColumn());
+
+        column = table.getColumn(1);
+
+        assertEquals("when",
+                     column.getName());
+        assertEquals("DATE",
+                     column.getType());
+        assertEquals(Types.DATE,
+                     column.getTypeCode());
+        assertFalse(column.isPrimaryKey());
+        assertFalse(column.isRequired());
+        assertFalse(column.isAutoIncrement());
+        assertNull(column.getDefaultValue());
+        assertNull(column.getDescription());
+
+        Index index = table.getIndex(0);
+
+        assertEquals("important column",
+                     index.getName());
+        assertTrue(index.isUnique());
+        assertEquals(1,
+                     index.getColumns().size());
+
+        IndexColumn indexColumn = index.getColumn(0);
+
+        assertEquals("id",
+                     indexColumn.getName());
+        assertNull(indexColumn.getSize());
+
+        index = table.getIndex(1);
+
+        assertNull(index.getName());
+        assertFalse(index.isUnique());
+        assertEquals(1,
+                     index.getColumns().size());
+
+        indexColumn = index.getColumn(0);
+
+        assertEquals("when",
+                     indexColumn.getName());
+        assertNull(indexColumn.getSize());
+
+        assertEquals(
+            "  <database name=\"test\">\n" +
+            "    <table name=\"TableWidthIndices\">\n" +
+            "      <column name=\"id\" primaryKey=\"false\" required=\"true\" type=\"SMALLINT\" autoIncrement=\"true\"/>\n" +
+            "      <column name=\"when\" primaryKey=\"false\" required=\"false\" type=\"DATE\" autoIncrement=\"false\"/>\n" +
+            "      <unique name=\"important column\">\n" +
+            "        <unique-column name=\"id\"/>\n" +
+            "      </unique>\n" +
+            "      <index>\n" +
+            "        <index-column name=\"when\"/>\n" +
+            "      </index>\n" +
+            "    </table>\n" +
+            "  </database>\n",
+            writeModel(model));
+    }
+
+    /**
+     * Tests a complex database model with multiple tables, foreign keys, indices and uniques.
+     */
+    public void testComplex() throws Exception
+    {
+        // A = id:INTEGER, parentId:INTEGER, name:VARCHAR(32); fk 'parent' -> A (parentId -> id), unique(name)
+        // B = id:TIMESTAMP, aid:INTEGER, cid:CHAR(32) fk -> A (aid -> id), fk -> C (cid -> id), index(aid,cid)
+        // C = id:CHAR(32), text:LONGVARCHAR; index 'byText' (text)
+        
+        Database model = readModel(
+            "<database name='test'>\n" +
+            "  <table name='A'\n" +
+            "         description='Table A'>\n" +
+            "    <column name='id'\n" +
+            "            type='INTEGER'\n" +
+            "            autoIncrement='true'\n" +
+            "            primaryKey='true'\n" +
+            "            required='true'\n" +
+            "            description='The primary key of table A'/>\n" +
+            "    <column name='parentId'\n" +
+            "            type='INTEGER'\n" +
+            "            description='The field for the foreign key parent'/>\n" +
+            "    <column name='name'\n" +
+            "            type='VARCHAR'\n" +
+            "            size='32'\n" +
+            "            required='true'\n" +
+            "            description='The name'/>\n" +
+            "    <foreign-key name='parent' foreignTable='A'>\n" +
+            "       <reference local='parentId' foreign='id'/>\n" +
+            "    </foreign-key>\n" +
+            "    <unique>\n" +
+            "      <unique-column name='name'/>\n" +
+            "    </unique>\n" +
+            "  </table>\n" +
+            "  <table name='B'\n" +
+            "         description='Table B'>\n" +
+            "    <column name='id'\n" +
+            "            type='TIMESTAMP'\n" +
+            "            primaryKey='true'\n" +
+            "            required='true'\n" +
+            "            description='The primary key of table B'/>\n" +
+            "    <column name='aid'\n" +
+            "            type='INTEGER'\n" +
+            "            description='The field for the foreign key towards A'/>\n" +
+            "    <column name='cid'\n" +
+            "            type='CHAR'\n" +
+            "            size='32'\n" +
+            "            description='The field for the foreign key towards C'/>\n" +
+            "    <foreign-key foreignTable='A'>\n" +
+            "       <reference local='aid' foreign='id'/>\n" +
+            "    </foreign-key>\n" +
+            "    <foreign-key foreignTable='C'>\n" +
+            "       <reference local='cid' foreign='id'/>\n" +
+            "    </foreign-key>\n" +
+            "    <index>\n" +
+            "      <index-column name='aid'/>\n" +
+            "      <index-column name='cid'/>\n" +
+            "    </index>\n" +
+            "  </table>\n" +
+            "  <table name='C'\n" +
+            "         description='Table C'>\n" +
+            "    <column name='id'\n" +
+            "            type='CHAR'\n" +
+            "            size='32'\n" +
+            "            primaryKey='true'\n" +
+            "            required='true'\n" +
+            "            description='The primary key of table C'/>\n" +
+            "    <column name='text'\n" +
+            "            type='LONGVARCHAR'\n" +
+            "            description='The text'/>\n" +
+            "    <index name='byText'>\n" +
+            "      <index-column name='text'/>\n" +
+            "    </index>\n" +
+            "  </table>\n" +
+            "</database>");
+
+        assertEquals("test",
+                     model.getName());
+        assertEquals(3,
+                     model.getTableCount());
+
+        // table A
+
+        Table table = model.getTable(0);
+
+        assertEquals("A",
+                     table.getName());
+        assertEquals("Table A",
+                     table.getDescription());
+        assertEquals(3,
+                     table.getColumnCount());
+        assertEquals(1,
+                     table.getForeignKeyCount());
+        assertEquals(1,
+                     table.getIndexCount());
+
+        Column column = table.getColumn(0);
+
+        assertEquals("id",
+                     column.getName());
+        assertEquals("INTEGER",
+                     column.getType());
+        assertEquals(Types.INTEGER,
+                     column.getTypeCode());
+        assertNull(column.getSize());
+        assertEquals(0,
+                     column.getSizeAsInt());
+        assertTrue(column.isPrimaryKey());
+        assertTrue(column.isRequired());
+        assertTrue(column.isAutoIncrement());
+        assertNull(column.getDefaultValue());
+        assertEquals("The primary key of table A",
+                     column.getDescription());
+        assertEquals(column,
+                     table.getAutoIncrementColumn());
+
+        column = table.getColumn(1);
+
+        assertEquals("parentId",
+                     column.getName());
+        assertEquals("INTEGER",
+                     column.getType());
+        assertEquals(Types.INTEGER,
+                     column.getTypeCode());
+        assertNull(column.getSize());
+        assertEquals(0,
+                     column.getSizeAsInt());
+        assertFalse(column.isPrimaryKey());
+        assertFalse(column.isRequired());
+        assertFalse(column.isAutoIncrement());
+        assertNull(column.getDefaultValue());
+        assertEquals("The field for the foreign key parent",
+                     column.getDescription());
+
+        column = table.getColumn(2);
+
+        assertEquals("name",
+                     column.getName());
+        assertEquals("VARCHAR",
+                     column.getType());
+        assertEquals(Types.VARCHAR,
+                     column.getTypeCode());
+        assertEquals("32",
+                     column.getSize());
+        assertEquals(32,
+                     column.getSizeAsInt());
+        assertFalse(column.isPrimaryKey());
+        assertTrue(column.isRequired());
+        assertFalse(column.isAutoIncrement());
+        assertNull(column.getDefaultValue());
+        assertEquals("The name",
+                     column.getDescription());
+
+        ForeignKey fk = table.getForeignKey(0);
+
+        assertEquals("parent",
+                     fk.getName());
+        assertEquals(table,
+                     fk.getForeignTable());
+        assertEquals("A",
+                     fk.getForeignTableName());
+        assertEquals(1,
+                     fk.getReferences().size());
+
+        Reference ref = fk.getFirstReference();
+
+        assertEquals(table.getColumn(1),
+                     ref.getLocalColumn());
+        assertEquals("parentId",
+                     ref.getLocalColumnName());
+        assertEquals(table.getColumn(0),
+                     ref.getForeignColumn());
+        assertEquals("id",
+                     ref.getForeignColumnName());
+
+        Index index = table.getIndex(0);
+
+        assertNull(index.getName());
+        assertTrue(index.isUnique());
+        assertEquals(1,
+                     index.getColumns().size());
+
+        IndexColumn indexColumn = index.getColumn(0);
+
+        assertEquals("name",
+                     indexColumn.getName());
+        assertNull(indexColumn.getSize());
+
+        // table B
+        
+        table = model.getTable(1);
+
+        assertEquals("B",
+                     table.getName());
+        assertEquals("Table B",
+                     table.getDescription());
+        assertNull(table.getAutoIncrementColumn());
+        assertEquals(3,
+                     table.getColumnCount());
+        assertEquals(2,
+                     table.getForeignKeyCount());
+        assertEquals(1,
+                     table.getIndexCount());
+
+        column = table.getColumn(0);
+
+        assertEquals("id",
+                     column.getName());
+        assertEquals("TIMESTAMP",
+                     column.getType());
+        assertEquals(Types.TIMESTAMP,
+                     column.getTypeCode());
+        assertNull(column.getSize());
+        assertEquals(0,
+                     column.getSizeAsInt());
+        assertTrue(column.isPrimaryKey());
+        assertTrue(column.isRequired());
+        assertFalse(column.isAutoIncrement());
+        assertNull(column.getDefaultValue());
+        assertEquals("The primary key of table B",
+                     column.getDescription());
+
+        column = table.getColumn(1);
+
+        assertEquals("aid",
+                     column.getName());
+        assertEquals("INTEGER",
+                     column.getType());
+        assertEquals(Types.INTEGER,
+                     column.getTypeCode());
+        assertNull(column.getSize());
+        assertEquals(0,
+                     column.getSizeAsInt());
+        assertFalse(column.isPrimaryKey());
+        assertFalse(column.isRequired());
+        assertFalse(column.isAutoIncrement());
+        assertNull(column.getDefaultValue());
+        assertEquals("The field for the foreign key towards A",
+                     column.getDescription());
+
+        column = table.getColumn(2);
+
+        assertEquals("cid",
+                     column.getName());
+        assertEquals("CHAR",
+                     column.getType());
+        assertEquals(Types.CHAR,
+                     column.getTypeCode());
+        assertEquals("32",
+                     column.getSize());
+        assertEquals(32,
+                     column.getSizeAsInt());
+        assertFalse(column.isPrimaryKey());
+        assertFalse(column.isRequired());
+        assertFalse(column.isAutoIncrement());
+        assertNull(column.getDefaultValue());
+        assertEquals("The field for the foreign key towards C",
+                     column.getDescription());
+
+        fk = table.getForeignKey(0);
+
+        assertNull(fk.getName());
+        assertEquals(model.getTable(0),
+                     fk.getForeignTable());
+        assertEquals("A",
+                     fk.getForeignTableName());
+        assertEquals(1,
+                     fk.getReferences().size());
+
+        ref = fk.getFirstReference();
+
+        assertEquals(table.getColumn(1),
+                     ref.getLocalColumn());
+        assertEquals("aid",
+                     ref.getLocalColumnName());
+        assertEquals(model.getTable(0).getColumn(0),
+                     ref.getForeignColumn());
+        assertEquals("id",
+                     ref.getForeignColumnName());
+
+        fk = table.getForeignKey(1);
+
+        assertNull(fk.getName());
+        assertEquals(model.getTable(2),
+                     fk.getForeignTable());
+        assertEquals("C",
+                     fk.getForeignTableName());
+        assertEquals(1,
+                     fk.getReferences().size());
+
+        ref = fk.getFirstReference();
+
+        assertEquals(table.getColumn(2),
+                     ref.getLocalColumn());
+        assertEquals("cid",
+                     ref.getLocalColumnName());
+        assertEquals(model.getTable(2).getColumn(0),
+                     ref.getForeignColumn());
+        assertEquals("id",
+                     ref.getForeignColumnName());
+
+        index = table.getIndex(0);
+
+        assertNull(index.getName());
+        assertFalse(index.isUnique());
+        assertEquals(2,
+                     index.getColumns().size());
+
+        indexColumn = index.getColumn(0);
+
+        assertEquals("aid",
+                     indexColumn.getName());
+        assertNull(indexColumn.getSize());
+
+        indexColumn = index.getColumn(1);
+
+        assertEquals("cid",
+                     indexColumn.getName());
+        assertNull(indexColumn.getSize());
+
+        // table C
+
+        table = model.getTable(2);
+
+        assertEquals("C",
+                     table.getName());
+        assertEquals("Table C",
+                     table.getDescription());
+        assertNull(table.getAutoIncrementColumn());
+        assertEquals(2,
+                     table.getColumnCount());
+        assertEquals(0,
+                     table.getForeignKeyCount());
+        assertEquals(1,
+                     table.getIndexCount());
+
+        column = table.getColumn(0);
+
+        assertEquals("id",
+                     column.getName());
+        assertEquals("CHAR",
+                     column.getType());
+        assertEquals(Types.CHAR,
+                     column.getTypeCode());
+        assertEquals("32",
+                     column.getSize());
+        assertEquals(32,
+                     column.getSizeAsInt());
+        assertTrue(column.isPrimaryKey());
+        assertTrue(column.isRequired());
+        assertFalse(column.isAutoIncrement());
+        assertNull(column.getDefaultValue());
+        assertEquals("The primary key of table C",
+                     column.getDescription());
+
+        column = table.getColumn(1);
+
+        assertEquals("text",
+                     column.getName());
+        assertEquals("LONGVARCHAR",
+                     column.getType());
+        assertEquals(Types.LONGVARCHAR,
+                     column.getTypeCode());
+        assertNull(column.getSize());
+        assertEquals(0,
+                     column.getSizeAsInt());
+        assertFalse(column.isPrimaryKey());
+        assertFalse(column.isRequired());
+        assertFalse(column.isAutoIncrement());
+        assertNull(column.getDefaultValue());
+        assertEquals("The text",
+                     column.getDescription());
+
+        index = table.getIndex(0);
+
+        assertEquals("byText",
+                     index.getName());
+        assertFalse(index.isUnique());
+        assertEquals(1,
+                     index.getColumns().size());
+
+        indexColumn = index.getColumn(0);
+
+        assertEquals("text",
+                     indexColumn.getName());
+        assertNull(indexColumn.getSize());
+
+        assertEquals(
+            "  <database name=\"test\">\n" +
+            "    <table name=\"A\" description=\"Table A\">\n" +
+            "      <column name=\"id\" primaryKey=\"true\" required=\"true\" type=\"INTEGER\" autoIncrement=\"true\" description=\"The primary key of table A\"/>\n" +
+            "      <column name=\"parentId\" primaryKey=\"false\" required=\"false\" type=\"INTEGER\" autoIncrement=\"false\" description=\"The field for the foreign key parent\"/>\n" +
+            "      <column name=\"name\" primaryKey=\"false\" required=\"true\" type=\"VARCHAR\" size=\"32\" autoIncrement=\"false\" description=\"The name\"/>\n" +
+            "      <foreign-key foreignTable=\"A\" name=\"parent\">\n" +
+            "        <reference local=\"parentId\" foreign=\"id\"/>\n" +
+            "      </foreign-key>\n" +
+            "      <unique>\n" +
+            "        <unique-column name=\"name\"/>\n" +
+            "      </unique>\n" +
+            "    </table>\n" +
+            "    <table name=\"B\" description=\"Table B\">\n" +
+            "      <column name=\"id\" primaryKey=\"true\" required=\"true\" type=\"TIMESTAMP\" autoIncrement=\"false\" description=\"The primary key of table B\"/>\n" +
+            "      <column name=\"aid\" primaryKey=\"false\" required=\"false\" type=\"INTEGER\" autoIncrement=\"false\" description=\"The field for the foreign key towards A\"/>\n" +
+            "      <column name=\"cid\" primaryKey=\"false\" required=\"false\" type=\"CHAR\" size=\"32\" autoIncrement=\"false\" description=\"The field for the foreign key towards C\"/>\n" +
+            "      <foreign-key foreignTable=\"A\">\n" +
+            "        <reference local=\"aid\" foreign=\"id\"/>\n" +
+            "      </foreign-key>\n" +
+            "      <foreign-key foreignTable=\"C\">\n" +
+            "        <reference local=\"cid\" foreign=\"id\"/>\n" +
+            "      </foreign-key>\n" +
+            "      <index>\n" +
+            "        <index-column name=\"aid\"/>\n" +
+            "        <index-column name=\"cid\"/>\n" +
+            "      </index>\n" +
+            "    </table>\n" +
+            "    <table name=\"C\" description=\"Table C\">\n" +
+            "      <column name=\"id\" primaryKey=\"true\" required=\"true\" type=\"CHAR\" size=\"32\" autoIncrement=\"false\" description=\"The primary key of table C\"/>\n" +
+            "      <column name=\"text\" primaryKey=\"false\" required=\"false\" type=\"LONGVARCHAR\" autoIncrement=\"false\" description=\"The text\"/>\n" +
+            "      <index name=\"byText\">\n" +
+            "        <index-column name=\"text\"/>\n" +
+            "      </index>\n" +
+            "    </table>\n" +
+            "  </database>\n",
+            writeModel(model));
+    }
+
+    public void testUndefinedIndexColumn()
+    {
+        try
+        {
+            readModel(
+                "<database name='test'>\n" +
+                "  <table name='TableWidthIndex'>\n" +
+                "    <column name='id'\n" +
+                "            type='INTEGER'\n" +
+                "            primaryKey='true'\n" +
+                "            required='true'/>\n" +
+                "    <index name='test index'>\n" +
+                "      <index-column name='id'/>\n" +
+                "      <index-column name='value'/>\n" +
+                "    </index>\n" +
+                "  </table>\n" +
+                "</database>");
+
+            fail();
+        }
+        catch (ModelException ex)
+        {}
+    }
+
+    public void testDatabaseWithoutName()
+    {
+        try
+        {
+            readModel(
+                "<database>\n" +
+                "  <table name='TestTable'>\n" +
+                "    <column name='id'\n" +
+                "            type='INTEGER'\n" +
+                "            primaryKey='true'\n" +
+                "            required='true'/>\n" +
+                "  </table>\n" +
+                "</database>");
+
+            fail();
+        }
+        catch (ModelException ex)
+        {}
+    }
+
+    public void testTableWithoutName()
+    {
+        try
+        {
+            readModel(
+                "<database name='test'>\n" +
+                "  <table>\n" +
+                "    <column name='id'\n" +
+                "            type='INTEGER'\n" +
+                "            primaryKey='true'\n" +
+                "            required='true'/>\n" +
+                "  </table>\n" +
+                "</database>");
+
+            fail();
+        }
+        catch (ModelException ex)
+        {}
+    }
+
+    public void testTwoTablesWithTheSameName()
+    {
+        try
+        {
+            readModel(
+                "<database name='test'>\n" +
+                "  <table name='TestTable'>\n" +
+                "    <column name='id1'\n" +
+                "            type='INTEGER'\n" +
+                "            primaryKey='true'\n" +
+                "            required='true'/>\n" +
+                "  </table>\n" +
+                "  <table name='TestTable'>\n" +
+                "    <column name='id2'\n" +
+                "            type='INTEGER'\n" +
+                "            primaryKey='true'\n" +
+                "            required='true'/>\n" +
+                "  </table>\n" +
+                "</database>");
+
+            fail();
+        }
+        catch (ModelException ex)
+        {}
+    }
+
+    public void testColumnWithoutName()
+    {
+        try
+        {
+            readModel(
+                "<database name='test'>\n" +
+                "  <table name='TestTable'>\n" +
+                "    <column type='INTEGER'\n" +
+                "            primaryKey='true'\n" +
+                "            required='true'/>\n" +
+                "  </table>\n" +
+                "</database>");
+
+            fail();
+        }
+        catch (ModelException ex)
+        {}
+    }
+
+    public void testTwoColumnsWithTheSameName()
+    {
+        try
+        {
+            readModel(
+                "<database name='test'>\n" +
+                "  <table name='TestTable'>\n" +
+                "    <column name='id'\n" +
+                "            type='INTEGER'\n" +
+                "            primaryKey='true'\n" +
+                "            required='true'/>\n" +
+                "    <column name='id'\n" +
+                "            type='VARCHAR'/>\n" +
+                "  </table>\n" +
+                "</database>");
+
+            fail();
+        }
+        catch (ModelException ex)
+        {}
+    }
+
+    public void testColumnWithoutType()
+    {
+        try
+        {
+            readModel(
+                "<database name='test'>\n" +
+                "  <table name='TestTable'>\n" +
+                "    <column name='id'\n" +
+                "            primaryKey='true'\n" +
+                "            required='true'/>\n" +
+                "  </table>\n" +
+                "</database>");
+
+            fail();
+        }
+        catch (ModelException ex)
+        {}
+    }
+
+    public void testUndefinedUniqueColumn()
+    {
+        try
+        {
+            readModel(
+                "<database name='test'>\n" +
+                "  <table name='TableWidthUnique'>\n" +
+                "    <column name='id'\n" +
+                "            type='INTEGER'\n" +
+                "            primaryKey='true'\n" +
+                "            required='true'/>\n" +
+                "    <unique>\n" +
+                "      <unique-column name='value'/>\n" +
+                "    </unique>\n" +
+                "  </table>\n" +
+                "</database>");
+
+            fail();
+        }
+        catch (ModelException ex)
+        {}
+    }
+
+    public void testTwoIndicesWithTheSameName()
+    {
+        try
+        {
+            readModel(
+                "<database name='test'>\n" +
+                "  <table name='TableWidthIndex'>\n" +
+                "    <column name='id'\n" +
+                "            type='INTEGER'\n" +
+                "            primaryKey='true'\n" +
+                "            required='true'/>\n" +
+                "    <column name='value1'\n" +
+                "            type='INTEGER'\n" +
+                "            required='true'/>\n" +
+                "    <column name='value2'\n" +
+                "            type='INTEGER'\n" +
+                "            required='true'/>\n" +
+                "    <index name='the index'>\n" +
+                "      <index-column name='value1'/>\n" +
+                "    </index>\n" +
+                "    <index name='the index'>\n" +
+                "      <index-column name='value2'/>\n" +
+                "    </index>\n" +
+                "  </table>\n" +
+                "</database>");
+
+            fail();
+        }
+        catch (ModelException ex)
+        {}
+    }
+
+    public void testTwoUniqueIndicesWithTheSameName()
+    {
+        try
+        {
+            readModel(
+                "<database name='test'>\n" +
+                "  <table name='TableWidthUnique'>\n" +
+                "    <column name='id'\n" +
+                "            type='INTEGER'\n" +
+                "            primaryKey='true'\n" +
+                "            required='true'/>\n" +
+                "    <column name='value1'\n" +
+                "            type='INTEGER'\n" +
+                "            required='true'/>\n" +
+                "    <column name='value2'\n" +
+                "            type='INTEGER'\n" +
+                "            required='true'/>\n" +
+                "    <unique name='the unique'>\n" +
+                "      <unique-column name='value1'/>\n" +
+                "    </unique>\n" +
+                "    <unique name='the unique'>\n" +
+                "      <unique-column name='value2'/>\n" +
+                "    </unique>\n" +
+                "  </table>\n" +
+                "</database>");
+
+            fail();
+        }
+        catch (ModelException ex)
+        {}
+    }
+
+    public void testUniqueAndNormalIndexWithTheSameName()
+    {
+        try
+        {
+            readModel(
+                "<database name='test'>\n" +
+                "  <table name='TableWidthUnique'>\n" +
+                "    <column name='id'\n" +
+                "            type='INTEGER'\n" +
+                "            primaryKey='true'\n" +
+                "            required='true'/>\n" +
+                "    <column name='value1'\n" +
+                "            type='INTEGER'\n" +
+                "            required='true'/>\n" +
+                "    <column name='value2'\n" +
+                "            type='INTEGER'\n" +
+                "            required='true'/>\n" +
+                "    <index name='test'>\n" +
+                "      <index-column name='value1'/>\n" +
+                "    </index>\n" +
+                "    <unique name='test'>\n" +
+                "      <unique-column name='value2'/>\n" +
+                "    </unique>\n" +
+                "  </table>\n" +
+                "</database>");
+
+            fail();
+        }
+        catch (ModelException ex)
+        {}
+    }
+
+    // TODO: Tests that include:
+    // * foreign key references undefined table
+    // * foreign key references undefined local column
+    // * foreign key references undefined foreign column
+    // * two foreign keys with the same name
+}



Mime
View raw message