Search in sources :

Example 1 with CoordType

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

the class ToXtfRecordConverter method addAttrValue.

public int addAttrValue(java.sql.ResultSet rs, int valuei, long sqlid, Iom_jObject iomObj, AttributeDef attr, ArrayList<StructWrapper> structQueue, ViewableWrapper table, FixIomObjectRefs fixref) throws SQLException {
    if (attr.getExtending() == null) {
        String attrName = attr.getName();
        String sqlAttrName = ili2sqlName.mapIliAttributeDef(attr, table.getSqlTablename(), null);
        if (attr.isDomainBoolean()) {
            boolean value = rs.getBoolean(valuei);
            valuei++;
            if (!rs.wasNull()) {
                if (value) {
                    iomObj.setattrvalue(attrName, "true");
                } else {
                    iomObj.setattrvalue(attrName, "false");
                }
            }
        } else if (attr.isDomainIli1Date()) {
            java.sql.Date value = rs.getDate(valuei);
            valuei++;
            if (!rs.wasNull()) {
                java.text.SimpleDateFormat fmt = new java.text.SimpleDateFormat("yyyyMMdd");
                GregorianCalendar date = new GregorianCalendar();
                date.setGregorianChange(PURE_GREGORIAN_CALENDAR);
                fmt.setCalendar(date);
                iomObj.setattrvalue(attrName, fmt.format(value));
            }
        } else if (attr.isDomainIli2Date()) {
            java.sql.Date value = rs.getDate(valuei);
            valuei++;
            if (!rs.wasNull()) {
                java.text.SimpleDateFormat fmt = new java.text.SimpleDateFormat("yyyy-MM-dd");
                GregorianCalendar date = new GregorianCalendar();
                date.setGregorianChange(PURE_GREGORIAN_CALENDAR);
                fmt.setCalendar(date);
                iomObj.setattrvalue(attrName, fmt.format(value));
            }
        } else if (attr.isDomainIli2Time()) {
            java.sql.Time value = rs.getTime(valuei);
            valuei++;
            if (!rs.wasNull()) {
                java.text.SimpleDateFormat fmt = new java.text.SimpleDateFormat("HH:mm:ss.SSS");
                iomObj.setattrvalue(attrName, fmt.format(value));
            }
        } else if (attr.isDomainIli2DateTime()) {
            java.sql.Timestamp value = rs.getTimestamp(valuei);
            valuei++;
            if (!rs.wasNull()) {
                // with timezone: yyyy-MM-dd'T'HH:mm:ss.SSSZ
                java.text.SimpleDateFormat fmt = new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
                GregorianCalendar date = new GregorianCalendar();
                date.setGregorianChange(PURE_GREGORIAN_CALENDAR);
                fmt.setCalendar(date);
                iomObj.setattrvalue(attrName, fmt.format(value));
            }
        } else {
            Type type = attr.getDomainResolvingAliases();
            if (type instanceof CompositionType) {
                if (TrafoConfigNames.CATALOGUE_REF_TRAFO_COALESCE.equals(trafoConfig.getAttrConfig(attr, TrafoConfigNames.CATALOGUE_REF_TRAFO))) {
                    Table catalogueReferenceTyp = ((CompositionType) type).getComponentType();
                    long value = rs.getLong(valuei);
                    valuei++;
                    if (!rs.wasNull()) {
                        IomObject catref = iomObj.addattrobj(attrName, catalogueReferenceTyp.getScopedName(null));
                        IomObject ref = catref.addattrobj(IliNames.CHBASE1_CATALOGUEREFERENCE_REFERENCE, "REF");
                        mapSqlid2Xtfid(fixref, value, ref, ((ReferenceType) ((AttributeDef) catalogueReferenceTyp.getAttributes().next()).getDomain()).getReferred());
                    }
                } else if (TrafoConfigNames.MULTISURFACE_TRAFO_COALESCE.equals(trafoConfig.getAttrConfig(attr, TrafoConfigNames.MULTISURFACE_TRAFO))) {
                    MultiSurfaceMapping attrMapping = multiSurfaceAttrs.getMapping(attr);
                    Table multiSurfaceType = ((CompositionType) type).getComponentType();
                    Table surfaceStructureType = ((CompositionType) ((AttributeDef) multiSurfaceType.getElement(AttributeDef.class, attrMapping.getBagOfSurfacesAttrName())).getDomain()).getComponentType();
                    String multiSurfaceQname = multiSurfaceType.getScopedName(null);
                    String surfaceStructureQname = surfaceStructureType.getScopedName(null);
                    SurfaceType surface = ((SurfaceType) ((AttributeDef) surfaceStructureType.getElement(AttributeDef.class, attrMapping.getSurfaceAttrName())).getDomainResolvingAliases());
                    CoordType coord = (CoordType) surface.getControlPointDomain().getType();
                    boolean is3D = coord.getDimensions().length == 3;
                    Object geomobj = rs.getObject(valuei);
                    valuei++;
                    if (!rs.wasNull()) {
                        try {
                            IomObject iomMultiSurface = geomConv.toIomMultiSurface(geomobj, sqlAttrName, is3D);
                            IomObject iomChbaseMultiSurface = new Iom_jObject(multiSurfaceQname, null);
                            int surfacec = iomMultiSurface.getattrvaluecount("surface");
                            for (int surfacei = 0; surfacei < surfacec; surfacei++) {
                                IomObject iomSurface = iomMultiSurface.getattrobj("surface", surfacei);
                                IomObject iomChbaseSurfaceStructure = iomChbaseMultiSurface.addattrobj(attrMapping.getBagOfSurfacesAttrName(), surfaceStructureQname);
                                IomObject iomSurfaceClone = new ch.interlis.iom_j.Iom_jObject("MULTISURFACE", null);
                                iomSurfaceClone.addattrobj("surface", iomSurface);
                                iomChbaseSurfaceStructure.addattrobj(attrMapping.getSurfaceAttrName(), iomSurfaceClone);
                            }
                            iomObj.addattrobj(attrName, iomChbaseMultiSurface);
                        } catch (ConverterException ex) {
                            EhiLogger.logError("Object " + sqlid + ": failed to convert surface/area", ex);
                        }
                    }
                } else if (TrafoConfigNames.MULTILINE_TRAFO_COALESCE.equals(trafoConfig.getAttrConfig(attr, TrafoConfigNames.MULTILINE_TRAFO))) {
                    MultiLineMapping attrMapping = multiLineAttrs.getMapping(attr);
                    Table multiLineType = ((CompositionType) type).getComponentType();
                    Table lineStructureType = ((CompositionType) ((AttributeDef) multiLineType.getElement(AttributeDef.class, attrMapping.getBagOfLinesAttrName())).getDomain()).getComponentType();
                    String multiLineQname = multiLineType.getScopedName(null);
                    String lineStructureQname = lineStructureType.getScopedName(null);
                    PolylineType surface = ((PolylineType) ((AttributeDef) lineStructureType.getElement(AttributeDef.class, attrMapping.getLineAttrName())).getDomainResolvingAliases());
                    CoordType coord = (CoordType) surface.getControlPointDomain().getType();
                    boolean is3D = coord.getDimensions().length == 3;
                    Object geomobj = rs.getObject(valuei);
                    valuei++;
                    if (!rs.wasNull()) {
                        try {
                            IomObject iomMultiPolygon = geomConv.toIomMultiPolyline(geomobj, sqlAttrName, is3D);
                            IomObject iomChbaseMultiLine = new Iom_jObject(multiLineQname, null);
                            int linec = iomMultiPolygon.getattrvaluecount(Wkb2iox.ATTR_POLYLINE);
                            for (int linei = 0; linei < linec; linei++) {
                                IomObject iomPolygon = iomMultiPolygon.getattrobj(Wkb2iox.ATTR_POLYLINE, linei);
                                IomObject iomChbaseSurfaceStructure = iomChbaseMultiLine.addattrobj(attrMapping.getBagOfLinesAttrName(), lineStructureQname);
                                iomChbaseSurfaceStructure.addattrobj(attrMapping.getLineAttrName(), iomPolygon);
                            }
                            iomObj.addattrobj(attrName, iomChbaseMultiLine);
                        } catch (ConverterException ex) {
                            EhiLogger.logError("Object " + sqlid + ": failed to convert polyline", ex);
                        }
                    }
                } else if (TrafoConfigNames.MULTIPOINT_TRAFO_COALESCE.equals(trafoConfig.getAttrConfig(attr, TrafoConfigNames.MULTIPOINT_TRAFO))) {
                    MultiPointMapping attrMapping = multiPointAttrs.getMapping(attr);
                    Table multiPointType = ((CompositionType) type).getComponentType();
                    Table pointStructureType = ((CompositionType) ((AttributeDef) multiPointType.getElement(AttributeDef.class, attrMapping.getBagOfPointsAttrName())).getDomain()).getComponentType();
                    String multiPointQname = multiPointType.getScopedName(null);
                    String pointStructureQname = pointStructureType.getScopedName(null);
                    CoordType coord = ((CoordType) ((AttributeDef) pointStructureType.getElement(AttributeDef.class, attrMapping.getPointAttrName())).getDomainResolvingAliases());
                    boolean is3D = coord.getDimensions().length == 3;
                    Object geomobj = rs.getObject(valuei);
                    valuei++;
                    if (!rs.wasNull()) {
                        try {
                            IomObject iomMultiPoint = geomConv.toIomMultiCoord(geomobj, sqlAttrName, is3D);
                            IomObject iomChbaseMultiPoint = new Iom_jObject(multiPointQname, null);
                            int pointc = iomMultiPoint.getattrvaluecount(Wkb2iox.ATTR_COORD);
                            for (int pointi = 0; pointi < pointc; pointi++) {
                                IomObject iomPoint = iomMultiPoint.getattrobj(Wkb2iox.ATTR_COORD, pointi);
                                IomObject iomChbasePointStructure = iomChbaseMultiPoint.addattrobj(attrMapping.getBagOfPointsAttrName(), pointStructureQname);
                                iomChbasePointStructure.addattrobj(attrMapping.getPointAttrName(), iomPoint);
                            }
                            iomObj.addattrobj(attrName, iomChbaseMultiPoint);
                        } catch (ConverterException ex) {
                            EhiLogger.logError("Object " + sqlid + ": failed to convert coord", ex);
                        }
                    }
                } else if (TrafoConfigNames.ARRAY_TRAFO_COALESCE.equals(trafoConfig.getAttrConfig(attr, TrafoConfigNames.ARRAY_TRAFO))) {
                    ArrayMapping attrMapping = arrayAttrs.getMapping(attr);
                    Object dbValue = rs.getObject(valuei);
                    valuei++;
                    if (!rs.wasNull()) {
                        try {
                            Table valueStructType = ((CompositionType) type).getComponentType();
                            String valueStructQname = valueStructType.getScopedName(null);
                            String[] iomArray = geomConv.toIomArray(attrMapping.getValueAttr(), dbValue, enumTypes);
                            for (int elei = 0; elei < iomArray.length; elei++) {
                                IomObject iomValueStruct = new Iom_jObject(valueStructQname, null);
                                iomValueStruct.setattrvalue(attrMapping.getValueAttr().getName(), iomArray[elei]);
                                iomObj.addattrobj(attrName, iomValueStruct);
                            }
                        } catch (ConverterException ex) {
                            EhiLogger.logError("Object " + sqlid + ": failed to convert array", ex);
                        }
                    }
                } else if (TrafoConfigNames.MULTILINGUAL_TRAFO_EXPAND.equals(trafoConfig.getAttrConfig(attr, TrafoConfigNames.MULTILINGUAL_TRAFO))) {
                    IomObject iomMulti = null;
                    Table multilingualTextType = ((CompositionType) type).getComponentType();
                    String multilingualTextQname = multilingualTextType.getScopedName(null);
                    String localizedTextQname = ((CompositionType) ((AttributeDef) multilingualTextType.getAttributes().next()).getDomain()).getComponentType().getScopedName(null);
                    for (String sfx : DbNames.MULTILINGUAL_TXT_COL_SUFFIXS) {
                        String value = rs.getString(valuei);
                        valuei++;
                        if (!rs.wasNull()) {
                            if (iomMulti == null) {
                                iomMulti = new Iom_jObject(multilingualTextQname, null);
                            }
                            IomObject iomTxt = iomMulti.addattrobj(IliNames.CHBASE1_LOCALISEDTEXT, localizedTextQname);
                            iomTxt.setattrvalue(IliNames.CHBASE1_LOCALISEDTEXT_LANGUAGE, sfx.length() == 0 ? null : sfx.substring(LEN_LANG_PREFIX));
                            iomTxt.setattrvalue(IliNames.CHBASE1_LOCALISEDTEXT_TEXT, value);
                        }
                    }
                    if (iomMulti != null) {
                        iomObj.addattrobj(attrName, iomMulti);
                    }
                } else {
                    // enque iomObj as parent
                    structQueue.add(new StructWrapper(sqlid, attr, iomObj, table));
                }
            } else if (type instanceof PolylineType) {
                Object geomobj = rs.getObject(valuei);
                valuei++;
                if (!rs.wasNull()) {
                    try {
                        boolean is3D = ((CoordType) ((PolylineType) type).getControlPointDomain().getType()).getDimensions().length == 3;
                        IomObject polyline = geomConv.toIomPolyline(geomobj, sqlAttrName, is3D);
                        iomObj.addattrobj(attrName, polyline);
                    } catch (ConverterException ex) {
                        EhiLogger.logError("Object " + sqlid + ": failed to convert polyline", ex);
                    }
                }
            } else if (type instanceof SurfaceOrAreaType) {
                if (createItfLineTables) {
                } else {
                    Object geomobj = rs.getObject(valuei);
                    valuei++;
                    if (!rs.wasNull()) {
                        try {
                            boolean is3D = ((CoordType) ((SurfaceOrAreaType) type).getControlPointDomain().getType()).getDimensions().length == 3;
                            IomObject surface = geomConv.toIomSurface(geomobj, sqlAttrName, is3D);
                            iomObj.addattrobj(attrName, surface);
                        } catch (ConverterException ex) {
                            EhiLogger.logError("Object " + sqlid + ": failed to convert surface/area", ex);
                        }
                    }
                }
                if (createItfAreaRef) {
                    if (type instanceof AreaType) {
                        Object geomobj = rs.getObject(valuei);
                        valuei++;
                        if (!rs.wasNull()) {
                            try {
                                boolean is3D = false;
                                IomObject coord = geomConv.toIomCoord(geomobj, sqlAttrName, is3D);
                                iomObj.addattrobj(attrName, coord);
                            } catch (ConverterException ex) {
                                EhiLogger.logError("Object " + sqlid + ": failed to convert coord", ex);
                            }
                        }
                    }
                }
            } else if (type instanceof CoordType) {
                Object geomobj = rs.getObject(valuei);
                valuei++;
                if (!rs.wasNull()) {
                    try {
                        boolean is3D = ((CoordType) type).getDimensions().length == 3;
                        IomObject coord = geomConv.toIomCoord(geomobj, sqlAttrName, is3D);
                        iomObj.addattrobj(attrName, coord);
                    } catch (ConverterException ex) {
                        EhiLogger.logError("Object " + sqlid + ": failed to convert coord", ex);
                    }
                }
            } else if (type instanceof EnumerationType) {
                if (createEnumColAsItfCode) {
                    int value = rs.getInt(valuei);
                    valuei++;
                    if (!rs.wasNull()) {
                        iomObj.setattrvalue(attrName, mapItfCode2XtfCode((EnumerationType) type, value));
                    }
                } else {
                    String value = rs.getString(valuei);
                    valuei++;
                    if (!rs.wasNull()) {
                        iomObj.setattrvalue(attrName, value);
                    }
                }
            } else if (type instanceof ReferenceType) {
                ArrayList<ViewableWrapper> targetTables = getTargetTables(((ReferenceType) type).getReferred());
                boolean refAlreadyDefined = false;
                for (ViewableWrapper targetTable : targetTables) {
                    long value = rs.getLong(valuei);
                    valuei++;
                    if (!rs.wasNull()) {
                        if (refAlreadyDefined) {
                            sqlAttrName = ili2sqlName.mapIliAttributeDef(attr, table.getSqlTablename(), targetTable.getSqlTablename(), targetTables.size() > 1);
                            EhiLogger.logAdaption("Table " + table.getSqlTablename() + "(id " + sqlid + ") more than one value for refattr " + attrName + "; value of " + sqlAttrName + " ignored");
                        } else {
                            IomObject ref = iomObj.addattrobj(attrName, "REF");
                            mapSqlid2Xtfid(fixref, value, ref, ((ReferenceType) type).getReferred());
                            refAlreadyDefined = true;
                        }
                    }
                }
            } else if (type instanceof BlackboxType) {
                if (((BlackboxType) type).getKind() == BlackboxType.eXML) {
                    Object obj = rs.getObject(valuei);
                    valuei++;
                    if (!rs.wasNull()) {
                        try {
                            iomObj.setattrvalue(attrName, geomConv.toIomXml(obj));
                        } catch (ConverterException ex) {
                            EhiLogger.logError("Object " + sqlid + ": failed to convert blackbox xml", ex);
                        }
                    }
                } else {
                    Object obj = rs.getObject(valuei);
                    valuei++;
                    if (!rs.wasNull()) {
                        try {
                            iomObj.setattrvalue(attrName, geomConv.toIomBlob(obj));
                        } catch (ConverterException ex) {
                            EhiLogger.logError("Object " + sqlid + ": failed to convert blackbox binary", ex);
                        }
                    }
                }
            } else {
                String value = rs.getString(valuei);
                valuei++;
                if (!rs.wasNull()) {
                    iomObj.setattrvalue(attrName, value);
                }
            }
        }
    }
    return valuei;
}
Also used : ConverterException(ch.ehi.ili2db.converter.ConverterException) SurfaceOrAreaType(ch.interlis.ili2c.metamodel.SurfaceOrAreaType) ArrayList(java.util.ArrayList) ViewableWrapper(ch.ehi.ili2db.mapping.ViewableWrapper) CompositionType(ch.interlis.ili2c.metamodel.CompositionType) AreaType(ch.interlis.ili2c.metamodel.AreaType) SurfaceOrAreaType(ch.interlis.ili2c.metamodel.SurfaceOrAreaType) Iom_jObject(ch.interlis.iom_j.Iom_jObject) ReferenceType(ch.interlis.ili2c.metamodel.ReferenceType) IomObject(ch.interlis.iom.IomObject) AttributeDef(ch.interlis.ili2c.metamodel.AttributeDef) PolylineType(ch.interlis.ili2c.metamodel.PolylineType) Table(ch.interlis.ili2c.metamodel.Table) Iom_jObject(ch.interlis.iom_j.Iom_jObject) MultiPointMapping(ch.ehi.ili2db.mapping.MultiPointMapping) BlackboxType(ch.interlis.ili2c.metamodel.BlackboxType) GregorianCalendar(java.util.GregorianCalendar) EnumerationType(ch.interlis.ili2c.metamodel.EnumerationType) SurfaceType(ch.interlis.ili2c.metamodel.SurfaceType) MultiSurfaceMapping(ch.ehi.ili2db.mapping.MultiSurfaceMapping) SurfaceType(ch.interlis.ili2c.metamodel.SurfaceType) CompositionType(ch.interlis.ili2c.metamodel.CompositionType) PolylineType(ch.interlis.ili2c.metamodel.PolylineType) Type(ch.interlis.ili2c.metamodel.Type) EnumerationType(ch.interlis.ili2c.metamodel.EnumerationType) BlackboxType(ch.interlis.ili2c.metamodel.BlackboxType) AreaType(ch.interlis.ili2c.metamodel.AreaType) ReferenceType(ch.interlis.ili2c.metamodel.ReferenceType) SurfaceOrAreaType(ch.interlis.ili2c.metamodel.SurfaceOrAreaType) ObjectType(ch.interlis.ili2c.metamodel.ObjectType) CoordType(ch.interlis.ili2c.metamodel.CoordType) ArrayMapping(ch.ehi.ili2db.mapping.ArrayMapping) Iom_jObject(ch.interlis.iom_j.Iom_jObject) IomObject(ch.interlis.iom.IomObject) MultiLineMapping(ch.ehi.ili2db.mapping.MultiLineMapping) CoordType(ch.interlis.ili2c.metamodel.CoordType)

