Search in sources :

Example 6 with AttributeDef

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

the class ArrayMappings method addArrayAttr.

public void addArrayAttr(AttributeDef arrayAttr) {
    // validate structure
    // create mapping
    Type multiPointTypeo = arrayAttr.getDomain();
    if (!(multiPointTypeo instanceof CompositionType)) {
        throw new IllegalArgumentException("not a valid array attribute " + arrayAttr.getScopedName(null));
    }
    CompositionType multiPointType = (CompositionType) multiPointTypeo;
    Table arrayEleStruct = multiPointType.getComponentType();
    Iterator<ViewableTransferElement> it = arrayEleStruct.getAttributesAndRoles2();
    if (!it.hasNext()) {
        throw new IllegalArgumentException("not a valid array structure " + arrayEleStruct.getScopedName(null));
    }
    ViewableTransferElement prop = it.next();
    if (!(prop.obj instanceof AttributeDef)) {
        throw new IllegalArgumentException("not a valid array structure " + arrayEleStruct.getScopedName(null));
    }
    AttributeDef valueAttr = (AttributeDef) prop.obj;
    ArrayMapping mapping = new ArrayMapping(valueAttr);
    mappings.put(arrayAttr, mapping);
}
Also used : ViewableTransferElement(ch.interlis.ili2c.metamodel.ViewableTransferElement) CompositionType(ch.interlis.ili2c.metamodel.CompositionType) Type(ch.interlis.ili2c.metamodel.Type) CoordType(ch.interlis.ili2c.metamodel.CoordType) Table(ch.interlis.ili2c.metamodel.Table) AttributeDef(ch.interlis.ili2c.metamodel.AttributeDef) CompositionType(ch.interlis.ili2c.metamodel.CompositionType)

Example 7 with AttributeDef

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

the class MultiPointMappings method addMultiPointAttr.

public void addMultiPointAttr(AttributeDef multiPointAttr) {
    String bagOfPointsAttrName = null;
    String pointAttrName = null;
    // validate structure
    // create mapping
    Type multiPointTypeo = multiPointAttr.getDomain();
    if (!(multiPointTypeo instanceof CompositionType)) {
        throw new IllegalArgumentException("not a valid multipoint attribute " + multiPointAttr.getScopedName(null));
    } else {
        CompositionType multiPointType = (CompositionType) multiPointTypeo;
        Table multiPointStruct = multiPointType.getComponentType();
        Iterator<ViewableTransferElement> it = multiPointStruct.getAttributesAndRoles2();
        if (!it.hasNext()) {
            throw new IllegalArgumentException("not a valid multipoint structure " + multiPointStruct.getScopedName(null));
        }
        ViewableTransferElement prop = it.next();
        if (!(prop.obj instanceof AttributeDef)) {
            throw new IllegalArgumentException("not a valid multipoint structure " + multiPointStruct.getScopedName(null));
        }
        AttributeDef pointsAttr = (AttributeDef) prop.obj;
        bagOfPointsAttrName = pointsAttr.getName();
        Type pointsTypeo = pointsAttr.getDomain();
        if (!(pointsTypeo instanceof CompositionType)) {
            throw new IllegalArgumentException("not a valid multipoint structure " + multiPointStruct.getScopedName(null));
        } else {
            CompositionType pointsType = (CompositionType) pointsTypeo;
            Table pointStruct = pointsType.getComponentType();
            Iterator<ViewableTransferElement> it2 = pointStruct.getAttributesAndRoles2();
            if (!it2.hasNext()) {
                throw new IllegalArgumentException("not a valid point structure " + pointStruct.getScopedName(null));
            }
            ViewableTransferElement prop2 = it2.next();
            if (!(prop2.obj instanceof AttributeDef)) {
                throw new IllegalArgumentException("not a valid point structure " + pointStruct.getScopedName(null));
            }
            AttributeDef pointAttr = (AttributeDef) prop2.obj;
            Type pointType = pointAttr.getDomainResolvingAliases();
            if (!(pointType instanceof CoordType)) {
                throw new IllegalArgumentException("not a valid point structure " + pointStruct.getScopedName(null));
            }
            pointAttrName = pointAttr.getName();
        }
    }
    MultiPointMapping mapping = new MultiPointMapping(bagOfPointsAttrName, pointAttrName);
    mappings.put(multiPointAttr, mapping);
}
Also used : ViewableTransferElement(ch.interlis.ili2c.metamodel.ViewableTransferElement) CompositionType(ch.interlis.ili2c.metamodel.CompositionType) Type(ch.interlis.ili2c.metamodel.Type) CoordType(ch.interlis.ili2c.metamodel.CoordType) Table(ch.interlis.ili2c.metamodel.Table) AttributeDef(ch.interlis.ili2c.metamodel.AttributeDef) CompositionType(ch.interlis.ili2c.metamodel.CompositionType) CoordType(ch.interlis.ili2c.metamodel.CoordType)

