Search in sources :

Example 26 with Viewable

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

the class FromXtfRecordConverter method setReferenceColumn.

private void setReferenceColumn(PreparedStatement ps, AbstractClassDef destination, String refoid, Holder<Integer> valuei) throws SQLException {
    String targetRootClassName = Ili2cUtility.getRootViewable(destination).getScopedName(null);
    ViewableWrapper targetObjTable = null;
    ArrayList<ViewableWrapper> targetTables = getTargetTables(destination);
    if (refoid != null) {
        String targetObjClass = oidPool.getObjecttag(targetRootClassName, refoid);
        if (targetObjClass == null) {
            // unknown object
            // handle reference as if it is null
            refoid = null;
        } else {
            targetObjTable = getViewableWrapper(getSqlType((Viewable) tag2class.get(targetObjClass)).getName());
            while (!targetTables.contains(targetObjTable)) {
                targetObjTable = targetObjTable.getExtending();
            }
            if (targetObjTable == null) {
                throw new IllegalStateException("targetObjTable==null");
            }
        }
    }
    for (ViewableWrapper targetTable : targetTables) {
        if (refoid != null && targetTable == targetObjTable) {
            long refsqlId = oidPool.getObjSqlId(targetRootClassName, refoid);
            ps.setLong(valuei.value, refsqlId);
        } else {
            ps.setNull(valuei.value, Types.BIGINT);
        }
        valuei.value++;
    }
}
Also used : Viewable(ch.interlis.ili2c.metamodel.Viewable) ViewableWrapper(ch.ehi.ili2db.mapping.ViewableWrapper)

Example 27 with Viewable

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

the class TransferFromXtf method readObjectSqlIds.

private void readObjectSqlIds(boolean noTypeCol, DbTableName sqltablename, long basketsqlid) {
    String stmt = createQueryStmt4sqlids(noTypeCol, sqltablename.getQName());
    EhiLogger.traceBackendCmd(stmt);
    java.sql.PreparedStatement dbstmt = null;
    try {
        dbstmt = conn.prepareStatement(stmt);
        dbstmt.clearParameters();
        dbstmt.setLong(1, basketsqlid);
        java.sql.ResultSet rs = dbstmt.executeQuery();
        while (rs.next()) {
            long sqlid = rs.getLong(1);
            String xtfid = rs.getString(2);
            String sqlType = null;
            if (!noTypeCol) {
                sqlType = rs.getString(3);
            } else {
                sqlType = sqltablename.getName();
            }
            Viewable aclass = (Viewable) tag2class.get(ili2sqlName.mapSqlTableName(sqlType));
            oidPool.putXtfid2sqlid(Ili2cUtility.getRootViewable(aclass).getScopedName(null), aclass.getScopedName(null), xtfid, sqlid);
            addExistingObjects(sqlType, sqlid);
        }
    } catch (java.sql.SQLException ex) {
        EhiLogger.logError("failed to query " + sqltablename, ex);
    } finally {
        if (dbstmt != null) {
            try {
                dbstmt.close();
            } catch (java.sql.SQLException ex) {
                EhiLogger.logError("failed to close query of " + sqltablename, ex);
            }
        }
    }
}
Also used : SQLException(java.sql.SQLException) Viewable(ch.interlis.ili2c.metamodel.Viewable) PreparedStatement(java.sql.PreparedStatement)

Example 28 with Viewable

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

the class TransferFromXtf method allReferencesKnownHelper.

