case TABLE:
{
final TableName tableName = new TableName(indexName.getSchemaName(), indexName.getTableName());
final Table newTable = targetAIS.getTable(tableName);
if(newTable == null) {
throw new NoSuchTableException(tableName);
}
curIndex = newTable.getIndex(indexName.getName());
newGroup = newTable.getGroup();
Integer newId = newIndexID(newGroup);
newIndex = TableIndex.create(targetAIS, newTable, indexName.getName(), newId, index.isUnique(),
index.isPrimaryKey(), index.getConstraintName());
}
break;
case GROUP:
{
GroupIndex gi = (GroupIndex)index;
newGroup = targetAIS.getGroup(gi.getGroup().getName());
if(newGroup == null) {
throw new NoSuchGroupException(gi.getGroup().getName());
}
curIndex = newGroup.getIndex(indexName.getName());
Integer newId = newIndexID(newGroup);
newIndex = GroupIndex.create(targetAIS, newGroup, indexName.getName(), newId, index.isUnique(),
index.isPrimaryKey(), index.getJoinType());
}
break;
case FULL_TEXT:
{
final TableName tableName = new TableName(indexName.getSchemaName(), indexName.getTableName());
final Table newTable = targetAIS.getTable(tableName);
if(newTable == null) {
throw new NoSuchTableException(tableName);
}
curIndex = newTable.getFullTextIndex(indexName.getName());
newGroup = newTable.getGroup();
Integer newId = newIndexID(newGroup);
newIndex = FullTextIndex.create(targetAIS, newTable, indexName.getName(), newId);
}
break;
default:
throw new IllegalArgumentException("Unknown index type: " + index);
}
if(index.getIndexMethod() == Index.IndexMethod.Z_ORDER_LAT_LON) {
newIndex.markSpatial(index.firstSpatialArgument(),
index.lastSpatialArgument() - index.firstSpatialArgument() + 1);
}
if(curIndex != null) {
throw new DuplicateIndexException(indexName);
}
if(index.getKeyColumns().isEmpty()) {
throw new IndexLacksColumnsException(indexName);
}
for(IndexColumn indexCol : index.getKeyColumns()) {
final TableName refTableName = indexCol.getColumn().getTable().getName();
final Table newRefTable = targetAIS.getTable(refTableName);
if(newRefTable == null) {
throw new NoSuchTableException(refTableName);
}
if(!newRefTable.getGroup().equals(newGroup)) {
throw new TableNotInGroupException(refTableName);
}