use of ch.interlis.ili2c.metamodel.Table 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.interlis.ili2c.metamodel.Table 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.Table 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.Table 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.Table 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