Example 2 with CoordType

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

the class ToXtfRecordConverter method addAttrToQueryStmt.

public String addAttrToQueryStmt(StringBuffer ret, String sep, String tableAlias, AttributeDef attr, String sqlTableName) {
    if (attr.getExtending() == null) {
        Type type = attr.getDomainResolvingAliases();
        String attrSqlName = ili2sqlName.mapIliAttributeDef(attr, sqlTableName, null);
        if (attr.isDomainIli1Date()) {
            ret.append(sep);
            sep = ",";
            ret.append(geomConv.getSelectValueWrapperDate(makeColumnRef(tableAlias, attrSqlName)));
        } else if (attr.isDomainIli2Date()) {
            ret.append(sep);
            sep = ",";
            ret.append(geomConv.getSelectValueWrapperDate(makeColumnRef(tableAlias, attrSqlName)));
        } else if (attr.isDomainIli2Time()) {
            ret.append(sep);
            sep = ",";
            ret.append(geomConv.getSelectValueWrapperTime(makeColumnRef(tableAlias, attrSqlName)));
        } else if (attr.isDomainIli2DateTime()) {
            ret.append(sep);
            sep = ",";
            ret.append(geomConv.getSelectValueWrapperDateTime(makeColumnRef(tableAlias, attrSqlName)));
        } else if (type instanceof CompositionType) {
            if (TrafoConfigNames.CATALOGUE_REF_TRAFO_COALESCE.equals(trafoConfig.getAttrConfig(attr, TrafoConfigNames.CATALOGUE_REF_TRAFO))) {
                ret.append(sep);
                sep = ",";
                ret.append(makeColumnRef(tableAlias, attrSqlName));
            } else if (TrafoConfigNames.MULTISURFACE_TRAFO_COALESCE.equals(trafoConfig.getAttrConfig(attr, TrafoConfigNames.MULTISURFACE_TRAFO))) {
                ret.append(sep);
                sep = ",";
                ret.append(geomConv.getSelectValueWrapperMultiSurface(makeColumnRef(tableAlias, attrSqlName)));
                multiSurfaceAttrs.addMultiSurfaceAttr(attr);
            } else if (TrafoConfigNames.MULTILINE_TRAFO_COALESCE.equals(trafoConfig.getAttrConfig(attr, TrafoConfigNames.MULTILINE_TRAFO))) {
                ret.append(sep);
                sep = ",";
                ret.append(geomConv.getSelectValueWrapperMultiPolyline(makeColumnRef(tableAlias, attrSqlName)));
                multiLineAttrs.addMultiLineAttr(attr);
            } else if (TrafoConfigNames.MULTIPOINT_TRAFO_COALESCE.equals(trafoConfig.getAttrConfig(attr, TrafoConfigNames.MULTIPOINT_TRAFO))) {
                ret.append(sep);
                sep = ",";
                ret.append(geomConv.getSelectValueWrapperMultiCoord(makeColumnRef(tableAlias, attrSqlName)));
                multiPointAttrs.addMultiPointAttr(attr);
            } else if (TrafoConfigNames.ARRAY_TRAFO_COALESCE.equals(trafoConfig.getAttrConfig(attr, TrafoConfigNames.ARRAY_TRAFO))) {
                ret.append(sep);
                sep = ",";
                ret.append(geomConv.getSelectValueWrapperArray(makeColumnRef(tableAlias, attrSqlName)));
                arrayAttrs.addArrayAttr(attr);
            } else if (TrafoConfigNames.MULTILINGUAL_TRAFO_EXPAND.equals(trafoConfig.getAttrConfig(attr, TrafoConfigNames.MULTILINGUAL_TRAFO))) {
                for (String sfx : DbNames.MULTILINGUAL_TXT_COL_SUFFIXS) {
                    ret.append(sep);
                    sep = ",";
                    ret.append(makeColumnRef(tableAlias, attrSqlName + sfx));
                }
            }
        } else if (type instanceof PolylineType) {
            ret.append(sep);
            sep = ",";
            ret.append(geomConv.getSelectValueWrapperPolyline(makeColumnRef(tableAlias, attrSqlName)));
        } else if (type instanceof SurfaceOrAreaType) {
            if (createItfLineTables) {
            } else {
                ret.append(sep);
                sep = ",";
                ret.append(geomConv.getSelectValueWrapperSurface(makeColumnRef(tableAlias, attrSqlName)));
            }
            if (createItfAreaRef) {
                if (type instanceof AreaType) {
                    ret.append(sep);
                    sep = ",";
                    ret.append(geomConv.getSelectValueWrapperCoord(makeColumnRef(tableAlias, attrSqlName + DbNames.ITF_MAINTABLE_GEOTABLEREF_COL_SUFFIX)));
                }
            }
        } else if (type instanceof CoordType) {
            ret.append(sep);
            sep = ",";
            ret.append(geomConv.getSelectValueWrapperCoord(makeColumnRef(tableAlias, attrSqlName)));
        } else if (type instanceof ReferenceType) {
            ArrayList<ViewableWrapper> targetTables = getTargetTables(((ReferenceType) type).getReferred());
            for (ViewableWrapper targetTable : targetTables) {
                attrSqlName = ili2sqlName.mapIliAttributeDef(attr, sqlTableName, targetTable.getSqlTablename(), targetTables.size() > 1);
                ret.append(sep);
                sep = ",";
                ret.append(makeColumnRef(tableAlias, attrSqlName));
            }
        } else {
            ret.append(sep);
            sep = ",";
            ret.append(makeColumnRef(tableAlias, attrSqlName));
        }
    }
    return sep;
}
Also used : PolylineType(ch.interlis.ili2c.metamodel.PolylineType) SurfaceType(ch.interlis.ili2c.metamodel.SurfaceType) CompositionType(ch.interlis.ili2c.metamodel.CompositionType) PolylineType(ch.interlis.ili2c.metamodel.PolylineType) Type(ch.interlis.ili2c.metamodel.Type) EnumerationType(ch.interlis.ili2c.metamodel.EnumerationType) BlackboxType(ch.interlis.ili2c.metamodel.BlackboxType) AreaType(ch.interlis.ili2c.metamodel.AreaType) ReferenceType(ch.interlis.ili2c.metamodel.ReferenceType) SurfaceOrAreaType(ch.interlis.ili2c.metamodel.SurfaceOrAreaType) ObjectType(ch.interlis.ili2c.metamodel.ObjectType) CoordType(ch.interlis.ili2c.metamodel.CoordType) SurfaceOrAreaType(ch.interlis.ili2c.metamodel.SurfaceOrAreaType) ViewableWrapper(ch.ehi.ili2db.mapping.ViewableWrapper) CompositionType(ch.interlis.ili2c.metamodel.CompositionType) AreaType(ch.interlis.ili2c.metamodel.AreaType) SurfaceOrAreaType(ch.interlis.ili2c.metamodel.SurfaceOrAreaType) ReferenceType(ch.interlis.ili2c.metamodel.ReferenceType) CoordType(ch.interlis.ili2c.metamodel.CoordType)

