Search in sources :

Example 1 with Domain

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

the class TransferToXtf method doitJava.

public void doitJava() {
    try {
        expgen = new ch.interlis.ili2c.generator.IndentPrintWriter(new java.io.BufferedWriter(new java.io.FileWriter("c:/tmp/ili2db/export.java")));
        expgen.println("import ch.ehi.basics.logging.EhiLogger;");
        expgen.println("import ch.interlis.iom.IomObject;");
        expgen.println("public class TransferToXtf implements IdMapper {");
        expgen.indent();
        expgen.println("private java.sql.Connection conn=null;");
        expgen.println("private IomObject newObject(String className,String tid)");
        expgen.println("{");
        expgen.indent();
        expgen.println("// TODO create new object");
        expgen.println("return null;");
        expgen.unindent();
        expgen.println("}");
        expgen.println("private void writeObject(IomObject iomObj)");
        expgen.println("{");
        expgen.indent();
        expgen.println("// TODO write object");
        expgen.unindent();
        expgen.println("}");
        expgen.println("public String mapId(String idSpace,String id)");
        expgen.println("{");
        expgen.indent();
        expgen.println("// TODO mapId");
        expgen.println("return id;");
        expgen.unindent();
        expgen.println("}");
        expgen.println("public String newId()");
        expgen.println("{");
        expgen.indent();
        expgen.println("// TODO newId");
        expgen.println("throw new UnsupportedOperationException(\"this mapper doesn't generate new ids\");");
        expgen.unindent();
        expgen.println("}");
    } catch (java.io.IOException ex) {
        EhiLogger.logError("failed to open file for java output", ex);
    }
    try {
        // for all MODELs
        Iterator modeli = td.iterator();
        while (modeli.hasNext()) {
            Object mObj = modeli.next();
            if ((mObj instanceof Model) && !(suppressModel((Model) mObj))) {
                Model model = (Model) mObj;
                // for all TOPICs
                Iterator topici = model.iterator();
                while (topici.hasNext()) {
                    Object tObj = topici.next();
                    if (tObj instanceof Topic && !(suppressTopic((Topic) tObj))) {
                        Topic topic = (Topic) tObj;
                        // IomBasket iomBasket=null;
                        // for all Viewables
                        Iterator iter = topic.getViewables().iterator();
                        while (iter.hasNext()) {
                            Object obj = iter.next();
                            if ((obj instanceof Viewable) && !suppressViewableIfJava((Viewable) obj)) {
                                Viewable aclass = (Viewable) obj;
                                // dump it
                                EhiLogger.logState(aclass.getScopedName(null) + "...");
                                genClassHelper(aclass);
                            } else if (obj instanceof Domain) {
                                Domain domainDef = (Domain) obj;
                                if (domainDef.getType() instanceof EnumerationType) {
                                    String enumName = domainDef.getScopedName(null);
                                    enumTypes.add(enumName);
                                }
                            }
                        }
                    } else if ((tObj instanceof Viewable) && !suppressViewableIfJava((Viewable) tObj)) {
                        Viewable aclass = (Viewable) tObj;
                        // dump it
                        EhiLogger.logState(aclass.getScopedName(null) + "...");
                        genClassHelper(aclass);
                    } else if (tObj instanceof Domain) {
                        Domain domainDef = (Domain) tObj;
                        if (domainDef.getType() instanceof EnumerationType) {
                            String enumName = domainDef.getScopedName(null);
                            enumTypes.add(enumName);
                        }
                    }
                }
            }
        }
    } finally {
        if (expgen != null) {
            {
                expgen.println("private void addAny(String iliClassName,String select){");
                expgen.indent();
                Iterator linei = addanyLines.iterator();
                String sep = "";
                while (linei.hasNext()) {
                    String line = (String) linei.next();
                    expgen.println(sep + line);
                    sep = "else ";
                }
                if (sep.length() > 0) {
                    expgen.println("else{EhiLogger.logError(\"unknown class \"+iliClassName);}");
                } else {
                    expgen.println("EhiLogger.logError(\"unknown class \"+iliClassName);");
                }
                expgen.unindent();
                expgen.println("}");
            }
            {
                expgen.println("private EnumMapper getEnumMapper(String enumName){");
                expgen.indent();
                Iterator enumi = enumTypes.iterator();
                String sep = "";
                while (enumi.hasNext()) {
                    String enumName = (String) enumi.next();
                    expgen.println(sep + "if(enumName.equals(\"" + enumName + "\")){return new IdentityEnumMapper();}");
                    sep = "else ";
                }
                if (sep.length() > 0) {
                    expgen.println("else{throw new IllegalArgumentException(\"unknown enum \"+enumName);}");
                } else {
                    expgen.println("throw new IllegalArgumentException(\"unknown enum \"+enumName);");
                }
                expgen.unindent();
                expgen.println("}");
            }
            expgen.unindent();
            expgen.println("}");
            expgen.close();
        }
    }
}
Also used : EnumerationType(ch.interlis.ili2c.metamodel.EnumerationType) Iterator(java.util.Iterator) ReduceToBaseModel(ch.interlis.iox_j.filter.ReduceToBaseModel) PredefinedModel(ch.interlis.ili2c.metamodel.PredefinedModel) TypeModel(ch.interlis.ili2c.metamodel.TypeModel) Model(ch.interlis.ili2c.metamodel.Model) Viewable(ch.interlis.ili2c.metamodel.Viewable) Iom_jObject(ch.interlis.iom_j.Iom_jObject) IomObject(ch.interlis.iom.IomObject) Topic(ch.interlis.ili2c.metamodel.Topic) Domain(ch.interlis.ili2c.metamodel.Domain)

