Search in sources :

Example 6 with Table

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

the class FromIliRecordConverter method addParentRef.

private void addParentRef(Viewable parentTable, AttributeDef attr) {
    CompositionType type = (CompositionType) attr.getDomainResolvingAll();
    Table structClass = type.getComponentType();
    // if abstract struct, might have multiple tables!
    for (ViewableWrapper structWrapper : getStructWrappers(structClass)) {
        DbTableName structClassSqlName = structWrapper.getSqlTable();
        // find struct table
        DbTable dbTable = schema.findTable(structClassSqlName);
        // add ref attr
        String refAttrSqlName = ili2sqlName.mapIliAttributeDefReverse(attr, structClassSqlName.getName(), class2wrapper.get(parentTable).getSqlTablename());
        DbColId dbParentId = new DbColId();
        dbParentId.setName(refAttrSqlName);
        // values of other struct attrs will have NULL
        dbParentId.setNotNull(false);
        dbParentId.setPrimaryKey(false);
        StringBuffer cmt = new StringBuffer();
        String cmtSep = "";
        if (attr.getDocumentation() != null) {
            cmt.append(cmtSep + attr.getDocumentation());
            cmtSep = nl;
        }
        cmt.append(cmtSep + "@iliname " + attr.getContainer().getScopedName(null) + "." + attr.getName());
        cmtSep = nl;
        if (cmt.length() > 0) {
            dbParentId.setComment(cmt.toString());
        }
        if (createFk) {
            dbParentId.setReferencedTable(class2wrapper.get(parentTable).getSqlTable());
        }
        if (createFkIdx) {
            dbParentId.setIndex(true);
        }
        dbTable.addColumn(dbParentId);
    }
}
Also used : DbTable(ch.ehi.sqlgen.repository.DbTable) Table(ch.interlis.ili2c.metamodel.Table) ViewableWrapper(ch.ehi.ili2db.mapping.ViewableWrapper) DbColId(ch.ehi.sqlgen.repository.DbColId) CompositionType(ch.interlis.ili2c.metamodel.CompositionType) DbTableName(ch.ehi.sqlgen.repository.DbTableName) DbTable(ch.ehi.sqlgen.repository.DbTable)

Example 7 with Table

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

Example 8 with Table

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

the class TransferFromIli method generateItfLineTable.

private void generateItfLineTable(AttributeDef attr, int pass) throws Ili2dbException {
    if (pass == 1) {
        DbTableName sqlName = getSqlTableNameItfLineTable(attr);
        DbTable dbTable = new DbTable();
        dbTable.setName(sqlName);
        dbTable.setIliName(attr.getContainer().getScopedName(null) + "." + attr.getName());
        schema.addTable(dbTable);
        return;
    }
    // second pass; add columns
    DbTableName sqlName = getSqlTableNameItfLineTable(attr);
    DbTable dbTable = schema.findTable(sqlName);
    StringBuffer cmt = new StringBuffer();
    String cmtSep = "";
    if (attr.getDocumentation() != null) {
        cmt.append(cmtSep + attr.getDocumentation());
        cmtSep = nl;
    }
    cmt.append(cmtSep + "@iliname " + attr.getContainer().getScopedName(null) + "." + attr.getName());
    cmtSep = nl;
    if (cmt.length() > 0) {
        dbTable.setComment(cmt.toString());
    }
    if (deleteExistingData) {
        dbTable.setDeleteDataIfTableExists(true);
    }
    dbTable.setRequiresSequence(true);
    DbColId dbColId = recConv.addKeyCol(dbTable);
    if (createIliTidCol) {
        recConv.addIliTidCol(dbTable, null);
    }
    if (createBasketCol) {
        // add basketCol
        DbColId t_basket = new DbColId();
        t_basket.setName(DbNames.T_BASKET_COL);
        t_basket.setNotNull(true);
        t_basket.setScriptComment("REFERENCES " + DbNames.BASKETS_TAB);
        if (createFk) {
            t_basket.setReferencedTable(new DbTableName(schema.getName(), DbNames.BASKETS_TAB));
        }
        if (createFkIdx) {
            t_basket.setIndex(true);
        }
        dbTable.addColumn(t_basket);
    }
    if (createDatasetCol) {
        DbColVarchar t_dsName = new DbColVarchar();
        t_dsName.setName(DbNames.T_DATASET_COL);
        t_dsName.setSize(DbNames.DATASETNAME_COL_SIZE);
        t_dsName.setNotNull(true);
        t_dsName.setIndex(true);
        dbTable.addColumn(t_dsName);
    }
    SurfaceOrAreaType type = (SurfaceOrAreaType) attr.getDomainResolvingAll();
    DbColGeometry dbCol = recConv.generatePolylineType(type, attr.getContainer().getScopedName(null) + "." + attr.getName());
    recConv.setCrs(dbCol, attr);
    dbCol.setName(ili2sqlName.getSqlColNameItfLineTableGeomAttr(attr, sqlName.getName()));
    dbCol.setNotNull(true);
    dbTable.addColumn(dbCol);
    if (type instanceof SurfaceType) {
        dbColId = new DbColId();
        dbColId.setName(ili2sqlName.getSqlColNameItfLineTableRefAttr(attr, sqlName.getName()));
        dbColId.setNotNull(true);
        dbColId.setPrimaryKey(false);
        dbColId.setScriptComment("REFERENCES " + recConv.getSqlType((Viewable) attr.getContainer()));
        if (createFk) {
            dbColId.setReferencedTable(recConv.getSqlType((Viewable) attr.getContainer()));
        }
        if (createFkIdx) {
            dbColId.setIndex(true);
        }
        dbTable.addColumn(dbColId);
    }
    Table lineAttrTable = type.getLineAttributeStructure();
    if (lineAttrTable != null) {
        Iterator attri = lineAttrTable.getAttributes();
        while (attri.hasNext()) {
            AttributeDef lineattr = (AttributeDef) attri.next();
            recConv.generateAttr(dbTable, lineAttrTable, lineattr);
        }
    }
    if (createStdCols) {
        AbstractRecordConverter.addStdCol(dbTable);
    }
}
Also used : DbTable(ch.ehi.sqlgen.repository.DbTable) Table(ch.interlis.ili2c.metamodel.Table) SurfaceOrAreaType(ch.interlis.ili2c.metamodel.SurfaceOrAreaType) DbColVarchar(ch.ehi.sqlgen.repository.DbColVarchar) SurfaceType(ch.interlis.ili2c.metamodel.SurfaceType) DbColGeometry(ch.ehi.sqlgen.repository.DbColGeometry) Viewable(ch.interlis.ili2c.metamodel.Viewable) Iterator(java.util.Iterator) AttributeDef(ch.interlis.ili2c.metamodel.AttributeDef) DbColId(ch.ehi.sqlgen.repository.DbColId) DbTableName(ch.ehi.sqlgen.repository.DbTableName) DbTable(ch.ehi.sqlgen.repository.DbTable)

