Add indexes
This commit is contained in:
parent
efe2b8e93d
commit
125176cd75
|
@ -48,7 +48,7 @@ public class JdbcUtils {
|
|||
DatabaseMetaData metadata;
|
||||
try {
|
||||
metadata = connection.getMetaData();
|
||||
ResultSet indexes = metadata.getIndexInfo(null, null, theTableName, false, false);
|
||||
ResultSet indexes = metadata.getIndexInfo(null, null, theTableName, false, true);
|
||||
|
||||
Set<String> indexNames = new HashSet<>();
|
||||
while (indexes.next()) {
|
||||
|
|
|
@ -70,7 +70,16 @@ public class AddIndexTask extends BaseTableTask<AddIndexTask> {
|
|||
String unique = myUnique ? "UNIQUE " : "";
|
||||
String columns = String.join(", ", myColumns);
|
||||
String sql = "CREATE " + unique + " INDEX " + myIndexName + " ON " + getTableName() + "(" + columns + ")";
|
||||
executeSql(sql);
|
||||
|
||||
try {
|
||||
executeSql(sql);
|
||||
} catch (Exception e) {
|
||||
if (e.toString().contains("already exists")) {
|
||||
ourLog.warn("Index {} already exists", myIndexName);
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setColumns(String... theColumns) {
|
||||
|
|
Loading…
Reference in New Issue