Example 2 with Domain

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

the class TransferToXtf method genClassHelper.

private void genClassHelper(Viewable aclass) {
    boolean doStruct = false;
    if (aclass instanceof Table) {
        doStruct = !((Table) aclass).isIdentifiable();
    }
    if (doStruct) {
        expgen.println("private void add" + aclass.getName() + "(String parentTid,String parentAttrSql,IomObject parent,String parentAttrIli)");
    } else {
        expgen.println("private void add" + aclass.getName() + "(String subset)");
        String addany = "if(iliClassName.equals(\"" + aclass.getScopedName(null) + "\")){add" + aclass.getName() + "(select);}";
        addanyLines.add(addany);
    }
    expgen.println("{");
    expgen.indent();
    expgen.println("String tabName=\"" + createQueryStmtFromClause(aclass) + "\";");
    expgen.println("String stmt=\"" + recConv.createQueryStmt(aclass, null, null) + "\";");
    if (!doStruct) {
        expgen.println("if(subset!=null){");
        expgen.println("stmt=stmt+\" AND \"+subset;");
        expgen.println("}");
    }
    expgen.println("EhiLogger.traceBackendCmd(stmt);");
    expgen.println("java.sql.PreparedStatement dbstmt = null;");
    expgen.println("try{");
    expgen.indent();
    // expgen.println("dbstmt = conn.createStatement();");
    // expgen.println("java.sql.ResultSet rs=dbstmt.executeQuery(stmt);");
    expgen.println("dbstmt = conn.prepareStatement(stmt);");
    expgen.println("dbstmt.clearParameters();");
    if (doStruct) {
        expgen.println("dbstmt.setString(1,parentTid);");
        expgen.println("dbstmt.setString(2,parentAttrSql);");
    }
    expgen.println("java.sql.ResultSet rs=dbstmt.executeQuery();");
    expgen.println("while(rs.next()){");
    expgen.indent();
    expgen.println("String tid=DbUtility.getString(rs,\"T_Id\",false,tabName);");
    expgen.println("String recInfo=tabName+\" \"+tid;");
    expgen.println("IomObject iomObj;");
    if (!doStruct) {
        expgen.println("iomObj=newObject(\"" + aclass.getScopedName(null) + "\",mapId(\"" + recConv.getSqlType(aclass) + "\",tid));");
    } else {
        expgen.println("iomObj=(IomObject)parent.addattrobj(parentAttrIli,\"" + aclass.getScopedName(null) + "\");");
    }
    Iterator iter = aclass.getAttributesAndRoles2();
    while (iter.hasNext()) {
        ViewableTransferElement obj = (ViewableTransferElement) iter.next();
        if (obj.obj instanceof AttributeDef) {
            AttributeDef attr = (AttributeDef) obj.obj;
            if (attr.getExtending() == null) {
                String attrName = attr.getName();
                String sqlAttrName = ili2sqlName.mapIliAttributeDef(attr, recConv.getSqlType(aclass).getName(), null);
                Type type = attr.getDomain();
                if ((type instanceof TypeAlias) && Ili2cUtility.isBoolean(td, type)) {
                    expgen.println("Boolean prop_" + attrName + "=Db2Xtf.getBoolean(rs,\"" + sqlAttrName + "\"," + (type.isMandatoryConsideringAliases() ? "false" : "true") + ",recInfo,iomObj,\"" + attrName + "\");");
                } else {
                    type = attr.getDomainResolvingAliases();
                    if (type instanceof CompositionType) {
                        // enque iomObj as parent
                        // enqueueStructAttr(new StructWrapper(tid,attr,iomObj));
                        CompositionType ct = (CompositionType) type;
                        expgen.println("add" + ct.getComponentType().getName() + "(tid,\"" + ili2sqlName.mapIliAttributeDef(attr, recConv.getSqlType(aclass).getName(), null) + "\",iomObj,\"" + attr.getName() + "\");");
                    } else if (type instanceof PolylineType) {
                    } else if (type instanceof SurfaceOrAreaType) {
                    } else if (type instanceof CoordType) {
                    } else if (type instanceof EnumerationType) {
                        String enumName = null;
                        if (attr.getDomain() instanceof TypeAlias) {
                            Domain domainDef = ((TypeAlias) attr.getDomain()).getAliasing();
                            enumName = domainDef.getScopedName(null);
                        } else {
                            enumName = aclass.getScopedName(null) + "->" + attrName;
                            enumTypes.add(enumName);
                        }
                        expgen.println("String prop_" + attrName + "=Db2Xtf.getEnum(rs,\"" + sqlAttrName + "\"," + (type.isMandatoryConsideringAliases() ? "false" : "true") + ",recInfo,getEnumMapper(\"" + enumName + "\"),iomObj,\"" + attrName + "\");");
                    } else {
                        expgen.println("String prop_" + attrName + "=Db2Xtf.getString(rs,\"" + sqlAttrName + "\"," + (type.isMandatoryConsideringAliases() ? "false" : "true") + ",recInfo,iomObj,\"" + attrName + "\");");
                    }
                }
            }
        }
        if (obj.obj instanceof RoleDef) {
            RoleDef role = (RoleDef) obj.obj;
            if (role.getExtending() == null) {
                String roleName = role.getName();
                String sqlRoleName = ili2sqlName.mapIliRoleDef(role, recConv.getSqlType(aclass).getName(), recConv.getSqlType(role.getDestination()).getName());
                // a role of an embedded association?
                if (obj.embedded) {
                    AssociationDef roleOwner = (AssociationDef) role.getContainer();
                    if (roleOwner.getDerivedFrom() == null) {
                        // TODO if(orderPos!=0){
                        expgen.println("String prop_" + roleName + "=Db2Xtf.getRef(rs,\"" + sqlRoleName + "\"," + "true" + ",recInfo,this,\"" + recConv.getSqlType(role.getDestination()) + "\",iomObj,\"" + roleName + "\",\"" + roleOwner.getScopedName(null) + "\");");
                    }
                } else {
                    // TODO if(orderPos!=0){
                    expgen.println("String prop_" + roleName + "=Db2Xtf.getRef(rs,\"" + sqlRoleName + "\"," + "false" + ",recInfo,this,\"" + recConv.getSqlType(role.getDestination()) + "\",iomObj,\"" + roleName + "\",\"REF\");");
                }
            }
        }
    }
    // add referenced and referencing objects if it is not a struct
    if (!doStruct && aclass instanceof AbstractClassDef) {
        AbstractClassDef aclass2 = (AbstractClassDef) aclass;
        Iterator associ = aclass2.getTargetForRoles();
        while (associ.hasNext()) {
            RoleDef roleThis = (RoleDef) associ.next();
            if (roleThis.getKind() == RoleDef.Kind.eAGGREGATE || roleThis.getKind() == RoleDef.Kind.eCOMPOSITE) {
                RoleDef oppEnd = roleThis.getOppEnd();
                if (roleThis.isAssociationEmbedded()) {
                    expgen.println("addPendingObject(\"" + oppEnd.getDestination().getScopedName(null) + "\",\"T_Id\",prop_" + oppEnd.getName() + ");");
                } else if (oppEnd.isAssociationEmbedded()) {
                    expgen.println("addPendingObject(\"" + oppEnd.getDestination().getScopedName(null) + "\",\"" + ili2sqlName.mapIliRoleDef(roleThis, null, null) + "\",tid);");
                } else {
                    expgen.println("addPendingObject(\"" + ((AssociationDef) (oppEnd.getContainer())).getScopedName(null) + "\",\"" + ili2sqlName.mapIliRoleDef(roleThis, null, null) + "\",prop_" + roleThis.getName() + ");");
                }
            }
        }
    }
    // writeObject if it is not a struct
    if (!doStruct) {
        expgen.println("writeObject(iomObj);");
    }
    expgen.unindent();
    expgen.println("}");
    expgen.unindent();
    expgen.println("}catch(java.sql.SQLException ex){");
    expgen.indent();
    expgen.println("EhiLogger.logError(\"failed to query \"+tabName,ex);");
    expgen.unindent();
    expgen.println("}finally{");
    expgen.indent();
    expgen.println("if(dbstmt!=null){");
    expgen.indent();
    expgen.println("try{");
    expgen.indent();
    expgen.println("dbstmt.close();");
    expgen.unindent();
    expgen.println("}catch(java.sql.SQLException ex){");
    expgen.indent();
    expgen.println("EhiLogger.logError(\"failed to close query of \"+tabName,ex);");
    expgen.unindent();
    expgen.println("}");
    expgen.unindent();
    expgen.println("}");
    expgen.unindent();
    expgen.println("}");
    expgen.unindent();
    expgen.println("}");
}
Also used : ViewableTransferElement(ch.interlis.ili2c.metamodel.ViewableTransferElement) PolylineType(ch.interlis.ili2c.metamodel.PolylineType) Table(ch.interlis.ili2c.metamodel.Table) SurfaceOrAreaType(ch.interlis.ili2c.metamodel.SurfaceOrAreaType) RoleDef(ch.interlis.ili2c.metamodel.RoleDef) EnumerationType(ch.interlis.ili2c.metamodel.EnumerationType) TypeAlias(ch.interlis.ili2c.metamodel.TypeAlias) CompositionType(ch.interlis.ili2c.metamodel.CompositionType) PolylineType(ch.interlis.ili2c.metamodel.PolylineType) Type(ch.interlis.ili2c.metamodel.Type) SurfaceOrAreaType(ch.interlis.ili2c.metamodel.SurfaceOrAreaType) SurfaceType(ch.interlis.ili2c.metamodel.SurfaceType) CompositionType(ch.interlis.ili2c.metamodel.CompositionType) EnumerationType(ch.interlis.ili2c.metamodel.EnumerationType) CoordType(ch.interlis.ili2c.metamodel.CoordType) Iterator(java.util.Iterator) AssociationDef(ch.interlis.ili2c.metamodel.AssociationDef) AttributeDef(ch.interlis.ili2c.metamodel.AttributeDef) AbstractClassDef(ch.interlis.ili2c.metamodel.AbstractClassDef) Domain(ch.interlis.ili2c.metamodel.Domain) CoordType(ch.interlis.ili2c.metamodel.CoordType)

