Search in sources :

Example 6 with AbstractClassDef

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

the class TransferFromXtf method getStructs_Helper.

private void getStructs_Helper(AbstractClassDef aclass, HashSet<AbstractClassDef> accu) {
    if (accu.contains(aclass)) {
        return;
    }
    java.util.Set seed = null;
    if (aclass instanceof Table && !((Table) aclass).isIdentifiable()) {
        // STRUCTURE
        seed = aclass.getExtensions();
    } else {
        // CLASS
        seed = new HashSet();
        seed.add(aclass);
    }
    for (Object defo : seed) {
        AbstractClassDef def = (AbstractClassDef) defo;
        if (accu.contains(def)) {
            continue;
        }
        if (def instanceof Table && !((Table) def).isIdentifiable()) {
            accu.add(def);
        }
        while (def != null) {
            Iterator attri = def.iterator();
            while (attri.hasNext()) {
                Object attro = attri.next();
                if (attro instanceof AttributeDef) {
                    AttributeDef attr = (AttributeDef) attro;
                    Type type = attr.getDomain();
                    if (type instanceof CompositionType) {
                        CompositionType compType = (CompositionType) type;
                        getStructs_Helper(compType.getComponentType(), accu);
                        Iterator resti = compType.iteratorRestrictedTo();
                        while (resti.hasNext()) {
                            AbstractClassDef rest = (AbstractClassDef) resti.next();
                            getStructs_Helper(rest, accu);
                        }
                    }
                }
            }
            // base viewable
            def = (AbstractClassDef) def.getExtending();
            if (accu.contains(def)) {
                def = null;
            }
        }
    }
}
Also used : 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) Table(ch.interlis.ili2c.metamodel.Table) Iterator(java.util.Iterator) IomObject(ch.interlis.iom.IomObject) AttributeDef(ch.interlis.ili2c.metamodel.AttributeDef) AbstractClassDef(ch.interlis.ili2c.metamodel.AbstractClassDef) CompositionType(ch.interlis.ili2c.metamodel.CompositionType) HashSet(java.util.HashSet)

Example 7 with AbstractClassDef

use of ch.interlis.ili2c.metamodel.AbstractClassDef 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 8 with AbstractClassDef

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

the class Viewable2TableMapper method isReferenced.

private static boolean isReferenced(Viewable viewable) {
    if (viewable instanceof AbstractClassDef) {
        AbstractClassDef aclass = (AbstractClassDef) viewable;
        Iterator<RoleDef> rolei = aclass.getDefinedTargetForRoles();
        while (rolei.hasNext()) {
            RoleDef role = rolei.next();
            AssociationDef assoc = (AssociationDef) role.getContainer();
            if (!assoc.isLightweight()) {
                return true;
            }
            if (!role.isAssociationEmbedded()) {
                // opposide role is embedded into opposide class, so opposide class references this viewable
                return true;
            }
        }
    }
    return false;
}
Also used : RoleDef(ch.interlis.ili2c.metamodel.RoleDef) AssociationDef(ch.interlis.ili2c.metamodel.AssociationDef) AbstractClassDef(ch.interlis.ili2c.metamodel.AbstractClassDef)

Example 9 with AbstractClassDef

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

the class ViewableWrapper method getOid.

public Domain getOid() {
    if (isSecondaryTable()) {
        return null;
    }
    Viewable def = getViewable();
    if (!(def instanceof AbstractClassDef)) {
        return null;
    }
    if ((def instanceof Table) && !((Table) def).isIdentifiable()) {
        return null;
    }
    AbstractClassDef aclass = (AbstractClassDef) def;
    if (aclass.getOid() != null) {
        return aclass.getOid();
    }
    for (Object exto : aclass.getExtensions()) {
        AbstractClassDef ext = (AbstractClassDef) exto;
        if (ext.getOid() != null) {
            return ext.getOid();
        }
    }
    return null;
}
Also used : Table(ch.interlis.ili2c.metamodel.Table) Viewable(ch.interlis.ili2c.metamodel.Viewable) AbstractClassDef(ch.interlis.ili2c.metamodel.AbstractClassDef)

Aggregations

AbstractClassDef (ch.interlis.ili2c.metamodel.AbstractClassDef)9 Table (ch.interlis.ili2c.metamodel.Table)4 Viewable (ch.interlis.ili2c.metamodel.Viewable)4 HashSet (java.util.HashSet)4 IomObject (ch.interlis.iom.IomObject)3 Iterator (java.util.Iterator)3 ConverterException (ch.ehi.ili2db.converter.ConverterException)2 AssociationDef (ch.interlis.ili2c.metamodel.AssociationDef)2 AttributeDef (ch.interlis.ili2c.metamodel.AttributeDef)2 CompositionType (ch.interlis.ili2c.metamodel.CompositionType)2 CoordType (ch.interlis.ili2c.metamodel.CoordType)2 EnumerationType (ch.interlis.ili2c.metamodel.EnumerationType)2 PolylineType (ch.interlis.ili2c.metamodel.PolylineType)2 RoleDef (ch.interlis.ili2c.metamodel.RoleDef)2 SurfaceOrAreaType (ch.interlis.ili2c.metamodel.SurfaceOrAreaType)2 SurfaceType (ch.interlis.ili2c.metamodel.SurfaceType)2 Type (ch.interlis.ili2c.metamodel.Type)2 ViewableTransferElement (ch.interlis.ili2c.metamodel.ViewableTransferElement)2 Ili2dbException (ch.ehi.ili2db.base.Ili2dbException)1 ViewableWrapper (ch.ehi.ili2db.mapping.ViewableWrapper)1