Search in sources :

Example 1 with ConverterException

use of ch.ehi.ili2db.converter.ConverterException 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 ConverterException

use of ch.ehi.ili2db.converter.ConverterException in project ili2db by claeis.

the class OracleColumnConverter method getSrsid.

@Override
public Integer getSrsid(String crsAuthority, String crsCode, Connection conn) throws ConverterException {
    int srsid = 0;
    try {
        java.sql.Statement stmt = conn.createStatement();
        String qryStmt = null;
        if (crsAuthority == null) {
            qryStmt = "SELECT srid FROM MDSYS.CS_SRS WHERE AUTH_NAME IS NULL AND AUTH_SRID=" + crsCode;
        } else {
            qryStmt = "SELECT srid FROM MDSYS.CS_SRS WHERE AUTH_NAME=\'" + crsAuthority + "\' AND AUTH_SRID=" + crsCode;
        }
        java.sql.ResultSet ret = stmt.executeQuery(qryStmt);
        if (!ret.next()) {
            return null;
        }
        srsid = ret.getInt("srid");
    } catch (java.sql.SQLException ex) {
        throw new ConverterException("failed to query srsid from database", ex);
    }
    return srsid;
}
Also used : ConverterException(ch.ehi.ili2db.converter.ConverterException) SQLException(java.sql.SQLException)

Example 3 with ConverterException

use of ch.ehi.ili2db.converter.ConverterException in project ili2db by claeis.

the class OracleColumnConverter method toIomPolyline.

@Override
public IomObject toIomPolyline(Object geomobj, String sqlAttrName, boolean is3D) throws java.sql.SQLException, ConverterException {
    JGeometry geometry = JGeometry.load((oracle.sql.STRUCT) geomobj);
    if (geometry.getType() != JGeometry.GTYPE_MULTICURVE) {
        throw new ConverterException("unexpected GTYPE (" + OracleUtility.gtype2str(geometry.getType()) + ") in attribute " + sqlAttrName);
    } else {
        int dim = geometry.getDimensions();
        boolean isCurrentValue3D = (dim == 3);
        if (is3D != isCurrentValue3D) {
            throw new ConverterException("unexpected dimension (" + Integer.toString(dim) + ") in attribute " + sqlAttrName);
        } else {
            int[] elev = geometry.getElemInfo();
            double[] ordv = geometry.getOrdinatesArray();
            final int SDO_STARTING_OFFSET = 0;
            final int SDO_ETYPE = 1;
            final int SDO_INTERPRETATION = 2;
            final int NEXT_TRIPLET = 3;
            final int COMPOUND_LINESTRING = 4;
            final int LINESTRING = 2;
            final int STRAIGHT = 1;
            final int ARC = 2;
            int elei = 0;
            if (elev[elei + SDO_ETYPE] != COMPOUND_LINESTRING) {
                throw new ConverterException("unexpected SDO_ETYPE (" + Integer.toString(elev[elei + SDO_ETYPE]) + ") in attribute " + sqlAttrName);
            } else {
                elei += NEXT_TRIPLET;
                IomObject polylineValue = new Iom_jObject("POLYLINE", null);
                // unclipped polyline, add one sequence
                IomObject sequence = polylineValue.addattrobj("sequence", "SEGMENTS");
                while (elei < elev.length) {
                    if (elev[elei + SDO_ETYPE] != LINESTRING) {
                        throw new ConverterException("unexpected SDO_ETYPE (" + Integer.toString(elev[elei + SDO_ETYPE]) + ") in attribute " + sqlAttrName);
                    } else {
                        if (elev[elei + SDO_INTERPRETATION] == STRAIGHT) {
                            int start = elev[elei + SDO_STARTING_OFFSET] - 1;
                            int end;
                            if (elei + NEXT_TRIPLET >= elev.length) {
                                end = ordv.length;
                            } else {
                                end = elev[elei + NEXT_TRIPLET + SDO_STARTING_OFFSET] - 1;
                            }
                            for (int i = start; i < end; ) {
                                // add control point
                                IomObject coordValue = sequence.addattrobj("segment", "COORD");
                                coordValue.setattrvalue("C1", Double.toString(ordv[i]));
                                coordValue.setattrvalue("C2", Double.toString(ordv[i + 1]));
                                if (isCurrentValue3D) {
                                    coordValue.setattrvalue("C3", Double.toString(ordv[i + 2]));
                                    i += 3;
                                } else {
                                    i += 2;
                                }
                            }
                        } else if (elev[elei + SDO_INTERPRETATION] == ARC) {
                            int start = elev[elei + SDO_STARTING_OFFSET] - 1;
                            int end;
                            if (elei + NEXT_TRIPLET >= elev.length) {
                                end = ordv.length;
                            } else {
                                end = elev[elei + NEXT_TRIPLET + SDO_STARTING_OFFSET] - 1;
                            }
                            for (int i = start; i < end; ) {
                                // add control point
                                IomObject coordValue = sequence.addattrobj("segment", "ARC");
                                coordValue.setattrvalue("A1", Double.toString(ordv[i]));
                                coordValue.setattrvalue("A2", Double.toString(ordv[i + 1]));
                                if (isCurrentValue3D) {
                                    // no A3 in XTF!
                                    i += 3;
                                } else {
                                    i += 2;
                                }
                                coordValue.setattrvalue("C1", Double.toString(ordv[i]));
                                coordValue.setattrvalue("C2", Double.toString(ordv[i + 1]));
                                if (isCurrentValue3D) {
                                    coordValue.setattrvalue("C3", Double.toString(ordv[i + 2]));
                                    i += 3;
                                } else {
                                    i += 2;
                                }
                            }
                        } else {
                            throw new ConverterException("unexpected SDO_INTERPRETATION (" + Integer.toString(elev[elei + SDO_INTERPRETATION]) + ") in attribute " + sqlAttrName);
                        }
                    }
                    elei += NEXT_TRIPLET;
                }
                return polylineValue;
            }
        }
    }
}
Also used : ConverterException(ch.ehi.ili2db.converter.ConverterException) IomObject(ch.interlis.iom.IomObject) JGeometry(oracle.spatial.geometry.JGeometry) Iom_jObject(ch.interlis.iom_j.Iom_jObject)

