use of ch.ehi.ili2db.base.Ili2dbException in project ili2db by claeis.
the class TransferFromXtf method deleteObjectsOfExistingDataset.
private void deleteObjectsOfExistingDataset(long datasetSqlId, Config config) throws Ili2dbException {
// get basket id, topicname
String schema = config.getDbschema();
String colT_ID = config.getColT_ID();
if (colT_ID == null) {
colT_ID = DbNames.T_ID_COL;
}
String sqlName = DbNames.BASKETS_TAB;
if (schema != null) {
sqlName = schema + "." + sqlName;
}
java.sql.PreparedStatement getstmt = null;
try {
String stmt = "SELECT " + colT_ID + "," + DbNames.BASKETS_TAB_TOPIC_COL + " FROM " + sqlName + " WHERE " + DbNames.BASKETS_TAB_DATASET_COL + "= ?";
EhiLogger.traceBackendCmd(stmt);
getstmt = conn.prepareStatement(stmt);
getstmt.setLong(1, datasetSqlId);
java.sql.ResultSet res = getstmt.executeQuery();
while (res.next()) {
long sqlId = res.getLong(1);
String topicQName = res.getString(2);
deleteObjectsOfBasket(sqlId, topicQName);
}
} catch (java.sql.SQLException ex) {
throw new Ili2dbException("failed to query " + sqlName, ex);
} finally {
if (getstmt != null) {
try {
getstmt.close();
getstmt = null;
} catch (java.sql.SQLException ex) {
EhiLogger.logError(ex);
}
}
}
try {
String stmt = "DELETE FROM " + sqlName + " WHERE " + DbNames.BASKETS_TAB_DATASET_COL + "= ?";
EhiLogger.traceBackendCmd(stmt);
getstmt = conn.prepareStatement(stmt);
getstmt.setLong(1, datasetSqlId);
getstmt.executeUpdate();
} catch (java.sql.SQLException ex) {
throw new Ili2dbException("failed to delete from " + sqlName, ex);
} finally {
if (getstmt != null) {
try {
getstmt.close();
getstmt = null;
} catch (java.sql.SQLException ex) {
EhiLogger.logError(ex);
}
}
}
}
use of ch.ehi.ili2db.base.Ili2dbException in project ili2db by claeis.
the class DbExtMetaInfo method saveTableTab.
private void saveTableTab(Connection conn, String schemaName) throws Ili2dbException {
DbTableName tabName = new DbTableName(schemaName, DbNames.META_INFO_TABLE_TAB);
String sqlName = tabName.getQName();
HashMap<String, HashMap<String, String>> exstEntries = readTableTab(conn, sqlName);
try {
// insert entries
String insStmt = "INSERT INTO " + sqlName + " (" + DbNames.META_INFO_TABLE_TAB_TABLENAME_COL + "," + DbNames.META_INFO_TABLE_TAB_TAG_COL + "," + DbNames.META_INFO_TABLE_TAB_SETTING_COL + ") VALUES (?,?,?)";
EhiLogger.traceBackendCmd(insStmt);
java.sql.PreparedStatement insPrepStmt = conn.prepareStatement(insStmt);
try {
for (String table : tabInfo.keySet()) {
HashMap<String, String> exstValues = exstEntries.get(table);
if (exstValues == null) {
exstValues = new HashMap<String, String>();
}
HashMap<String, String> newValues = tabInfo.get(table);
for (String tag : newValues.keySet()) {
if (!exstValues.containsKey(tag)) {
String value = newValues.get(tag);
insPrepStmt.setString(1, table);
insPrepStmt.setString(2, tag);
insPrepStmt.setString(3, value);
insPrepStmt.executeUpdate();
}
}
}
} catch (java.sql.SQLException ex) {
throw new Ili2dbException("failed to insert meta info values to " + sqlName, ex);
} finally {
insPrepStmt.close();
}
} catch (java.sql.SQLException ex) {
throw new Ili2dbException("failed to update meta-info table " + sqlName, ex);
}
}
use of ch.ehi.ili2db.base.Ili2dbException in project ili2db by claeis.
the class DbExtMetaInfo method readColumnTab.
private HashMap<ColKey, HashMap<String, String>> readColumnTab(Connection conn, String sqlName) throws Ili2dbException {
HashMap<ColKey, HashMap<String, String>> exstEntries = new HashMap<ColKey, HashMap<String, String>>();
try {
// insert entries
String selStmt = "SELECT " + DbNames.META_INFO_COLUMN_TAB_TABLENAME_COL + "," + DbNames.META_INFO_COLUMN_TAB_SUBTYPE_COL + "," + DbNames.META_INFO_COLUMN_TAB_COLUMNNAME_COL + "," + DbNames.META_INFO_COLUMN_TAB_TAG_COL + "," + DbNames.META_INFO_COLUMN_TAB_SETTING_COL + " FROM " + sqlName;
EhiLogger.traceBackendCmd(selStmt);
java.sql.PreparedStatement selPrepStmt = conn.prepareStatement(selStmt);
ResultSet rs = selPrepStmt.executeQuery();
try {
while (rs.next()) {
String table = rs.getString(1);
String subtype = rs.getString(2);
String col = rs.getString(3);
String tag = rs.getString(4);
String val = rs.getString(5);
ColKey colKey = new ColKey(table, subtype, col);
HashMap<String, String> exstValues = exstEntries.get(colKey);
if (exstValues == null) {
exstValues = new HashMap<String, String>();
exstEntries.put(colKey, exstValues);
}
exstValues.put(tag, val);
}
} catch (java.sql.SQLException ex) {
throw new Ili2dbException("failed to read meta info values from " + sqlName, ex);
} finally {
selPrepStmt.close();
}
} catch (java.sql.SQLException ex) {
throw new Ili2dbException("failed to read meta-info table " + sqlName, ex);
}
return exstEntries;
}
use of ch.ehi.ili2db.base.Ili2dbException in project ili2db by claeis.
the class NameMapping method updateTableMappingTable.
public void updateTableMappingTable(java.sql.Connection conn, String schema) throws Ili2dbException {
HashSet<String> exstEntries = readTableMappingTableEntries(conn, schema);
String mapTabName = DbNames.CLASSNAME_TAB;
if (schema != null) {
mapTabName = schema + "." + mapTabName;
}
// create table
try {
// insert mapping entries
String stmt = "INSERT INTO " + mapTabName + " (" + DbNames.CLASSNAME_TAB_ILINAME_COL + "," + DbNames.CLASSNAME_TAB_SQLNAME_COL + ") VALUES (?,?)";
EhiLogger.traceBackendCmd(stmt);
java.sql.PreparedStatement ps = conn.prepareStatement(stmt);
String iliname = null;
String sqlname = null;
try {
java.util.Iterator<String> entri = classNameIli2sql.keySet().iterator();
while (entri.hasNext()) {
iliname = entri.next();
if (!exstEntries.contains(iliname)) {
sqlname = classNameIli2sql.get(iliname);
ps.setString(1, iliname);
ps.setString(2, sqlname);
ps.executeUpdate();
}
}
} catch (java.sql.SQLException ex) {
throw new Ili2dbException("failed to insert classname-mapping " + iliname, ex);
} finally {
ps.close();
}
} catch (java.sql.SQLException ex) {
throw new Ili2dbException("failed to update mapping-table " + mapTabName, ex);
}
}
use of ch.ehi.ili2db.base.Ili2dbException in project ili2db by claeis.
the class NameMapping method readTableMappingTableEntries.
private static HashSet<String> readTableMappingTableEntries(java.sql.Connection conn, String schema) throws Ili2dbException {
HashSet<String> ret = new HashSet<String>();
String sqlName = DbNames.CLASSNAME_TAB;
if (schema != null) {
sqlName = schema + "." + sqlName;
}
try {
String exstStmt = null;
exstStmt = "SELECT " + DbNames.CLASSNAME_TAB_ILINAME_COL + " FROM " + sqlName;
EhiLogger.traceBackendCmd(exstStmt);
java.sql.PreparedStatement exstPrepStmt = conn.prepareStatement(exstStmt);
try {
java.sql.ResultSet rs = exstPrepStmt.executeQuery();
while (rs.next()) {
String iliCode = rs.getString(1);
ret.add(iliCode);
}
} finally {
exstPrepStmt.close();
}
} catch (java.sql.SQLException ex) {
throw new Ili2dbException("failed to read class-mapping-table " + sqlName, ex);
}
return ret;
}
Aggregations