Search in sources :

Example 1 with View

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

the class TransferFromIli method isTransferableView.

public static boolean isTransferableView(Object modelo) {
    if (!(modelo instanceof View)) {
        return false;
    }
    View view = (View) modelo;
    Topic parent = (Topic) view.getContainer();
    if (!parent.isViewTopic()) {
        return false;
    }
    if (view.isTransient()) {
        return false;
    }
    return true;
}
Also used : Topic(ch.interlis.ili2c.metamodel.Topic) View(ch.interlis.ili2c.metamodel.View)

Example 2 with View

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

use of ch.interlis.ili2c.metamodel.View 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());
    }
    Model model = (Model) topic.getContainer();
    // for all Viewables
    Iterator iter = null;
    if (isItf) {
        ArrayList itftablev = ModelUtilities.getItfTables(td, model.getName(), topic.getName());
        iter = itftablev.iterator();
    } else {
        iter = getXtfTables(td, topic).iterator();
    }
    HashSet<String> visitedTables = new HashSet<String>();
    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 aclass = (Viewable) obj;
                if (aclass.isAbstract()) {
                    throw new IllegalArgumentException("unexpected abstract viewable " + aclass.getScopedName(null));
                }
                // get sql name
                DbTableName sqlName = recConv.getSqlType(aclass);
                ViewableWrapper wrapper = recConv.getViewableWrapper(sqlName.getName());
                ViewableWrapper base = wrapper.getExtending();
                while (base != null) {
                    wrapper = base;
                    base = wrapper.getExtending();
                }
                sqlName = wrapper.getSqlTable();
                if (!visitedTables.contains(sqlName.getQName())) {
                    visitedTables.add(sqlName.getQName());
                    // if table exists?
                    if (DbUtility.tableExists(conn, sqlName)) {
                        // dump it
                        EhiLogger.logState(aclass.getScopedName(null) + " read ids...");
                        readObjectSqlIds(!wrapper.includesMultipleTypes(), sqlName, basketSqlId);
                    } else {
                        // skip it
                        EhiLogger.traceUnusualState(aclass.getScopedName(null) + "...skipped; no table " + sqlName + " in db");
                    }
                }
            }
        } else if (obj instanceof AttributeDef) {
            if (isItf) {
                AttributeDef attr = (AttributeDef) obj;
                // get sql name
                DbTableName sqlName = getSqlTableNameItfLineTable(attr);
                // if table exists?
                if (DbUtility.tableExists(conn, sqlName)) {
                    // dump it
                    EhiLogger.logState(attr.getContainer().getScopedName(null) + "_" + attr.getName() + " read ids...");
                    readObjectSqlIds(isItf, sqlName, basketSqlId);
                } else {
                    // skip it
                    EhiLogger.traceUnusualState(attr.getScopedName(null) + "...skipped; no table " + sqlName + " in db");
                }
            }
        }
    }
    return basketSqlId;
}
Also used : Ili2dbException(ch.ehi.ili2db.base.Ili2dbException) ArrayList(java.util.ArrayList) ViewableWrapper(ch.ehi.ili2db.mapping.ViewableWrapper) View(ch.interlis.ili2c.metamodel.View) 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 4 with View

use of ch.interlis.ili2c.metamodel.View 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 (DbUtility.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 (DbUtility.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;
                // get sql name
                DbTableName sqlName = getSqlTableNameItfLineTable(attr);
                // if table exists?
                if (DbUtility.tableExists(conn, sqlName)) {
                    dropRecords(sqlName, basketSqlId);
                } else {
                // skip it; no table
                }
            }
        }
    }
    dropExistingStructEles(topicQName, basketSqlId);
    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 5 with View

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

the class TransferToXtf method doBasket.

