use of ch.interlis.ili2c.metamodel.Viewable in project ili2db by claeis.
the class FromXtfRecordConverter method setReferenceColumn.
private void setReferenceColumn(PreparedStatement ps, AbstractClassDef destination, String refoid, Holder<Integer> valuei) throws SQLException {
String targetRootClassName = Ili2cUtility.getRootViewable(destination).getScopedName(null);
ViewableWrapper targetObjTable = null;
ArrayList<ViewableWrapper> targetTables = getTargetTables(destination);
if (refoid != null) {
String targetObjClass = oidPool.getObjecttag(targetRootClassName, refoid);
if (targetObjClass == null) {
// unknown object
// handle reference as if it is null
refoid = null;
} else {
targetObjTable = getViewableWrapper(getSqlType((Viewable) tag2class.get(targetObjClass)).getName());
while (!targetTables.contains(targetObjTable)) {
targetObjTable = targetObjTable.getExtending();
}
if (targetObjTable == null) {
throw new IllegalStateException("targetObjTable==null");
}
}
}
for (ViewableWrapper targetTable : targetTables) {
if (refoid != null && targetTable == targetObjTable) {
long refsqlId = oidPool.getObjSqlId(targetRootClassName, refoid);
ps.setLong(valuei.value, refsqlId);
} else {
ps.setNull(valuei.value, Types.BIGINT);
}
valuei.value++;
}
}
use of ch.interlis.ili2c.metamodel.Viewable in project ili2db by claeis.
the class TransferFromXtf method readObjectSqlIds.
private void readObjectSqlIds(boolean noTypeCol, DbTableName sqltablename, long basketsqlid) {
String stmt = createQueryStmt4sqlids(noTypeCol, sqltablename.getQName());
EhiLogger.traceBackendCmd(stmt);
java.sql.PreparedStatement dbstmt = null;
try {
dbstmt = conn.prepareStatement(stmt);
dbstmt.clearParameters();
dbstmt.setLong(1, basketsqlid);
java.sql.ResultSet rs = dbstmt.executeQuery();
while (rs.next()) {
long sqlid = rs.getLong(1);
String xtfid = rs.getString(2);
String sqlType = null;
if (!noTypeCol) {
sqlType = rs.getString(3);
} else {
sqlType = sqltablename.getName();
}
Viewable aclass = (Viewable) tag2class.get(ili2sqlName.mapSqlTableName(sqlType));
oidPool.putXtfid2sqlid(Ili2cUtility.getRootViewable(aclass).getScopedName(null), aclass.getScopedName(null), xtfid, sqlid);
addExistingObjects(sqlType, sqlid);
}
} catch (java.sql.SQLException ex) {
EhiLogger.logError("failed to query " + sqltablename, ex);
} finally {
if (dbstmt != null) {
try {
dbstmt.close();
} catch (java.sql.SQLException ex) {
EhiLogger.logError("failed to close query of " + sqltablename, ex);
}
}
}
}
use of ch.interlis.ili2c.metamodel.Viewable in project ili2db by claeis.
the class TransferFromXtf method allReferencesKnownHelper.
private void allReferencesKnownHelper(IomObject iomObj, AttributeDef attr, FixIomObjectExtRefs extref) {
String attrName = attr.getName();
if (attr.isDomainBoolean()) {
} else if (attr.isDomainIli1Date()) {
} else if (attr.isDomainIli2Date()) {
} else if (attr.isDomainIli2Time()) {
} else if (attr.isDomainIli2DateTime()) {
} else {
Type type = attr.getDomainResolvingAliases();
if (type instanceof CompositionType) {
// enqueue struct values
int structc = iomObj.getattrvaluecount(attrName);
for (int structi = 0; structi < structc; structi++) {
IomObject struct = iomObj.getattrobj(attrName, structi);
allReferencesKnownHelper(struct, extref);
}
} else if (type instanceof PolylineType) {
} else if (type instanceof SurfaceOrAreaType) {
} else if (type instanceof CoordType) {
} else if (type instanceof NumericType) {
} else if (type instanceof EnumerationType) {
} else if (type instanceof ReferenceType) {
IomObject structvalue = iomObj.getattrobj(attrName, 0);
String refoid = null;
if (structvalue != null) {
refoid = structvalue.getobjectrefoid();
}
if (refoid != null) {
Viewable targetClass = ((ReferenceType) type).getReferred();
if (!oidPool.containsXtfid(Ili2cUtility.getRootViewable(targetClass).getScopedName(null), refoid)) {
extref.addFix(structvalue, targetClass);
}
}
} else {
}
}
}
use of ch.interlis.ili2c.metamodel.Viewable in project ili2db by claeis.
the class TransferFromXtf method readObjectSqlid.
private Long readObjectSqlid(Viewable xclass, String xtfid) {
String stmt = createQueryStmt4sqlid(xclass);
EhiLogger.traceBackendCmd(stmt);
java.sql.PreparedStatement dbstmt = null;
long sqlid = 0;
String sqlType = null;
try {
dbstmt = conn.prepareStatement(stmt);
dbstmt.clearParameters();
if ((xclass instanceof AbstractClassDef) && ((AbstractClassDef) xclass).getOid() != null && AbstractRecordConverter.isUuidOid(td, ((AbstractClassDef) xclass).getOid())) {
dbstmt.setObject(1, geomConv.fromIomUuid(xtfid));
} else {
dbstmt.setString(1, xtfid);
}
java.sql.ResultSet rs = dbstmt.executeQuery();
if (rs.next()) {
sqlid = rs.getLong(1);
sqlType = rs.getString(3);
} else {
// unknown object
return null;
}
} catch (java.sql.SQLException ex) {
EhiLogger.logError("failed to query " + xclass.getScopedName(null), ex);
} catch (ConverterException ex) {
EhiLogger.logError("failed to query " + xclass.getScopedName(null), ex);
} finally {
if (dbstmt != null) {
try {
dbstmt.close();
} catch (java.sql.SQLException ex) {
EhiLogger.logError("failed to close query of " + xclass.getScopedName(null), ex);
}
}
}
// remember found sqlid
Viewable aclass = (Viewable) tag2class.get(ili2sqlName.mapSqlTableName(sqlType));
oidPool.putXtfid2sqlid(Ili2cUtility.getRootViewable(aclass).getScopedName(null), aclass.getScopedName(null), xtfid, sqlid);
return sqlid;
}
use of ch.interlis.ili2c.metamodel.Viewable in project ili2db by claeis.
the class AbstractRecordConverter method getTargetTables.
public ArrayList<ViewableWrapper> getTargetTables(Viewable destination) {
if (targetTablesPool.containsKey(destination)) {
return targetTablesPool.get(destination);
}
ArrayList<ViewableWrapper> ret = new ArrayList<ViewableWrapper>();
ArrayList<Viewable> candids = new ArrayList<Viewable>();
candids.add(destination);
while (!candids.isEmpty()) {
Viewable candid = candids.remove(0);
String inheritanceStrategy = trafoConfig.getViewableConfig(candid, TrafoConfigNames.INHERITANCE_TRAFO);
if (TrafoConfigNames.INHERITANCE_TRAFO_SUPERCLASS.equals(inheritanceStrategy)) {
// ViewableWrapper of base
ret.add(class2wrapper.get(candid));
} else if (TrafoConfigNames.INHERITANCE_TRAFO_SUBCLASS.equals(inheritanceStrategy)) {
// visit all sub classes
candids.addAll(candid.getDirectExtensions());
} else if (TrafoConfigNames.INHERITANCE_TRAFO_NEWCLASS.equals(inheritanceStrategy)) {
ViewableWrapper wrapper = class2wrapper.get(candid);
// classes that have no defined Wrapper are loaded by the compiler, but are not used
if (wrapper != null) {
ret.add(wrapper);
}
} else if (TrafoConfigNames.INHERITANCE_TRAFO_NEWANDSUBCLASS.equals(inheritanceStrategy)) {
ViewableWrapper wrapper = class2wrapper.get(candid);
// classes that have no defined Wrapper are loaded by the compiler, but are not used
if (wrapper != null) {
ret.add(wrapper);
}
// visit all sub classes
candids.addAll(candid.getDirectExtensions());
} else {
// skip it
// classes that have no assigned inheritanceStrategy are loaded by the compiler, but are not used
// example:
// CLASS CatalogueObjectTrees_V1.Catalogues.Item is loaded and an extension
// of CLASS CatalogueObjects_V1.Catalogues.Item.
// It is loaded because it is defined in the same ili-file, but is normally not used.
}
}
// buffer result, so that later calls return exactly the same ordering of targetTables
// first call: build sql statement
// second++ calls: set/get sql parameters
targetTablesPool.put(destination, ret);
return ret;
}
Aggregations