Example 4 with ConverterException

use of ch.ehi.ili2db.converter.ConverterException 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 5 with ConverterException

use of ch.ehi.ili2db.converter.ConverterException in project ili2db by claeis.

the class PostgisColumnConverter method toIomMultiSurface.

@Override
public IomObject toIomMultiSurface(Object geomobj, String sqlAttrName, boolean is3D) throws SQLException, ConverterException {
    byte[] bv = (byte[]) geomobj;
    Wkb2iox conv = new Wkb2iox();
    try {
        return conv.read(bv);
    } catch (ParseException e) {
        throw new ConverterException(e);
    }
}
Also used : ConverterException(ch.ehi.ili2db.converter.ConverterException) ParseException(com.vividsolutions.jts.io.ParseException) Wkb2iox(ch.interlis.iox_j.wkb.Wkb2iox)

Aggregations

ConverterException (ch.ehi.ili2db.converter.ConverterException)32 ParseException (com.vividsolutions.jts.io.ParseException)17 IomObject (ch.interlis.iom.IomObject)8 IoxException (ch.interlis.iox.IoxException)8 Wkb2iox (ch.interlis.iox_j.wkb.Wkb2iox)6 SQLException (java.sql.SQLException)6 Iom_jObject (ch.interlis.iom_j.Iom_jObject)5 AttributeDef (ch.interlis.ili2c.metamodel.AttributeDef)3 BlackboxType (ch.interlis.ili2c.metamodel.BlackboxType)3 CoordType (ch.interlis.ili2c.metamodel.CoordType)3 EnumerationType (ch.interlis.ili2c.metamodel.EnumerationType)3 SurfaceOrAreaType (ch.interlis.ili2c.metamodel.SurfaceOrAreaType)3 SurfaceType (ch.interlis.ili2c.metamodel.SurfaceType)3 Viewable (ch.interlis.ili2c.metamodel.Viewable)3 JGeometry (oracle.spatial.geometry.JGeometry)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 AbstractClassDef (ch.interlis.ili2c.metamodel.AbstractClassDef)2