Example 3 with Domain

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

the class TransferFromIli method addEnumTable.

public void addEnumTable(DbSchema schema) {
    if (Config.CREATE_ENUM_DEFS_SINGLE.equals(createEnumTable)) {
        DbTable tab = new DbTable();
        DbColVarchar thisClass = new DbColVarchar();
        thisClass.setName(DbNames.ENUM_TAB_THIS_COL);
        thisClass.setNotNull(true);
        thisClass.setSize(1024);
        tab.addColumn(thisClass);
        DbColVarchar baseClass = new DbColVarchar();
        baseClass.setName(DbNames.ENUM_TAB_BASE_COL);
        baseClass.setNotNull(false);
        baseClass.setSize(1024);
        tab.addColumn(baseClass);
        DbColNumber seq = new DbColNumber();
        seq.setName(DbNames.ENUM_TAB_SEQ_COL);
        seq.setNotNull(false);
        seq.setSize(4);
        tab.addColumn(seq);
        DbColBoolean inactiveCol = new DbColBoolean();
        inactiveCol.setName(DbNames.ENUM_TAB_INACTIVE_COL);
        inactiveCol.setNotNull(true);
        tab.addColumn(inactiveCol);
        DbColVarchar iliCode = new DbColVarchar();
        iliCode.setName(DbNames.ENUM_TAB_ILICODE_COL);
        iliCode.setNotNull(true);
        iliCode.setSize(1024);
        tab.addColumn(iliCode);
        tab.setName(new DbTableName(schema.getName(), DbNames.ENUM_TAB));
        DbColNumber itfCode = new DbColNumber();
        itfCode.setName(DbNames.ENUM_TAB_ITFCODE_COL);
        itfCode.setNotNull(true);
        itfCode.setSize(4);
        tab.addColumn(itfCode);
        DbColVarchar dispName = new DbColVarchar();
        dispName.setName(DbNames.ENUM_TAB_DISPNAME_COL);
        dispName.setNotNull(true);
        dispName.setSize(250);
        tab.addColumn(dispName);
        DbColVarchar description = new DbColVarchar();
        description.setName(DbNames.ENUM_TAB_DESCRIPTION_COL);
        description.setNotNull(false);
        description.setSize(1024);
        tab.addColumn(description);
        schema.addTable(tab);
    } else if (Config.CREATE_ENUM_DEFS_MULTI.equals(createEnumTable)) {
        addMissingEnumDomains(visitedEnums);
        java.util.Iterator entri = visitedEnums.iterator();
        while (entri.hasNext()) {
            Object entro = entri.next();
            DbTableName thisSqlName = null;
            if (entro instanceof AttributeDef) {
                AttributeDef attr = (AttributeDef) entro;
                ch.interlis.ili2c.metamodel.Type type = attr.getDomain();
                if (type instanceof ch.interlis.ili2c.metamodel.TypeAlias) {
                    // skip it
                    continue;
                } else {
                    thisSqlName = getSqlTableNameEnum(attr);
                }
            } else if (entro instanceof Domain) {
                Domain domain = (Domain) entro;
                if (domain == td.INTERLIS.BOOLEAN) {
                    continue;
                }
                thisSqlName = getSqlTableName(domain);
            }
            if (thisSqlName != null) {
                DbTable tab = new DbTable();
                tab.setName(thisSqlName);
                DbColNumber itfCode = new DbColNumber();
                itfCode.setName(DbNames.ENUM_TAB_ITFCODE_COL);
                itfCode.setNotNull(true);
                itfCode.setSize(4);
                itfCode.setPrimaryKey(true);
                tab.addColumn(itfCode);
                DbColVarchar iliCode = new DbColVarchar();
                iliCode.setName(DbNames.ENUM_TAB_ILICODE_COL);
                iliCode.setNotNull(true);
                iliCode.setSize(1024);
                tab.addColumn(iliCode);
                DbColNumber seq = new DbColNumber();
                seq.setName(DbNames.ENUM_TAB_SEQ_COL);
                seq.setNotNull(false);
                seq.setSize(4);
                tab.addColumn(seq);
                DbColBoolean inactiveCol = new DbColBoolean();
                inactiveCol.setName(DbNames.ENUM_TAB_INACTIVE_COL);
                inactiveCol.setNotNull(true);
                tab.addColumn(inactiveCol);
                DbColVarchar dispName = new DbColVarchar();
                dispName.setName(DbNames.ENUM_TAB_DISPNAME_COL);
                dispName.setNotNull(true);
                dispName.setSize(250);
                tab.addColumn(dispName);
                DbColVarchar description = new DbColVarchar();
                description.setName(DbNames.ENUM_TAB_DESCRIPTION_COL);
                description.setNotNull(false);
                description.setSize(1024);
                tab.addColumn(description);
                schema.addTable(tab);
                metaInfo.setTableInfo(tab.getName().getName(), DbExtMetaInfo.TAG_TAB_TABLEKIND, DbExtMetaInfo.TAG_TAB_TABLEKIND_ENUM);
            }
        }
    }
}
Also used : DbColVarchar(ch.ehi.sqlgen.repository.DbColVarchar) DbColNumber(ch.ehi.sqlgen.repository.DbColNumber) DbColBoolean(ch.ehi.sqlgen.repository.DbColBoolean) SurfaceType(ch.interlis.ili2c.metamodel.SurfaceType) EnumerationType(ch.interlis.ili2c.metamodel.EnumerationType) SurfaceOrAreaType(ch.interlis.ili2c.metamodel.SurfaceOrAreaType) Iterator(java.util.Iterator) AttributeDef(ch.interlis.ili2c.metamodel.AttributeDef) Domain(ch.interlis.ili2c.metamodel.Domain) DbTableName(ch.ehi.sqlgen.repository.DbTableName) DbTable(ch.ehi.sqlgen.repository.DbTable)

