com.huawei.dataconvert.db.convert

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();

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值