Search in sources :

Example 6 with Topic

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

the class TransferFromXtf method deleteObjectsOfBasket.

private void deleteObjectsOfBasket(long basketSqlId, String topicQName) throws Ili2dbException {
    boolean isItf = false;
    Topic topic = TransferToXtf.getTopicDef(td, topicQName);
    if (topic == null) {
        throw new Ili2dbException("unkown topic " + topicQName.toString());
    }
    Model model = (Model) topic.getContainer();
    // for all Viewables
    // see also export
    Iterator iter = null;
    if (isItf) {
        ArrayList itftablev = ModelUtilities.getItfTables(td, model.getName(), topic.getName());
        iter = itftablev.iterator();
    } else {
        // get transferable viewables of topic
        iter = topic.getViewables().iterator();
    }
    HashSet<ViewableWrapper> visitedTables = new HashSet<ViewableWrapper>();
    while (iter.hasNext()) {
        Object obj = iter.next();
        if (obj instanceof Viewable) {
            if ((obj instanceof View) && !TransferFromIli.isTransferableView(obj)) {
            // skip it
            } else if (!TransferToXtf.suppressViewable((Viewable) obj)) {
                Viewable aclass1 = (Viewable) obj;
                ViewableWrapper wrapper = class2wrapper.get(aclass1);
                while (wrapper != null) {
                    {
                        if (!visitedTables.contains(wrapper)) {
                            visitedTables.add(wrapper);
                            // if table exists?
                            // get sql name
                            DbTableName sqlName = wrapper.getSqlTable();
                            if (customMapping.tableExists(conn, sqlName)) {
                                // delete it
                                dropRecords(sqlName, basketSqlId);
                            } else {
                            // skip it; no table
                            }
                        }
                    }
                    for (ViewableWrapper secondary : wrapper.getSecondaryTables()) {
                        if (!visitedTables.contains(secondary)) {
                            visitedTables.add(secondary);
                            // if table exists?
                            // get sql name
                            DbTableName sqlName = secondary.getSqlTable();
                            if (customMapping.tableExists(conn, sqlName)) {
                                // delete it
                                dropRecords(sqlName, basketSqlId);
                            } else {
                            // skip it; no table
                            }
                        }
                    }
                    wrapper = wrapper.getExtending();
                }
            }
        } else if (obj instanceof AttributeDef) {
            if (isItf) {
                AttributeDef attr = (AttributeDef) obj;
                int[] epsgCodes = TransferFromIli.getEpsgCodes(attr, srsModelAssignment, defaultCrsCode);
                for (int epsgCode : epsgCodes) {
                    // get sql name
                    DbTableName sqlName = getSqlTableNameItfLineTable(attr, epsgCode);
                    // if table exists?
                    if (customMapping.tableExists(conn, sqlName)) {
                        dropRecords(sqlName, basketSqlId);
                    } else {
                    // skip it; no table
                    }
                }
            }
        }
    }
    dropExistingStructEles(topicQName, basketSqlId);
    if (createImportTabs) {
        String sqlName = DbNames.IMPORTS_BASKETS_TAB;
        if (schema != null) {
            sqlName = schema + "." + sqlName;
        }
        java.sql.PreparedStatement getstmt = null;
        try {
            String stmt = "DELETE FROM " + sqlName + " WHERE " + DbNames.IMPORTS_BASKETS_TAB_BASKET_COL + "= ?";
            EhiLogger.traceBackendCmd(stmt);
            getstmt = conn.prepareStatement(stmt);
            getstmt.setLong(1, basketSqlId);
            getstmt.executeUpdate();
        } catch (java.sql.SQLException ex) {
            throw new Ili2dbException("failed to delete from " + sqlName, ex);
        } finally {
            if (getstmt != null) {
                try {
                    getstmt.close();
                    getstmt = null;
                } catch (java.sql.SQLException ex) {
                    EhiLogger.logError(ex);
                }
            }
        }
    }
}
Also used : Ili2dbException(ch.ehi.ili2db.base.Ili2dbException) ArrayList(java.util.ArrayList) ViewableWrapper(ch.ehi.ili2db.mapping.ViewableWrapper) PreparedStatement(java.sql.PreparedStatement) View(ch.interlis.ili2c.metamodel.View) SQLException(java.sql.SQLException) Model(ch.interlis.ili2c.metamodel.Model) Iterator(java.util.Iterator) Viewable(ch.interlis.ili2c.metamodel.Viewable) IomObject(ch.interlis.iom.IomObject) AttributeDef(ch.interlis.ili2c.metamodel.AttributeDef) Topic(ch.interlis.ili2c.metamodel.Topic) DbTableName(ch.ehi.sqlgen.repository.DbTableName) HashSet(java.util.HashSet)

Example 7 with Topic

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

the class TransferFromXtf method readExistingSqlObjIds.

private Long readExistingSqlObjIds(boolean isItf, String bid) throws Ili2dbException {
    StringBuilder topicQName = new StringBuilder();
    Long basketSqlId = Ili2db.getBasketSqlIdFromBID(bid, conn, schema, colT_ID, topicQName);
    if (basketSqlId == null) {
        // new basket
        return null;
    }
    Topic topic = TransferToXtf.getTopicDef(td, topicQName.toString());
    if (topic == null) {
        throw new Ili2dbException("unkown topic " + topicQName.toString());
    }
    readExistingSqlObjIds(isItf, topic, basketSqlId);
    return basketSqlId;
}
Also used : Ili2dbException(ch.ehi.ili2db.base.Ili2dbException) Topic(ch.interlis.ili2c.metamodel.Topic)