Example 3 with CoordType

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

the class TransferToXtf method genClassHelper.

private void genClassHelper(Viewable aclass) {
    boolean doStruct = false;
    if (aclass instanceof Table) {
        doStruct = !((Table) aclass).isIdentifiable();
    }
    if (doStruct) {
        expgen.println("private void add" + aclass.getName() + "(String parentTid,String parentAttrSql,IomObject parent,String parentAttrIli)");
    } else {
        expgen.println("private void add" + aclass.getName() + "(String subset)");
        String addany = "if(iliClassName.equals(\"" + aclass.getScopedName(null) + "\")){add" + aclass.getName() + "(select);}";
        addanyLines.add(addany);
    }
    expgen.println("{");
    expgen.indent();
    expgen.println("String tabName=\"" + createQueryStmtFromClause(aclass) + "\";");
    expgen.println("String stmt=\"" + recConv.createQueryStmt(aclass, null, null) + "\";");
    if (!doStruct) {
        expgen.println("if(subset!=null){");
        expgen.println("stmt=stmt+\" AND \"+subset;");
        expgen.println("}");
    }
    expgen.println("EhiLogger.traceBackendCmd(stmt);");
    expgen.println("java.sql.PreparedStatement dbstmt = null;");
    expgen.println("try{");
    expgen.indent();
    // expgen.println("dbstmt = conn.createStatement();");
    // expgen.println("java.sql.ResultSet rs=dbstmt.executeQuery(stmt);");
    expgen.println("dbstmt = conn.prepareStatement(stmt);");
    expgen.println("dbstmt.clearParameters();");
    if (doStruct) {
        expgen.println("dbstmt.setString(1,parentTid);");
        expgen.println("dbstmt.setString(2,parentAttrSql);");
    }
    expgen.println("java.sql.ResultSet rs=dbstmt.executeQuery();");
    expgen.println("while(rs.next()){");
    expgen.indent();
    expgen.println("String tid=DbUtility.getString(rs,\"T_Id\",false,tabName);");
    expgen.println("String recInfo=tabName+\" \"+tid;");
    expgen.println("IomObject iomObj;");
    if (!doStruct) {
        expgen.println("iomObj=newObject(\"" + aclass.getScopedName(null) + "\",mapId(\"" + recConv.getSqlType(aclass) + "\",tid));");
    } else {
        expgen.println("iomObj=(IomObject)parent.addattrobj(parentAttrIli,\"" + aclass.getScopedName(null) + "\");");
    }
    Iterator iter = aclass.getAttributesAndRoles2();
    while (iter.hasNext()) {
        ViewableTransferElement obj = (ViewableTransferElement) iter.next();
        if (obj.obj instanceof AttributeDef) {
            AttributeDef attr = (AttributeDef) obj.obj;
            if (attr.getExtending() == null) {
                String attrName = attr.getName();
                String sqlAttrName = ili2sqlName.mapIliAttributeDef(attr, recConv.getSqlType(aclass).getName(), null);
                Type type = attr.getDomain();
                if ((type instanceof TypeAlias) && Ili2cUtility.isBoolean(td, type)) {
                    expgen.println("Boolean prop_" + attrName + "=Db2Xtf.getBoolean(rs,\"" + sqlAttrName + "\"," + (type.isMandatoryConsideringAliases() ? "false" : "true") + ",recInfo,iomObj,\"" + attrName + "\");");
                } else {
                    type = attr.getDomainResolvingAliases();
                    if (type instanceof CompositionType) {
                        // enque iomObj as parent
                        // enqueueStructAttr(new StructWrapper(tid,attr,iomObj));
                        CompositionType ct = (CompositionType) type;
                        expgen.println("add" + ct.getComponentType().getName() + "(tid,\"" + ili2sqlName.mapIliAttributeDef(attr, recConv.getSqlType(aclass).getName(), null) + "\",iomObj,\"" + attr.getName() + "\");");
                    } else if (type instanceof PolylineType) {
                    } else if (type instanceof SurfaceOrAreaType) {
                    } else if (type instanceof CoordType) {
                    } else if (type instanceof EnumerationType) {
                        String enumName = null;
                        if (attr.getDomain() instanceof TypeAlias) {
                            Domain domainDef = ((TypeAlias) attr.getDomain()).getAliasing();
                            enumName = domainDef.getScopedName(null);
                        } else {
                            enumName = aclass.getScopedName(null) + "->" + attrName;
                            enumTypes.add(enumName);
                        }
                        expgen.println("String prop_" + attrName + "=Db2Xtf.getEnum(rs,\"" + sqlAttrName + "\"," + (type.isMandatoryConsideringAliases() ? "false" : "true") + ",recInfo,getEnumMapper(\"" + enumName + "\"),iomObj,\"" + attrName + "\");");
                    } else {
                        expgen.println("String prop_" + attrName + "=Db2Xtf.getString(rs,\"" + sqlAttrName + "\"," + (type.isMandatoryConsideringAliases() ? "false" : "true") + ",recInfo,iomObj,\"" + attrName + "\");");
                    }
                }
            }
        }
        if (obj.obj instanceof RoleDef) {
            RoleDef role = (RoleDef) obj.obj;
            if (role.getExtending() == null) {
                String roleName = role.getName();
                String sqlRoleName = ili2sqlName.mapIliRoleDef(role, recConv.getSqlType(aclass).getName(), recConv.getSqlType(role.getDestination()).getName());
                // a role of an embedded association?
                if (obj.embedded) {
                    AssociationDef roleOwner = (AssociationDef) role.getContainer();
                    if (roleOwner.getDerivedFrom() == null) {
                        // TODO if(orderPos!=0){
                        expgen.println("String prop_" + roleName + "=Db2Xtf.getRef(rs,\"" + sqlRoleName + "\"," + "true" + ",recInfo,this,\"" + recConv.getSqlType(role.getDestination()) + "\",iomObj,\"" + roleName + "\",\"" + roleOwner.getScopedName(null) + "\");");
                    }
                } else {
                    // TODO if(orderPos!=0){
                    expgen.println("String prop_" + roleName + "=Db2Xtf.getRef(rs,\"" + sqlRoleName + "\"," + "false" + ",recInfo,this,\"" + recConv.getSqlType(role.getDestination()) + "\",iomObj,\"" + roleName + "\",\"REF\");");
                }
            }
        }
    }
    // add referenced and referencing objects if it is not a struct
    if (!doStruct && aclass instanceof AbstractClassDef) {
        AbstractClassDef aclass2 = (AbstractClassDef) aclass;
        Iterator associ = aclass2.getTargetForRoles();
        while (associ.hasNext()) {
            RoleDef roleThis = (RoleDef) associ.next();
            if (roleThis.getKind() == RoleDef.Kind.eAGGREGATE || roleThis.getKind() == RoleDef.Kind.eCOMPOSITE) {
                RoleDef oppEnd = roleThis.getOppEnd();
                if (roleThis.isAssociationEmbedded()) {
                    expgen.println("addPendingObject(\"" + oppEnd.getDestination().getScopedName(null) + "\",\"T_Id\",prop_" + oppEnd.getName() + ");");
                } else if (oppEnd.isAssociationEmbedded()) {
                    expgen.println("addPendingObject(\"" + oppEnd.getDestination().getScopedName(null) + "\",\"" + ili2sqlName.mapIliRoleDef(roleThis, null, null) + "\",tid);");
                } else {
                    expgen.println("addPendingObject(\"" + ((AssociationDef) (oppEnd.getContainer())).getScopedName(null) + "\",\"" + ili2sqlName.mapIliRoleDef(roleThis, null, null) + "\",prop_" + roleThis.getName() + ");");
                }
            }
        }
    }
    // writeObject if it is not a struct
    if (!doStruct) {
        expgen.println("writeObject(iomObj);");
    }
    expgen.unindent();
    expgen.println("}");
    expgen.unindent();
    expgen.println("}catch(java.sql.SQLException ex){");
    expgen.indent();
    expgen.println("EhiLogger.logError(\"failed to query \"+tabName,ex);");
    expgen.unindent();
    expgen.println("}finally{");
    expgen.indent();
    expgen.println("if(dbstmt!=null){");
    expgen.indent();
    expgen.println("try{");
    expgen.indent();
    expgen.println("dbstmt.close();");
    expgen.unindent();
    expgen.println("}catch(java.sql.SQLException ex){");
    expgen.indent();
    expgen.println("EhiLogger.logError(\"failed to close query of \"+tabName,ex);");
    expgen.unindent();
    expgen.println("}");
    expgen.unindent();
    expgen.println("}");
    expgen.unindent();
    expgen.println("}");
    expgen.unindent();
    expgen.println("}");
}
Also used : ViewableTransferElement(ch.interlis.ili2c.metamodel.ViewableTransferElement) PolylineType(ch.interlis.ili2c.metamodel.PolylineType) Table(ch.interlis.ili2c.metamodel.Table) SurfaceOrAreaType(ch.interlis.ili2c.metamodel.SurfaceOrAreaType) RoleDef(ch.interlis.ili2c.metamodel.RoleDef) EnumerationType(ch.interlis.ili2c.metamodel.EnumerationType) TypeAlias(ch.interlis.ili2c.metamodel.TypeAlias) CompositionType(ch.interlis.ili2c.metamodel.CompositionType) PolylineType(ch.interlis.ili2c.metamodel.PolylineType) Type(ch.interlis.ili2c.metamodel.Type) SurfaceOrAreaType(ch.interlis.ili2c.metamodel.SurfaceOrAreaType) SurfaceType(ch.interlis.ili2c.metamodel.SurfaceType) CompositionType(ch.interlis.ili2c.metamodel.CompositionType) EnumerationType(ch.interlis.ili2c.metamodel.EnumerationType) CoordType(ch.interlis.ili2c.metamodel.CoordType) Iterator(java.util.Iterator) AssociationDef(ch.interlis.ili2c.metamodel.AssociationDef) AttributeDef(ch.interlis.ili2c.metamodel.AttributeDef) AbstractClassDef(ch.interlis.ili2c.metamodel.AbstractClassDef) Domain(ch.interlis.ili2c.metamodel.Domain) CoordType(ch.interlis.ili2c.metamodel.CoordType)

