Search in sources :

Example 1 with Viewable

use of ch.interlis.ili2c.metamodel.Viewable in project ili2db by claeis.

the class TransferToXtf method createQueryStmtFromClause.

private String createQueryStmtFromClause(Viewable aclass) {
    StringBuffer ret = new StringBuffer();
    ArrayList tablev = new ArrayList(10);
    tablev.add(aclass);
    Viewable base = (Viewable) aclass.getExtending();
    while (base != null) {
        tablev.add(base);
        base = (Viewable) base.getExtending();
    }
    String sep = "";
    int tablec = tablev.size();
    for (int i = 0; i < tablec; i++) {
        ret.append(sep);
        ret.append(recConv.getSqlType((Viewable) tablev.get(i)));
        sep = ", ";
    }
    return ret.toString();
}
Also used : ArrayList(java.util.ArrayList) Viewable(ch.interlis.ili2c.metamodel.Viewable)

Example 2 with Viewable

use of ch.interlis.ili2c.metamodel.Viewable in project ili2db by claeis.

the class TransferToXtf method doitJava.

public void doitJava() {
    try {
        expgen = new ch.interlis.ili2c.generator.IndentPrintWriter(new java.io.BufferedWriter(new java.io.FileWriter("c:/tmp/ili2db/export.java")));
        expgen.println("import ch.ehi.basics.logging.EhiLogger;");
        expgen.println("import ch.interlis.iom.IomObject;");
        expgen.println("public class TransferToXtf implements IdMapper {");
        expgen.indent();
        expgen.println("private java.sql.Connection conn=null;");
        expgen.println("private IomObject newObject(String className,String tid)");
        expgen.println("{");
        expgen.indent();
        expgen.println("// TODO create new object");
        expgen.println("return null;");
        expgen.unindent();
        expgen.println("}");
        expgen.println("private void writeObject(IomObject iomObj)");
        expgen.println("{");
        expgen.indent();
        expgen.println("// TODO write object");
        expgen.unindent();
        expgen.println("}");
        expgen.println("public String mapId(String idSpace,String id)");
        expgen.println("{");
        expgen.indent();
        expgen.println("// TODO mapId");
        expgen.println("return id;");
        expgen.unindent();
        expgen.println("}");
        expgen.println("public String newId()");
        expgen.println("{");
        expgen.indent();
        expgen.println("// TODO newId");
        expgen.println("throw new UnsupportedOperationException(\"this mapper doesn't generate new ids\");");
        expgen.unindent();
        expgen.println("}");
    } catch (java.io.IOException ex) {
        EhiLogger.logError("failed to open file for java output", ex);
    }
    try {
        // for all MODELs
        Iterator modeli = td.iterator();
        while (modeli.hasNext()) {
            Object mObj = modeli.next();
            if ((mObj instanceof Model) && !(suppressModel((Model) mObj))) {
                Model model = (Model) mObj;
                // for all TOPICs
                Iterator topici = model.iterator();
                while (topici.hasNext()) {
                    Object tObj = topici.next();
                    if (tObj instanceof Topic && !(suppressTopic((Topic) tObj))) {
                        Topic topic = (Topic) tObj;
                        // IomBasket iomBasket=null;
                        // for all Viewables
                        Iterator iter = topic.getViewables().iterator();
                        while (iter.hasNext()) {
                            Object obj = iter.next();
                            if ((obj instanceof Viewable) && !suppressViewableIfJava((Viewable) obj)) {
                                Viewable aclass = (Viewable) obj;
                                // dump it
                                EhiLogger.logState(aclass.getScopedName(null) + "...");
                                genClassHelper(aclass);
                            } else if (obj instanceof Domain) {
                                Domain domainDef = (Domain) obj;
                                if (domainDef.getType() instanceof EnumerationType) {
                                    String enumName = domainDef.getScopedName(null);
                                    enumTypes.add(enumName);
                                }
                            }
                        }
                    } else if ((tObj instanceof Viewable) && !suppressViewableIfJava((Viewable) tObj)) {
                        Viewable aclass = (Viewable) tObj;
                        // dump it
                        EhiLogger.logState(aclass.getScopedName(null) + "...");
                        genClassHelper(aclass);
                    } else if (tObj instanceof Domain) {
                        Domain domainDef = (Domain) tObj;
                        if (domainDef.getType() instanceof EnumerationType) {
                            String enumName = domainDef.getScopedName(null);
                            enumTypes.add(enumName);
                        }
                    }
                }
            }
        }
    } finally {
        if (expgen != null) {
            {
                expgen.println("private void addAny(String iliClassName,String select){");
                expgen.indent();
                Iterator linei = addanyLines.iterator();
                String sep = "";
                while (linei.hasNext()) {
                    String line = (String) linei.next();
                    expgen.println(sep + line);
                    sep = "else ";
                }
                if (sep.length() > 0) {
                    expgen.println("else{EhiLogger.logError(\"unknown class \"+iliClassName);}");
                } else {
                    expgen.println("EhiLogger.logError(\"unknown class \"+iliClassName);");
                }
                expgen.unindent();
                expgen.println("}");
            }
            {
                expgen.println("private EnumMapper getEnumMapper(String enumName){");
                expgen.indent();
                Iterator enumi = enumTypes.iterator();
                String sep = "";
                while (enumi.hasNext()) {
                    String enumName = (String) enumi.next();
                    expgen.println(sep + "if(enumName.equals(\"" + enumName + "\")){return new IdentityEnumMapper();}");
                    sep = "else ";
                }
                if (sep.length() > 0) {
                    expgen.println("else{throw new IllegalArgumentException(\"unknown enum \"+enumName);}");
                } else {
                    expgen.println("throw new IllegalArgumentException(\"unknown enum \"+enumName);");
                }
                expgen.unindent();
                expgen.println("}");
            }
            expgen.unindent();
            expgen.println("}");
            expgen.close();
        }
    }
}
Also used : EnumerationType(ch.interlis.ili2c.metamodel.EnumerationType) Iterator(java.util.Iterator) ReduceToBaseModel(ch.interlis.iox_j.filter.ReduceToBaseModel) PredefinedModel(ch.interlis.ili2c.metamodel.PredefinedModel) TypeModel(ch.interlis.ili2c.metamodel.TypeModel) Model(ch.interlis.ili2c.metamodel.Model) Viewable(ch.interlis.ili2c.metamodel.Viewable) Iom_jObject(ch.interlis.iom_j.Iom_jObject) IomObject(ch.interlis.iom.IomObject) Topic(ch.interlis.ili2c.metamodel.Topic) Domain(ch.interlis.ili2c.metamodel.Domain)