Example 4 with Domain

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

the class TransferFromIli method updateMultiEnumTable.

public void updateMultiEnumTable(java.sql.Connection conn) throws Ili2dbException {
    addMissingEnumDomains(visitedEnums);
    java.util.Iterator entri = visitedEnums.iterator();
    while (entri.hasNext()) {
        Object entro = entri.next();
        if (entro instanceof AttributeDef) {
            AttributeDef attr = (AttributeDef) entro;
            if (attr.getDomain() instanceof ch.interlis.ili2c.metamodel.TypeAlias) {
                continue;
            }
            EnumerationType type = (EnumerationType) attr.getDomainResolvingAll();
            String thisClass = attr.getContainer().getScopedName(null) + "." + attr.getName();
            DbTableName thisSqlName = getSqlTableNameEnum(attr);
            HashSet exstEntries = readEnumTable(conn, false, thisClass, thisSqlName);
            try {
                // insert entries
                String stmt = "INSERT INTO " + thisSqlName + " (" + DbNames.ENUM_TAB_SEQ_COL + "," + DbNames.ENUM_TAB_ILICODE_COL + "," + DbNames.ENUM_TAB_ITFCODE_COL + "," + DbNames.ENUM_TAB_DISPNAME_COL + "," + DbNames.ENUM_TAB_INACTIVE_COL + "," + DbNames.ENUM_TAB_DESCRIPTION_COL + ") VALUES (?,?,?,?,?,?)";
                EhiLogger.traceBackendCmd(stmt);
                java.sql.PreparedStatement ps = conn.prepareStatement(stmt);
                try {
                    updateEnumEntries(exstEntries, ps, type, null, null);
                } catch (java.sql.SQLException ex) {
                    throw new Ili2dbException("failed to insert enum values for type " + thisClass, ex);
                } finally {
                    ps.close();
                }
            } catch (java.sql.SQLException ex) {
                throw new Ili2dbException("failed to update enum-table " + thisSqlName, ex);
            }
        } else if (entro instanceof Domain) {
            Domain domain = (Domain) entro;
            if (domain == td.INTERLIS.BOOLEAN) {
                continue;
            }
            EnumerationType type = (EnumerationType) domain.getType();
            String thisClass = domain.getScopedName(null);
            DbTableName thisSqlName = getSqlTableName(domain);
            HashSet exstEntries = readEnumTable(conn, false, thisClass, thisSqlName);
            try {
                // insert entries
                String stmt = "INSERT INTO " + thisSqlName + " (" + DbNames.ENUM_TAB_SEQ_COL + "," + DbNames.ENUM_TAB_ILICODE_COL + "," + DbNames.ENUM_TAB_ITFCODE_COL + "," + DbNames.ENUM_TAB_DISPNAME_COL + "," + DbNames.ENUM_TAB_INACTIVE_COL + "," + DbNames.ENUM_TAB_DESCRIPTION_COL + ") VALUES (?,?,?,?,?,?)";
                EhiLogger.traceBackendCmd(stmt);
                java.sql.PreparedStatement ps = conn.prepareStatement(stmt);
                try {
                    updateEnumEntries(exstEntries, ps, type, null, null);
                } catch (java.sql.SQLException ex) {
                    throw new Ili2dbException("failed to insert enum values for type " + thisClass, ex);
                } finally {
                    ps.close();
                }
            } catch (java.sql.SQLException ex) {
                throw new Ili2dbException("failed to update enum-table " + thisSqlName, ex);
            }
        }
    }
}
Also used : Ili2dbException(ch.ehi.ili2db.base.Ili2dbException) Iterator(java.util.Iterator) SQLException(java.sql.SQLException) EnumerationType(ch.interlis.ili2c.metamodel.EnumerationType) SQLException(java.sql.SQLException) AttributeDef(ch.interlis.ili2c.metamodel.AttributeDef) Domain(ch.interlis.ili2c.metamodel.Domain) DbTableName(ch.ehi.sqlgen.repository.DbTableName) HashSet(java.util.HashSet)

