use of ch.ehi.ili2db.base.Ili2dbException in project ili2db by claeis.
the class TransferFromIli method updateSingleEnumTable.
public void updateSingleEnumTable(java.sql.Connection conn) throws Ili2dbException {
DbTableName tabName = new DbTableName(schema.getName(), DbNames.ENUM_TAB);
String sqlName = tabName.getName();
if (tabName.getSchema() != null) {
sqlName = tabName.getSchema() + "." + sqlName;
}
try {
// insert entries
String insStmt = "INSERT INTO " + sqlName + " (" + DbNames.ENUM_TAB_SEQ_COL + "," + DbNames.ENUM_TAB_ILICODE_COL + "," + DbNames.ENUM_TAB_ITFCODE_COL + "," + DbNames.ENUM_TAB_DISPNAME_COL + "," + DbNames.ENUM_TAB_INACTIVE_COL + "," + DbNames.ENUM_TAB_DESCRIPTION_COL + "," + DbNames.ENUM_TAB_THIS_COL + "," + DbNames.ENUM_TAB_BASE_COL + ") VALUES (?,?,?,?,?,?,?,?)";
EhiLogger.traceBackendCmd(insStmt);
java.sql.PreparedStatement insPrepStmt = conn.prepareStatement(insStmt);
String thisClass = null;
try {
addMissingEnumDomains(visitedEnums);
java.util.Iterator entri = visitedEnums.iterator();
while (entri.hasNext()) {
Object entro = entri.next();
if (entro instanceof AttributeDef) {
AttributeDef attr = (AttributeDef) entro;
if (attr.getDomain() instanceof ch.interlis.ili2c.metamodel.TypeAlias) {
continue;
}
EnumerationType type = (EnumerationType) attr.getDomainResolvingAll();
thisClass = attr.getContainer().getScopedName(null) + "." + attr.getName();
AttributeDef base = (AttributeDef) attr.getExtending();
String baseClass = null;
if (base != null) {
baseClass = base.getContainer().getScopedName(null) + "." + base.getName();
}
HashSet exstEntries = readEnumTable(conn, true, thisClass, tabName);
updateEnumEntries(exstEntries, insPrepStmt, type, thisClass, baseClass);
} else if (entro instanceof Domain) {
Domain domain = (Domain) entro;
if (domain == td.INTERLIS.BOOLEAN) {
continue;
}
EnumerationType type = (EnumerationType) domain.getType();
thisClass = domain.getScopedName(null);
Domain base = (Domain) domain.getExtending();
String baseClass = null;
if (base != null) {
baseClass = base.getScopedName(null);
}
HashSet exstEntries = readEnumTable(conn, true, thisClass, tabName);
updateEnumEntries(exstEntries, insPrepStmt, type, thisClass, baseClass);
}
}
} catch (java.sql.SQLException ex) {
throw new Ili2dbException("failed to insert enum values for type " + thisClass, ex);
} finally {
insPrepStmt.close();
}
} catch (java.sql.SQLException ex) {
throw new Ili2dbException("failed to update enum-table " + sqlName, ex);
}
}
use of ch.ehi.ili2db.base.Ili2dbException in project ili2db by claeis.
the class TransferFromIli method readIliFile.
public static String readIliFile(java.sql.Connection conn, String schema, String filename) throws Ili2dbException {
String sqlName = DbNames.MODELS_TAB;
if (schema != null) {
sqlName = schema + "." + sqlName;
}
try {
// select entries
String selStmt = "SELECT " + DbNames.MODELS_TAB_CONTENT_COL + " FROM " + sqlName + " WHERE " + DbNames.MODELS_TAB_FILE_COL + "=?";
if (isMsSqlServer(conn)) {
selStmt = "SELECT " + DbNames.MODELS_TAB_CONTENT_COL + " FROM " + sqlName + " WHERE \"" + DbNames.MODELS_TAB_FILE_COL + "\"=?";
}
EhiLogger.traceBackendCmd(selStmt);
java.sql.PreparedStatement selPrepStmt = conn.prepareStatement(selStmt);
try {
selPrepStmt.clearParameters();
selPrepStmt.setString(1, filename);
java.sql.ResultSet rs = selPrepStmt.executeQuery();
while (rs.next()) {
String file = rs.getString(1);
return file;
}
} catch (java.sql.SQLException ex) {
throw new Ili2dbException("failed to read ili-file <" + filename + "> from db", ex);
} finally {
selPrepStmt.close();
}
} catch (java.sql.SQLException ex) {
throw new Ili2dbException("failed to read models-table " + sqlName, ex);
}
return null;
}
use of ch.ehi.ili2db.base.Ili2dbException in project ili2db by claeis.
the class TransferFromIli method readSettings.
public static void readSettings(java.sql.Connection conn, Config settings, String schema) throws Ili2dbException {
String sqlName = DbNames.SETTINGS_TAB;
if (schema != null) {
sqlName = schema + "." + sqlName;
}
if (DbUtility.tableExists(conn, new DbTableName(schema, DbNames.SETTINGS_TAB))) {
try {
// select entries
String insStmt = "SELECT " + DbNames.SETTINGS_TAB_TAG_COL + "," + DbNames.SETTINGS_TAB_SETTING_COL + " FROM " + sqlName;
EhiLogger.traceBackendCmd(insStmt);
java.sql.PreparedStatement insPrepStmt = conn.prepareStatement(insStmt);
boolean settingsExists = false;
try {
java.sql.ResultSet rs = insPrepStmt.executeQuery();
while (rs.next()) {
String tag = rs.getString(1);
String value = rs.getString(2);
if (tag.equals(Config.SENDER))
continue;
settings.setValue(tag, value);
settingsExists = true;
}
if (settingsExists) {
settings.setConfigReadFromDb(true);
}
} catch (java.sql.SQLException ex) {
throw new Ili2dbException("failed to read setting", ex);
} finally {
insPrepStmt.close();
}
} catch (java.sql.SQLException ex) {
throw new Ili2dbException("failed to read settings-table " + sqlName, ex);
}
}
}
use of ch.ehi.ili2db.base.Ili2dbException in project ili2db by claeis.
the class TransferFromIli method readEnumTable.
private static HashSet readEnumTable(java.sql.Connection conn, boolean singleTable, String qualifiedIliName, DbTableName sqlDbName) throws Ili2dbException {
HashSet ret = new HashSet();
String sqlName = sqlDbName.getName();
if (sqlDbName.getSchema() != null) {
sqlName = sqlDbName.getSchema() + "." + sqlName;
}
try {
String exstStmt = null;
if (!singleTable) {
exstStmt = "SELECT " + DbNames.ENUM_TAB_ILICODE_COL + " FROM " + sqlName;
} else {
exstStmt = "SELECT " + DbNames.ENUM_TAB_ILICODE_COL + " FROM " + sqlName + " WHERE " + DbNames.ENUM_TAB_THIS_COL + " = '" + qualifiedIliName + "'";
}
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);
}
} catch (java.sql.SQLException ex) {
throw new Ili2dbException("failed to read enum values for type " + qualifiedIliName, ex);
} finally {
exstPrepStmt.close();
}
} catch (java.sql.SQLException ex) {
throw new Ili2dbException("failed to read enum-table " + sqlName, ex);
}
return ret;
}
use of ch.ehi.ili2db.base.Ili2dbException in project ili2db by claeis.
the class TransferFromIli method readInheritanceTable.
private static HashSet<String> readInheritanceTable(java.sql.Connection conn, String schema) throws Ili2dbException {
HashSet<String> ret = new HashSet<String>();
String sqlName = DbNames.INHERIT_TAB;
if (schema != null) {
sqlName = schema + "." + sqlName;
}
try {
String exstStmt = null;
exstStmt = "SELECT " + DbNames.INHERIT_TAB_THIS_COL + " FROM " + sqlName;
EhiLogger.traceBackendCmd(exstStmt);
java.sql.PreparedStatement exstPrepStmt = conn.prepareStatement(exstStmt);
try {
java.sql.ResultSet rs = exstPrepStmt.executeQuery();
while (rs.next()) {
String iliClassQName = rs.getString(1);
ret.add(iliClassQName);
}
} finally {
exstPrepStmt.close();
}
} catch (java.sql.SQLException ex) {
throw new Ili2dbException("failed to read inheritance-table " + sqlName, ex);
}
return ret;
}
Aggregations