Example 3 with Viewable

use of ch.interlis.ili2c.metamodel.Viewable in project ili2db by claeis.

the class Viewable2TableMapper method doit.

private Viewable2TableMapping doit(List<Element> eles) {
    // 
    if (Config.INHERITANCE_TRAFO_SMART1.equals(config.getInheritanceTrafo())) {
        doSmart1(eles);
    } else if (Config.INHERITANCE_TRAFO_SMART2.equals(config.getInheritanceTrafo())) {
        doSmart2(eles);
    } else {
        doSmartOff(eles);
    }
    // 
    // create ViewableWrappers for all NewClass or NewAndSubClass tagged viewables
    // 
    Viewable2TableMapping ret = new Viewable2TableMapping();
    for (Element ele : eles) {
        if (!(ele instanceof Viewable)) {
        // not a Viewable; skip it
        } else {
            // a Viewable
            Viewable aclass = (Viewable) ele;
            String inheritanceStrategy = trafoConfig.getViewableConfig(aclass, TrafoConfigNames.INHERITANCE_TRAFO);
            if (TrafoConfigNames.INHERITANCE_TRAFO_NEWCLASS.equals(inheritanceStrategy) || TrafoConfigNames.INHERITANCE_TRAFO_NEWANDSUBCLASS.equals(inheritanceStrategy)) {
                String sqlTablename = nameMapping.mapIliClassDef(aclass);
                ViewableWrapper wrapper = new ViewableWrapper(sqlSchemaname, sqlTablename, aclass);
                List<ViewableTransferElement> props = new java.util.ArrayList<ViewableTransferElement>();
                // defined attrs
                {
                    addProps(wrapper, props, aclass.getDefinedAttributesAndRoles2());
                }
                // defined attrs of bases with subclass or newAndSubclass strategy
                {
                    Viewable base = (Viewable) aclass.getExtending();
                    while (base != null) {
                        String baseInheritanceStrategy = trafoConfig.getViewableConfig(base, TrafoConfigNames.INHERITANCE_TRAFO);
                        if (!TrafoConfigNames.INHERITANCE_TRAFO_SUBCLASS.equals(baseInheritanceStrategy) && !TrafoConfigNames.INHERITANCE_TRAFO_NEWANDSUBCLASS.equals(baseInheritanceStrategy)) {
                            break;
                        }
                        addProps(wrapper, props, base.getDefinedAttributesAndRoles2());
                        base = (Viewable) base.getExtending();
                    }
                }
                // add attrs of extensions with superclass strategy while visiting extensions
                wrapper.setAttrv(props);
                // link to base ViewableWrapper
                {
                    Viewable base = (Viewable) aclass.getExtending();
                    while (base != null) {
                        String baseInheritanceStrategy = trafoConfig.getViewableConfig(base, TrafoConfigNames.INHERITANCE_TRAFO);
                        if (TrafoConfigNames.INHERITANCE_TRAFO_NEWCLASS.equals(baseInheritanceStrategy)) {
                            // but NOT INHERITANCE_TRAFO_NEWANDSUBCLASS!
                            break;
                        }
                        base = (Viewable) base.getExtending();
                    }
                    if (base != null) {
                        ViewableWrapper baseWrapper = ret.get(base);
                        if (baseWrapper != wrapper) {
                            wrapper.setExtending(baseWrapper);
                        }
                    }
                }
                // includes more than one type
                if (wrapper.getExtending() != null) {
                    // base contains type typediscriminator
                    wrapper.setMultipleTypes(false);
                } else {
                    // if a concrete base
                    if (hasAnyConcreteBaseWithSubClass(trafoConfig, aclass)) {
                        wrapper.setMultipleTypes(true);
                    } else if (TrafoConfigNames.INHERITANCE_TRAFO_NEWCLASS.equals(inheritanceStrategy) && hasAnyConreteExtension(aclass)) {
                        // newClass and any concrete extensions
                        wrapper.setMultipleTypes(true);
                    } else if (TrafoConfigNames.INHERITANCE_TRAFO_NEWANDSUBCLASS.equals(inheritanceStrategy) && hasAnyConreteExtensionWithoutNewClass(trafoConfig, aclass)) {
                        // newAndSubClass and any concrete extensions without newClass or newAndSubClass
                        wrapper.setMultipleTypes(true);
                    } else {
                        wrapper.setMultipleTypes(false);
                    }
                    aclass.getDirectExtensions();
                }
                ret.add(aclass, wrapper);
            } else if (TrafoConfigNames.INHERITANCE_TRAFO_SUPERCLASS.equals(inheritanceStrategy)) {
                // add props of extensions with superclass strategy to base-class
                // find base
                Viewable base = (Viewable) aclass.getExtending();
                while (base != null) {
                    String baseInheritanceStrategy = trafoConfig.getViewableConfig(base, TrafoConfigNames.INHERITANCE_TRAFO);
                    if (TrafoConfigNames.INHERITANCE_TRAFO_NEWCLASS.equals(baseInheritanceStrategy) || TrafoConfigNames.INHERITANCE_TRAFO_NEWANDSUBCLASS.equals(baseInheritanceStrategy)) {
                        break;
                    }
                    base = (Viewable) base.getExtending();
                }
                ViewableWrapper wrapper = ret.get(base);
                List<ViewableTransferElement> props = wrapper.getAttrv();
                // add props of extension
                addProps(wrapper, props, aclass.getDefinedAttributesAndRoles2());
                wrapper.setAttrv(props);
                ret.add(aclass, wrapper);
            } else if (TrafoConfigNames.INHERITANCE_TRAFO_SUBCLASS.equals(inheritanceStrategy)) {
            // skip it; props already added when visiting subclass
            } else {
                throw new IllegalStateException("unexpected inheritance config <" + inheritanceStrategy + ">");
            }
        }
    }
    return ret;
}
Also used : ViewableTransferElement(ch.interlis.ili2c.metamodel.ViewableTransferElement) ViewableTransferElement(ch.interlis.ili2c.metamodel.ViewableTransferElement) Element(ch.interlis.ili2c.metamodel.Element) Viewable(ch.interlis.ili2c.metamodel.Viewable) List(java.util.List)