Example 8 with AttributeDef

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

the class FromIliRecordConverter method getUniqueAttrs.

private HashSet getUniqueAttrs(UniquenessConstraint cnstr, HashSet wrapperCols) {
    if (cnstr.getLocal()) {
        return null;
    }
    HashSet ret = new HashSet();
    UniqueEl attribs = cnstr.getElements();
    Iterator attri = attribs.iteratorAttribute();
    for (; attri.hasNext(); ) {
        ObjectPath path = (ObjectPath) attri.next();
        PathEl[] pathEles = path.getPathElements();
        if (pathEles.length != 1) {
            return null;
        }
        PathEl pathEle = pathEles[0];
        if (pathEle instanceof AttributeRef) {
            AttributeDef attr = ((AttributeRef) pathEle).getAttr();
            while (attr.getExtending() != null) {
                attr = (AttributeDef) attr.getExtending();
            }
            if (!wrapperCols.contains(attr)) {
                return null;
            }
            ret.add(attr);
        } else if (pathEle instanceof PathElAssocRole) {
            RoleDef role = ((PathElAssocRole) pathEle).getRole();
            while (role.getExtending() != null) {
                role = (RoleDef) role.getExtending();
            }
            if (!wrapperCols.contains(role)) {
                return null;
            }
            ret.add(role);
        } else {
            return null;
        }
    }
    return ret;
}
Also used : ObjectPath(ch.interlis.ili2c.metamodel.ObjectPath) PathElAssocRole(ch.interlis.ili2c.metamodel.PathElAssocRole) AttributeRef(ch.interlis.ili2c.metamodel.AttributeRef) UniqueEl(ch.interlis.ili2c.metamodel.UniqueEl) RoleDef(ch.interlis.ili2c.metamodel.RoleDef) Iterator(java.util.Iterator) AttributeDef(ch.interlis.ili2c.metamodel.AttributeDef) PathEl(ch.interlis.ili2c.metamodel.PathEl) HashSet(java.util.HashSet)

Example 9 with AttributeDef

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

the class FromIliRecordConverter method generateAttr.