private void allReferencesKnownHelper(IomObject iomObj, AttributeDef attr, FixIomObjectExtRefs extref) {
    String attrName = attr.getName();
    if (attr.isDomainBoolean()) {
    } else if (attr.isDomainIli1Date()) {
    } else if (attr.isDomainIli2Date()) {
    } else if (attr.isDomainIli2Time()) {
    } else if (attr.isDomainIli2DateTime()) {
    } else {
        Type type = attr.getDomainResolvingAliases();
        if (type instanceof CompositionType) {
            // enqueue struct values
            int structc = iomObj.getattrvaluecount(attrName);
            for (int structi = 0; structi < structc; structi++) {
                IomObject struct = iomObj.getattrobj(attrName, structi);
                allReferencesKnownHelper(struct, extref);
            }
        } else if (type instanceof PolylineType) {
        } else if (type instanceof SurfaceOrAreaType) {
        } else if (type instanceof CoordType) {
        } else if (type instanceof NumericType) {
        } else if (type instanceof EnumerationType) {
        } else if (type instanceof ReferenceType) {
            IomObject structvalue = iomObj.getattrobj(attrName, 0);
            String refoid = null;
            if (structvalue != null) {
                refoid = structvalue.getobjectrefoid();
            }
            if (refoid != null) {
                Viewable targetClass = ((ReferenceType) type).getReferred();
                if (!oidPool.containsXtfid(Ili2cUtility.getRootViewable(targetClass).getScopedName(null), refoid)) {
                    extref.addFix(structvalue, targetClass);
                }
            }
        } else {
        }
    }
}
Also used : PolylineType(ch.interlis.ili2c.metamodel.PolylineType) NumericType(ch.interlis.ili2c.metamodel.NumericType) 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) ObjectType(ch.interlis.ili2c.metamodel.ObjectType) CoordType(ch.interlis.ili2c.metamodel.CoordType) IomObject(ch.interlis.iom.IomObject) SurfaceOrAreaType(ch.interlis.ili2c.metamodel.SurfaceOrAreaType) EnumerationType(ch.interlis.ili2c.metamodel.EnumerationType) Viewable(ch.interlis.ili2c.metamodel.Viewable) CompositionType(ch.interlis.ili2c.metamodel.CompositionType) ReferenceType(ch.interlis.ili2c.metamodel.ReferenceType) CoordType(ch.interlis.ili2c.metamodel.CoordType)

Example 29 with Viewable

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

the class TransferFromXtf method readObjectSqlid.

private Long readObjectSqlid(Viewable xclass, String xtfid) {
    String stmt = createQueryStmt4sqlid(xclass);
    EhiLogger.traceBackendCmd(stmt);
    java.sql.PreparedStatement dbstmt = null;
    long sqlid = 0;
    String sqlType = null;
    try {
        dbstmt = conn.prepareStatement(stmt);
        dbstmt.clearParameters();
        if ((xclass instanceof AbstractClassDef) && ((AbstractClassDef) xclass).getOid() != null && AbstractRecordConverter.isUuidOid(td, ((AbstractClassDef) xclass).getOid())) {
            dbstmt.setObject(1, geomConv.fromIomUuid(xtfid));
        } else {
            dbstmt.setString(1, xtfid);
        }
        java.sql.ResultSet rs = dbstmt.executeQuery();
        if (rs.next()) {
            sqlid = rs.getLong(1);
            sqlType = rs.getString(3);
        } else {
            // unknown object
            return null;
        }
    } catch (java.sql.SQLException ex) {
        EhiLogger.logError("failed to query " + xclass.getScopedName(null), ex);
    } catch (ConverterException ex) {
        EhiLogger.logError("failed to query " + xclass.getScopedName(null), ex);
    } finally {
        if (dbstmt != null) {
            try {
                dbstmt.close();
            } catch (java.sql.SQLException ex) {
                EhiLogger.logError("failed to close query of " + xclass.getScopedName(null), ex);
            }
        }
    }
    // remember found sqlid
    Viewable aclass = (Viewable) tag2class.get(ili2sqlName.mapSqlTableName(sqlType));
    oidPool.putXtfid2sqlid(Ili2cUtility.getRootViewable(aclass).getScopedName(null), aclass.getScopedName(null), xtfid, sqlid);
    return sqlid;
}
Also used : ConverterException(ch.ehi.ili2db.converter.ConverterException) SQLException(java.sql.SQLException) Viewable(ch.interlis.ili2c.metamodel.Viewable) AbstractClassDef(ch.interlis.ili2c.metamodel.AbstractClassDef) PreparedStatement(java.sql.PreparedStatement)

Example 30 with Viewable

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

the class AbstractRecordConverter method getTargetTables.