private boolean doBasket(String filename, IoxWriter iomFile, Topic topic, Long basketSqlId, String basketXtfId) throws IoxException {
    Model model = (Model) topic.getContainer();
    boolean referrs = false;
    StartBasketEvent iomBasket = null;
    delayedObjects = new ArrayList<FixIomObjectRefs>();
    // for all Viewables
    Iterator iter = null;
    if (iomFile instanceof ItfWriter) {
        ArrayList itftablev = ModelUtilities.getItfTables(td, model.getName(), topic.getName());
        iter = itftablev.iterator();
    } else {
        iter = topic.getViewables().iterator();
    }
    while (iter.hasNext()) {
        Object obj = iter.next();
        if (obj instanceof Viewable) {
            if ((obj instanceof View) && !TransferFromIli.isTransferableView(obj)) {
            // skip it
            } else if (!suppressViewable((Viewable) obj)) {
                Viewable aclass = (Viewable) obj;
                if (languageFilter != null) {
                    aclass = (Viewable) aclass.getTranslationOfOrSame();
                }
                ViewableWrapper wrapper = class2wrapper.get(aclass);
                // get sql name
                DbTableName sqlName = recConv.getSqlType(wrapper.getViewable());
                // if table exists?
                if (DbUtility.tableExists(conn, sqlName)) {
                    // dump it
                    EhiLogger.logState(aclass.getScopedName(null) + "...");
                    if (iomBasket == null) {
                        iomBasket = new StartBasketEvent(topic.getScopedName(null), basketXtfId);
                        if (languageFilter != null) {
                            iomBasket = (StartBasketEvent) languageFilter.filter(iomBasket);
                        }
                        if (exportBaseModelFilter != null) {
                            iomBasket = (StartBasketEvent) exportBaseModelFilter.filter(iomBasket);
                        }
                        if (validator != null)
                            validator.validate(iomBasket);
                        iomFile.write(iomBasket);
                    }
                    dumpObject(iomFile, aclass, basketSqlId);
                } else {
                    // skip it
                    EhiLogger.traceUnusualState(aclass.getScopedName(null) + "...skipped; no table " + sqlName + " in db");
                }
            }
        } else if (obj instanceof AttributeDef) {
            if (iomFile instanceof ItfWriter) {
                AttributeDef attr = (AttributeDef) obj;
                // get sql name
                DbTableName sqlName = getSqlTableNameItfLineTable(attr);
                // if table exists?
                if (DbUtility.tableExists(conn, sqlName)) {
                    // dump it
                    EhiLogger.logState(attr.getContainer().getScopedName(null) + "_" + attr.getName() + "...");
                    if (iomBasket == null) {
                        iomBasket = new StartBasketEvent(topic.getScopedName(null), topic.getScopedName(null));
                        if (languageFilter != null) {
                            iomBasket = (StartBasketEvent) languageFilter.filter(iomBasket);
                        }
                        if (exportBaseModelFilter != null) {
                            iomBasket = (StartBasketEvent) exportBaseModelFilter.filter(iomBasket);
                        }
                        if (validator != null)
                            validator.validate(iomBasket);
                        iomFile.write(iomBasket);
                    }
                    dumpItfTableObject(iomFile, attr, basketSqlId);
                } else {
                    // skip it
                    EhiLogger.traceUnusualState(attr.getScopedName(null) + "...skipped; no table " + sqlName + " in db");
                }
            }
        }
    }
    if (iomBasket != null) {
        // fix forward references
        for (FixIomObjectRefs fixref : delayedObjects) {
            boolean skipObj = false;
            for (IomObject ref : fixref.getRefs()) {
                long sqlid = fixref.getTargetSqlid(ref);
                if (sqlidPool.containsSqlid(sqlid)) {
                    // fix it
                    ref.setobjectrefoid(sqlidPool.getXtfid(sqlid));
                } else {
                    // object in another basket
                    Viewable aclass = fixref.getTargetClass(ref);
                    // read object
                    String tid = readObjectTid(aclass, sqlid);
                    if (tid == null) {
                        EhiLogger.logError("unknown referenced object " + aclass.getScopedName(null) + " sqlid " + fixref.getTargetSqlid(ref) + " referenced from " + fixref.getRoot().getobjecttag() + " TID " + fixref.getRoot().getobjectoid());
                        referrs = true;
                        skipObj = true;
                    } else {
                        // fix reference
                        ref.setobjectrefoid(tid);
                    }
                }
            }
            if (!skipObj) {
                ObjectEvent objEvent = new ObjectEvent(fixref.getRoot());
                if (languageFilter != null) {
                    objEvent = (ObjectEvent) languageFilter.filter(objEvent);
                }
                if (exportBaseModelFilter != null) {
                    objEvent = (ObjectEvent) exportBaseModelFilter.filter(objEvent);
                }
                if (objEvent != null) {
                    if (validator != null)
                        validator.validate(objEvent);
                    iomFile.write(objEvent);
                }
            }
        }
        EndBasketEvent endBasket = new EndBasketEvent();
        if (languageFilter != null) {
            endBasket = (EndBasketEvent) languageFilter.filter(endBasket);
        }
        if (exportBaseModelFilter != null) {
            endBasket = (EndBasketEvent) exportBaseModelFilter.filter(endBasket);
        }
        if (validator != null)
            validator.validate(endBasket);
        iomFile.write(endBasket);
        saveObjStat(iomBasket.getBid(), basketSqlId, filename, iomBasket.getType());
    }
    return referrs;
}
Also used : ObjectEvent(ch.interlis.iox_j.ObjectEvent) ArrayList(java.util.ArrayList) ViewableWrapper(ch.ehi.ili2db.mapping.ViewableWrapper) View(ch.interlis.ili2c.metamodel.View) EndBasketEvent(ch.interlis.iox_j.EndBasketEvent) IomObject(ch.interlis.iom.IomObject) ReduceToBaseModel(ch.interlis.iox_j.filter.ReduceToBaseModel) PredefinedModel(ch.interlis.ili2c.metamodel.PredefinedModel) TypeModel(ch.interlis.ili2c.metamodel.TypeModel) Model(ch.interlis.ili2c.metamodel.Model) Iterator(java.util.Iterator) Viewable(ch.interlis.ili2c.metamodel.Viewable) StartBasketEvent(ch.interlis.iox_j.StartBasketEvent) Iom_jObject(ch.interlis.iom_j.Iom_jObject) IomObject(ch.interlis.iom.IomObject) AttributeDef(ch.interlis.ili2c.metamodel.AttributeDef) ItfWriter(ch.interlis.iom_j.itf.ItfWriter) DbTableName(ch.ehi.sqlgen.repository.DbTableName)

