Search in sources :

Example 6 with Iom_jObject

use of ch.interlis.iom_j.Iom_jObject in project ili2db by claeis.

the class ToXtfRecordConverter method convertRecord.

public Iom_jObject convertRecord(java.sql.ResultSet rs, Viewable aclass1, FixIomObjectRefs fixref, StructWrapper structWrapper, HashMap structelev, ArrayList<StructWrapper> structQueue, long sqlid) throws SQLException {
    ViewableWrapper aclass = class2wrapper.get(aclass1);
    Iom_jObject iomObj;
    int valuei = 1;
    valuei++;
    if (createTypeDiscriminator || aclass.includesMultipleTypes()) {
        // String t_type=rs.getString(valuei);
        valuei++;
    }
    String sqlIliTid = null;
    if (structWrapper == null) {
        if (!aclass.isStructure()) {
            if (createIliTidCol || aclass.getOid() != null) {
                sqlIliTid = rs.getString(valuei);
                sqlid2xtfid.putSqlid2Xtfid(sqlid, sqlIliTid);
                valuei++;
            } else {
                sqlIliTid = Long.toString(sqlid);
                sqlid2xtfid.putSqlid2Xtfid(sqlid, sqlIliTid);
            }
        }
    }
    if (structWrapper == null) {
        if (!aclass.isStructure()) {
            iomObj = new Iom_jObject(aclass1.getScopedName(null), sqlIliTid);
        } else {
            iomObj = new Iom_jObject(aclass1.getScopedName(null), null);
        }
        iomObj.setattrvalue(ItfWriter2.INTERNAL_T_ID, Long.toString(sqlid));
        fixref.setRoot(iomObj);
    } else {
        iomObj = (Iom_jObject) structelev.get(Long.toString(sqlid));
        if (createGenericStructRef) {
            valuei += 4;
        } else {
            valuei += 2;
        }
    }
    HashSet<AttributeDef> visitedAttrs = new HashSet<AttributeDef>();
    for (ViewableWrapper table : aclass.getWrappers()) {
        Iterator iter = table.getAttrIterator();
        while (iter.hasNext()) {
            ViewableTransferElement obj = (ViewableTransferElement) iter.next();
            if (obj.obj instanceof AttributeDef) {
                AttributeDef attr = (AttributeDef) obj.obj;
                AttributeDef baseAttr = attr;
                while (true) {
                    AttributeDef baseAttr1 = (AttributeDef) baseAttr.getExtending();
                    if (baseAttr1 == null) {
                        break;
                    }
                    baseAttr = baseAttr1;
                }
                if (!visitedAttrs.contains(baseAttr)) {
                    visitedAttrs.add(baseAttr);
                    if (!baseAttr.isTransient()) {
                        Type proxyType = baseAttr.getDomain();
                        if (proxyType != null && (proxyType instanceof ObjectType)) {
                        // skip implicit particles (base-viewables) of views
                        } else {
                            valuei = addAttrValue(rs, valuei, sqlid, iomObj, baseAttr, structQueue, table, fixref);
                        }
                    }
                }
            }
            if (obj.obj instanceof RoleDef) {
                RoleDef role = (RoleDef) obj.obj;
                if (role.getExtending() == null) {
                    String roleName = role.getName();
                    ArrayList<ViewableWrapper> targetTables = getTargetTables(role.getDestination());
                    boolean refAlreadyDefined = false;
                    for (ViewableWrapper targetTable : targetTables) {
                        String sqlRoleName = ili2sqlName.mapIliRoleDef(role, getSqlType(table.getViewable()).getName(), targetTable.getSqlTablename(), targetTables.size() > 1);
                        // a role of an embedded association?
                        if (obj.embedded) {
                            AssociationDef roleOwner = (AssociationDef) role.getContainer();
                            if (roleOwner.getDerivedFrom() == null) {
                                // TODO if(orderPos!=0){
                                long value = rs.getLong(valuei);
                                valuei++;
                                if (!rs.wasNull()) {
                                    if (refAlreadyDefined) {
                                        EhiLogger.logAdaption("Table " + table.getSqlTablename() + "(id " + sqlid + ") more than one value for role " + roleName + "; value of " + sqlRoleName + " ignored");
                                    } else {
                                        IomObject ref = iomObj.addattrobj(roleName, roleOwner.getScopedName(null));
                                        mapSqlid2Xtfid(fixref, value, ref, role.getDestination());
                                        refAlreadyDefined = true;
                                    }
                                }
                            }
                        } else {
                            // TODO if(orderPos!=0){
                            long value = rs.getLong(valuei);
                            valuei++;
                            if (!rs.wasNull()) {
                                if (refAlreadyDefined) {
                                    EhiLogger.logAdaption("Table " + table.getSqlTablename() + "(id " + sqlid + ") more than one value for role " + roleName + "; value of " + sqlRoleName + " ignored");
                                } else {
                                    IomObject ref = iomObj.addattrobj(roleName, "REF");
                                    mapSqlid2Xtfid(fixref, value, ref, role.getDestination());
                                    refAlreadyDefined = true;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return iomObj;
}
Also used : ViewableTransferElement(ch.interlis.ili2c.metamodel.ViewableTransferElement) RoleDef(ch.interlis.ili2c.metamodel.RoleDef) ViewableWrapper(ch.ehi.ili2db.mapping.ViewableWrapper) Iom_jObject(ch.interlis.iom_j.Iom_jObject) ObjectType(ch.interlis.ili2c.metamodel.ObjectType) 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) IomObject(ch.interlis.iom.IomObject) Iterator(java.util.Iterator) AssociationDef(ch.interlis.ili2c.metamodel.AssociationDef) AttributeDef(ch.interlis.ili2c.metamodel.AttributeDef) HashSet(java.util.HashSet)

Example 7 with Iom_jObject

use of ch.interlis.iom_j.Iom_jObject in project ili2db by claeis.

the class OracleColumnConverter method toIomCoord.

@Override
public IomObject toIomCoord(Object geomobj, String sqlAttrName, boolean is3D) throws java.sql.SQLException, ConverterException {
    JGeometry geometry = JGeometry.load((oracle.sql.STRUCT) geomobj);
    if (geometry.getType() != JGeometry.GTYPE_POINT) {
        throw new ConverterException("unexpected GTYPE (" + OracleUtility.gtype2str(geometry.getType()) + ")");
    } else {
        int dim = geometry.getDimensions();
        boolean isCurrentValue3D = (dim == 3);
        if (isCurrentValue3D != is3D) {
            throw new ConverterException("unexpected dimension (" + Integer.toString(dim) + ")");
        } else {
            double[] valuev = geometry.getFirstPoint();
            IomObject coord = new Iom_jObject("COORD", null);
            coord.setattrvalue("C1", Double.toString(valuev[0]));
            coord.setattrvalue("C2", Double.toString(valuev[1]));
            if (dim == 3) {
                coord.setattrvalue("C3", Double.toString(valuev[2]));
            }
            return coord;
        }
    }
}
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 8 with Iom_jObject

use of ch.interlis.iom_j.Iom_jObject in project ili2db by claeis.

the class OracleColumnConverter method toIomSurface.

@Override
public IomObject toIomSurface(Object geomobj, String sqlAttrName, boolean is3D) throws java.sql.SQLException, ConverterException {
    JGeometry geometry = JGeometry.load((oracle.sql.STRUCT) geomobj);
    if (geometry.getType() != JGeometry.GTYPE_POLYGON) {
        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;
            // (must be specified in counterclockwise order)
            final int EXTERIOR_POLYGON_RING = 1005;
            // (must be specified in clockwise order)
            final int INTERIOR_POLYGON_RING = 2005;
            final int LINESTRING = 2;
            final int STRAIGHT = 1;
            final int ARC = 2;
            int elei = 0;
            IomObject multisurface = new Iom_jObject("MULTISURFACE", null);
            IomObject surface = multisurface.addattrobj("surface", "SURFACE");
            while (elei < elev.length) {
                if (elev[elei + SDO_ETYPE] != EXTERIOR_POLYGON_RING && elev[elei + SDO_ETYPE] != INTERIOR_POLYGON_RING) {
                    throw new ConverterException("unexpected SDO_ETYPE (" + Integer.toString(elev[elei + SDO_ETYPE]) + ") in attribute " + sqlAttrName);
                } else {
                    int nTriplet = elev[elei + SDO_INTERPRETATION];
                    elei += NEXT_TRIPLET;
                    IomObject boundary = surface.addattrobj("boundary", "BOUNDARY");
                    IomObject polylineValue = boundary.addattrobj("polyline", "POLYLINE");
                    IomObject sequence = polylineValue.addattrobj("sequence", "SEGMENTS");
                    for (int iTriplet = 0; iTriplet < nTriplet; iTriplet++) {
                        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 multisurface;
        }
    }
}
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)

Aggregations

Iom_jObject (ch.interlis.iom_j.Iom_jObject)8 IomObject (ch.interlis.iom.IomObject)7 ConverterException (ch.ehi.ili2db.converter.ConverterException)5 AttributeDef (ch.interlis.ili2c.metamodel.AttributeDef)3 SurfaceOrAreaType (ch.interlis.ili2c.metamodel.SurfaceOrAreaType)3 SurfaceType (ch.interlis.ili2c.metamodel.SurfaceType)3 IoxException (ch.interlis.iox.IoxException)3 ArrayList (java.util.ArrayList)3 JGeometry (oracle.spatial.geometry.JGeometry)3 ViewableWrapper (ch.ehi.ili2db.mapping.ViewableWrapper)2 AreaType (ch.interlis.ili2c.metamodel.AreaType)2 BlackboxType (ch.interlis.ili2c.metamodel.BlackboxType)2 CompositionType (ch.interlis.ili2c.metamodel.CompositionType)2 CoordType (ch.interlis.ili2c.metamodel.CoordType)2 EnumerationType (ch.interlis.ili2c.metamodel.EnumerationType)2 ObjectType (ch.interlis.ili2c.metamodel.ObjectType)2 PolylineType (ch.interlis.ili2c.metamodel.PolylineType)2 ReferenceType (ch.interlis.ili2c.metamodel.ReferenceType)2 Table (ch.interlis.ili2c.metamodel.Table)2 Type (ch.interlis.ili2c.metamodel.Type)2