public ArrayList<ViewableWrapper> getTargetTables(Viewable destination) {
    if (targetTablesPool.containsKey(destination)) {
        return targetTablesPool.get(destination);
    }
    ArrayList<ViewableWrapper> ret = new ArrayList<ViewableWrapper>();
    ArrayList<Viewable> candids = new ArrayList<Viewable>();
    candids.add(destination);
    while (!candids.isEmpty()) {
        Viewable candid = candids.remove(0);
        String inheritanceStrategy = trafoConfig.getViewableConfig(candid, TrafoConfigNames.INHERITANCE_TRAFO);
        if (TrafoConfigNames.INHERITANCE_TRAFO_SUPERCLASS.equals(inheritanceStrategy)) {
            // ViewableWrapper of base
            ret.add(class2wrapper.get(candid));
        } else if (TrafoConfigNames.INHERITANCE_TRAFO_SUBCLASS.equals(inheritanceStrategy)) {
            // visit all sub classes
            candids.addAll(candid.getDirectExtensions());
        } else if (TrafoConfigNames.INHERITANCE_TRAFO_NEWCLASS.equals(inheritanceStrategy)) {
            ViewableWrapper wrapper = class2wrapper.get(candid);
            // classes that have no defined Wrapper are loaded by the compiler, but are not used
            if (wrapper != null) {
                ret.add(wrapper);
            }
        } else if (TrafoConfigNames.INHERITANCE_TRAFO_NEWANDSUBCLASS.equals(inheritanceStrategy)) {
            ViewableWrapper wrapper = class2wrapper.get(candid);
            // classes that have no defined Wrapper are loaded by the compiler, but are not used
            if (wrapper != null) {
                ret.add(wrapper);
            }
            // visit all sub classes
            candids.addAll(candid.getDirectExtensions());
        } else {
        // skip it
        // classes that have no assigned inheritanceStrategy are loaded by the compiler, but are not used
        // example:
        // CLASS CatalogueObjectTrees_V1.Catalogues.Item is loaded and an extension
        // of CLASS CatalogueObjects_V1.Catalogues.Item.
        // It is loaded because it is defined in the same ili-file, but is normally not used.
        }
    }
    // buffer result, so that later calls return exactly the same ordering of targetTables
    // first call: build sql statement
    // second++ calls: set/get sql parameters
    targetTablesPool.put(destination, ret);
    return ret;
}
Also used : ArrayList(java.util.ArrayList) Viewable(ch.interlis.ili2c.metamodel.Viewable) ViewableWrapper(ch.ehi.ili2db.mapping.ViewableWrapper)

Aggregations

Viewable (ch.interlis.ili2c.metamodel.Viewable)36 Iterator (java.util.Iterator)16 AttributeDef (ch.interlis.ili2c.metamodel.AttributeDef)14 IomObject (ch.interlis.iom.IomObject)13 ViewableWrapper (ch.ehi.ili2db.mapping.ViewableWrapper)11 SurfaceOrAreaType (ch.interlis.ili2c.metamodel.SurfaceOrAreaType)10 EnumerationType (ch.interlis.ili2c.metamodel.EnumerationType)9 ArrayList (java.util.ArrayList)9 CompositionType (ch.interlis.ili2c.metamodel.CompositionType)8 SurfaceType (ch.interlis.ili2c.metamodel.SurfaceType)8 ViewableTransferElement (ch.interlis.ili2c.metamodel.ViewableTransferElement)8 Topic (ch.interlis.ili2c.metamodel.Topic)7 Type (ch.interlis.ili2c.metamodel.Type)7 HashSet (java.util.HashSet)7 Ili2dbException (ch.ehi.ili2db.base.Ili2dbException)6 Model (ch.interlis.ili2c.metamodel.Model)6 ObjectType (ch.interlis.ili2c.metamodel.ObjectType)6 DbTableName (ch.ehi.sqlgen.repository.DbTableName)5 CoordType (ch.interlis.ili2c.metamodel.CoordType)5 NumericType (ch.interlis.ili2c.metamodel.NumericType)5