* table. Then create Full-Text indexes on the new table.
* @see nexj.core.persistence.sql.SQLSchemaManager#createIndex(nexj.core.meta.persistence.sql.Index)
*/
protected void createIndex(Index index)
{
Table table = index.getTable();
if (index.getType() != Index.TEXT || table.getType() != Table.MANAGED)
{
super.createIndex(index); // let super deal with regular indexes
return;
}
String sTable = table.getFullName(getOwner(), "$", true);
Column column = index.getIndexColumn(0).getColumn();
Index primaryKey = table.getPrimaryKey();
boolean bColInPK = primaryKey.findIndexColumn(column) != null;
boolean bHaveMoreIndexes = false;
StringBuffer buf = new StringBuffer(128);
// determine if this is the first Full-Text index to be created (i.e. Full-Text table needed)
for (int i = 0, nCount = table.getIndexCount(); i < nCount && !bHaveMoreIndexes; ++i)
{
Index idx = table.getIndex(i);
bHaveMoreIndexes = idx != index && idx.getType() == Index.TEXT;
}
if (!bHaveMoreIndexes) // Need to create a new Full-Text table
{
createTextTable(table);
}
if (!bColInPK) // Existing Full-Text table to alter, column does not exist yet
{
buf.append("alter table ").append(sTable).append(" add column ");
appendColumnDeclaration(buf, column, false, false, ", "); // take only first column
m_appender.appendSQL(buf.toString()); // column nullable since rows can exist
buf.setLength(0);
dropTextTriggers(table);
createTextTriggers(table, null, null);
buf.append("update ").append(sTable).append(" dst inner join ");
buf.append(table.getFullName(getOwner(), null, true)).append(" src on ");
for (int i = 0, nCount = primaryKey.getIndexColumnCount(); i < nCount; ++i) // add PK cols
{
Column col = table.getColumn(i);
if (i != 0)
{
buf.append("and ");
}