/**
* @see nexj.core.meta.persistence.sql.upgrade.RelationalSchemaUpgradeStep#apply(nexj.core.meta.persistence.sql.upgrade.RelationalSchemaUpgradeState)
*/
public void apply(RelationalSchemaUpgradeState state)
{
final RelationalSchema schema = state.getSchema();
m_table = new Table(schema);
m_table.setType(m_nType);
m_table.setName(m_sName);
m_table.setQuotedName(m_sAlias);
m_table.setTablespaceName(m_sTablespaceName);
m_table.setIndexspaceName(m_sIndexspaceName);
m_table.setLongspaceName(m_sLongspaceName);
schema.addTable(m_table);
for (Lookup.Iterator itr = m_columnMap.valueIterator(); itr.hasNext();)
{
ColumnOutline outline = (ColumnOutline)itr.next();
Column column = new Column(outline.getName(), m_table);
outline.copyTo(column);
m_table.addColumn(column);
}
m_table.setViewScript(m_viewScript);
m_table.setViewAutoUpdated(m_bViewAutoUpdated);
addAspects(schema, m_table);
RelationalSchemaAspectManager aspectManager = new RelationalSchemaAspectManager(schema)
{
protected Iterator getTableAspectIterator()
{
return schema.getTableIterator();
}
protected Iterator getTablePointcutIterator()
{
return Collections.singletonList(m_table).iterator();
}
protected Iterator getIndexAspectIterator()
{
return schema.getIndexIterator();
}
protected Iterator getIndexPointcutIterator()
{
return m_table.getIndexIterator();
}
};
aspectManager.applyAspects(0);
for (Lookup.Iterator itr = m_indexMap.valueIterator(); itr.hasNext();)
{
IndexOutline outline = (IndexOutline)itr.next();
Index index = new Index(outline.getName(), outline.getType(), m_table);
outline.copyTo(index);
m_table.addIndex(index);
}
aspectManager.applyAspects(1);
for (Lookup.Iterator itr = m_indexMap.valueIterator(); itr.hasNext();)
{
IndexOutline outline = (IndexOutline)itr.next();
Index index = m_table.getIndex(outline.getName());
if (outline.getRelatedTableName() != null)
{
schema.getTable(outline.getRelatedTableName()).addRelatedKey(index);
}
}
aspectManager.applyAspects(2);
if (m_hintList != null)
{
for (int i = 0, nCount = m_hintList.size(); i < nCount; ++i)
{
m_table.addHint(m_hintList.get(i).toString());
}
}
if (m_sPrimaryKeyName != null)
{
m_table.setPrimaryKey(schema.getIndex(m_sPrimaryKeyName));
}
m_table.computePrimaryKeyParts();
m_table.validate(state.getSchema().getMetadata(), null);
}