Search in sources :

Example 1 with TypeAlias

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

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

the class ModelElementSelector method visitViewable.

private void visitViewable(HashSet<Element> visitedElements, HashSet<Model> accuScope, Viewable def) {
    if (visitedElements.contains(def)) {
        return;
    }
    visitedElements.add(def);
    // generateViewable(def);
    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;
                visitViewable(visitedElements, accuScope, compType.getComponentType());
                Iterator resti = compType.iteratorRestrictedTo();
                while (resti.hasNext()) {
                    Viewable rest = (Viewable) resti.next();
                    visitViewable(visitedElements, accuScope, rest);
                }
            } else if (createItfLineTables && attr.getDomainResolvingAll() instanceof SurfaceOrAreaType) {
                visitItfLineTable(visitedElements, accuScope, attr);
            } else if (includeEnums && attr.getDomainResolvingAll() instanceof EnumerationType) {
                visitAttributeDef(visitedElements, accuScope, attr);
            }
            // collect referenced domains
            if (type instanceof TypeAlias) {
                visitDomain(visitedElements, accuScope, ((TypeAlias) type).getAliasing());
            }
        }
    }
    // base viewable
    Viewable base = (Viewable) def.getExtending();
    if (base != null) {
        visitViewable(visitedElements, accuScope, base);
    }
}
Also used : EnumerationType(ch.interlis.ili2c.metamodel.EnumerationType) CompositionType(ch.interlis.ili2c.metamodel.CompositionType) SurfaceOrAreaType(ch.interlis.ili2c.metamodel.SurfaceOrAreaType) Type(ch.interlis.ili2c.metamodel.Type) SurfaceOrAreaType(ch.interlis.ili2c.metamodel.SurfaceOrAreaType) Iterator(java.util.Iterator) Viewable(ch.interlis.ili2c.metamodel.Viewable) EnumerationType(ch.interlis.ili2c.metamodel.EnumerationType) AttributeDef(ch.interlis.ili2c.metamodel.AttributeDef) TypeAlias(ch.interlis.ili2c.metamodel.TypeAlias) CompositionType(ch.interlis.ili2c.metamodel.CompositionType)

Example 3 with TypeAlias

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

the class ModelElementSelector method visitDomain.

private void visitDomain(HashSet<Element> visitedElements, HashSet<Model> accuScope, Domain def) {
    if (def == td.INTERLIS.BOOLEAN) {
        // skip it
        return;
    }
    if (visitedElements.contains(def)) {
        return;
    }
    visitedElements.add(def);
    // generateDomain(def);
    if (def.getType() instanceof TypeAlias) {
        visitDomain(visitedElements, accuScope, ((TypeAlias) def.getType()).getAliasing());
    }
    // base viewable
    Domain base = (Domain) def.getExtending();
    if (base != null) {
        visitDomain(visitedElements, accuScope, base);
    }
}
Also used : TypeAlias(ch.interlis.ili2c.metamodel.TypeAlias) Domain(ch.interlis.ili2c.metamodel.Domain)

Aggregations

TypeAlias (ch.interlis.ili2c.metamodel.TypeAlias)3 AttributeDef (ch.interlis.ili2c.metamodel.AttributeDef)2 CompositionType (ch.interlis.ili2c.metamodel.CompositionType)2 Domain (ch.interlis.ili2c.metamodel.Domain)2 EnumerationType (ch.interlis.ili2c.metamodel.EnumerationType)2 SurfaceOrAreaType (ch.interlis.ili2c.metamodel.SurfaceOrAreaType)2 Type (ch.interlis.ili2c.metamodel.Type)2 Iterator (java.util.Iterator)2 AbstractClassDef (ch.interlis.ili2c.metamodel.AbstractClassDef)1 AssociationDef (ch.interlis.ili2c.metamodel.AssociationDef)1 CoordType (ch.interlis.ili2c.metamodel.CoordType)1 PolylineType (ch.interlis.ili2c.metamodel.PolylineType)1 RoleDef (ch.interlis.ili2c.metamodel.RoleDef)1 SurfaceType (ch.interlis.ili2c.metamodel.SurfaceType)1 Table (ch.interlis.ili2c.metamodel.Table)1 Viewable (ch.interlis.ili2c.metamodel.Viewable)1 ViewableTransferElement (ch.interlis.ili2c.metamodel.ViewableTransferElement)1