Example 9 with Table

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

the class FromXtfRecordConverter method getMultiSurfaceAttrDef.

protected AttributeDef getMultiSurfaceAttrDef(Type type, MultiSurfaceMapping attrMapping) {
    Table multiSurfaceType = ((CompositionType) type).getComponentType();
    Table surfaceStructureType = ((CompositionType) ((AttributeDef) multiSurfaceType.getElement(AttributeDef.class, attrMapping.getBagOfSurfacesAttrName())).getDomain()).getComponentType();
    AttributeDef surfaceAttr = (AttributeDef) surfaceStructureType.getElement(AttributeDef.class, attrMapping.getSurfaceAttrName());
    return surfaceAttr;
}
Also used : Table(ch.interlis.ili2c.metamodel.Table) AttributeDef(ch.interlis.ili2c.metamodel.AttributeDef) CompositionType(ch.interlis.ili2c.metamodel.CompositionType)

Example 10 with Table

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

the class FromXtfRecordConverter method getMultiLineAttrDef.

protected AttributeDef getMultiLineAttrDef(Type type, MultiLineMapping attrMapping) {
    Table multiLineType = ((CompositionType) type).getComponentType();
    Table lineStructureType = ((CompositionType) ((AttributeDef) multiLineType.getElement(AttributeDef.class, attrMapping.getBagOfLinesAttrName())).getDomain()).getComponentType();
    AttributeDef polylineAttr = (AttributeDef) lineStructureType.getElement(AttributeDef.class, attrMapping.getLineAttrName());
    return polylineAttr;
}
Also used : Table(ch.interlis.ili2c.metamodel.Table) AttributeDef(ch.interlis.ili2c.metamodel.AttributeDef) CompositionType(ch.interlis.ili2c.metamodel.CompositionType)

Aggregations

Table (ch.interlis.ili2c.metamodel.Table)24 AttributeDef (ch.interlis.ili2c.metamodel.AttributeDef)16 CompositionType (ch.interlis.ili2c.metamodel.CompositionType)15 Type (ch.interlis.ili2c.metamodel.Type)11 SurfaceType (ch.interlis.ili2c.metamodel.SurfaceType)10 Iterator (java.util.Iterator)10 SurfaceOrAreaType (ch.interlis.ili2c.metamodel.SurfaceOrAreaType)9 CoordType (ch.interlis.ili2c.metamodel.CoordType)6 Viewable (ch.interlis.ili2c.metamodel.Viewable)5 ViewableTransferElement (ch.interlis.ili2c.metamodel.ViewableTransferElement)5 IomObject (ch.interlis.iom.IomObject)5 AbstractClassDef (ch.interlis.ili2c.metamodel.AbstractClassDef)4 EnumerationType (ch.interlis.ili2c.metamodel.EnumerationType)4 PolylineType (ch.interlis.ili2c.metamodel.PolylineType)4 ViewableWrapper (ch.ehi.ili2db.mapping.ViewableWrapper)3 DbTable (ch.ehi.sqlgen.repository.DbTable)3 DbTableName (ch.ehi.sqlgen.repository.DbTableName)3 ConverterException (ch.ehi.ili2db.converter.ConverterException)2 DbColId (ch.ehi.sqlgen.repository.DbColId)2 Domain (ch.interlis.ili2c.metamodel.Domain)2