use of ch.ehi.sqlgen.repository.DbTable in project ili2db by claeis.
the class MetaAttrUtility method addMetaAttributesTable.
// Create meta-attributes table
public static void addMetaAttributesTable(DbSchema schema) {
DbTable tab = new DbTable();
tab.setName(new DbTableName(schema.getName(), DbNames.META_ATTRIBUTES_TAB));
DbColVarchar ilielementCol = new DbColVarchar();
ilielementCol.setName(DbNames.META_ATTRIBUTES_TAB_ILIELEMENT_COL);
ilielementCol.setNotNull(true);
ilielementCol.setSize(255);
tab.addColumn(ilielementCol);
DbColVarchar attrnameCol = new DbColVarchar();
attrnameCol.setName(DbNames.META_ATTRIBUTES_TAB_ATTRNAME_COL);
attrnameCol.setNotNull(true);
attrnameCol.setSize(1024);
tab.addColumn(attrnameCol);
DbColVarchar attrvalueCol = new DbColVarchar();
attrvalueCol.setName(DbNames.META_ATTRIBUTES_TAB_ATTRVALUE_COL);
attrvalueCol.setNotNull(true);
attrvalueCol.setSize(1024);
tab.addColumn(attrvalueCol);
schema.addTable(tab);
}
use of ch.ehi.sqlgen.repository.DbTable in project ili2db by claeis.
the class GeneratorMsSql method visitIndex.
@Override
public void visitIndex(DbIndex idx) throws IOException {
if (idx.isUnique()) {
java.io.StringWriter out = new java.io.StringWriter();
DbTable tab = idx.getTable();
String tableName = tab.getName().getQName();
String constraintName = idx.getName();
if (constraintName == null) {
String[] colNames = new String[idx.sizeAttr()];
int i = 0;
for (Iterator attri = idx.iteratorAttr(); attri.hasNext(); ) {
DbColumn attr = (DbColumn) attri.next();
colNames[i++] = attr.getName();
}
constraintName = createConstraintName(tab, "key", colNames);
}
out.write(getIndent() + "CREATE UNIQUE INDEX " + constraintName + " ON " + tableName + " (");
String sep = "";
String condition = " ";
String sepCondition = " ";
for (Iterator attri = idx.iteratorAttr(); attri.hasNext(); ) {
DbColumn attr = (DbColumn) attri.next();
out.write(sep + attr.getName());
condition += sepCondition + attr.getName() + " is not null";
sep = ",";
sepCondition = " AND ";
}
out.write(") WHERE" + condition + newline());
String stmt = out.toString();
addCreateLine(new Stmt(stmt));
out = null;
if (createdTables.contains(tab.getName())) {
Statement dbstmt = null;
try {
try {
dbstmt = conn.createStatement();
EhiLogger.traceBackendCmd(stmt);
dbstmt.executeUpdate(stmt);
} finally {
dbstmt.close();
}
} catch (SQLException ex) {
IOException iox = new IOException("failed to add UNIQUE to table " + tab.getName());
iox.initCause(ex);
throw iox;
}
}
}
}
use of ch.ehi.sqlgen.repository.DbTable in project ili2db by claeis.
the class FromIliRecordConverter method addParentRef.
private void addParentRef(Viewable parentTable, AttributeDef attr) {
CompositionType type = (CompositionType) attr.getDomainResolvingAll();
Table structClass = type.getComponentType();
// if abstract struct, might have multiple tables!
for (ViewableWrapper structWrapper : getStructWrappers(structClass)) {
DbTableName structClassSqlName = structWrapper.getSqlTable();
// find struct table
DbTable dbTable = schema.findTable(structClassSqlName);
// add ref attr
String refAttrSqlName = ili2sqlName.mapIliAttributeDefReverse(attr, structClassSqlName.getName(), class2wrapper.get(parentTable).getSqlTablename());
DbColId dbParentId = new DbColId();
dbParentId.setName(refAttrSqlName);
// values of other struct attrs will have NULL
dbParentId.setNotNull(false);
dbParentId.setPrimaryKey(false);
StringBuffer cmt = new StringBuffer();
String cmtSep = "";
if (attr.getDocumentation() != null) {
cmt.append(cmtSep + attr.getDocumentation());
cmtSep = nl;
}
cmt.append(cmtSep + "@iliname " + attr.getContainer().getScopedName(null) + "." + attr.getName());
cmtSep = nl;
if (cmt.length() > 0) {
dbParentId.setComment(cmt.toString());
}
if (createFk) {
dbParentId.setReferencedTable(class2wrapper.get(parentTable).getSqlTable());
}
if (createFkIdx) {
dbParentId.setIndex(true);
}
dbTable.addColumn(dbParentId);
}
}
use of ch.ehi.sqlgen.repository.DbTable 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.DbTable 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);
}
}
}
}
Aggregations