Example 5 with Domain

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

the class TransferFromIli method generatModelEles.

private void generatModelEles(java.util.List<Element> modelEles, int pass) throws Ili2dbException {
    Iterator modeli = modelEles.iterator();
    while (modeli.hasNext()) {
        Object modelo = modeli.next();
        if (modelo instanceof Model) {
            Model model = (Model) modelo;
        // generateModel(model);
        } else if (modelo instanceof Topic) {
        // generateTopic((Topic)modelo);
        } else if (modelo instanceof Domain) {
            if (pass == 2) {
                generateDomain((Domain) modelo);
                visitedElements.add((Domain) modelo);
            }
        } else if (modelo instanceof Viewable) {
            if (modelo instanceof Table && ((Table) modelo).isIli1LineAttrStruct()) {
            // skip it
            } else if ((modelo instanceof View) && !isTransferableView(modelo)) {
            // skip it
            } else {
                try {
                    ViewableWrapper wrapper = class2wrapper.get((Viewable) modelo);
                    if (wrapper != null) {
                        generateViewable(wrapper, pass);
                    }
                    if (pass == 2) {
                        visitedElements.add((Viewable) modelo);
                    }
                } catch (Ili2dbException ex) {
                    throw new Ili2dbException("mapping of " + ((Viewable) modelo).getScopedName(null) + " failed", ex);
                }
            }
        } else if (modelo instanceof AttributeDef) {
            AttributeDef attr = (AttributeDef) modelo;
            if (attr.getDomainResolvingAll() instanceof SurfaceOrAreaType) {
                generateItfLineTable(attr, pass);
            } else if (attr.getDomainResolvingAll() instanceof EnumerationType) {
                if (pass == 2) {
                    visitedEnums.add(attr);
                }
            } else {
            // skip it
            }
        } else {
        // skip it
        }
    }
}
Also used : Ili2dbException(ch.ehi.ili2db.base.Ili2dbException) DbTable(ch.ehi.sqlgen.repository.DbTable) Table(ch.interlis.ili2c.metamodel.Table) SurfaceOrAreaType(ch.interlis.ili2c.metamodel.SurfaceOrAreaType) EnumerationType(ch.interlis.ili2c.metamodel.EnumerationType) ViewableWrapper(ch.ehi.ili2db.mapping.ViewableWrapper) View(ch.interlis.ili2c.metamodel.View) Iterator(java.util.Iterator) Model(ch.interlis.ili2c.metamodel.Model) Viewable(ch.interlis.ili2c.metamodel.Viewable) AttributeDef(ch.interlis.ili2c.metamodel.AttributeDef) Topic(ch.interlis.ili2c.metamodel.Topic) Domain(ch.interlis.ili2c.metamodel.Domain)

