Search in sources :

Example 11 with Table

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

the class TransferFromXtf method writeItfLineTableObject.

private void writeItfLineTableObject(String datasetName, long basketSqlId, IomObject iomObj, AttributeDef attrDef) throws java.sql.SQLException, ConverterException {
    SurfaceOrAreaType type = (SurfaceOrAreaType) attrDef.getDomainResolvingAliases();
    String geomAttrName = ch.interlis.iom_j.itf.ModelUtilities.getHelperTableGeomAttrName(attrDef);
    String refAttrName = null;
    if (type instanceof SurfaceType) {
        refAttrName = ch.interlis.iom_j.itf.ModelUtilities.getHelperTableMainTableRef(attrDef);
    }
    Table lineAttrTable = type.getLineAttributeStructure();
    // map oid of transfer file to a sql id
    String idTag = attrDef.getContainer().getScopedName(null) + "." + attrDef.getName();
    long sqlId = oidPool.createObjSqlId(idTag, idTag, iomObj.getobjectoid());
    String sqlTableName = getSqlTableNameItfLineTable(attrDef).getQName();
    String insert = createItfLineTableInsertStmt(attrDef);
    EhiLogger.traceBackendCmd(insert);
    PreparedStatement ps = conn.prepareStatement(insert);
    try {
        int valuei = 1;
        ps.setLong(valuei, sqlId);
        valuei++;
        if (createBasketCol) {
            ps.setLong(valuei, basketSqlId);
            valuei++;
        }
        if (createDatasetCol) {
            ps.setString(valuei, datasetName);
            valuei++;
        }
        if (readIliTid) {
            // import TID from transfer file
            ps.setString(valuei, iomObj.getobjectoid());
            valuei++;
        }
        IomObject value = iomObj.getattrobj(geomAttrName, 0);
        if (value != null) {
            boolean is3D = ((CoordType) (type).getControlPointDomain().getType()).getDimensions().length == 3;
            ps.setObject(valuei, geomConv.fromIomPolyline(value, recConv.getSrsid(attrDef), is3D, recConv.getP(type)));
        } else {
            geomConv.setPolylineNull(ps, valuei);
        }
        valuei++;
        if (type instanceof SurfaceType) {
            IomObject structvalue = iomObj.getattrobj(refAttrName, 0);
            String refoid = structvalue.getobjectrefoid();
            long refsqlId = oidPool.getObjSqlId(attrDef.getContainer().getScopedName(null), refoid);
            ps.setLong(valuei, refsqlId);
            valuei++;
        }
        if (lineAttrTable != null) {
            Iterator attri = lineAttrTable.getAttributes();
            while (attri.hasNext()) {
                AttributeDef lineattr = (AttributeDef) attri.next();
                valuei = recConv.addAttrValue(iomObj, ili2sqlName.mapGeometryAsTable(attrDef), sqlId, sqlTableName, ps, valuei, lineattr, null);
            }
        }
        if (createStdCols) {
            // T_LastChange
            ps.setTimestamp(valuei, today);
            valuei++;
            // T_CreateDate
            ps.setTimestamp(valuei, today);
            valuei++;
            // T_User
            ps.setString(valuei, dbusr);
            valuei++;
        }
        ps.executeUpdate();
    } finally {
        ps.close();
    }
}
Also used : Table(ch.interlis.ili2c.metamodel.Table) IomObject(ch.interlis.iom.IomObject) SurfaceOrAreaType(ch.interlis.ili2c.metamodel.SurfaceOrAreaType) Iterator(java.util.Iterator) PreparedStatement(java.sql.PreparedStatement) AttributeDef(ch.interlis.ili2c.metamodel.AttributeDef) SurfaceType(ch.interlis.ili2c.metamodel.SurfaceType) CoordType(ch.interlis.ili2c.metamodel.CoordType)

Example 12 with Table

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

the class TransferFromXtf method getStructs.

private HashSet<AbstractClassDef> getStructs(String topicQName) {
    Topic def = TransferToXtf.getTopicDef(td, topicQName);
    HashSet<AbstractClassDef> visitedStructs = new HashSet<AbstractClassDef>();
    while (def != null) {
        Iterator classi = def.iterator();
        while (classi.hasNext()) {
            Object classo = classi.next();
            if (classo instanceof Viewable) {
                if (classo instanceof Table && ((Table) classo).isIdentifiable()) {
                    getStructs_Helper((AbstractClassDef) classo, visitedStructs);
                }
            }
        }
        def = (Topic) def.getExtending();
    }
    return visitedStructs;
}
Also used : Table(ch.interlis.ili2c.metamodel.Table) Iterator(java.util.Iterator) Viewable(ch.interlis.ili2c.metamodel.Viewable) IomObject(ch.interlis.iom.IomObject) AbstractClassDef(ch.interlis.ili2c.metamodel.AbstractClassDef) Topic(ch.interlis.ili2c.metamodel.Topic) HashSet(java.util.HashSet)

