Search in sources :

Example 1 with BlackboxType

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

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

the class PostgisColumnConverter method fromIomArray.

@Override
public Object fromIomArray(ch.interlis.ili2c.metamodel.AttributeDef attr, String[] iomValues, EnumCodeMapper enumTypes) throws SQLException, ConverterException {
    java.sql.Array array = null;
    ch.interlis.ili2c.metamodel.Type type = attr.getDomainResolvingAliases();
    if (attr.isDomainBoolean()) {
        Boolean[] values = new Boolean[iomValues.length];
        for (int i = 0; i < values.length; i++) {
            if (iomValues[i].equals("true")) {
                values[i] = true;
            } else {
                values[i] = false;
            }
        }
        array = conn.createArrayOf("bool", values);
    } else if (attr.isDomainIli1Date()) {
        java.sql.Date[] values = new java.sql.Date[iomValues.length];
        for (int i = 0; i < values.length; i++) {
            String iomValue = iomValues[i];
            GregorianCalendar gdate = new GregorianCalendar(Integer.parseInt(iomValue.substring(0, 4)), Integer.parseInt(iomValue.substring(4, 6)) - 1, Integer.parseInt(iomValue.substring(6, 8)));
            values[i] = new java.sql.Date(gdate.getTimeInMillis());
        }
        array = conn.createArrayOf("DATE", values);
    } else if (attr.isDomainIliUuid()) {
        Object[] values = new Object[iomValues.length];
        for (int i = 0; i < values.length; i++) {
            String iomValue = iomValues[i];
            values[i] = fromIomUuid(iomValue);
        }
        array = conn.createArrayOf("uuid", values);
    } else if (attr.isDomainIli2Date()) {
        java.sql.Date[] values = new java.sql.Date[iomValues.length];
        for (int i = 0; i < values.length; i++) {
            String iomValue = iomValues[i];
            XMLGregorianCalendar xmldate;
            try {
                xmldate = javax.xml.datatype.DatatypeFactory.newInstance().newXMLGregorianCalendar(iomValue);
            } catch (DatatypeConfigurationException e) {
                throw new ConverterException(e);
            }
            values[i] = new java.sql.Date(xmldate.toGregorianCalendar().getTimeInMillis());
        }
        array = conn.createArrayOf("DATE", values);
    } else if (attr.isDomainIli2DateTime()) {
        java.sql.Timestamp[] values = new java.sql.Timestamp[iomValues.length];
        for (int i = 0; i < values.length; i++) {
            String iomValue = iomValues[i];
            XMLGregorianCalendar xmldate;
            try {
                xmldate = javax.xml.datatype.DatatypeFactory.newInstance().newXMLGregorianCalendar(iomValue);
            } catch (DatatypeConfigurationException e) {
                throw new ConverterException(e);
            }
            values[i] = new java.sql.Timestamp(xmldate.toGregorianCalendar().getTimeInMillis());
        }
        array = conn.createArrayOf("TIMESTAMP", values);
    } else if (attr.isDomainIli2Time()) {
        java.sql.Time[] values = new java.sql.Time[iomValues.length];
        for (int i = 0; i < values.length; i++) {
            String iomValue = iomValues[i];
            XMLGregorianCalendar xmldate;
            try {
                xmldate = javax.xml.datatype.DatatypeFactory.newInstance().newXMLGregorianCalendar(iomValue);
            } catch (DatatypeConfigurationException e) {
                throw new ConverterException(e);
            }
            values[i] = new java.sql.Time(xmldate.toGregorianCalendar().getTimeInMillis());
        }
        array = conn.createArrayOf("TIME", values);
    } else if (type instanceof EnumerationType) {
        if (createEnumColAsItfCode) {
            Integer[] values = new Integer[iomValues.length];
            for (int i = 0; i < values.length; i++) {
                String iomValue = iomValues[i];
                int itfCode = Integer.parseInt(enumTypes.mapXtfCode2ItfCode((EnumerationType) type, iomValue));
                values[i] = itfCode;
            }
            array = conn.createArrayOf("INTEGER", values);
        } else {
            array = conn.createArrayOf("VARCHAR", iomValues);
        }
    } else if (type instanceof NumericType) {
        if (type.isAbstract()) {
        } else {
            PrecisionDecimal min = ((NumericType) type).getMinimum();
            PrecisionDecimal max = ((NumericType) type).getMaximum();
            if (min.getAccuracy() > 0) {
                Double[] values = new Double[iomValues.length];
                for (int i = 0; i < values.length; i++) {
                    String iomValue = iomValues[i];
                    double value = Double.parseDouble(iomValue);
                    values[i] = value;
                }
                array = conn.createArrayOf("DECIMAL", values);
            } else {
                Integer[] values = new Integer[iomValues.length];
                for (int i = 0; i < values.length; i++) {
                    String iomValue = iomValues[i];
                    int value = (int) Math.round(Double.parseDouble(iomValue));
                    values[i] = value;
                }
                array = conn.createArrayOf("INTEGER", values);
            }
        }
    } else if (type instanceof TextType) {
        array = conn.createArrayOf("VARCHAR", iomValues);
    } else if (type instanceof BlackboxType) {
        if (((BlackboxType) type).getKind() == BlackboxType.eXML) {
            Object[] values = new Object[iomValues.length];
            for (int i = 0; i < values.length; i++) {
                String iomValue = iomValues[i];
                values[i] = fromIomXml(iomValue);
            }
            array = conn.createArrayOf("xml", values);
        } else {
            Object[] values = new Object[iomValues.length];
            for (int i = 0; i < values.length; i++) {
                String iomValue = iomValues[i];
                values[i] = fromIomBlob(iomValue);
            }
            array = conn.createArrayOf("bytea", values);
        }
    } else {
        throw new IllegalArgumentException(attr.getScopedName());
    }
    return array;
}
Also used : NumericType(ch.interlis.ili2c.metamodel.NumericType) ConverterException(ch.ehi.ili2db.converter.ConverterException) DbColTime(ch.ehi.sqlgen.repository.DbColTime) DbColDateTime(ch.ehi.sqlgen.repository.DbColDateTime) PrecisionDecimal(ch.interlis.ili2c.metamodel.PrecisionDecimal) DbColBoolean(ch.ehi.sqlgen.repository.DbColBoolean) BlackboxType(ch.interlis.ili2c.metamodel.BlackboxType) GregorianCalendar(java.util.GregorianCalendar) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) EnumerationType(ch.interlis.ili2c.metamodel.EnumerationType) DbColDate(ch.ehi.sqlgen.repository.DbColDate) TextType(ch.interlis.ili2c.metamodel.TextType) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) IomObject(ch.interlis.iom.IomObject)

