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);
}
}
}
}
}
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;
}
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;
}
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);
}
}
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);
}
}
Aggregations