Example 13 with Table

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

the class Ili2cUtility method isPureChbaseCatalogueRef.

public static boolean isPureChbaseCatalogueRef(TransferDescription td, AttributeDef attr) {
    Type typeo = attr.getDomain();
    if (typeo instanceof CompositionType) {
        CompositionType type = (CompositionType) typeo;
        Table struct = type.getComponentType();
        Table root = (Table) struct.getRootExtending();
        if (root == null) {
            root = struct;
        }
        if (root.getContainer().getScopedName(null).equals(IliNames.CHBASE1_CATALOGUEOBJECTS_CATALOGUES)) {
            if (root.getName().equals(IliNames.CHBASE1_CATALOGUEREFERENCE) || root.getName().equals(IliNames.CHBASE1_MANDATORYCATALOGUEREFERENCE)) {
                java.util.Iterator it = struct.getAttributesAndRoles2();
                int c = 0;
                while (it.hasNext()) {
                    it.next();
                    c++;
                }
                if (c == 1) {
                    // only one attribute
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : CompositionType(ch.interlis.ili2c.metamodel.CompositionType) Type(ch.interlis.ili2c.metamodel.Type) Table(ch.interlis.ili2c.metamodel.Table) CompositionType(ch.interlis.ili2c.metamodel.CompositionType)

Example 14 with Table

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

the class TransferToXtf method dumpItfTableObject.

private void dumpItfTableObject(IoxWriter out, AttributeDef attr, Long basketSqlId) {
    String stmt = createItfLineTableQueryStmt(attr, basketSqlId, geomConv);
    String sqlTabName = ili2sqlName.mapGeometryAsTable(attr);
    EhiLogger.traceBackendCmd(stmt);
    SurfaceOrAreaType type = (SurfaceOrAreaType) attr.getDomainResolvingAliases();
    String geomAttrName = ch.interlis.iom_j.itf.ModelUtilities.getHelperTableGeomAttrName(attr);
    String refAttrName = null;
    if (type instanceof SurfaceType) {
        refAttrName = ch.interlis.iom_j.itf.ModelUtilities.getHelperTableMainTableRef(attr);
    }
    java.sql.PreparedStatement dbstmt = null;
    try {
        dbstmt = conn.prepareStatement(stmt);
        dbstmt.clearParameters();
        int paramIdx = 1;
        if (basketSqlId != null) {
            dbstmt.setLong(paramIdx++, basketSqlId);
        }
        java.sql.ResultSet rs = dbstmt.executeQuery();
        while (rs.next()) {
            int valuei = 1;
            long sqlid = rs.getLong(valuei);
            valuei++;
            String sqlIliTid = null;
            if (writeIliTid) {
                sqlIliTid = rs.getString(valuei);
                valuei++;
            } else {
                sqlIliTid = Long.toString(sqlid);
            }
            Viewable aclass = (Viewable) attr.getContainer();
            Iom_jObject iomObj;
            iomObj = new Iom_jObject(aclass.getScopedName(null) + "_" + attr.getName(), sqlIliTid);
            // geomAttr
            Object geomobj = rs.getObject(valuei);
            valuei++;
            if (!rs.wasNull()) {
                try {
                    boolean is3D = false;
                    IomObject polyline = geomConv.toIomPolyline(geomobj, ili2sqlName.getSqlColNameItfLineTableGeomAttr(attr, sqlTabName), is3D);
                    iomObj.addattrobj(geomAttrName, polyline);
                } catch (ConverterException ex) {
                    EhiLogger.logError("Object " + sqlid + ": failed to convert polyline", ex);
                }
            }
            // is of type SURFACE?
            if (type instanceof SurfaceType) {
                // -> mainTable
                IomObject ref = iomObj.addattrobj(refAttrName, "REF");
                long refSqlId = rs.getLong(valuei);
                if (sqlidPool.containsSqlid(refSqlId)) {
                    String refTid = sqlidPool.getXtfid(refSqlId);
                    ref.setobjectrefoid(refTid);
                } else {
                    EhiLogger.logError("unknown referenced object " + attr.getContainer().getScopedName(null) + " sqlid " + refSqlId + " referenced from " + sqlTabName + " " + colT_ID + " " + sqlid);
                }
                valuei++;
            }
            Table lineAttrTable = type.getLineAttributeStructure();
            if (lineAttrTable != null) {
                Iterator attri = lineAttrTable.getAttributes();
                while (attri.hasNext()) {
                    AttributeDef lineattr = (AttributeDef) attri.next();
                    valuei = recConv.addAttrValue(rs, valuei, sqlid, iomObj, lineattr, null, class2wrapper.get(lineAttrTable), null);
                }
            }
            if (out != null) {
                // write object
                ObjectEvent objEvent = new ObjectEvent(iomObj);
                if (languageFilter != null) {
                    objEvent = (ObjectEvent) languageFilter.filter(objEvent);
                }
                if (exportBaseModelFilter != null) {
                    objEvent = (ObjectEvent) exportBaseModelFilter.filter(objEvent);
                }
                if (validator != null)
                    validator.validate(objEvent);
                out.write(objEvent);
            }
        }
    } catch (java.sql.SQLException ex) {
        EhiLogger.logError("failed to query " + attr.getScopedName(null), ex);
    } catch (ch.interlis.iox.IoxException ex) {
        EhiLogger.logError("failed to write " + attr.getScopedName(null), ex);
    } finally {
        if (dbstmt != null) {
            try {
                dbstmt.close();
            } catch (java.sql.SQLException ex) {
                EhiLogger.logError("failed to close query of " + attr.getScopedName(null), ex);
            }
        }
    }
}
Also used : ObjectEvent(ch.interlis.iox_j.ObjectEvent) ConverterException(ch.ehi.ili2db.converter.ConverterException) Table(ch.interlis.ili2c.metamodel.Table) SurfaceOrAreaType(ch.interlis.ili2c.metamodel.SurfaceOrAreaType) SurfaceType(ch.interlis.ili2c.metamodel.SurfaceType) Iom_jObject(ch.interlis.iom_j.Iom_jObject) IoxException(ch.interlis.iox.IoxException) IomObject(ch.interlis.iom.IomObject) Viewable(ch.interlis.ili2c.metamodel.Viewable) Iterator(java.util.Iterator) Iom_jObject(ch.interlis.iom_j.Iom_jObject) IomObject(ch.interlis.iom.IomObject) AttributeDef(ch.interlis.ili2c.metamodel.AttributeDef)

Example 15 with Table

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

the class FromXtfRecordConverter method getMultiPointAttrDef.

protected AttributeDef getMultiPointAttrDef(Type type, MultiPointMapping attrMapping) {
    Table multiPointType = ((CompositionType) type).getComponentType();
    Table pointStructureType = ((CompositionType) ((AttributeDef) multiPointType.getElement(AttributeDef.class, attrMapping.getBagOfPointsAttrName())).getDomain()).getComponentType();
    AttributeDef coordAttr = (AttributeDef) pointStructureType.getElement(AttributeDef.class, attrMapping.getPointAttrName());
    return coordAttr;
}
Also used : Table(ch.interlis.ili2c.metamodel.Table) AttributeDef(ch.interlis.ili2c.metamodel.AttributeDef) CompositionType(ch.interlis.ili2c.metamodel.CompositionType)

Aggregations

Table (ch.interlis.ili2c.metamodel.Table)24 AttributeDef (ch.interlis.ili2c.metamodel.AttributeDef)16 CompositionType (ch.interlis.ili2c.metamodel.CompositionType)15 Type (ch.interlis.ili2c.metamodel.Type)11 SurfaceType (ch.interlis.ili2c.metamodel.SurfaceType)10 Iterator (java.util.Iterator)10 SurfaceOrAreaType (ch.interlis.ili2c.metamodel.SurfaceOrAreaType)9 CoordType (ch.interlis.ili2c.metamodel.CoordType)6 Viewable (ch.interlis.ili2c.metamodel.Viewable)5 ViewableTransferElement (ch.interlis.ili2c.metamodel.ViewableTransferElement)5 IomObject (ch.interlis.iom.IomObject)5 AbstractClassDef (ch.interlis.ili2c.metamodel.AbstractClassDef)4 EnumerationType (ch.interlis.ili2c.metamodel.EnumerationType)4 PolylineType (ch.interlis.ili2c.metamodel.PolylineType)4 ViewableWrapper (ch.ehi.ili2db.mapping.ViewableWrapper)3 DbTable (ch.ehi.sqlgen.repository.DbTable)3 DbTableName (ch.ehi.sqlgen.repository.DbTableName)3 ConverterException (ch.ehi.ili2db.converter.ConverterException)2 DbColId (ch.ehi.sqlgen.repository.DbColId)2 Domain (ch.interlis.ili2c.metamodel.Domain)2