Aggregations

View (ch.interlis.ili2c.metamodel.View)5 ViewableWrapper (ch.ehi.ili2db.mapping.ViewableWrapper)4 AttributeDef (ch.interlis.ili2c.metamodel.AttributeDef)4 Model (ch.interlis.ili2c.metamodel.Model)4 Topic (ch.interlis.ili2c.metamodel.Topic)4 Viewable (ch.interlis.ili2c.metamodel.Viewable)4 Iterator (java.util.Iterator)4 Ili2dbException (ch.ehi.ili2db.base.Ili2dbException)3 DbTableName (ch.ehi.sqlgen.repository.DbTableName)3 IomObject (ch.interlis.iom.IomObject)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)2 DbTable (ch.ehi.sqlgen.repository.DbTable)1 Domain (ch.interlis.ili2c.metamodel.Domain)1 EnumerationType (ch.interlis.ili2c.metamodel.EnumerationType)1 PredefinedModel (ch.interlis.ili2c.metamodel.PredefinedModel)1 SurfaceOrAreaType (ch.interlis.ili2c.metamodel.SurfaceOrAreaType)1 Table (ch.interlis.ili2c.metamodel.Table)1 TypeModel (ch.interlis.ili2c.metamodel.TypeModel)1 Iom_jObject (ch.interlis.iom_j.Iom_jObject)1