use of ch.interlis.ili2c.metamodel.AttributeDef 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.interlis.ili2c.metamodel.AttributeDef in project ili2db by claeis.
the class TransferFromIli method generatModelEles.
private void generatModelEles(java.util.List<Element> modelEles, int pass) throws Ili2dbException {
Iterator modeli = modelEles.iterator();
while (modeli.hasNext()) {
Object modelo = modeli.next();
if (modelo instanceof Model) {
Model model = (Model) modelo;
// generateModel(model);
} else if (modelo instanceof Topic) {
// generateTopic((Topic)modelo);
} else if (modelo instanceof Domain) {
if (pass == 2) {
generateDomain((Domain) modelo);
visitedElements.add((Domain) modelo);
}
} else if (modelo instanceof Viewable) {
if (modelo instanceof Table && ((Table) modelo).isIli1LineAttrStruct()) {
// skip it
} else if ((modelo instanceof View) && !isTransferableView(modelo)) {
// skip it
} else {
try {
ViewableWrapper wrapper = class2wrapper.get((Viewable) modelo);
if (wrapper != null) {
generateViewable(wrapper, pass);
}
if (pass == 2) {
visitedElements.add((Viewable) modelo);
}
} catch (Ili2dbException ex) {
throw new Ili2dbException("mapping of " + ((Viewable) modelo).getScopedName(null) + " failed", ex);
}
}
} else if (modelo instanceof AttributeDef) {
AttributeDef attr = (AttributeDef) modelo;
if (attr.getDomainResolvingAll() instanceof SurfaceOrAreaType) {
generateItfLineTable(attr, pass);
} else if (attr.getDomainResolvingAll() instanceof EnumerationType) {
if (pass == 2) {
visitedEnums.add(attr);
}
} else {
// skip it
}
} else {
// skip it
}
}
}
use of ch.interlis.ili2c.metamodel.AttributeDef in project ili2db by claeis.
the class TransferFromIli method generateItfLineTable.
private void generateItfLineTable(AttributeDef attr, int pass) throws Ili2dbException {
if (pass == 1) {
DbTableName sqlName = getSqlTableNameItfLineTable(attr);
DbTable dbTable = new DbTable();
dbTable.setName(sqlName);
dbTable.setIliName(attr.getContainer().getScopedName(null) + "." + attr.getName());
schema.addTable(dbTable);
return;
}
// second pass; add columns
DbTableName sqlName = getSqlTableNameItfLineTable(attr);
DbTable dbTable = schema.findTable(sqlName);
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) {
dbTable.setComment(cmt.toString());
}
if (deleteExistingData) {
dbTable.setDeleteDataIfTableExists(true);
}
dbTable.setRequiresSequence(true);
DbColId dbColId = recConv.addKeyCol(dbTable);
if (createIliTidCol) {
recConv.addIliTidCol(dbTable, null);
}
if (createBasketCol) {
// add basketCol
DbColId t_basket = new DbColId();
t_basket.setName(DbNames.T_BASKET_COL);
t_basket.setNotNull(true);
t_basket.setScriptComment("REFERENCES " + DbNames.BASKETS_TAB);
if (createFk) {
t_basket.setReferencedTable(new DbTableName(schema.getName(), DbNames.BASKETS_TAB));
}
if (createFkIdx) {
t_basket.setIndex(true);
}
dbTable.addColumn(t_basket);
}
if (createDatasetCol) {
DbColVarchar t_dsName = new DbColVarchar();
t_dsName.setName(DbNames.T_DATASET_COL);
t_dsName.setSize(DbNames.DATASETNAME_COL_SIZE);
t_dsName.setNotNull(true);
t_dsName.setIndex(true);
dbTable.addColumn(t_dsName);
}
SurfaceOrAreaType type = (SurfaceOrAreaType) attr.getDomainResolvingAll();
DbColGeometry dbCol = recConv.generatePolylineType(type, attr.getContainer().getScopedName(null) + "." + attr.getName());
recConv.setCrs(dbCol, attr);
dbCol.setName(ili2sqlName.getSqlColNameItfLineTableGeomAttr(attr, sqlName.getName()));
dbCol.setNotNull(true);
dbTable.addColumn(dbCol);
if (type instanceof SurfaceType) {
dbColId = new DbColId();
dbColId.setName(ili2sqlName.getSqlColNameItfLineTableRefAttr(attr, sqlName.getName()));
dbColId.setNotNull(true);
dbColId.setPrimaryKey(false);
dbColId.setScriptComment("REFERENCES " + recConv.getSqlType((Viewable) attr.getContainer()));
if (createFk) {
dbColId.setReferencedTable(recConv.getSqlType((Viewable) attr.getContainer()));
}
if (createFkIdx) {
dbColId.setIndex(true);
}
dbTable.addColumn(dbColId);
}
Table lineAttrTable = type.getLineAttributeStructure();
if (lineAttrTable != null) {
Iterator attri = lineAttrTable.getAttributes();
while (attri.hasNext()) {
AttributeDef lineattr = (AttributeDef) attri.next();
recConv.generateAttr(dbTable, lineAttrTable, lineattr);
}
}
if (createStdCols) {
AbstractRecordConverter.addStdCol(dbTable);
}
}
use of ch.interlis.ili2c.metamodel.AttributeDef in project ili2db by claeis.
the class FromXtfRecordConverter method getMultiSurfaceAttrDef.
protected AttributeDef getMultiSurfaceAttrDef(Type type, MultiSurfaceMapping attrMapping) {
Table multiSurfaceType = ((CompositionType) type).getComponentType();
Table surfaceStructureType = ((CompositionType) ((AttributeDef) multiSurfaceType.getElement(AttributeDef.class, attrMapping.getBagOfSurfacesAttrName())).getDomain()).getComponentType();
AttributeDef surfaceAttr = (AttributeDef) surfaceStructureType.getElement(AttributeDef.class, attrMapping.getSurfaceAttrName());
return surfaceAttr;
}
use of ch.interlis.ili2c.metamodel.AttributeDef in project ili2db by claeis.
the class FromXtfRecordConverter method getMultiLineAttrDef.
protected AttributeDef getMultiLineAttrDef(Type type, MultiLineMapping attrMapping) {
Table multiLineType = ((CompositionType) type).getComponentType();
Table lineStructureType = ((CompositionType) ((AttributeDef) multiLineType.getElement(AttributeDef.class, attrMapping.getBagOfLinesAttrName())).getDomain()).getComponentType();
AttributeDef polylineAttr = (AttributeDef) lineStructureType.getElement(AttributeDef.class, attrMapping.getLineAttrName());
return polylineAttr;
}
Aggregations