Example 4 with Viewable

use of ch.interlis.ili2c.metamodel.Viewable in project ili2db by claeis.

the class FromIliRecordConverter method generateAttr.

public void generateAttr(DbTable dbTable, Viewable aclass, AttributeDef attr) throws Ili2dbException {
    Holder<DbColumn> dbCol = new Holder<DbColumn>();
    dbCol.value = null;
    Holder<Unit> unitDef = new Holder<Unit>();
    unitDef.value = null;
    Holder<Boolean> mText = new Holder<Boolean>();
    mText.value = false;
    ArrayList<DbColumn> dbColExts = new ArrayList<DbColumn>();
    Type type = attr.getDomainResolvingAll();
    if (createSimpleDbCol(dbTable, aclass, attr, type, dbCol, unitDef, mText, dbColExts)) {
    } else if (type instanceof SurfaceOrAreaType) {
        if (createItfLineTables) {
            dbCol.value = null;
        } else {
            DbColGeometry ret = new DbColGeometry();
            boolean curvePolygon = false;
            if (!strokeArcs) {
                curvePolygon = true;
            }
            ret.setType(curvePolygon ? DbColGeometry.CURVEPOLYGON : DbColGeometry.POLYGON);
            // get crs from ili
            setCrs(ret, attr);
            CoordType coord = (CoordType) ((SurfaceOrAreaType) type).getControlPointDomain().getType();
            ret.setDimension(coord.getDimensions().length);
            setBB(ret, coord, attr.getContainer().getScopedName(null) + "." + attr.getName());
            dbCol.value = ret;
        }
        if (createItfAreaRef) {
            if (type instanceof AreaType) {
                DbColGeometry ret = new DbColGeometry();
                String sqlName = getSqlAttrName(attr, dbTable.getName().getName(), null) + DbNames.ITF_MAINTABLE_GEOTABLEREF_COL_SUFFIX;
                ret.setName(sqlName);
                ret.setType(DbColGeometry.POINT);
                setNullable(aclass, attr, ret);
                // get crs from ili
                setCrs(ret, attr);
                // always 2 (even if defined as 3d in ili)
                ret.setDimension(2);
                CoordType coord = (CoordType) ((SurfaceOrAreaType) type).getControlPointDomain().getType();
                setBB(ret, coord, attr.getContainer().getScopedName(null) + "." + attr.getName());
                dbColExts.add(ret);
            }
        }
    } else if (type instanceof PolylineType) {
        String attrName = attr.getContainer().getScopedName(null) + "." + attr.getName();
        DbColGeometry ret = generatePolylineType((PolylineType) type, attrName);
        setCrs(ret, attr);
        dbCol.value = ret;
    } else if (type instanceof CoordType) {
        DbColGeometry ret = new DbColGeometry();
        ret.setType(DbColGeometry.POINT);
        // get crs from ili
        setCrs(ret, attr);
        CoordType coord = (CoordType) type;
        ret.setDimension(coord.getDimensions().length);
        setBB(ret, coord, attr.getContainer().getScopedName(null) + "." + attr.getName());
        dbCol.value = ret;
    } else if (type instanceof CompositionType) {
        // skip it
        if (!createGenericStructRef) {
            if (isChbaseCatalogueRef(td, attr) && (coalesceCatalogueRef || TrafoConfigNames.CATALOGUE_REF_TRAFO_COALESCE.equals(trafoConfig.getAttrConfig(attr, TrafoConfigNames.CATALOGUE_REF_TRAFO)))) {
                DbColId ret = new DbColId();
                ret.setNotNull(false);
                ret.setPrimaryKey(false);
                if (createFk) {
                    ret.setReferencedTable(getSqlType(((ReferenceType) ((AttributeDef) ((CompositionType) type).getComponentType().getAttributes().next()).getDomain()).getReferred()));
                }
                if (createFkIdx) {
                    ret.setIndex(true);
                }
                trafoConfig.setAttrConfig(attr, TrafoConfigNames.CATALOGUE_REF_TRAFO, TrafoConfigNames.CATALOGUE_REF_TRAFO_COALESCE);
                dbCol.value = ret;
            } else if (Ili2cUtility.isMultiSurfaceAttr(td, attr) && (coalesceMultiSurface || TrafoConfigNames.MULTISURFACE_TRAFO_COALESCE.equals(trafoConfig.getAttrConfig(attr, TrafoConfigNames.MULTISURFACE_TRAFO)))) {
                multiSurfaceAttrs.addMultiSurfaceAttr(attr);
                MultiSurfaceMapping attrMapping = multiSurfaceAttrs.getMapping(attr);
                DbColGeometry ret = new DbColGeometry();
                boolean curvePolygon = false;
                if (!strokeArcs) {
                    curvePolygon = true;
                }
                ret.setType(curvePolygon ? DbColGeometry.MULTISURFACE : DbColGeometry.MULTIPOLYGON);
                // get crs from ili
                AttributeDef surfaceAttr = (AttributeDef) ((CompositionType) ((AttributeDef) ((CompositionType) type).getComponentType().getElement(AttributeDef.class, attrMapping.getBagOfSurfacesAttrName())).getDomain()).getComponentType().getElement(AttributeDef.class, attrMapping.getSurfaceAttrName());
                setCrs(ret, surfaceAttr);
                SurfaceType surface = ((SurfaceType) surfaceAttr.getDomainResolvingAliases());
                CoordType coord = (CoordType) surface.getControlPointDomain().getType();
                ret.setDimension(coord.getDimensions().length);
                setBB(ret, coord, attr.getContainer().getScopedName(null) + "." + attr.getName());
                dbCol.value = ret;
                trafoConfig.setAttrConfig(attr, TrafoConfigNames.MULTISURFACE_TRAFO, TrafoConfigNames.MULTISURFACE_TRAFO_COALESCE);
            } else if (Ili2cUtility.isMultiLineAttr(td, attr) && (coalesceMultiLine || TrafoConfigNames.MULTILINE_TRAFO_COALESCE.equals(trafoConfig.getAttrConfig(attr, TrafoConfigNames.MULTILINE_TRAFO)))) {
                multiLineAttrs.addMultiLineAttr(attr);
                MultiLineMapping attrMapping = multiLineAttrs.getMapping(attr);
                DbColGeometry ret = new DbColGeometry();
                boolean curvePolyline = false;
                if (!strokeArcs) {
                    curvePolyline = true;
                }
                ret.setType(curvePolyline ? DbColGeometry.MULTICURVE : DbColGeometry.MULTILINESTRING);
                // get crs from ili
                AttributeDef polylineAttr = (AttributeDef) ((CompositionType) ((AttributeDef) ((CompositionType) type).getComponentType().getElement(AttributeDef.class, attrMapping.getBagOfLinesAttrName())).getDomain()).getComponentType().getElement(AttributeDef.class, attrMapping.getLineAttrName());
                setCrs(ret, polylineAttr);
                PolylineType polylineType = ((PolylineType) polylineAttr.getDomainResolvingAliases());
                CoordType coord = (CoordType) polylineType.getControlPointDomain().getType();
                ret.setDimension(coord.getDimensions().length);
                setBB(ret, coord, attr.getContainer().getScopedName(null) + "." + attr.getName());
                dbCol.value = ret;
                trafoConfig.setAttrConfig(attr, TrafoConfigNames.MULTILINE_TRAFO, TrafoConfigNames.MULTILINE_TRAFO_COALESCE);
            } else if (Ili2cUtility.isMultiPointAttr(td, attr) && (coalesceMultiPoint || TrafoConfigNames.MULTIPOINT_TRAFO_COALESCE.equals(trafoConfig.getAttrConfig(attr, TrafoConfigNames.MULTIPOINT_TRAFO)))) {
                multiPointAttrs.addMultiPointAttr(attr);
                MultiPointMapping attrMapping = multiPointAttrs.getMapping(attr);
                DbColGeometry ret = new DbColGeometry();
                ret.setType(DbColGeometry.MULTIPOINT);
                // get crs from ili
                AttributeDef coordAttr = (AttributeDef) ((CompositionType) ((AttributeDef) ((CompositionType) type).getComponentType().getElement(AttributeDef.class, attrMapping.getBagOfPointsAttrName())).getDomain()).getComponentType().getElement(AttributeDef.class, attrMapping.getPointAttrName());
                setCrs(ret, coordAttr);
                CoordType coord = (CoordType) (coordAttr.getDomainResolvingAliases());
                ret.setDimension(coord.getDimensions().length);
                setBB(ret, coord, attr.getContainer().getScopedName(null) + "." + attr.getName());
                dbCol.value = ret;
                trafoConfig.setAttrConfig(attr, TrafoConfigNames.MULTIPOINT_TRAFO, TrafoConfigNames.MULTIPOINT_TRAFO_COALESCE);
            } else if (Ili2cUtility.isArrayAttr(td, attr) && (coalesceArray || TrafoConfigNames.ARRAY_TRAFO_COALESCE.equals(trafoConfig.getAttrConfig(attr, TrafoConfigNames.ARRAY_TRAFO)))) {
                arrayAttrs.addArrayAttr(attr);
                ArrayMapping attrMapping = arrayAttrs.getMapping(attr);
                AttributeDef localAttr = attrMapping.getValueAttr();
                Type localType = localAttr.getDomainResolvingAll();
                if (!createSimpleDbCol(dbTable, aclass, localAttr, localType, dbCol, unitDef, mText, dbColExts)) {
                    throw new IllegalStateException("unexpected attr type " + localAttr.getScopedName());
                }
                dbCol.value.setArraySize(DbColumn.UNLIMITED_ARRAY);
                trafoConfig.setAttrConfig(attr, TrafoConfigNames.ARRAY_TRAFO, TrafoConfigNames.ARRAY_TRAFO_COALESCE);
            } else if (isChbaseMultilingual(td, attr) && (expandMultilingual || TrafoConfigNames.MULTILINGUAL_TRAFO_EXPAND.equals(trafoConfig.getAttrConfig(attr, TrafoConfigNames.MULTILINGUAL_TRAFO)))) {
                for (String sfx : DbNames.MULTILINGUAL_TXT_COL_SUFFIXS) {
                    DbColVarchar ret = new DbColVarchar();
                    ret.setName(getSqlAttrName(attr, dbTable.getName().getName(), null) + sfx);
                    ret.setSize(DbColVarchar.UNLIMITED);
                    ret.setNotNull(false);
                    ret.setPrimaryKey(false);
                    dbColExts.add(ret);
                }
                trafoConfig.setAttrConfig(attr, TrafoConfigNames.MULTILINGUAL_TRAFO, TrafoConfigNames.MULTILINGUAL_TRAFO_EXPAND);
            } else {
                // add reference col from struct ele to parent obj to struct table
                addParentRef(aclass, attr);
                dbCol.value = null;
            }
        } else {
            dbCol.value = null;
        }
    } else if (type instanceof ReferenceType) {
        ArrayList<ViewableWrapper> targetTables = getTargetTables(((ReferenceType) type).getReferred());
        for (ViewableWrapper targetTable : targetTables) {
            DbColId ret = new DbColId();
            ret.setName(ili2sqlName.mapIliAttributeDef(attr, dbTable.getName().getName(), targetTable.getSqlTablename(), targetTables.size() > 1));
            ret.setNotNull(false);
            ret.setPrimaryKey(false);
            if (createFk) {
                ret.setReferencedTable(targetTable.getSqlTable());
            }
            if (createFkIdx) {
                ret.setIndex(true);
            }
            dbColExts.add(ret);
        }
    } else {
        DbColVarchar ret = new DbColVarchar();
        ret.setSize(255);
        dbCol.value = ret;
    }
    if (type instanceof EnumerationType) {
        if (createEnumTxtCol) {
            DbColVarchar ret = new DbColVarchar();
            ret.setSize(255);
            ret.setName(getSqlAttrName(attr, dbTable.getName().getName(), null) + DbNames.ENUM_TXT_COL_SUFFIX);
            setNullable(aclass, attr, ret);
            dbColExts.add(ret);
        }
    }
    if (dbCol.value != null) {
        String sqlColName = getSqlAttrName(attr, dbTable.getName().getName(), null);
        setAttrDbColProps(aclass, attr, dbCol.value, sqlColName);
        String subType = null;
        Viewable attrClass = (Viewable) attr.getContainer();
        if (attrClass != aclass && attrClass.isExtending(aclass)) {
            subType = getSqlType(attrClass).getName();
        }
        if (unitDef.value != null) {
            String unitName = unitDef.value.getName();
            metaInfo.setColumnInfo(dbTable.getName().getName(), subType, sqlColName, DbExtMetaInfo.TAG_COL_UNIT, unitName);
        }
        if (mText.value) {
            metaInfo.setColumnInfo(dbTable.getName().getName(), subType, sqlColName, DbExtMetaInfo.TAG_COL_TEXTKIND, DbExtMetaInfo.TAG_COL_TEXTKIND_MTEXT);
        }
        if (dbCol.value instanceof DbColGeometry) {
            metaInfo.setColumnInfo(dbTable.getName().getName(), subType, sqlColName, DbExtMetaInfo.TAG_COL_C1_MIN, Double.toString(((DbColGeometry) dbCol.value).getMin1()));
            metaInfo.setColumnInfo(dbTable.getName().getName(), subType, sqlColName, DbExtMetaInfo.TAG_COL_C1_MAX, Double.toString(((DbColGeometry) dbCol.value).getMax1()));
            metaInfo.setColumnInfo(dbTable.getName().getName(), subType, sqlColName, DbExtMetaInfo.TAG_COL_C2_MIN, Double.toString(((DbColGeometry) dbCol.value).getMin2()));
            metaInfo.setColumnInfo(dbTable.getName().getName(), subType, sqlColName, DbExtMetaInfo.TAG_COL_C2_MAX, Double.toString(((DbColGeometry) dbCol.value).getMax2()));
            if (((DbColGeometry) dbCol.value).getDimension() == 3) {
                metaInfo.setColumnInfo(dbTable.getName().getName(), subType, sqlColName, DbExtMetaInfo.TAG_COL_C3_MIN, Double.toString(((DbColGeometry) dbCol.value).getMin3()));
                metaInfo.setColumnInfo(dbTable.getName().getName(), subType, sqlColName, DbExtMetaInfo.TAG_COL_C3_MAX, Double.toString(((DbColGeometry) dbCol.value).getMax3()));
            }
        }
        String dispName = attr.getMetaValues().getValue(IliMetaAttrNames.METAATTR_DISPNAME);
        if (dispName != null) {
            metaInfo.setColumnInfo(dbTable.getName().getName(), subType, sqlColName, DbExtMetaInfo.TAG_COL_DISPNAME, dispName);
        }
        customMapping.fixupAttribute(dbTable, dbCol.value, attr);
        dbTable.addColumn(dbCol.value);
    }
    for (DbColumn dbColExt : dbColExts) {
        customMapping.fixupAttribute(dbTable, dbColExt, attr);
        dbTable.addColumn(dbColExt);
    }
    if (dbCol.value == null && dbColExts.size() == 0) {
        customMapping.fixupAttribute(dbTable, null, attr);
    }
}
Also used : DbColumn(ch.ehi.sqlgen.repository.DbColumn) SurfaceOrAreaType(ch.interlis.ili2c.metamodel.SurfaceOrAreaType) ArrayList(java.util.ArrayList) ViewableWrapper(ch.ehi.ili2db.mapping.ViewableWrapper) Unit(ch.interlis.ili2c.metamodel.Unit) SurfaceOrAreaType(ch.interlis.ili2c.metamodel.SurfaceOrAreaType) AreaType(ch.interlis.ili2c.metamodel.AreaType) CompositionType(ch.interlis.ili2c.metamodel.CompositionType) ReferenceType(ch.interlis.ili2c.metamodel.ReferenceType) DbColGeometry(ch.ehi.sqlgen.repository.DbColGeometry) AttributeDef(ch.interlis.ili2c.metamodel.AttributeDef) DbColBoolean(ch.ehi.sqlgen.repository.DbColBoolean) PolylineType(ch.interlis.ili2c.metamodel.PolylineType) MultiPointMapping(ch.ehi.ili2db.mapping.MultiPointMapping) Holder(javax.xml.ws.Holder) DbColVarchar(ch.ehi.sqlgen.repository.DbColVarchar) EnumerationType(ch.interlis.ili2c.metamodel.EnumerationType) SurfaceType(ch.interlis.ili2c.metamodel.SurfaceType) MultiSurfaceMapping(ch.ehi.ili2db.mapping.MultiSurfaceMapping) PolylineType(ch.interlis.ili2c.metamodel.PolylineType) Type(ch.interlis.ili2c.metamodel.Type) BasketType(ch.interlis.ili2c.metamodel.BasketType) ReferenceType(ch.interlis.ili2c.metamodel.ReferenceType) SurfaceOrAreaType(ch.interlis.ili2c.metamodel.SurfaceOrAreaType) SurfaceType(ch.interlis.ili2c.metamodel.SurfaceType) CompositionType(ch.interlis.ili2c.metamodel.CompositionType) TextType(ch.interlis.ili2c.metamodel.TextType) EnumerationType(ch.interlis.ili2c.metamodel.EnumerationType) NumericType(ch.interlis.ili2c.metamodel.NumericType) BlackboxType(ch.interlis.ili2c.metamodel.BlackboxType) AreaType(ch.interlis.ili2c.metamodel.AreaType) ObjectType(ch.interlis.ili2c.metamodel.ObjectType) CoordType(ch.interlis.ili2c.metamodel.CoordType) ArrayMapping(ch.ehi.ili2db.mapping.ArrayMapping) Viewable(ch.interlis.ili2c.metamodel.Viewable) MultiLineMapping(ch.ehi.ili2db.mapping.MultiLineMapping) DbColId(ch.ehi.sqlgen.repository.DbColId) CoordType(ch.interlis.ili2c.metamodel.CoordType)

