use of ch.interlis.iox_j.EndBasketEvent 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;
}
Aggregations