Search in sources :

Example 11 with AttributeDef

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

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

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

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

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

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