Search in sources :

Example 31 with AttributeDef

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

the class TransferFromIli method updateSingleEnumTable.

public void updateSingleEnumTable(java.sql.Connection conn) throws Ili2dbException {
    DbTableName tabName = new DbTableName(schema.getName(), DbNames.ENUM_TAB);
    String sqlName = tabName.getName();
    if (tabName.getSchema() != null) {
        sqlName = tabName.getSchema() + "." + sqlName;
    }
    try {
        // insert entries
        String insStmt = "INSERT INTO " + sqlName + " (" + 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 + "," + DbNames.ENUM_TAB_THIS_COL + "," + DbNames.ENUM_TAB_BASE_COL + ") VALUES (?,?,?,?,?,?,?,?)";
        EhiLogger.traceBackendCmd(insStmt);
        java.sql.PreparedStatement insPrepStmt = conn.prepareStatement(insStmt);
        String thisClass = null;
        try {
            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();
                    thisClass = attr.getContainer().getScopedName(null) + "." + attr.getName();
                    AttributeDef base = (AttributeDef) attr.getExtending();
                    String baseClass = null;
                    if (base != null) {
                        baseClass = base.getContainer().getScopedName(null) + "." + base.getName();
                    }
                    HashSet exstEntries = readEnumTable(conn, true, thisClass, tabName);
                    updateEnumEntries(exstEntries, insPrepStmt, type, thisClass, baseClass);
                } else if (entro instanceof Domain) {
                    Domain domain = (Domain) entro;
                    if (domain == td.INTERLIS.BOOLEAN) {
                        continue;
                    }
                    EnumerationType type = (EnumerationType) domain.getType();
                    thisClass = domain.getScopedName(null);
                    Domain base = (Domain) domain.getExtending();
                    String baseClass = null;
                    if (base != null) {
                        baseClass = base.getScopedName(null);
                    }
                    HashSet exstEntries = readEnumTable(conn, true, thisClass, tabName);
                    updateEnumEntries(exstEntries, insPrepStmt, type, thisClass, baseClass);
                }
            }
        } catch (java.sql.SQLException ex) {
            throw new Ili2dbException("failed to insert enum values for type " + thisClass, ex);
        } finally {
            insPrepStmt.close();
        }
    } catch (java.sql.SQLException ex) {
        throw new Ili2dbException("failed to update enum-table " + sqlName, ex);
    }
}
Also used : Ili2dbException(ch.ehi.ili2db.base.Ili2dbException) Iterator(java.util.Iterator) 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 32 with AttributeDef

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

the class TransferFromIli method addMissingEnumDomains.

private void addMissingEnumDomains(HashSet enums) {
    java.util.Iterator entri = enums.iterator();
    HashSet<Domain> missingDomains = new HashSet<Domain>();
    while (entri.hasNext()) {
        Object entro = entri.next();
        if (entro instanceof AttributeDef) {
            AttributeDef attr = (AttributeDef) entro;
            ch.interlis.ili2c.metamodel.Type type = attr.getDomain();
            if (type instanceof ch.interlis.ili2c.metamodel.TypeAlias) {
                Domain domain = ((ch.interlis.ili2c.metamodel.TypeAlias) type).getAliasing();
                if (!enums.contains(domain)) {
                    missingDomains.add(domain);
                }
            }
        } else if (entro instanceof Domain) {
        // skip
        }
    }
    enums.addAll(missingDomains);
}
Also used : Iterator(java.util.Iterator) AttributeDef(ch.interlis.ili2c.metamodel.AttributeDef) Domain(ch.interlis.ili2c.metamodel.Domain) HashSet(java.util.HashSet)

Example 33 with AttributeDef

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

the class TransferFromIli method generateViewable.

private void generateViewable(ViewableWrapper def, int pass) throws Ili2dbException {
    if (def.getViewable() instanceof AssociationDef) {
        AssociationDef assoc = (AssociationDef) def.getViewable();
        if (assoc.getDerivedFrom() != null) {
            return;
        }
        if (assoc.isLightweight() && !assoc.getAttributes().hasNext() && !assoc.getLightweightAssociations().iterator().hasNext()) {
            if (pass == 1) {
                customMapping.fixupViewable(null, def.getViewable());
            }
            return;
        }
    }
    EhiLogger.traceState("wrapper of viewable " + def.getViewable());
    if (!visitedWrapper.contains(def)) {
        visitedWrapper.add(def);
        recConv.generateTable(def, pass);
        for (ViewableWrapper secondary : def.getSecondaryTables()) {
            recConv.generateTable(secondary, pass);
        }
        if (false && createItfLineTables) {
            for (AttributeDef attr : recConv.getSurfaceAttrs()) {
                generateItfLineTable(attr, pass);
            }
        }
    }
}
Also used : AssociationDef(ch.interlis.ili2c.metamodel.AssociationDef) AttributeDef(ch.interlis.ili2c.metamodel.AttributeDef) ViewableWrapper(ch.ehi.ili2db.mapping.ViewableWrapper)

Example 34 with AttributeDef

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

the class FromXtfRecordConverter method getIomObjectAttrs.

