private String getCreateIndexStmt(Connection oraConn, SqlRecord record,
String indexName, boolean isUnique) throws Exception
{
String tableName = record.getTableName().replace(
Constant.SPECIAL_CHAR_$, Constant.SPECIAL_CHAR_R$);
Statement stmt = oraConn.createStatement();
oraConn.setAutoCommit(true);
String sql = "select column_name from user_ind_columns where index_name='"
+ indexName + "' order by column_position";
ResultSet cols = stmt.executeQuery(sql);
StringBuffer resultSql = new StringBuffer();
// if (isUnique) {
// resultSql.append("create unique index "
// + indexName.replaceAll("\\$", "_S_") + " on "
// + tableName.replaceAll("\\$", "_S_") + "(");
// } else {
// resultSql.append("create index "
// + indexName.replaceAll("\\$", "_S_") + " on "
// + tableName.replaceAll("\\$", "_S_") + "(");
// }
if (indexName.contains(Constant.SPECIAL_CHAR_$))
{
String rIndexName = indexName.replace(Constant.SPECIAL_CHAR_$,
Constant.SPECIAL_CHAR_R$);
this.hsqlDataBase.saveReplaceInfo(record.getUser(),
DataBase.OBJ_TYPE_INDEX, record.getTableName(), indexName,
rIndexName);
indexName = rIndexName;
}
if (isUnique)
{
resultSql.append("create unique index " + indexName + " on "
+ tableName + "(");
} else
{
resultSql.append("create index " + indexName + " on " + tableName
+ "(");
}
int colIndex = 0;
while (cols.next())
{
// 有极少量特殊情况要跳过的列
// TODO 可能会带来问题,如:对违反唯一性约束的数据未做校验
if (cols.getString("column_name").indexOf(Constant.SPECIAL_CHAR_$) != -1)
{
stmt.close();
cols.close();
return null;
}
if (0 != colIndex)
{
resultSql.append(", ");
}
String colName = cols.getString("column_name");
resultSql.append("" + colName);
colIndex++;
}
resultSql.append(");");
// 如果所以一个数据列都没有(不知为何,Oracle库中有这种情况),则不创建这个索引
if (0 == colIndex)
{
stmt.close();
cols.close();
return null;
}
stmt.close();
cols.close();
return resultSql.toString();
}
String indexName, boolean isUnique) throws Exception
{
String tableName = record.getTableName().replace(
Constant.SPECIAL_CHAR_$, Constant.SPECIAL_CHAR_R$);
Statement stmt = oraConn.createStatement();
oraConn.setAutoCommit(true);
String sql = "select column_name from user_ind_columns where index_name='"
+ indexName + "' order by column_position";
ResultSet cols = stmt.executeQuery(sql);
StringBuffer resultSql = new StringBuffer();
// if (isUnique) {
// resultSql.append("create unique index "
// + indexName.replaceAll("\\$", "_S_") + " on "
// + tableName.replaceAll("\\$", "_S_") + "(");
// } else {
// resultSql.append("create index "
// + indexName.replaceAll("\\$", "_S_") + " on "
// + tableName.replaceAll("\\$", "_S_") + "(");
// }
if (indexName.contains(Constant.SPECIAL_CHAR_$))
{
String rIndexName = indexName.replace(Constant.SPECIAL_CHAR_$,
Constant.SPECIAL_CHAR_R$);
this.hsqlDataBase.saveReplaceInfo(record.getUser(),
DataBase.OBJ_TYPE_INDEX, record.getTableName(), indexName,
rIndexName);
indexName = rIndexName;
}
if (isUnique)
{
resultSql.append("create unique index " + indexName + " on "
+ tableName + "(");
} else
{
resultSql.append("create index " + indexName + " on " + tableName
+ "(");
}
int colIndex = 0;
while (cols.next())
{
// 有极少量特殊情况要跳过的列
// TODO 可能会带来问题,如:对违反唯一性约束的数据未做校验
if (cols.getString("column_name").indexOf(Constant.SPECIAL_CHAR_$) != -1)
{
stmt.close();
cols.close();
return null;
}
if (0 != colIndex)
{
resultSql.append(", ");
}
String colName = cols.getString("column_name");
resultSql.append("" + colName);
colIndex++;
}
resultSql.append(");");
// 如果所以一个数据列都没有(不知为何,Oracle库中有这种情况),则不创建这个索引
if (0 == colIndex)
{
stmt.close();
cols.close();
return null;
}
stmt.close();
cols.close();
return resultSql.toString();
}