Example 3 with BlackboxType

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

the class FromIliRecordConverter method createSimpleDbCol.

private boolean createSimpleDbCol(DbTable dbTable, Viewable aclass, AttributeDef attr, Type type, Holder<DbColumn> dbCol, Holder<Unit> unitDef, Holder<Boolean> mText, ArrayList<DbColumn> dbColExts) {
    if (attr.isDomainBoolean()) {
        dbCol.value = new DbColBoolean();
    } else if (attr.isDomainIli1Date()) {
        dbCol.value = new DbColDate();
    } else if (attr.isDomainIliUuid()) {
        dbCol.value = new DbColUuid();
    } else if (attr.isDomainIli2Date()) {
        dbCol.value = new DbColDate();
    } else if (attr.isDomainIli2DateTime()) {
        dbCol.value = new DbColDateTime();
    } else if (attr.isDomainIli2Time()) {
        dbCol.value = new DbColTime();
    } else if (type instanceof BasketType) {
        // skip it; type no longer exists in ili 2.3
        dbCol.value = null;
    } else if (type instanceof EnumerationType) {
        visitedEnumsAttrs.add(attr);
        if (createEnumColAsItfCode) {
            DbColId ret = new DbColId();
            dbCol.value = ret;
        } else {
            DbColVarchar ret = new DbColVarchar();
            ret.setSize(255);
            dbCol.value = ret;
        }
    } else if (type instanceof NumericType) {
        if (type.isAbstract()) {
        } else {
            PrecisionDecimal min = ((NumericType) type).getMinimum();
            PrecisionDecimal max = ((NumericType) type).getMaximum();
            int minLen = min.toString().length();
            int maxLen = max.toString().length();
            if (min.toString().startsWith("-")) {
                minLen -= 1;
            }
            if (max.toString().startsWith("-")) {
                maxLen -= 1;
            }
            if (min.getAccuracy() > 0) {
                DbColDecimal ret = new DbColDecimal();
                int size = Math.max(minLen, maxLen) - 1;
                int precision = min.getAccuracy();
                // EhiLogger.debug("attr "+ attr.getName()+", maxStr <"+maxStr+">, size "+Integer.toString(size)+", precision "+Integer.toString(precision));
                ret.setSize(size);
                ret.setPrecision(precision);
                if (createNumCheck) {
                    ret.setMinValue(min.doubleValue());
                    ret.setMaxValue(max.doubleValue());
                }
                dbCol.value = ret;
            } else {
                DbColNumber ret = new DbColNumber();
                int size = Math.max(minLen, maxLen);
                ret.setSize(size);
                if (createNumCheck) {
                    ret.setMinValue((int) min.doubleValue());
                    ret.setMaxValue((int) max.doubleValue());
                }
                dbCol.value = ret;
            }
            unitDef.value = ((NumericType) type).getUnit();
        }
    } else if (type instanceof TextType) {
        DbColVarchar ret = new DbColVarchar();
        if (((TextType) type).getMaxLength() > 0) {
            ret.setSize(((TextType) type).getMaxLength());
        } else {
            ret.setSize(DbColVarchar.UNLIMITED);
        }
        if (!((TextType) type).isNormalized()) {
            mText.value = true;
        }
        dbCol.value = ret;
    } else if (type instanceof BlackboxType) {
        if (((BlackboxType) type).getKind() == BlackboxType.eXML) {
            DbColXml ret = new DbColXml();
            dbCol.value = ret;
        } else {
            DbColBlob ret = new DbColBlob();
            dbCol.value = ret;
        }
    } else {
        return false;
    }
    return true;
}
Also used : NumericType(ch.interlis.ili2c.metamodel.NumericType) DbColXml(ch.ehi.sqlgen.repository.DbColXml) DbColBlob(ch.ehi.sqlgen.repository.DbColBlob) BasketType(ch.interlis.ili2c.metamodel.BasketType) BlackboxType(ch.interlis.ili2c.metamodel.BlackboxType) EnumerationType(ch.interlis.ili2c.metamodel.EnumerationType) DbColVarchar(ch.ehi.sqlgen.repository.DbColVarchar) DbColTime(ch.ehi.sqlgen.repository.DbColTime) DbColDecimal(ch.ehi.sqlgen.repository.DbColDecimal) DbColDateTime(ch.ehi.sqlgen.repository.DbColDateTime) DbColNumber(ch.ehi.sqlgen.repository.DbColNumber) DbColDate(ch.ehi.sqlgen.repository.DbColDate) UniquenessConstraint(ch.interlis.ili2c.metamodel.UniquenessConstraint) TextType(ch.interlis.ili2c.metamodel.TextType) PrecisionDecimal(ch.interlis.ili2c.metamodel.PrecisionDecimal) DbColBoolean(ch.ehi.sqlgen.repository.DbColBoolean) DbColUuid(ch.ehi.sqlgen.repository.DbColUuid) DbColId(ch.ehi.sqlgen.repository.DbColId)