public HashSet getIomObjectAttrs(Viewable aclass) {
    HashSet ret = new HashSet();
    Iterator iter = aclass.getAttributesAndRoles2();
    while (iter.hasNext()) {
        ViewableTransferElement obj = (ViewableTransferElement) iter.next();
        if (obj.obj instanceof AttributeDef) {
            AttributeDef attr = (AttributeDef) obj.obj;
            if (!attr.isTransient()) {
                Type proxyType = attr.getDomain();
                if (proxyType != null && (proxyType instanceof ObjectType)) {
                // skip implicit particles (base-viewables) of views
                } else {
                    AttributeDef base = (AttributeDef) attr.getExtending();
                    while (base != null) {
                        attr = base;
                        base = (AttributeDef) attr.getExtending();
                    }
                    ret.add(attr);
                }
            }
        }
        if (obj.obj instanceof RoleDef) {
            RoleDef role = (RoleDef) obj.obj;
            if (role.getExtending() == null) {
                // a role of an embedded association?
                if (obj.embedded) {
                    AssociationDef roleOwner = (AssociationDef) role.getContainer();
                    if (roleOwner.getDerivedFrom() == null) {
                        RoleDef base = (RoleDef) role.getExtending();
                        while (base != null) {
                            role = base;
                            base = (RoleDef) role.getExtending();
                        }
                        ret.add(role);
                    }
                } else {
                    RoleDef base = (RoleDef) role.getExtending();
                    while (base != null) {
                        role = base;
                        base = (RoleDef) role.getExtending();
                    }
                    ret.add(role);
                }
            }
        }
    }
    return ret;
}
Also used : ViewableTransferElement(ch.interlis.ili2c.metamodel.ViewableTransferElement) ObjectType(ch.interlis.ili2c.metamodel.ObjectType) NumericalType(ch.interlis.ili2c.metamodel.NumericalType) PolylineType(ch.interlis.ili2c.metamodel.PolylineType) Type(ch.interlis.ili2c.metamodel.Type) ReferenceType(ch.interlis.ili2c.metamodel.ReferenceType) SurfaceOrAreaType(ch.interlis.ili2c.metamodel.SurfaceOrAreaType) SurfaceType(ch.interlis.ili2c.metamodel.SurfaceType) CompositionType(ch.interlis.ili2c.metamodel.CompositionType) EnumerationType(ch.interlis.ili2c.metamodel.EnumerationType) NumericType(ch.interlis.ili2c.metamodel.NumericType) BlackboxType(ch.interlis.ili2c.metamodel.BlackboxType) AreaType(ch.interlis.ili2c.metamodel.AreaType) LineType(ch.interlis.ili2c.metamodel.LineType) ObjectType(ch.interlis.ili2c.metamodel.ObjectType) CoordType(ch.interlis.ili2c.metamodel.CoordType) RoleDef(ch.interlis.ili2c.metamodel.RoleDef) Iterator(java.util.Iterator) AssociationDef(ch.interlis.ili2c.metamodel.AssociationDef) AttributeDef(ch.interlis.ili2c.metamodel.AttributeDef) HashSet(java.util.HashSet)

Example 35 with AttributeDef

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

the class FromXtfRecordConverter method writeRecord.

