use of ch.ehi.ili2db.base.Ili2dbException in project ili2db by claeis.
the class MetaAttrUtility method insertMetaAttributeEntry.
// Write meta-attribute into db
private static void insertMetaAttributeEntry(Connection conn, String schema, String ilielement, String attrname, String attrvalue) throws Ili2dbException {
String sqlName = DbNames.META_ATTRIBUTES_TAB;
if (schema != null) {
sqlName = schema + "." + sqlName;
}
try {
String stmt = "INSERT INTO " + sqlName + " (" + DbNames.META_ATTRIBUTES_TAB_ILIELEMENT_COL + "," + DbNames.META_ATTRIBUTES_TAB_ATTRNAME_COL + "," + DbNames.META_ATTRIBUTES_TAB_ATTRVALUE_COL + ") VALUES (?, ?, ?)";
EhiLogger.traceBackendCmd(stmt);
PreparedStatement ps = conn.prepareStatement(stmt);
ps.setString(1, ilielement);
ps.setString(2, attrname);
ps.setString(3, attrvalue);
ps.executeUpdate();
} catch (java.sql.SQLException ex) {
throw new Ili2dbException("failed to insert meta-attribute", ex);
}
}
use of ch.ehi.ili2db.base.Ili2dbException in project ili2db by claeis.
the class MetaAttrUtility method addMetaAttrsFromDb.
/**
* Read meta-attributes from the db and add them to the ili2c metamodel.
* @param td
* @param conn
* @param schema
* @throws Ili2dbException
*/
public static void addMetaAttrsFromDb(TransferDescription td, Connection conn, String schema) throws Ili2dbException {
String sqlName = DbNames.META_ATTRIBUTES_TAB;
if (schema != null) {
sqlName = schema + "." + sqlName;
}
try {
String stmt = "SELECT " + DbNames.META_ATTRIBUTES_TAB_ILIELEMENT_COL + ", " + DbNames.META_ATTRIBUTES_TAB_ATTRNAME_COL + ", " + DbNames.META_ATTRIBUTES_TAB_ATTRVALUE_COL + " " + "FROM " + sqlName;
EhiLogger.traceBackendCmd(stmt);
Statement dbstmt = conn.createStatement();
ResultSet rs = dbstmt.executeQuery(stmt);
while (rs.next()) {
String ilielement = rs.getString(DbNames.META_ATTRIBUTES_TAB_ILIELEMENT_COL);
String attrname = rs.getString(DbNames.META_ATTRIBUTES_TAB_ATTRNAME_COL);
String attrvalue = rs.getString(DbNames.META_ATTRIBUTES_TAB_ATTRVALUE_COL);
// Add meta-attr to the Element
Element element = td.getElement(ilielement);
// known element?
if (element != null) {
// meta-attr not yet set/defined?
if (element.getMetaValue(attrname) == null) {
// set it to the read value
element.setMetaValue(attrname, attrvalue);
}
}
}
} catch (java.sql.SQLException ex) {
throw new Ili2dbException("failed to read meta-attributes table", ex);
}
}
use of ch.ehi.ili2db.base.Ili2dbException in project ili2db by claeis.
the class NameMapping method readTableMappingTable.
public void readTableMappingTable(java.sql.Connection conn, String schema) throws Ili2dbException {
String mapTableName = DbNames.CLASSNAME_TAB;
if (schema != null) {
mapTableName = schema + "." + mapTableName;
}
// create table
String stmt = "SELECT " + DbNames.CLASSNAME_TAB_ILINAME_COL + ", " + DbNames.CLASSNAME_TAB_SQLNAME_COL + " FROM " + mapTableName;
java.sql.Statement dbstmt = null;
try {
dbstmt = conn.createStatement();
java.sql.ResultSet rs = dbstmt.executeQuery(stmt);
while (rs.next()) {
String iliname = rs.getString(DbNames.CLASSNAME_TAB_ILINAME_COL);
String sqlname = rs.getString(DbNames.CLASSNAME_TAB_SQLNAME_COL);
// EhiLogger.debug("map: "+iliname+"->"+sqlname);
if (classNameIli2sql.get(iliname) == null) {
sqlname = normalizeSqlName(sqlname);
addTableNameMapping(iliname, sqlname);
}
}
} catch (java.sql.SQLException ex) {
throw new Ili2dbException("failed to query mapping-table " + mapTableName, ex);
} finally {
if (dbstmt != null) {
try {
dbstmt.close();
} catch (java.sql.SQLException ex) {
throw new Ili2dbException("failed to close query of " + mapTableName, ex);
}
}
}
}
use of ch.ehi.ili2db.base.Ili2dbException in project ili2db by claeis.
the class TrafoConfig method read.
private static HashMap<String, HashMap<String, String>> read(java.sql.Connection conn, String schema) throws Ili2dbException {
HashMap<String, HashMap<String, String>> settings = new HashMap<String, HashMap<String, String>>();
String sqlName = DbNames.TRAFO_TAB;
if (schema != null) {
sqlName = schema + "." + sqlName;
}
if (DbUtility.tableExists(conn, new DbTableName(schema, DbNames.TRAFO_TAB))) {
try {
// select entries
String insStmt = "SELECT " + DbNames.TRAFO_TAB_ILINAME_COL + "," + DbNames.TRAFO_TAB_TAG_COL + "," + DbNames.TRAFO_TAB_SETTING_COL + " FROM " + sqlName;
EhiLogger.traceBackendCmd(insStmt);
java.sql.PreparedStatement insPrepStmt = conn.prepareStatement(insStmt);
try {
java.sql.ResultSet rs = insPrepStmt.executeQuery();
while (rs.next()) {
int valIdx = 1;
String iliname = rs.getString(valIdx++);
String tag = rs.getString(valIdx++);
String value = rs.getString(valIdx++);
setSetting(settings, iliname, tag, value);
}
} catch (java.sql.SQLException ex) {
throw new Ili2dbException("failed to read " + sqlName, ex);
} finally {
insPrepStmt.close();
}
} catch (java.sql.SQLException ex) {
throw new Ili2dbException("failed to read " + sqlName, ex);
}
}
return settings;
}
use of ch.ehi.ili2db.base.Ili2dbException in project ili2db by claeis.
the class ColumnNameMapping method readAttrMappingTableEntries.
private static HashSet<AttrMappingKey> readAttrMappingTableEntries(java.sql.Connection conn, String schema) throws Ili2dbException {
HashSet<AttrMappingKey> ret = new HashSet<AttrMappingKey>();
String sqlName = DbNames.ATTRNAME_TAB;
if (schema != null) {
sqlName = schema + "." + sqlName;
}
try {
String exstStmt = null;
exstStmt = "SELECT " + DbNames.ATTRNAME_TAB_ILINAME_COL + "," + DbNames.ATTRNAME_TAB_OWNER_COL + "," + DbNames.ATTRNAME_TAB_TARGET_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);
String owner = rs.getString(2);
String target = rs.getString(3);
ret.add(new AttrMappingKey(iliCode, owner, target));
}
} finally {
exstPrepStmt.close();
}
} catch (java.sql.SQLException ex) {
throw new Ili2dbException("failed to read attr-mapping-table " + sqlName, ex);
}
return ret;
}
Aggregations