use of ch.ehi.ili2db.base.Ili2dbException in project ili2db by claeis.
the class TrafoConfig method updateTrafoConfig.
public void updateTrafoConfig(java.sql.Connection conn, String schema) throws Ili2dbException {
HashMap<String, HashMap<String, String>> existingEntries = read(conn, schema);
String sqlName = DbNames.TRAFO_TAB;
if (schema != null) {
sqlName = schema + "." + sqlName;
}
try {
// update entries
{
// UPDATE table_name
// SET column1=value1,column2=value2,...
// WHERE some_column=some_value;
String updStmt = "UPDATE " + sqlName + " SET " + DbNames.TRAFO_TAB_SETTING_COL + "=? WHERE " + DbNames.TRAFO_TAB_ILINAME_COL + "=? AND " + DbNames.TRAFO_TAB_TAG_COL + "=?";
EhiLogger.traceBackendCmd(updStmt);
java.sql.PreparedStatement updPrepStmt = conn.prepareStatement(updStmt);
try {
;
for (String iliname : config.keySet()) {
HashMap<String, String> values = config.get(iliname);
for (String tag : values.keySet()) {
if (containsSetting(existingEntries, iliname, tag)) {
// update
String value = values.get(tag);
updPrepStmt.clearParameters();
updPrepStmt.setString(1, value);
updPrepStmt.setString(2, iliname);
updPrepStmt.setString(3, tag);
updPrepStmt.executeUpdate();
}
}
}
} catch (java.sql.SQLException ex) {
throw new Ili2dbException("failed to update trafo", ex);
} finally {
updPrepStmt.close();
}
}
// insert entries
{
String insStmt = "INSERT INTO " + sqlName + " (" + DbNames.TRAFO_TAB_ILINAME_COL + "," + DbNames.TRAFO_TAB_TAG_COL + "," + DbNames.TRAFO_TAB_SETTING_COL + ") VALUES (?,?,?)";
EhiLogger.traceBackendCmd(insStmt);
java.sql.PreparedStatement insPrepStmt = conn.prepareStatement(insStmt);
try {
;
for (String iliname : config.keySet()) {
HashMap<String, String> values = config.get(iliname);
for (String tag : values.keySet()) {
if (!containsSetting(existingEntries, iliname, tag)) {
// insert
String value = values.get(tag);
insPrepStmt.clearParameters();
insPrepStmt.setString(1, iliname);
insPrepStmt.setString(2, tag);
insPrepStmt.setString(3, value);
insPrepStmt.executeUpdate();
}
}
}
} catch (java.sql.SQLException ex) {
throw new Ili2dbException("failed to insert trafo", ex);
} finally {
insPrepStmt.close();
}
}
} catch (java.sql.SQLException ex) {
throw new Ili2dbException("failed to update trafo-table " + sqlName, ex);
}
}
Aggregations