Example 4 with CoordType

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

the class MultiPointMappings method addMultiPointAttr.

public void addMultiPointAttr(AttributeDef multiPointAttr) {
    String bagOfPointsAttrName = null;
    String pointAttrName = null;
    // validate structure
    // create mapping
    Type multiPointTypeo = multiPointAttr.getDomain();
    if (!(multiPointTypeo instanceof CompositionType)) {
        throw new IllegalArgumentException("not a valid multipoint attribute " + multiPointAttr.getScopedName(null));
    } else {
        CompositionType multiPointType = (CompositionType) multiPointTypeo;
        Table multiPointStruct = multiPointType.getComponentType();
        Iterator<ViewableTransferElement> it = multiPointStruct.getAttributesAndRoles2();
        if (!it.hasNext()) {
            throw new IllegalArgumentException("not a valid multipoint structure " + multiPointStruct.getScopedName(null));
        }
        ViewableTransferElement prop = it.next();
        if (!(prop.obj instanceof AttributeDef)) {
            throw new IllegalArgumentException("not a valid multipoint structure " + multiPointStruct.getScopedName(null));
        }
        AttributeDef pointsAttr = (AttributeDef) prop.obj;
        bagOfPointsAttrName = pointsAttr.getName();
        Type pointsTypeo = pointsAttr.getDomain();
        if (!(pointsTypeo instanceof CompositionType)) {
            throw new IllegalArgumentException("not a valid multipoint structure " + multiPointStruct.getScopedName(null));
        } else {
            CompositionType pointsType = (CompositionType) pointsTypeo;
            Table pointStruct = pointsType.getComponentType();
            Iterator<ViewableTransferElement> it2 = pointStruct.getAttributesAndRoles2();
            if (!it2.hasNext()) {
                throw new IllegalArgumentException("not a valid point structure " + pointStruct.getScopedName(null));
            }
            ViewableTransferElement prop2 = it2.next();
            if (!(prop2.obj instanceof AttributeDef)) {
                throw new IllegalArgumentException("not a valid point structure " + pointStruct.getScopedName(null));
            }
            AttributeDef pointAttr = (AttributeDef) prop2.obj;
            Type pointType = pointAttr.getDomainResolvingAliases();
            if (!(pointType instanceof CoordType)) {
                throw new IllegalArgumentException("not a valid point structure " + pointStruct.getScopedName(null));
            }
            pointAttrName = pointAttr.getName();
        }
    }
    MultiPointMapping mapping = new MultiPointMapping(bagOfPointsAttrName, pointAttrName);
    mappings.put(multiPointAttr, mapping);
}
Also used : ViewableTransferElement(ch.interlis.ili2c.metamodel.ViewableTransferElement) CompositionType(ch.interlis.ili2c.metamodel.CompositionType) Type(ch.interlis.ili2c.metamodel.Type) CoordType(ch.interlis.ili2c.metamodel.CoordType) Table(ch.interlis.ili2c.metamodel.Table) AttributeDef(ch.interlis.ili2c.metamodel.AttributeDef) CompositionType(ch.interlis.ili2c.metamodel.CompositionType) CoordType(ch.interlis.ili2c.metamodel.CoordType)

