{
String errorMessage = "Table '" + currTable.getName()
+ "' is marked as autoincrement, but it does not "
+ "have a column which declared as the one to "
+ "auto increment (i.e. autoIncrement=\"true\")\n";
throw new EngineException("Error in XML schema: " + errorMessage);
}
}
currTable.doFinalInitialization();
// setup reverse fk relations
Iterator fks = currTable.getForeignKeys().iterator();
while (fks.hasNext())
{
ForeignKey currFK = (ForeignKey) fks.next();
Table foreignTable = getTable(currFK.getForeignTableName());
if (foreignTable == null)
{
throw new EngineException("Attempt to set foreign"
+ " key to nonexistent table, "
+ currFK.getForeignTableName());
}
else
{
// TODO check type and size
List referrers = foreignTable.getReferrers();
if ((referrers == null || !referrers.contains(currFK)))
{
foreignTable.addReferrer(currFK);
}
// local column references
Iterator localColumnNames = currFK.getLocalColumns().iterator();
while (localColumnNames.hasNext())
{
Column local = currTable
.getColumn((String) localColumnNames.next());
// give notice of a schema inconsistency.
// note we do not prevent the npe as there is nothing
// that we can do, if it is to occur.
if (local == null)
{
throw new EngineException("Attempt to define foreign"
+ " key with nonexistent column in table, "
+ currTable.getName());
}
else
{
//check for foreign pk's
if (local.isPrimaryKey())
{
currTable.setContainsForeignPK(true);
}
}
}
// foreign column references
Iterator foreignColumnNames
= currFK.getForeignColumns().iterator();
while (foreignColumnNames.hasNext())
{
String foreignColumnName = (String) foreignColumnNames.next();
Column foreign = foreignTable.getColumn(foreignColumnName);
// if the foreign column does not exist, we may have an
// external reference or a misspelling
if (foreign == null)
{
throw new EngineException("Attempt to set foreign"
+ " key to nonexistent column: table="
+ currTable.getName() + ", foreign column="
+ foreignColumnName);
}
else