Example 8 with Topic

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

the class TransferFromXtf method getStructs.

private HashSet<AbstractClassDef> getStructs(String topicQName) {
    Topic def = TransferToXtf.getTopicDef(td, topicQName);
    HashSet<AbstractClassDef> visitedStructs = new HashSet<AbstractClassDef>();
    while (def != null) {
        Iterator classi = def.iterator();
        while (classi.hasNext()) {
            Object classo = classi.next();
            if (classo instanceof Viewable) {
                if (classo instanceof Table && ((Table) classo).isIdentifiable()) {
                    getStructs_Helper((AbstractClassDef) classo, visitedStructs);
                } else if (classo instanceof AssociationDef && !((AssociationDef) classo).isIdentifiable()) {
                    // handle associations without an OID like struct eles
                    visitedStructs.add((AssociationDef) classo);
                }
            }
        }
        def = (Topic) def.getExtending();
    }
    return visitedStructs;
}
Also used : Table(ch.interlis.ili2c.metamodel.Table) Iterator(java.util.Iterator) Viewable(ch.interlis.ili2c.metamodel.Viewable) AssociationDef(ch.interlis.ili2c.metamodel.AssociationDef) IomObject(ch.interlis.iom.IomObject) AbstractClassDef(ch.interlis.ili2c.metamodel.AbstractClassDef) Topic(ch.interlis.ili2c.metamodel.Topic) HashSet(java.util.HashSet)

Example 9 with Topic

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

the class ModelElementSelector method visitTopic.

private void visitTopic(HashSet<Element> visitedElements, HashSet<Model> accuScope, Topic def) {
    if (visitedElements.contains(def)) {
        return;
    }
    visitedElements.add(def);
    Iterator classi = def.iterator();
    while (classi.hasNext()) {
        Object classo = classi.next();
        if (classo instanceof Viewable) {
            visitViewable(visitedElements, accuScope, (Viewable) classo);
        } else if (classo instanceof Domain) {
            visitDomain(visitedElements, accuScope, (Domain) classo);
        }
    }
    // base topic
    Topic base = (Topic) def.getExtending();
    if (base != null) {
        visitTopic(visitedElements, accuScope, base);
    }
    // depends on
    Iterator depi = def.getDependentOn();
    while (depi.hasNext()) {
        Topic dep = (Topic) depi.next();
        visitTopic(visitedElements, accuScope, dep);
    }
    // parent model
    Model model = (Model) def.getContainer(Model.class);
    if (!accuScope.contains(model)) {
        accuScope.add(model);
    }
}
Also used : Iterator(java.util.Iterator) Viewable(ch.interlis.ili2c.metamodel.Viewable) Model(ch.interlis.ili2c.metamodel.Model) Domain(ch.interlis.ili2c.metamodel.Domain) Topic(ch.interlis.ili2c.metamodel.Topic)

Example 10 with Topic

use of ch.interlis.ili2c.metamodel.Topic 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 (type instanceof ReferenceType) {
                ReferenceType refType = (ReferenceType) type;
                Viewable targetClass = refType.getReferred();
                visitTopic(visitedElements, accuScope, (Topic) targetClass.getContainer(Topic.class));
            } 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());
            }
        } else if (attro instanceof RoleDef) {
            RoleDef role = (RoleDef) attro;
            for (Iterator<ReferenceType> refTypeIt = role.iteratorReference(); refTypeIt.hasNext(); ) {
                ReferenceType refType = refTypeIt.next();
                Viewable targetClass = refType.getReferred();
                visitTopic(visitedElements, accuScope, (Topic) targetClass.getContainer(Topic.class));
            }
        }
    }
    // 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) ReferenceType(ch.interlis.ili2c.metamodel.ReferenceType) SurfaceOrAreaType(ch.interlis.ili2c.metamodel.SurfaceOrAreaType) Type(ch.interlis.ili2c.metamodel.Type) SurfaceOrAreaType(ch.interlis.ili2c.metamodel.SurfaceOrAreaType) RoleDef(ch.interlis.ili2c.metamodel.RoleDef) 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) Topic(ch.interlis.ili2c.metamodel.Topic) ReferenceType(ch.interlis.ili2c.metamodel.ReferenceType)

Aggregations

Topic (ch.interlis.ili2c.metamodel.Topic)19 Iterator (java.util.Iterator)13 Model (ch.interlis.ili2c.metamodel.Model)9 Viewable (ch.interlis.ili2c.metamodel.Viewable)9 IomObject (ch.interlis.iom.IomObject)7 IoxException (ch.interlis.iox.IoxException)6 Ili2dbException (ch.ehi.ili2db.base.Ili2dbException)5 Domain (ch.interlis.ili2c.metamodel.Domain)5 AttributeDef (ch.interlis.ili2c.metamodel.AttributeDef)4 PredefinedModel (ch.interlis.ili2c.metamodel.PredefinedModel)4 TypeModel (ch.interlis.ili2c.metamodel.TypeModel)4 Iom_jObject (ch.interlis.iom_j.Iom_jObject)4 ArrayList (java.util.ArrayList)4 ViewableWrapper (ch.ehi.ili2db.mapping.ViewableWrapper)3 EnumerationType (ch.interlis.ili2c.metamodel.EnumerationType)3 View (ch.interlis.ili2c.metamodel.View)3 IoxLogging (ch.interlis.iox.IoxLogging)3 PipelinePool (ch.interlis.iox_j.PipelinePool)3 ReduceToBaseModel (ch.interlis.iox_j.filter.ReduceToBaseModel)3 LogEventFactory (ch.interlis.iox_j.logging.LogEventFactory)3