public void writeRecord(long basketSqlId, IomObject iomObj, Viewable iomClass, StructWrapper structEle, ViewableWrapper aclass, String sqlType, long sqlId, boolean updateObj, PreparedStatement ps, ArrayList structQueue) throws SQLException, ConverterException {
    int valuei = 1;
    if (updateObj) {
    // if update, t_id is last param
    // ps.setInt(valuei, sqlId);
    // valuei++;
    } else {
        ps.setLong(valuei, sqlId);
        valuei++;
    }
    if (createBasketCol) {
        ps.setLong(valuei, basketSqlId);
        valuei++;
    }
    if (createDatasetCol) {
        ps.setString(valuei, datasetName);
        valuei++;
    }
    if (!aclass.isSecondaryTable()) {
        if (aclass.getExtending() == null) {
            if (createTypeDiscriminator || aclass.includesMultipleTypes()) {
                ps.setString(valuei, sqlType);
                valuei++;
            }
            // if class
            if (structEle == null) {
                if (!updateObj) {
                    if (!aclass.isStructure()) {
                        if (createIliTidCol || aclass.getOid() != null) {
                            // import TID from transfer file
                            if (AbstractRecordConverter.isUuidOid(td, aclass.getOid())) {
                                Object toInsertUUID = geomConv.fromIomUuid(iomObj.getobjectoid());
                                ps.setObject(valuei, toInsertUUID);
                            } else {
                                ps.setString(valuei, iomObj.getobjectoid());
                            }
                            valuei++;
                        }
                    }
                }
            }
            // if struct, add ref to parent
            if (structEle != null) {
                ps.setLong(valuei, structEle.getParentSqlId());
                valuei++;
                if (createGenericStructRef) {
                    ps.setString(valuei, structEle.getParentSqlType());
                    valuei++;
                    // T_ParentAttr
                    ps.setString(valuei, structEle.getParentSqlAttr());
                    valuei++;
                }
                // T_Seq
                ps.setInt(valuei, structEle.getStructi());
                valuei++;
            }
        }
    }
    HashSet attrs = getIomObjectAttrs(iomClass);
    Iterator iter = aclass.getAttrIterator();
    while (iter.hasNext()) {
        ViewableTransferElement obj = (ViewableTransferElement) iter.next();
        if (obj.obj instanceof AttributeDef) {
            AttributeDef attr = (AttributeDef) obj.obj;
            if (attrs.contains(attr)) {
                if (!attr.isTransient()) {
                    Type proxyType = attr.getDomain();
                    if (proxyType != null && (proxyType instanceof ObjectType)) {
                    // skip implicit particles (base-viewables) of views
                    } else {
                        valuei = addAttrValue(iomObj, sqlType, sqlId, aclass.getSqlTablename(), ps, valuei, attr, structQueue);
                    }
                }
            }
        }
        if (obj.obj instanceof RoleDef) {
            RoleDef role = (RoleDef) obj.obj;
            if (role.getExtending() == null) {
                if (attrs.contains(role)) {
                    String refoid = null;
                    String roleName = role.getName();
                    // a role of an embedded association?
                    if (obj.embedded) {
                        AssociationDef roleOwner = (AssociationDef) role.getContainer();
                        if (roleOwner.getDerivedFrom() == null) {
                            // not just a link?
                            IomObject structvalue = iomObj.getattrobj(roleName, 0);
                            if (roleOwner.getAttributes().hasNext() || roleOwner.getLightweightAssociations().iterator().hasNext()) {
                            // TODO handle attributes of link
                            }
                            if (structvalue != null) {
                                refoid = structvalue.getobjectrefoid();
                                long orderPos = structvalue.getobjectreforderpos();
                                if (orderPos != 0) {
                                // refoid,orderPos
                                // ret.setStringAttribute(roleName, refoid);
                                // ret.setStringAttribute(roleName+".orderPos", Long.toString(orderPos));
                                } else {
                                // refoid
                                // ret.setStringAttribute(roleName, refoid);
                                }
                            } else {
                                refoid = null;
                            }
                        }
                    } else {
                        IomObject structvalue = iomObj.getattrobj(roleName, 0);
                        refoid = structvalue.getobjectrefoid();
                        long orderPos = structvalue.getobjectreforderpos();
                        if (orderPos != 0) {
                        // refoid,orderPos
                        // ret.setStringAttribute(roleName, refoid);
                        // ret.setStringAttribute(roleName+".orderPos", Long.toString(orderPos));
                        } else {
                        // refoid
                        // ret.setStringAttribute(roleName, refoid);
                        }
                    }
                    Holder<Integer> valueiRef = new Holder<Integer>(valuei);
                    setReferenceColumn(ps, role.getDestination(), refoid, valueiRef);
                    valuei = valueiRef.value;
                }
            }
        }
    }
    if (createStdCols) {
        // T_LastChange
        ps.setTimestamp(valuei, today);
        valuei++;
        // T_CreateDate
        if (!updateObj) {
            ps.setTimestamp(valuei, today);
            valuei++;
        }
        // T_User
        ps.setString(valuei, dbusr);
        valuei++;
    }
    if (updateObj) {
        // if update, t_id is last param
        ps.setLong(valuei, sqlId);
        valuei++;
    } else {
    // if insert, t_id is first param
    // ps.setInt(valuei, sqlId);
    // valuei++;
    }
}
Also used : ViewableTransferElement(ch.interlis.ili2c.metamodel.ViewableTransferElement) RoleDef(ch.interlis.ili2c.metamodel.RoleDef) Holder(javax.xml.ws.Holder) ObjectType(ch.interlis.ili2c.metamodel.ObjectType) NumericalType(ch.interlis.ili2c.metamodel.NumericalType) PolylineType(ch.interlis.ili2c.metamodel.PolylineType) Type(ch.interlis.ili2c.metamodel.Type) ReferenceType(ch.interlis.ili2c.metamodel.ReferenceType) SurfaceOrAreaType(ch.interlis.ili2c.metamodel.SurfaceOrAreaType) SurfaceType(ch.interlis.ili2c.metamodel.SurfaceType) CompositionType(ch.interlis.ili2c.metamodel.CompositionType) EnumerationType(ch.interlis.ili2c.metamodel.EnumerationType) NumericType(ch.interlis.ili2c.metamodel.NumericType) BlackboxType(ch.interlis.ili2c.metamodel.BlackboxType) AreaType(ch.interlis.ili2c.metamodel.AreaType) LineType(ch.interlis.ili2c.metamodel.LineType) ObjectType(ch.interlis.ili2c.metamodel.ObjectType) CoordType(ch.interlis.ili2c.metamodel.CoordType) IomObject(ch.interlis.iom.IomObject) Iterator(java.util.Iterator) AssociationDef(ch.interlis.ili2c.metamodel.AssociationDef) IomObject(ch.interlis.iom.IomObject) AttributeDef(ch.interlis.ili2c.metamodel.AttributeDef) HashSet(java.util.HashSet)

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