Example 4 with BlackboxType

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

the class PostgisColumnConverter method toIomArray.

@Override
public String[] toIomArray(ch.interlis.ili2c.metamodel.AttributeDef attr, Object sqlArray, EnumCodeMapper enumTypes) throws SQLException, ConverterException {
    java.sql.Array array = (java.sql.Array) sqlArray;
    String[] ret = null;
    ch.interlis.ili2c.metamodel.Type type = attr.getDomainResolvingAliases();
    if (attr.isDomainBoolean()) {
        Boolean[] values = (Boolean[]) array.getArray();
        ret = new String[values.length];
        for (int i = 0; i < values.length; i++) {
            if (values[i]) {
                ret[i] = "true";
            } else {
                ret[i] = "false";
            }
        }
    } else if (attr.isDomainIli1Date()) {
        java.sql.Date[] values = (java.sql.Date[]) array.getArray();
        ret = new String[values.length];
        for (int i = 0; i < values.length; i++) {
            java.text.SimpleDateFormat fmt = new java.text.SimpleDateFormat("yyyyMMdd");
            GregorianCalendar date = new GregorianCalendar();
            date.setGregorianChange(ToXtfRecordConverter.PURE_GREGORIAN_CALENDAR);
            fmt.setCalendar(date);
            ret[i] = fmt.format(values[i]);
        }
    } else if (attr.isDomainIliUuid()) {
        java.util.UUID[] values = (java.util.UUID[]) array.getArray();
        ret = new String[values.length];
        for (int i = 0; i < values.length; i++) {
            ret[i] = values[i].toString();
        }
    } else if (attr.isDomainIli2Date()) {
        java.sql.Date[] values = (java.sql.Date[]) array.getArray();
        ret = new String[values.length];
        for (int i = 0; i < values.length; i++) {
            java.text.SimpleDateFormat fmt = new java.text.SimpleDateFormat("yyyy-MM-dd");
            GregorianCalendar date = new GregorianCalendar();
            date.setGregorianChange(ToXtfRecordConverter.PURE_GREGORIAN_CALENDAR);
            fmt.setCalendar(date);
            ret[i] = fmt.format(values[i]);
        }
    } else if (attr.isDomainIli2DateTime()) {
        java.sql.Timestamp[] values = (java.sql.Timestamp[]) array.getArray();
        ret = new String[values.length];
        for (int i = 0; i < values.length; i++) {
            // 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(ToXtfRecordConverter.PURE_GREGORIAN_CALENDAR);
            fmt.setCalendar(date);
            ret[i] = fmt.format(values[i]);
        }
    } else if (attr.isDomainIli2Time()) {
        java.sql.Time[] values = (java.sql.Time[]) array.getArray();
        ret = new String[values.length];
        for (int i = 0; i < values.length; i++) {
            java.text.SimpleDateFormat fmt = new java.text.SimpleDateFormat("HH:mm:ss.SSS");
            ret[i] = fmt.format(values[i]);
        }
    } else if (type instanceof EnumerationType) {
        if (createEnumColAsItfCode) {
            Integer[] values = (Integer[]) array.getArray();
            ret = new String[values.length];
            for (int i = 0; i < values.length; i++) {
                ret[i] = enumTypes.mapItfCode2XtfCode((EnumerationType) type, values[i].toString());
            }
        } else {
            ret = ((String[]) array.getArray());
        }
    } else if (type instanceof NumericType) {
        if (type.isAbstract()) {
        } else {
            PrecisionDecimal min = ((NumericType) type).getMinimum();
            PrecisionDecimal max = ((NumericType) type).getMaximum();
            if (min.getAccuracy() > 0) {
                BigDecimal[] values = (BigDecimal[]) array.getArray();
                ret = new String[values.length];
                for (int i = 0; i < values.length; i++) {
                    ret[i] = values[i].toString();
                }
            } else {
                Integer[] values = (Integer[]) array.getArray();
                ret = new String[values.length];
                for (int i = 0; i < values.length; i++) {
                    ret[i] = values[i].toString();
                }
            }
        }
    } else if (type instanceof TextType) {
        ret = ((String[]) array.getArray());
    } else if (type instanceof BlackboxType) {
        if (((BlackboxType) type).getKind() == BlackboxType.eXML) {
            Object[] values = (Object[]) array.getArray();
            ret = new String[values.length];
            for (int i = 0; i < values.length; i++) {
                ret[i] = toIomXml(values[i]);
            }
        } else {
            Object[] values = (Object[]) array.getArray();
            ret = new String[values.length];
            for (int i = 0; i < values.length; i++) {
                ret[i] = toIomBlob(values[i]);
            }
        }
    } else {
        throw new IllegalArgumentException(attr.getScopedName());
    }
    return ret;
}
Also used : NumericType(ch.interlis.ili2c.metamodel.NumericType) DbColTime(ch.ehi.sqlgen.repository.DbColTime) DbColDateTime(ch.ehi.sqlgen.repository.DbColDateTime) PrecisionDecimal(ch.interlis.ili2c.metamodel.PrecisionDecimal) DbColBoolean(ch.ehi.sqlgen.repository.DbColBoolean) BlackboxType(ch.interlis.ili2c.metamodel.BlackboxType) GregorianCalendar(java.util.GregorianCalendar) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) EnumerationType(ch.interlis.ili2c.metamodel.EnumerationType) DbColDate(ch.ehi.sqlgen.repository.DbColDate) BigDecimal(java.math.BigDecimal) TextType(ch.interlis.ili2c.metamodel.TextType) IomObject(ch.interlis.iom.IomObject)

