NoiseModelling
NoiseModelling copied to clipboard
Check if index exists before running scripts
Check if index exists before running scripts. If not create it. Assume indexes on Geometry fields are SPATIAL.
Here is a code exemple :
logger.info("searching index on attenuation matrix IDSOURCE ... ")
DatabaseMetaData dbMeta = connection.getMetaData();
ResultSet rs = dbMeta.getIndexInfo(null, null, attenuationTable, false, false);
boolean indexIDSOURCE = false;
while (rs.next()) {
String column = rs.getString("COLUMN_NAME");
String pos = rs.getString("ORDINAL_POSITION");
if (column == "IDSOURCE" && pos == "1") {
indexIDSOURCE = true;
logger.info("index on attenuation matrix IDSOURCE found")
break;
}
}
if (!indexIDSOURCE) {
logger.info("index on attenuation matrix IDSOURCE, NOT found, creating one...")
sql.execute("CREATE INDEX ON " + attenuationTable + " (IDSOURCE)");
}