Example 5 with CoordType

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

Aggregations

CoordType (ch.interlis.ili2c.metamodel.CoordType)13 Type (ch.interlis.ili2c.metamodel.Type)9 CompositionType (ch.interlis.ili2c.metamodel.CompositionType)8 SurfaceOrAreaType (ch.interlis.ili2c.metamodel.SurfaceOrAreaType)8 SurfaceType (ch.interlis.ili2c.metamodel.SurfaceType)8 EnumerationType (ch.interlis.ili2c.metamodel.EnumerationType)7 PolylineType (ch.interlis.ili2c.metamodel.PolylineType)7 AttributeDef (ch.interlis.ili2c.metamodel.AttributeDef)6 ObjectType (ch.interlis.ili2c.metamodel.ObjectType)6 ReferenceType (ch.interlis.ili2c.metamodel.ReferenceType)6 AreaType (ch.interlis.ili2c.metamodel.AreaType)5 BlackboxType (ch.interlis.ili2c.metamodel.BlackboxType)5 ViewableWrapper (ch.ehi.ili2db.mapping.ViewableWrapper)4 Domain (ch.interlis.ili2c.metamodel.Domain)4 LineType (ch.interlis.ili2c.metamodel.LineType)4 NumericType (ch.interlis.ili2c.metamodel.NumericType)4 Table (ch.interlis.ili2c.metamodel.Table)4 IomObject (ch.interlis.iom.IomObject)4 ConverterException (ch.ehi.ili2db.converter.ConverterException)3 ArrayMapping (ch.ehi.ili2db.mapping.ArrayMapping)3