Example 5 with BlackboxType

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

the class FromXtfRecordConverter method addAttrValue.

public int addAttrValue(IomObject iomObj, String sqlType, long sqlId, String sqlTableName, PreparedStatement ps, int valuei, AttributeDef attr, ArrayList structQueue) throws SQLException, ConverterException {
    if (attr.getExtending() == null) {
        String attrName = attr.getName();
        if (attr.isDomainBoolean()) {
            String value = iomObj.getattrvalue(attrName);
            if (value != null) {
                if (value.equals("true")) {
                    geomConv.setBoolean(ps, valuei, true);
                } else {
                    geomConv.setBoolean(ps, valuei, false);
                }
            } else {
                ps.setNull(valuei, Types.BIT);
            }
            valuei++;
        } else if (attr.isDomainIliUuid()) {
            String value = iomObj.getattrvalue(attrName);
            if (value == null) {
                geomConv.setUuidNull(ps, valuei);
            } else {
                Object toInsertUUID = geomConv.fromIomUuid(value);
                ps.setObject(valuei, toInsertUUID);
            }
            valuei++;
        } else if (attr.isDomainIli1Date()) {
            String value = iomObj.getattrvalue(attrName);
            if (value != null) {
                GregorianCalendar gdate = new GregorianCalendar(Integer.parseInt(value.substring(0, 4)), Integer.parseInt(value.substring(4, 6)) - 1, Integer.parseInt(value.substring(6, 8)));
                java.sql.Date date = new java.sql.Date(gdate.getTimeInMillis());
                geomConv.setDate(ps, valuei, date);
            } else {
                ps.setNull(valuei, Types.DATE);
            }
            valuei++;
        } else if (attr.isDomainIli2Date()) {
            String value = iomObj.getattrvalue(attrName);
            if (value != null) {
                XMLGregorianCalendar xmldate;
                try {
                    xmldate = javax.xml.datatype.DatatypeFactory.newInstance().newXMLGregorianCalendar(value);
                } catch (DatatypeConfigurationException e) {
                    throw new ConverterException(e);
                }
                java.sql.Date date = new java.sql.Date(xmldate.toGregorianCalendar().getTimeInMillis());
                geomConv.setDate(ps, valuei, date);
            } else {
                ps.setNull(valuei, Types.DATE);
            }
            valuei++;
        } else if (attr.isDomainIli2Time()) {
            String value = iomObj.getattrvalue(attrName);
            if (value != null) {
                XMLGregorianCalendar xmldate;
                try {
                    xmldate = javax.xml.datatype.DatatypeFactory.newInstance().newXMLGregorianCalendar(value);
                } catch (DatatypeConfigurationException e) {
                    throw new ConverterException(e);
                }
                java.sql.Time time = new java.sql.Time(xmldate.toGregorianCalendar().getTimeInMillis());
                geomConv.setTime(ps, valuei, time);
            } else {
                ps.setNull(valuei, Types.TIME);
            }
            valuei++;
        } else if (attr.isDomainIli2DateTime()) {
            String value = iomObj.getattrvalue(attrName);
            if (value != null) {
                XMLGregorianCalendar xmldate;
                try {
                    xmldate = javax.xml.datatype.DatatypeFactory.newInstance().newXMLGregorianCalendar(value);
                } catch (DatatypeConfigurationException e) {
                    throw new ConverterException(e);
                }
                java.sql.Timestamp datetime = new java.sql.Timestamp(xmldate.toGregorianCalendar().getTimeInMillis());
                geomConv.setTimestamp(ps, valuei, datetime);
            } else {
                ps.setNull(valuei, Types.TIMESTAMP);
            }
            valuei++;
        } else {
            Type type = attr.getDomainResolvingAliases();
            if (type instanceof CompositionType) {
                int structc = iomObj.getattrvaluecount(attrName);
                if (TrafoConfigNames.CATALOGUE_REF_TRAFO_COALESCE.equals(trafoConfig.getAttrConfig(attr, TrafoConfigNames.CATALOGUE_REF_TRAFO))) {
                    IomObject catref = iomObj.getattrobj(attrName, 0);
                    String refoid = null;
                    if (catref != null) {
                        IomObject structvalue = catref.getattrobj(IliNames.CHBASE1_CATALOGUEREFERENCE_REFERENCE, 0);
                        if (structvalue != null) {
                            refoid = structvalue.getobjectrefoid();
                        }
                    }
                    if (refoid != null) {
                        String targetClassName = IliNames.CHBASE1_CATALOGUES_ITEM;
                        long refsqlId = oidPool.getObjSqlId(targetClassName, refoid);
                        ps.setLong(valuei, refsqlId);
                    } else {
                        ps.setNull(valuei, Types.BIGINT);
                    }
                    valuei++;
                } else if (TrafoConfigNames.MULTISURFACE_TRAFO_COALESCE.equals(trafoConfig.getAttrConfig(attr, TrafoConfigNames.MULTISURFACE_TRAFO))) {
                    IomObject iomValue = iomObj.getattrobj(attrName, 0);
                    IomObject iomMultisurface = null;
                    MultiSurfaceMapping attrMapping = null;
                    if (iomValue != null) {
                        attrMapping = multiSurfaceAttrs.getMapping(attr);
                        int surfacec = iomValue.getattrvaluecount(attrMapping.getBagOfSurfacesAttrName());
                        for (int surfacei = 0; surfacei < surfacec; surfacei++) {
                            IomObject iomSurfaceStructure = iomValue.getattrobj(attrMapping.getBagOfSurfacesAttrName(), surfacei);
                            IomObject iomPoly = iomSurfaceStructure.getattrobj(attrMapping.getSurfaceAttrName(), 0);
                            IomObject iomSurface = iomPoly.getattrobj("surface", 0);
                            if (iomMultisurface == null) {
                                iomMultisurface = new ch.interlis.iom_j.Iom_jObject("MULTISURFACE", null);
                            }
                            iomMultisurface.addattrobj("surface", iomSurface);
                        }
                    }
                    if (iomMultisurface != null) {
                        AttributeDef surfaceAttr = getMultiSurfaceAttrDef(type, attrMapping);
                        SurfaceType surface = ((SurfaceType) surfaceAttr.getDomainResolvingAliases());
                        CoordType coord = (CoordType) surface.getControlPointDomain().getType();
                        boolean is3D = coord.getDimensions().length == 3;
                        Object geomObj = geomConv.fromIomMultiSurface(iomMultisurface, getSrsid(surfaceAttr), surface.getLineAttributeStructure() != null, is3D, getP(surface));
                        ps.setObject(valuei, geomObj);
                    } else {
                        geomConv.setSurfaceNull(ps, valuei);
                    }
                    valuei++;
                } else if (TrafoConfigNames.MULTILINE_TRAFO_COALESCE.equals(trafoConfig.getAttrConfig(attr, TrafoConfigNames.MULTILINE_TRAFO))) {
                    IomObject iomValue = iomObj.getattrobj(attrName, 0);
                    IomObject iomMultiline = null;
                    MultiLineMapping attrMapping = null;
                    if (iomValue != null) {
                        attrMapping = multiLineAttrs.getMapping(attr);
                        int polylinec = iomValue.getattrvaluecount(attrMapping.getBagOfLinesAttrName());
                        for (int polylinei = 0; polylinei < polylinec; polylinei++) {
                            IomObject iomPolylineStructure = iomValue.getattrobj(attrMapping.getBagOfLinesAttrName(), polylinei);
                            IomObject iomPoly = iomPolylineStructure.getattrobj(attrMapping.getLineAttrName(), 0);
                            if (iomMultiline == null) {
                                iomMultiline = new ch.interlis.iom_j.Iom_jObject(Wkb2iox.OBJ_MULTIPOLYLINE, null);
                            }
                            iomMultiline.addattrobj(Wkb2iox.ATTR_POLYLINE, iomPoly);
                        }
                    }
                    if (iomMultiline != null) {
                        AttributeDef polylineAttr = getMultiLineAttrDef(type, attrMapping);
                        PolylineType line = ((PolylineType) polylineAttr.getDomainResolvingAliases());
                        CoordType coord = (CoordType) line.getControlPointDomain().getType();
                        boolean is3D = coord.getDimensions().length == 3;
                        Object geomObj = geomConv.fromIomMultiPolyline(iomMultiline, getSrsid(polylineAttr), is3D, getP(line));
                        ps.setObject(valuei, geomObj);
                    } else {
                        geomConv.setPolylineNull(ps, valuei);
                    }
                    valuei++;
                } else if (TrafoConfigNames.MULTIPOINT_TRAFO_COALESCE.equals(trafoConfig.getAttrConfig(attr, TrafoConfigNames.MULTIPOINT_TRAFO))) {
                    IomObject iomValue = iomObj.getattrobj(attrName, 0);
                    IomObject iomMultipoint = null;
                    MultiPointMapping attrMapping = null;
                    if (iomValue != null) {
                        attrMapping = multiPointAttrs.getMapping(attr);
                        int pointc = iomValue.getattrvaluecount(attrMapping.getBagOfPointsAttrName());
                        for (int pointi = 0; pointi < pointc; pointi++) {
                            IomObject iomPointStructure = iomValue.getattrobj(attrMapping.getBagOfPointsAttrName(), pointi);
                            IomObject iomPoint = iomPointStructure.getattrobj(attrMapping.getPointAttrName(), 0);
                            if (iomMultipoint == null) {
                                iomMultipoint = new ch.interlis.iom_j.Iom_jObject(Wkb2iox.OBJ_MULTIPOINT, null);
                            }
                            iomMultipoint.addattrobj(Wkb2iox.ATTR_COORD, iomPoint);
                        }
                    }
                    if (iomMultipoint != null) {
                        AttributeDef coordAttr = getMultiPointAttrDef(type, attrMapping);
                        CoordType coord = ((CoordType) coordAttr.getDomainResolvingAliases());
                        boolean is3D = coord.getDimensions().length == 3;
                        Object geomObj = geomConv.fromIomMultiCoord(iomMultipoint, getSrsid(coordAttr), is3D);
                        ps.setObject(valuei, geomObj);
                    } else {
                        geomConv.setCoordNull(ps, valuei);
                    }
                    valuei++;
                } else if (TrafoConfigNames.ARRAY_TRAFO_COALESCE.equals(trafoConfig.getAttrConfig(attr, TrafoConfigNames.ARRAY_TRAFO))) {
                    int valuec = iomObj.getattrvaluecount(attrName);
                    String[] iomArray = new String[valuec];
                    ArrayMapping attrMapping = arrayAttrs.getMapping(attr);
                    for (int elei = 0; elei < valuec; elei++) {
                        IomObject iomValue = iomObj.getattrobj(attrName, elei);
                        String value = iomValue.getattrvalue(attrMapping.getValueAttr().getName());
                        iomArray[elei] = value;
                    }
                    if (iomArray.length > 0) {
                        Object geomObj = geomConv.fromIomArray(attrMapping.getValueAttr(), iomArray, enumTypes);
                        ps.setObject(valuei, geomObj);
                    } else {
                        geomConv.setArrayNull(ps, valuei);
                    }
                    valuei++;
                } else if (TrafoConfigNames.MULTILINGUAL_TRAFO_EXPAND.equals(trafoConfig.getAttrConfig(attr, TrafoConfigNames.MULTILINGUAL_TRAFO))) {
                    IomObject iomMulti = iomObj.getattrobj(attrName, 0);
                    for (String sfx : DbNames.MULTILINGUAL_TXT_COL_SUFFIXS) {
                        if (iomMulti != null) {
                            String value = getMultilingualText(iomMulti, sfx);
                            if (value != null) {
                                ps.setString(valuei, value);
                            } else {
                                ps.setNull(valuei, Types.VARCHAR);
                            }
                        } else {
                            ps.setNull(valuei, Types.VARCHAR);
                        }
                        valuei++;
                    }
                } else {
                    // enqueue struct values
                    for (int structi = 0; structi < structc; structi++) {
                        IomObject struct = iomObj.getattrobj(attrName, structi);
                        String sqlAttrName = ili2sqlName.mapIliAttributeDef(attr, sqlTableName, null);
                        enqueStructValue(structQueue, sqlId, sqlType, sqlAttrName, struct, structi, attr);
                    }
                }
            } else if (type instanceof PolylineType) {
                IomObject value = iomObj.getattrobj(attrName, 0);
                if (value != null) {
                    boolean is3D = ((CoordType) ((PolylineType) type).getControlPointDomain().getType()).getDimensions().length == 3;
                    ps.setObject(valuei, geomConv.fromIomPolyline(value, getSrsid(attr), is3D, getP((PolylineType) type)));
                } else {
                    geomConv.setPolylineNull(ps, valuei);
                }
                valuei++;
            } else if (type instanceof SurfaceOrAreaType) {
                if (createItfLineTables) {
                } else {
                    IomObject value = iomObj.getattrobj(attrName, 0);
                    if (value != null) {
                        boolean is3D = ((CoordType) ((SurfaceOrAreaType) type).getControlPointDomain().getType()).getDimensions().length == 3;
                        Object geomObj = geomConv.fromIomSurface(value, getSrsid(attr), ((SurfaceOrAreaType) type).getLineAttributeStructure() != null, is3D, getP((SurfaceOrAreaType) type));
                        ps.setObject(valuei, geomObj);
                    } else {
                        geomConv.setSurfaceNull(ps, valuei);
                    }
                    valuei++;
                }
                if (createItfAreaRef) {
                    if (type instanceof AreaType) {
                        IomObject value = null;
                        if (isItfReader) {
                            value = iomObj.getattrobj(attrName, 0);
                        } else {
                            value = iomObj.getattrobj(ItfReader2.SAVED_GEOREF_PREFIX + attrName, 0);
                        }
                        if (value != null) {
                            boolean is3D = ((CoordType) ((SurfaceOrAreaType) type).getControlPointDomain().getType()).getDimensions().length == 3;
                            ps.setObject(valuei, geomConv.fromIomCoord(value, getSrsid(attr), is3D));
                        } else {
                            geomConv.setCoordNull(ps, valuei);
                        }
                        valuei++;
                    }
                }
            } else if (type instanceof CoordType) {
                IomObject value = iomObj.getattrobj(attrName, 0);
                if (value != null) {
                    boolean is3D = ((CoordType) type).getDimensions().length == 3;
                    ps.setObject(valuei, geomConv.fromIomCoord(value, getSrsid(attr), is3D));
                } else {
                    geomConv.setCoordNull(ps, valuei);
                }
                valuei++;
            } else if (type instanceof NumericType) {
                String value = iomObj.getattrvalue(attrName);
                if (type.isAbstract()) {
                } else {
                    PrecisionDecimal min = ((NumericType) type).getMinimum();
                    PrecisionDecimal max = ((NumericType) type).getMaximum();
                    if (min.getAccuracy() > 0) {
                        if (value != null) {
                            try {
                                ps.setDouble(valuei, Double.parseDouble(value));
                            } catch (java.lang.NumberFormatException ex) {
                                EhiLogger.logError(ex);
                            }
                        } else {
                            geomConv.setDecimalNull(ps, valuei);
                        }
                    } else {
                        if (value != null) {
                            try {
                                int val = (int) Math.round(Double.parseDouble(value));
                                ps.setInt(valuei, val);
                            } catch (java.lang.NumberFormatException ex) {
                                EhiLogger.logError(ex);
                            }
                        } else {
                            ps.setNull(valuei, Types.INTEGER);
                        }
                    }
                    valuei++;
                }
            } else if (type instanceof EnumerationType) {
                String value = iomObj.getattrvalue(attrName);
                if (createEnumColAsItfCode) {
                    if (value != null) {
                        int itfCode = mapXtfCode2ItfCode((EnumerationType) type, value);
                        ps.setInt(valuei, itfCode);
                    } else {
                        ps.setNull(valuei, Types.INTEGER);
                    }
                } else {
                    if (value != null) {
                        ps.setString(valuei, value);
                    } else {
                        ps.setNull(valuei, Types.VARCHAR);
                    }
                }
                valuei++;
                if (createEnumTxtCol) {
                    if (value != null) {
                        ps.setString(valuei, beautifyEnumDispName(value));
                    } else {
                        ps.setNull(valuei, Types.VARCHAR);
                    }
                    valuei++;
                }
            } else if (type instanceof ReferenceType) {
                IomObject structvalue = iomObj.getattrobj(attrName, 0);
                String refoid = null;
                if (structvalue != null) {
                    refoid = structvalue.getobjectrefoid();
                }
                Holder<Integer> valueiRef = new Holder<Integer>(valuei);
                setReferenceColumn(ps, ((ReferenceType) type).getReferred(), refoid, valueiRef);
                valuei = valueiRef.value;
            } else if (type instanceof BlackboxType) {
                String value = iomObj.getattrvalue(attrName);
                if (((BlackboxType) type).getKind() == BlackboxType.eXML) {
                    if (value == null) {
                        geomConv.setXmlNull(ps, valuei);
                    } else {
                        Object toInsertXml = geomConv.fromIomXml(value);
                        ps.setObject(valuei, toInsertXml);
                    }
                    valuei++;
                } else {
                    if (value == null) {
                        geomConv.setBlobNull(ps, valuei);
                    } else {
                        Object toInsertBlob = geomConv.fromIomBlob(value);
                        ps.setObject(valuei, toInsertBlob);
                    }
                    valuei++;
                }
            } else {
                String value = iomObj.getattrvalue(attrName);
                if (value != null) {
                    ps.setString(valuei, value);
                } else {
                    ps.setNull(valuei, Types.VARCHAR);
                }
                valuei++;
            }
        }
    }
    return valuei;
}
Also used : NumericType(ch.interlis.ili2c.metamodel.NumericType) ConverterException(ch.ehi.ili2db.converter.ConverterException) SurfaceOrAreaType(ch.interlis.ili2c.metamodel.SurfaceOrAreaType) CompositionType(ch.interlis.ili2c.metamodel.CompositionType) SurfaceOrAreaType(ch.interlis.ili2c.metamodel.SurfaceOrAreaType) AreaType(ch.interlis.ili2c.metamodel.AreaType) ReferenceType(ch.interlis.ili2c.metamodel.ReferenceType) PrecisionDecimal(ch.interlis.ili2c.metamodel.PrecisionDecimal) IomObject(ch.interlis.iom.IomObject) AttributeDef(ch.interlis.ili2c.metamodel.AttributeDef) PolylineType(ch.interlis.ili2c.metamodel.PolylineType) MultiPointMapping(ch.ehi.ili2db.mapping.MultiPointMapping) BlackboxType(ch.interlis.ili2c.metamodel.BlackboxType) Holder(javax.xml.ws.Holder) GregorianCalendar(java.util.GregorianCalendar) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) EnumerationType(ch.interlis.ili2c.metamodel.EnumerationType) SurfaceType(ch.interlis.ili2c.metamodel.SurfaceType) MultiSurfaceMapping(ch.ehi.ili2db.mapping.MultiSurfaceMapping) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) NumericalType(ch.interlis.ili2c.metamodel.NumericalType) PolylineType(ch.interlis.ili2c.metamodel.PolylineType) Type(ch.interlis.ili2c.metamodel.Type) ReferenceType(ch.interlis.ili2c.metamodel.ReferenceType) SurfaceOrAreaType(ch.interlis.ili2c.metamodel.SurfaceOrAreaType) SurfaceType(ch.interlis.ili2c.metamodel.SurfaceType) CompositionType(ch.interlis.ili2c.metamodel.CompositionType) EnumerationType(ch.interlis.ili2c.metamodel.EnumerationType) NumericType(ch.interlis.ili2c.metamodel.NumericType) BlackboxType(ch.interlis.ili2c.metamodel.BlackboxType) AreaType(ch.interlis.ili2c.metamodel.AreaType) LineType(ch.interlis.ili2c.metamodel.LineType) ObjectType(ch.interlis.ili2c.metamodel.ObjectType) CoordType(ch.interlis.ili2c.metamodel.CoordType) ArrayMapping(ch.ehi.ili2db.mapping.ArrayMapping) IomObject(ch.interlis.iom.IomObject) MultiLineMapping(ch.ehi.ili2db.mapping.MultiLineMapping) CoordType(ch.interlis.ili2c.metamodel.CoordType)

