Add indexes
This commit is contained in:
parent
efe2b8e93d
commit
125176cd75
|
@ -48,7 +48,7 @@ public class JdbcUtils {
|
||||||
DatabaseMetaData metadata;
|
DatabaseMetaData metadata;
|
||||||
try {
|
try {
|
||||||
metadata = connection.getMetaData();
|
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<>();
|
Set<String> indexNames = new HashSet<>();
|
||||||
while (indexes.next()) {
|
while (indexes.next()) {
|
||||||
|
|
|
@ -70,7 +70,16 @@ public class AddIndexTask extends BaseTableTask<AddIndexTask> {
|
||||||
String unique = myUnique ? "UNIQUE " : "";
|
String unique = myUnique ? "UNIQUE " : "";
|
||||||
String columns = String.join(", ", myColumns);
|
String columns = String.join(", ", myColumns);
|
||||||
String sql = "CREATE " + unique + " INDEX " + myIndexName + " ON " + getTableName() + "(" + columns + ")";
|
String sql = "CREATE " + unique + " INDEX " + myIndexName + " ON " + getTableName() + "(" + columns + ")";
|
||||||
|
|
||||||
|
try {
|
||||||
executeSql(sql);
|
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) {
|
public void setColumns(String... theColumns) {
|
||||||
|
|
Loading…
Reference in New Issue