Aggregations

Domain (ch.interlis.ili2c.metamodel.Domain)13 Iterator (java.util.Iterator)9 AttributeDef (ch.interlis.ili2c.metamodel.AttributeDef)6 EnumerationType (ch.interlis.ili2c.metamodel.EnumerationType)6 CoordType (ch.interlis.ili2c.metamodel.CoordType)4 Topic (ch.interlis.ili2c.metamodel.Topic)4 Viewable (ch.interlis.ili2c.metamodel.Viewable)4 Ili2dbException (ch.ehi.ili2db.base.Ili2dbException)3 DbTableName (ch.ehi.sqlgen.repository.DbTableName)3 Model (ch.interlis.ili2c.metamodel.Model)3 SurfaceOrAreaType (ch.interlis.ili2c.metamodel.SurfaceOrAreaType)3 HashSet (java.util.HashSet)3 DbTable (ch.ehi.sqlgen.repository.DbTable)2 LineType (ch.interlis.ili2c.metamodel.LineType)2 SurfaceType (ch.interlis.ili2c.metamodel.SurfaceType)2 Table (ch.interlis.ili2c.metamodel.Table)2 Type (ch.interlis.ili2c.metamodel.Type)2 TypeAlias (ch.interlis.ili2c.metamodel.TypeAlias)2 SQLException (java.sql.SQLException)2 ConverterException (ch.ehi.ili2db.converter.ConverterException)1