Aggregations

BlackboxType (ch.interlis.ili2c.metamodel.BlackboxType)5 EnumerationType (ch.interlis.ili2c.metamodel.EnumerationType)5 NumericType (ch.interlis.ili2c.metamodel.NumericType)4 PrecisionDecimal (ch.interlis.ili2c.metamodel.PrecisionDecimal)4 IomObject (ch.interlis.iom.IomObject)4 GregorianCalendar (java.util.GregorianCalendar)4 ConverterException (ch.ehi.ili2db.converter.ConverterException)3 DbColBoolean (ch.ehi.sqlgen.repository.DbColBoolean)3 DbColDate (ch.ehi.sqlgen.repository.DbColDate)3 DbColDateTime (ch.ehi.sqlgen.repository.DbColDateTime)3 DbColTime (ch.ehi.sqlgen.repository.DbColTime)3 TextType (ch.interlis.ili2c.metamodel.TextType)3 ArrayMapping (ch.ehi.ili2db.mapping.ArrayMapping)2 MultiLineMapping (ch.ehi.ili2db.mapping.MultiLineMapping)2 MultiPointMapping (ch.ehi.ili2db.mapping.MultiPointMapping)2 MultiSurfaceMapping (ch.ehi.ili2db.mapping.MultiSurfaceMapping)2 AreaType (ch.interlis.ili2c.metamodel.AreaType)2 AttributeDef (ch.interlis.ili2c.metamodel.AttributeDef)2 CompositionType (ch.interlis.ili2c.metamodel.CompositionType)2 CoordType (ch.interlis.ili2c.metamodel.CoordType)2