use of ch.ehi.sqlgen.repository.DbTableName in project ili2db by claeis.
the class TransferFromIli method readIliFiles.
public static ch.interlis.ilirepository.IliFiles readIliFiles(java.sql.Connection conn, String schema) throws Ili2dbException {
String sqlName = DbNames.MODELS_TAB;
if (!DbUtility.tableExists(conn, new DbTableName(schema, sqlName))) {
return null;
}
ch.interlis.ilirepository.IliFiles ret = new ch.interlis.ilirepository.IliFiles();
try {
String reposUri = conn.getMetaData().getURL();
if (schema != null) {
sqlName = schema + "." + sqlName;
reposUri = reposUri + "/" + schema;
}
// select entries
String insStmt = "SELECT " + DbNames.MODELS_TAB_FILE_COL + "," + DbNames.MODELS_TAB_ILIVERSION_COL + "," + DbNames.MODELS_TAB_MODELNAME_COL + " FROM " + sqlName;
if (isMsSqlServer(conn)) {
// 'file' is keyword in sql server
insStmt = "SELECT \"" + DbNames.MODELS_TAB_FILE_COL + "\"," + DbNames.MODELS_TAB_ILIVERSION_COL + "," + DbNames.MODELS_TAB_MODELNAME_COL + " FROM " + sqlName;
}
EhiLogger.traceBackendCmd(insStmt);
java.sql.PreparedStatement insPrepStmt = conn.prepareStatement(insStmt);
try {
java.sql.ResultSet rs = insPrepStmt.executeQuery();
while (rs.next()) {
String file = rs.getString(1);
double iliversion = Double.parseDouble(rs.getString(2));
String imports = rs.getString(3);
ch.interlis.ili2c.modelscan.IliFile iliFile = IliImportsUtility.parseIliImports(iliversion, imports);
iliFile.setPath(file);
iliFile.setRepositoryUri(reposUri);
ret.addFile(iliFile);
}
} catch (java.sql.SQLException ex) {
throw new Ili2dbException("failed to read IliFiles from db", ex);
} finally {
insPrepStmt.close();
}
} catch (java.sql.SQLException ex) {
throw new Ili2dbException("failed to read models-table " + sqlName, ex);
}
return ret;
}
use of ch.ehi.sqlgen.repository.DbTableName in project ili2db by claeis.
the class TransferFromIli method addSettingsTable.
public static void addSettingsTable(DbSchema schema) {
DbTable tab = new DbTable();
tab.setName(new DbTableName(schema.getName(), DbNames.SETTINGS_TAB));
DbColVarchar tagCol = new DbColVarchar();
tagCol.setName(DbNames.SETTINGS_TAB_TAG_COL);
tagCol.setNotNull(true);
tagCol.setPrimaryKey(true);
tagCol.setSize(60);
tab.addColumn(tagCol);
DbColVarchar settingCol = new DbColVarchar();
settingCol.setName(DbNames.SETTINGS_TAB_SETTING_COL);
settingCol.setNotNull(false);
settingCol.setSize(255);
tab.addColumn(settingCol);
schema.addTable(tab);
}
use of ch.ehi.sqlgen.repository.DbTableName in project ili2db by claeis.
the class TransferFromIli method addEnumTable.
public void addEnumTable(DbSchema schema) {
if (Config.CREATE_ENUM_DEFS_SINGLE.equals(createEnumTable)) {
DbTable tab = new DbTable();
DbColVarchar thisClass = new DbColVarchar();
thisClass.setName(DbNames.ENUM_TAB_THIS_COL);
thisClass.setNotNull(true);
thisClass.setSize(1024);
tab.addColumn(thisClass);
DbColVarchar baseClass = new DbColVarchar();
baseClass.setName(DbNames.ENUM_TAB_BASE_COL);
baseClass.setNotNull(false);
baseClass.setSize(1024);
tab.addColumn(baseClass);
DbColNumber seq = new DbColNumber();
seq.setName(DbNames.ENUM_TAB_SEQ_COL);
seq.setNotNull(false);
seq.setSize(4);
tab.addColumn(seq);
DbColBoolean inactiveCol = new DbColBoolean();
inactiveCol.setName(DbNames.ENUM_TAB_INACTIVE_COL);
inactiveCol.setNotNull(true);
tab.addColumn(inactiveCol);
DbColVarchar iliCode = new DbColVarchar();
iliCode.setName(DbNames.ENUM_TAB_ILICODE_COL);
iliCode.setNotNull(true);
iliCode.setSize(1024);
tab.addColumn(iliCode);
tab.setName(new DbTableName(schema.getName(), DbNames.ENUM_TAB));
DbColNumber itfCode = new DbColNumber();
itfCode.setName(DbNames.ENUM_TAB_ITFCODE_COL);
itfCode.setNotNull(true);
itfCode.setSize(4);
tab.addColumn(itfCode);
DbColVarchar dispName = new DbColVarchar();
dispName.setName(DbNames.ENUM_TAB_DISPNAME_COL);
dispName.setNotNull(true);
dispName.setSize(250);
tab.addColumn(dispName);
DbColVarchar description = new DbColVarchar();
description.setName(DbNames.ENUM_TAB_DESCRIPTION_COL);
description.setNotNull(false);
description.setSize(1024);
tab.addColumn(description);
schema.addTable(tab);
} else if (Config.CREATE_ENUM_DEFS_MULTI.equals(createEnumTable)) {
addMissingEnumDomains(visitedEnums);
java.util.Iterator entri = visitedEnums.iterator();
while (entri.hasNext()) {
Object entro = entri.next();
DbTableName thisSqlName = null;
if (entro instanceof AttributeDef) {
AttributeDef attr = (AttributeDef) entro;
ch.interlis.ili2c.metamodel.Type type = attr.getDomain();
if (type instanceof ch.interlis.ili2c.metamodel.TypeAlias) {
// skip it
continue;
} else {
thisSqlName = getSqlTableNameEnum(attr);
}
} else if (entro instanceof Domain) {
Domain domain = (Domain) entro;
if (domain == td.INTERLIS.BOOLEAN) {
continue;
}
thisSqlName = getSqlTableName(domain);
}
if (thisSqlName != null) {
DbTable tab = new DbTable();
tab.setName(thisSqlName);
DbColNumber itfCode = new DbColNumber();
itfCode.setName(DbNames.ENUM_TAB_ITFCODE_COL);
itfCode.setNotNull(true);
itfCode.setSize(4);
itfCode.setPrimaryKey(true);
tab.addColumn(itfCode);
DbColVarchar iliCode = new DbColVarchar();
iliCode.setName(DbNames.ENUM_TAB_ILICODE_COL);
iliCode.setNotNull(true);
iliCode.setSize(1024);
tab.addColumn(iliCode);
DbColNumber seq = new DbColNumber();
seq.setName(DbNames.ENUM_TAB_SEQ_COL);
seq.setNotNull(false);
seq.setSize(4);
tab.addColumn(seq);
DbColBoolean inactiveCol = new DbColBoolean();
inactiveCol.setName(DbNames.ENUM_TAB_INACTIVE_COL);
inactiveCol.setNotNull(true);
tab.addColumn(inactiveCol);
DbColVarchar dispName = new DbColVarchar();
dispName.setName(DbNames.ENUM_TAB_DISPNAME_COL);
dispName.setNotNull(true);
dispName.setSize(250);
tab.addColumn(dispName);
DbColVarchar description = new DbColVarchar();
description.setName(DbNames.ENUM_TAB_DESCRIPTION_COL);
description.setNotNull(false);
description.setSize(1024);
tab.addColumn(description);
schema.addTable(tab);
metaInfo.setTableInfo(tab.getName().getName(), DbExtMetaInfo.TAG_TAB_TABLEKIND, DbExtMetaInfo.TAG_TAB_TABLEKIND_ENUM);
}
}
}
}
use of ch.ehi.sqlgen.repository.DbTableName in project ili2db by claeis.
the class TransferFromIli method updateMultiEnumTable.
public void updateMultiEnumTable(java.sql.Connection conn) throws Ili2dbException {
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();
String thisClass = attr.getContainer().getScopedName(null) + "." + attr.getName();
DbTableName thisSqlName = getSqlTableNameEnum(attr);
HashSet exstEntries = readEnumTable(conn, false, thisClass, thisSqlName);
try {
// insert entries
String stmt = "INSERT INTO " + thisSqlName + " (" + 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 + ") VALUES (?,?,?,?,?,?)";
EhiLogger.traceBackendCmd(stmt);
java.sql.PreparedStatement ps = conn.prepareStatement(stmt);
try {
updateEnumEntries(exstEntries, ps, type, null, null);
} catch (java.sql.SQLException ex) {
throw new Ili2dbException("failed to insert enum values for type " + thisClass, ex);
} finally {
ps.close();
}
} catch (java.sql.SQLException ex) {
throw new Ili2dbException("failed to update enum-table " + thisSqlName, ex);
}
} else if (entro instanceof Domain) {
Domain domain = (Domain) entro;
if (domain == td.INTERLIS.BOOLEAN) {
continue;
}
EnumerationType type = (EnumerationType) domain.getType();
String thisClass = domain.getScopedName(null);
DbTableName thisSqlName = getSqlTableName(domain);
HashSet exstEntries = readEnumTable(conn, false, thisClass, thisSqlName);
try {
// insert entries
String stmt = "INSERT INTO " + thisSqlName + " (" + 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 + ") VALUES (?,?,?,?,?,?)";
EhiLogger.traceBackendCmd(stmt);
java.sql.PreparedStatement ps = conn.prepareStatement(stmt);
try {
updateEnumEntries(exstEntries, ps, type, null, null);
} catch (java.sql.SQLException ex) {
throw new Ili2dbException("failed to insert enum values for type " + thisClass, ex);
} finally {
ps.close();
}
} catch (java.sql.SQLException ex) {
throw new Ili2dbException("failed to update enum-table " + thisSqlName, ex);
}
}
}
}
use of ch.ehi.sqlgen.repository.DbTableName in project ili2db by claeis.
the class TransferFromIli method addTableMappingTable.
public static void addTableMappingTable(ch.ehi.sqlgen.repository.DbSchema schema) {
ch.ehi.sqlgen.repository.DbTable tab = new ch.ehi.sqlgen.repository.DbTable();
tab.setName(new DbTableName(schema.getName(), DbNames.CLASSNAME_TAB));
ch.ehi.sqlgen.repository.DbColVarchar iliClassName = new ch.ehi.sqlgen.repository.DbColVarchar();
iliClassName.setName(DbNames.CLASSNAME_TAB_ILINAME_COL);
iliClassName.setNotNull(true);
iliClassName.setSize(1024);
iliClassName.setPrimaryKey(true);
tab.addColumn(iliClassName);
ch.ehi.sqlgen.repository.DbColVarchar sqlTableName = new ch.ehi.sqlgen.repository.DbColVarchar();
sqlTableName.setName(DbNames.CLASSNAME_TAB_SQLNAME_COL);
sqlTableName.setNotNull(true);
sqlTableName.setSize(1024);
tab.addColumn(sqlTableName);
schema.addTable(tab);
}
Aggregations