public void generateAttr(DbTable dbTable, Viewable aclass, AttributeDef attr) throws Ili2dbException {
    Holder<DbColumn> dbCol = new Holder<DbColumn>();
    dbCol.value = null;
    Holder<Unit> unitDef = new Holder<Unit>();
    unitDef.value = null;
    Holder<Boolean> mText = new Holder<Boolean>();
    mText.value = false;
    ArrayList<DbColumn> dbColExts = new ArrayList<DbColumn>();
    Type type = attr.getDomainResolvingAll();
    if (createSimpleDbCol(dbTable, aclass, attr, type, dbCol, unitDef, mText, dbColExts)) {
    } else if (type instanceof SurfaceOrAreaType) {
        if (createItfLineTables) {
            dbCol.value = null;
        } else {
            DbColGeometry ret = new DbColGeometry();
            boolean curvePolygon = false;
            if (!strokeArcs) {
                curvePolygon = true;
            }
            ret.setType(curvePolygon ? DbColGeometry.CURVEPOLYGON : DbColGeometry.POLYGON);
            // get crs from ili
            setCrs(ret, attr);
            CoordType coord = (CoordType) ((SurfaceOrAreaType) type).getControlPointDomain().getType();
            ret.setDimension(coord.getDimensions().length);
            setBB(ret, coord, attr.getContainer().getScopedName(null) + "." + attr.getName());
            dbCol.value = ret;
        }
        if (createItfAreaRef) {
            if (type instanceof AreaType) {
                DbColGeometry ret = new DbColGeometry();
                String sqlName = getSqlAttrName(attr, dbTable.getName().getName(), null) + DbNames.ITF_MAINTABLE_GEOTABLEREF_COL_SUFFIX;
                ret.setName(sqlName);
                ret.setType(DbColGeometry.POINT);
                setNullable(aclass, attr, ret);
                // get crs from ili
                setCrs(ret, attr);
                // always 2 (even if defined as 3d in ili)
                ret.setDimension(2);
                CoordType coord = (CoordType) ((SurfaceOrAreaType) type).getControlPointDomain().getType();
                setBB(ret, coord, attr.getContainer().getScopedName(null) + "." + attr.getName());
                dbColExts.add(ret);
            }
        }
    } else if (type instanceof PolylineType) {
        String attrName = attr.getContainer().getScopedName(null) + "." + attr.getName();
        DbColGeometry ret = generatePolylineType((PolylineType) type, attrName);
        setCrs(ret, attr);
        dbCol.value = ret;
    } else if (type instanceof CoordType) {
        DbColGeometry ret = new DbColGeometry();
        ret.setType(DbColGeometry.POINT);
        // get crs from ili
        setCrs(ret, attr);
        CoordType coord = (CoordType) type;
        ret.setDimension(coord.getDimensions().length);
        setBB(ret, coord, attr.getContainer().getScopedName(null) + "." + attr.getName());
        dbCol.value = ret;
    } else if (type instanceof CompositionType) {
        // skip it
        if (!createGenericStructRef) {
            if (isChbaseCatalogueRef(td, attr) && (coalesceCatalogueRef || TrafoConfigNames.CATALOGUE_REF_TRAFO_COALESCE.equals(trafoConfig.getAttrConfig(attr, TrafoConfigNames.CATALOGUE_REF_TRAFO)))) {
                DbColId ret = new DbColId();
                ret.setNotNull(false);
                ret.setPrimaryKey(false);
                if (createFk) {
                    ret.setReferencedTable(getSqlType(((ReferenceType) ((AttributeDef) ((CompositionType) type).getComponentType().getAttributes().next()).getDomain()).getReferred()));
                }
                if (createFkIdx) {
                    ret.setIndex(true);
                }
                trafoConfig.setAttrConfig(attr, TrafoConfigNames.CATALOGUE_REF_TRAFO, TrafoConfigNames.CATALOGUE_REF_TRAFO_COALESCE);
                dbCol.value = ret;
            } else if (Ili2cUtility.isMultiSurfaceAttr(td, attr) && (coalesceMultiSurface || TrafoConfigNames.MULTISURFACE_TRAFO_COALESCE.equals(trafoConfig.getAttrConfig(attr, TrafoConfigNames.MULTISURFACE_TRAFO)))) {
                multiSurfaceAttrs.addMultiSurfaceAttr(attr);
                MultiSurfaceMapping attrMapping = multiSurfaceAttrs.getMapping(attr);
                DbColGeometry ret = new DbColGeometry();
                boolean curvePolygon = false;
                if (!strokeArcs) {
                    curvePolygon = true;
                }
                ret.setType(curvePolygon ? DbColGeometry.MULTISURFACE : DbColGeometry.MULTIPOLYGON);
                // get crs from ili
                AttributeDef surfaceAttr = (AttributeDef) ((CompositionType) ((AttributeDef) ((CompositionType) type).getComponentType().getElement(AttributeDef.class, attrMapping.getBagOfSurfacesAttrName())).getDomain()).getComponentType().getElement(AttributeDef.class, attrMapping.getSurfaceAttrName());
                setCrs(ret, surfaceAttr);
                SurfaceType surface = ((SurfaceType) surfaceAttr.getDomainResolvingAliases());
                CoordType coord = (CoordType) surface.getControlPointDomain().getType();
                ret.setDimension(coord.getDimensions().length);
                setBB(ret, coord, attr.getContainer().getScopedName(null) + "." + attr.getName());
                dbCol.value = ret;
                trafoConfig.setAttrConfig(attr, TrafoConfigNames.MULTISURFACE_TRAFO, TrafoConfigNames.MULTISURFACE_TRAFO_COALESCE);
            } else if (Ili2cUtility.isMultiLineAttr(td, attr) && (coalesceMultiLine || TrafoConfigNames.MULTILINE_TRAFO_COALESCE.equals(trafoConfig.getAttrConfig(attr, TrafoConfigNames.MULTILINE_TRAFO)))) {
                multiLineAttrs.addMultiLineAttr(attr);
                MultiLineMapping attrMapping = multiLineAttrs.getMapping(attr);
                DbColGeometry ret = new DbColGeometry();
                boolean curvePolyline = false;
                if (!strokeArcs) {
                    curvePolyline = true;
                }
                ret.setType(curvePolyline ? DbColGeometry.MULTICURVE : DbColGeometry.MULTILINESTRING);
                // get crs from ili
                AttributeDef polylineAttr = (AttributeDef) ((CompositionType) ((AttributeDef) ((CompositionType) type).getComponentType().getElement(AttributeDef.class, attrMapping.getBagOfLinesAttrName())).getDomain()).getComponentType().getElement(AttributeDef.class, attrMapping.getLineAttrName());
                setCrs(ret, polylineAttr);
                PolylineType polylineType = ((PolylineType) polylineAttr.getDomainResolvingAliases());
                CoordType coord = (CoordType) polylineType.getControlPointDomain().getType();
                ret.setDimension(coord.getDimensions().length);
                setBB(ret, coord, attr.getContainer().getScopedName(null) + "." + attr.getName());
                dbCol.value = ret;
                trafoConfig.setAttrConfig(attr, TrafoConfigNames.MULTILINE_TRAFO, TrafoConfigNames.MULTILINE_TRAFO_COALESCE);
            } else if (Ili2cUtility.isMultiPointAttr(td, attr) && (coalesceMultiPoint || TrafoConfigNames.MULTIPOINT_TRAFO_COALESCE.equals(trafoConfig.getAttrConfig(attr, TrafoConfigNames.MULTIPOINT_TRAFO)))) {
                multiPointAttrs.addMultiPointAttr(attr);
                MultiPointMapping attrMapping = multiPointAttrs.getMapping(attr);
                DbColGeometry ret = new DbColGeometry();
                ret.setType(DbColGeometry.MULTIPOINT);
                // get crs from ili
                AttributeDef coordAttr = (AttributeDef) ((CompositionType) ((AttributeDef) ((CompositionType) type).getComponentType().getElement(AttributeDef.class, attrMapping.getBagOfPointsAttrName())).getDomain()).getComponentType().getElement(AttributeDef.class, attrMapping.getPointAttrName());
                setCrs(ret, coordAttr);
                CoordType coord = (CoordType) (coordAttr.getDomainResolvingAliases());
                ret.setDimension(coord.getDimensions().length);
                setBB(ret, coord, attr.getContainer().getScopedName(null) + "." + attr.getName());
                dbCol.value = ret;
                trafoConfig.setAttrConfig(attr, TrafoConfigNames.MULTIPOINT_TRAFO, TrafoConfigNames.MULTIPOINT_TRAFO_COALESCE);
            } else if (Ili2cUtility.isArrayAttr(td, attr) && (coalesceArray || TrafoConfigNames.ARRAY_TRAFO_COALESCE.equals(trafoConfig.getAttrConfig(attr, TrafoConfigNames.ARRAY_TRAFO)))) {
                arrayAttrs.addArrayAttr(attr);
                ArrayMapping attrMapping = arrayAttrs.getMapping(attr);
                AttributeDef localAttr = attrMapping.getValueAttr();
                Type localType = localAttr.getDomainResolvingAll();
                if (!createSimpleDbCol(dbTable, aclass, localAttr, localType, dbCol, unitDef, mText, dbColExts)) {
                    throw new IllegalStateException("unexpected attr type " + localAttr.getScopedName());
                }
                dbCol.value.setArraySize(DbColumn.UNLIMITED_ARRAY);
                trafoConfig.setAttrConfig(attr, TrafoConfigNames.ARRAY_TRAFO, TrafoConfigNames.ARRAY_TRAFO_COALESCE);
            } else if (isChbaseMultilingual(td, attr) && (expandMultilingual || TrafoConfigNames.MULTILINGUAL_TRAFO_EXPAND.equals(trafoConfig.getAttrConfig(attr, TrafoConfigNames.MULTILINGUAL_TRAFO)))) {
                for (String sfx : DbNames.MULTILINGUAL_TXT_COL_SUFFIXS) {
                    DbColVarchar ret = new DbColVarchar();
                    ret.setName(getSqlAttrName(attr, dbTable.getName().getName(), null) + sfx);
                    ret.setSize(DbColVarchar.UNLIMITED);
                    ret.setNotNull(false);
                    ret.setPrimaryKey(false);
                    dbColExts.add(ret);
                }
                trafoConfig.setAttrConfig(attr, TrafoConfigNames.MULTILINGUAL_TRAFO, TrafoConfigNames.MULTILINGUAL_TRAFO_EXPAND);
            } else {
                // add reference col from struct ele to parent obj to struct table
                addParentRef(aclass, attr);
                dbCol.value = null;
            }
        } else {
            dbCol.value = null;
        }
    } else if (type instanceof ReferenceType) {
        ArrayList<ViewableWrapper> targetTables = getTargetTables(((ReferenceType) type).getReferred());
        for (ViewableWrapper targetTable : targetTables) {
            DbColId ret = new DbColId();
            ret.setName(ili2sqlName.mapIliAttributeDef(attr, dbTable.getName().getName(), targetTable.getSqlTablename(), targetTables.size() > 1));
            ret.setNotNull(false);
            ret.setPrimaryKey(false);
            if (createFk) {
                ret.setReferencedTable(targetTable.getSqlTable());
            }
            if (createFkIdx) {
                ret.setIndex(true);
            }
            dbColExts.add(ret);
        }
    } else {
        DbColVarchar ret = new DbColVarchar();
        ret.setSize(255);
        dbCol.value = ret;
    }
    if (type instanceof EnumerationType) {
        if (createEnumTxtCol) {
            DbColVarchar ret = new DbColVarchar();
            ret.setSize(255);
            ret.setName(getSqlAttrName(attr, dbTable.getName().getName(), null) + DbNames.ENUM_TXT_COL_SUFFIX);
            setNullable(aclass, attr, ret);
            dbColExts.add(ret);
        }
    }
    if (dbCol.value != null) {
        String sqlColName = getSqlAttrName(attr, dbTable.getName().getName(), null);
        setAttrDbColProps(aclass, attr, dbCol.value, sqlColName);
        String subType = null;
        Viewable attrClass = (Viewable) attr.getContainer();
        if (attrClass != aclass && attrClass.isExtending(aclass)) {
            subType = getSqlType(attrClass).getName();
        }
        if (unitDef.value != null) {
            String unitName = unitDef.value.getName();
            metaInfo.setColumnInfo(dbTable.getName().getName(), subType, sqlColName, DbExtMetaInfo.TAG_COL_UNIT, unitName);
        }
        if (mText.value) {
            metaInfo.setColumnInfo(dbTable.getName().getName(), subType, sqlColName, DbExtMetaInfo.TAG_COL_TEXTKIND, DbExtMetaInfo.TAG_COL_TEXTKIND_MTEXT);
        }
        if (dbCol.value instanceof DbColGeometry) {
            metaInfo.setColumnInfo(dbTable.getName().getName(), subType, sqlColName, DbExtMetaInfo.TAG_COL_C1_MIN, Double.toString(((DbColGeometry) dbCol.value).getMin1()));
            metaInfo.setColumnInfo(dbTable.getName().getName(), subType, sqlColName, DbExtMetaInfo.TAG_COL_C1_MAX, Double.toString(((DbColGeometry) dbCol.value).getMax1()));
            metaInfo.setColumnInfo(dbTable.getName().getName(), subType, sqlColName, DbExtMetaInfo.TAG_COL_C2_MIN, Double.toString(((DbColGeometry) dbCol.value).getMin2()));
            metaInfo.setColumnInfo(dbTable.getName().getName(), subType, sqlColName, DbExtMetaInfo.TAG_COL_C2_MAX, Double.toString(((DbColGeometry) dbCol.value).getMax2()));
            if (((DbColGeometry) dbCol.value).getDimension() == 3) {
                metaInfo.setColumnInfo(dbTable.getName().getName(), subType, sqlColName, DbExtMetaInfo.TAG_COL_C3_MIN, Double.toString(((DbColGeometry) dbCol.value).getMin3()));
                metaInfo.setColumnInfo(dbTable.getName().getName(), subType, sqlColName, DbExtMetaInfo.TAG_COL_C3_MAX, Double.toString(((DbColGeometry) dbCol.value).getMax3()));
            }
        }
        String dispName = attr.getMetaValues().getValue(IliMetaAttrNames.METAATTR_DISPNAME);
        if (dispName != null) {
            metaInfo.setColumnInfo(dbTable.getName().getName(), subType, sqlColName, DbExtMetaInfo.TAG_COL_DISPNAME, dispName);
        }
        customMapping.fixupAttribute(dbTable, dbCol.value, attr);
        dbTable.addColumn(dbCol.value);
    }
    for (DbColumn dbColExt : dbColExts) {
        customMapping.fixupAttribute(dbTable, dbColExt, attr);
        dbTable.addColumn(dbColExt);
    }
    if (dbCol.value == null && dbColExts.size() == 0) {
        customMapping.fixupAttribute(dbTable, null, attr);
    }
}
Also used : DbColumn(ch.ehi.sqlgen.repository.DbColumn) SurfaceOrAreaType(ch.interlis.ili2c.metamodel.SurfaceOrAreaType) ArrayList(java.util.ArrayList) ViewableWrapper(ch.ehi.ili2db.mapping.ViewableWrapper) Unit(ch.interlis.ili2c.metamodel.Unit) SurfaceOrAreaType(ch.interlis.ili2c.metamodel.SurfaceOrAreaType) AreaType(ch.interlis.ili2c.metamodel.AreaType) CompositionType(ch.interlis.ili2c.metamodel.CompositionType) ReferenceType(ch.interlis.ili2c.metamodel.ReferenceType) DbColGeometry(ch.ehi.sqlgen.repository.DbColGeometry) AttributeDef(ch.interlis.ili2c.metamodel.AttributeDef) DbColBoolean(ch.ehi.sqlgen.repository.DbColBoolean) PolylineType(ch.interlis.ili2c.metamodel.PolylineType) MultiPointMapping(ch.ehi.ili2db.mapping.MultiPointMapping) Holder(javax.xml.ws.Holder) DbColVarchar(ch.ehi.sqlgen.repository.DbColVarchar) EnumerationType(ch.interlis.ili2c.metamodel.EnumerationType) SurfaceType(ch.interlis.ili2c.metamodel.SurfaceType) MultiSurfaceMapping(ch.ehi.ili2db.mapping.MultiSurfaceMapping) PolylineType(ch.interlis.ili2c.metamodel.PolylineType) Type(ch.interlis.ili2c.metamodel.Type) BasketType(ch.interlis.ili2c.metamodel.BasketType) ReferenceType(ch.interlis.ili2c.metamodel.ReferenceType) SurfaceOrAreaType(ch.interlis.ili2c.metamodel.SurfaceOrAreaType) SurfaceType(ch.interlis.ili2c.metamodel.SurfaceType) CompositionType(ch.interlis.ili2c.metamodel.CompositionType) TextType(ch.interlis.ili2c.metamodel.TextType) EnumerationType(ch.interlis.ili2c.metamodel.EnumerationType) NumericType(ch.interlis.ili2c.metamodel.NumericType) BlackboxType(ch.interlis.ili2c.metamodel.BlackboxType) AreaType(ch.interlis.ili2c.metamodel.AreaType) ObjectType(ch.interlis.ili2c.metamodel.ObjectType) CoordType(ch.interlis.ili2c.metamodel.CoordType) ArrayMapping(ch.ehi.ili2db.mapping.ArrayMapping) Viewable(ch.interlis.ili2c.metamodel.Viewable) MultiLineMapping(ch.ehi.ili2db.mapping.MultiLineMapping) DbColId(ch.ehi.sqlgen.repository.DbColId) CoordType(ch.interlis.ili2c.metamodel.CoordType)