Example 5 with Viewable

use of ch.interlis.ili2c.metamodel.Viewable 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
        }
    }
}
Also used : Ili2dbException(ch.ehi.ili2db.base.Ili2dbException) DbTable(ch.ehi.sqlgen.repository.DbTable) Table(ch.interlis.ili2c.metamodel.Table) SurfaceOrAreaType(ch.interlis.ili2c.metamodel.SurfaceOrAreaType) EnumerationType(ch.interlis.ili2c.metamodel.EnumerationType) ViewableWrapper(ch.ehi.ili2db.mapping.ViewableWrapper) View(ch.interlis.ili2c.metamodel.View) Iterator(java.util.Iterator) Model(ch.interlis.ili2c.metamodel.Model) Viewable(ch.interlis.ili2c.metamodel.Viewable) AttributeDef(ch.interlis.ili2c.metamodel.AttributeDef) Topic(ch.interlis.ili2c.metamodel.Topic) Domain(ch.interlis.ili2c.metamodel.Domain)

Aggregations

Viewable (ch.interlis.ili2c.metamodel.Viewable)36 Iterator (java.util.Iterator)16 AttributeDef (ch.interlis.ili2c.metamodel.AttributeDef)14 IomObject (ch.interlis.iom.IomObject)13 ViewableWrapper (ch.ehi.ili2db.mapping.ViewableWrapper)11 SurfaceOrAreaType (ch.interlis.ili2c.metamodel.SurfaceOrAreaType)10 EnumerationType (ch.interlis.ili2c.metamodel.EnumerationType)9 ArrayList (java.util.ArrayList)9 CompositionType (ch.interlis.ili2c.metamodel.CompositionType)8 SurfaceType (ch.interlis.ili2c.metamodel.SurfaceType)8 ViewableTransferElement (ch.interlis.ili2c.metamodel.ViewableTransferElement)8 Topic (ch.interlis.ili2c.metamodel.Topic)7 Type (ch.interlis.ili2c.metamodel.Type)7 HashSet (java.util.HashSet)7 Ili2dbException (ch.ehi.ili2db.base.Ili2dbException)6 Model (ch.interlis.ili2c.metamodel.Model)6 ObjectType (ch.interlis.ili2c.metamodel.ObjectType)6 DbTableName (ch.ehi.sqlgen.repository.DbTableName)5 CoordType (ch.interlis.ili2c.metamodel.CoordType)5 NumericType (ch.interlis.ili2c.metamodel.NumericType)5