Example 10 with AttributeDef

use of ch.interlis.ili2c.metamodel.AttributeDef 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)

Aggregations

AttributeDef (ch.interlis.ili2c.metamodel.AttributeDef)41 Iterator (java.util.Iterator)25 CompositionType (ch.interlis.ili2c.metamodel.CompositionType)22 SurfaceOrAreaType (ch.interlis.ili2c.metamodel.SurfaceOrAreaType)21 SurfaceType (ch.interlis.ili2c.metamodel.SurfaceType)21 EnumerationType (ch.interlis.ili2c.metamodel.EnumerationType)19 Type (ch.interlis.ili2c.metamodel.Type)18 Table (ch.interlis.ili2c.metamodel.Table)16 CoordType (ch.interlis.ili2c.metamodel.CoordType)15 IomObject (ch.interlis.iom.IomObject)15 Viewable (ch.interlis.ili2c.metamodel.Viewable)14 ViewableTransferElement (ch.interlis.ili2c.metamodel.ViewableTransferElement)14 PolylineType (ch.interlis.ili2c.metamodel.PolylineType)13 HashSet (java.util.HashSet)13 ViewableWrapper (ch.ehi.ili2db.mapping.ViewableWrapper)12 ObjectType (ch.interlis.ili2c.metamodel.ObjectType)12 AssociationDef (ch.interlis.ili2c.metamodel.AssociationDef)11 ReferenceType (ch.interlis.ili2c.metamodel.ReferenceType)11 RoleDef (ch.interlis.ili2c.metamodel.RoleDef)10 DbTableName (ch.ehi.sqlgen.repository.DbTableName)9