use of ch.interlis.ili2c.metamodel.Table in project ili2db by claeis.
the class TransferFromXtf method writeItfLineTableObject.
private void writeItfLineTableObject(String datasetName, long basketSqlId, IomObject iomObj, AttributeDef attrDef) throws java.sql.SQLException, ConverterException {
SurfaceOrAreaType type = (SurfaceOrAreaType) attrDef.getDomainResolvingAliases();
String geomAttrName = ch.interlis.iom_j.itf.ModelUtilities.getHelperTableGeomAttrName(attrDef);
String refAttrName = null;
if (type instanceof SurfaceType) {
refAttrName = ch.interlis.iom_j.itf.ModelUtilities.getHelperTableMainTableRef(attrDef);
}
Table lineAttrTable = type.getLineAttributeStructure();
// map oid of transfer file to a sql id
String idTag = attrDef.getContainer().getScopedName(null) + "." + attrDef.getName();
long sqlId = oidPool.createObjSqlId(idTag, idTag, iomObj.getobjectoid());
String sqlTableName = getSqlTableNameItfLineTable(attrDef).getQName();
String insert = createItfLineTableInsertStmt(attrDef);
EhiLogger.traceBackendCmd(insert);
PreparedStatement ps = conn.prepareStatement(insert);
try {
int valuei = 1;
ps.setLong(valuei, sqlId);
valuei++;
if (createBasketCol) {
ps.setLong(valuei, basketSqlId);
valuei++;
}
if (createDatasetCol) {
ps.setString(valuei, datasetName);
valuei++;
}
if (readIliTid) {
// import TID from transfer file
ps.setString(valuei, iomObj.getobjectoid());
valuei++;
}
IomObject value = iomObj.getattrobj(geomAttrName, 0);
if (value != null) {
boolean is3D = ((CoordType) (type).getControlPointDomain().getType()).getDimensions().length == 3;
ps.setObject(valuei, geomConv.fromIomPolyline(value, recConv.getSrsid(attrDef), is3D, recConv.getP(type)));
} else {
geomConv.setPolylineNull(ps, valuei);
}
valuei++;
if (type instanceof SurfaceType) {
IomObject structvalue = iomObj.getattrobj(refAttrName, 0);
String refoid = structvalue.getobjectrefoid();
long refsqlId = oidPool.getObjSqlId(attrDef.getContainer().getScopedName(null), refoid);
ps.setLong(valuei, refsqlId);
valuei++;
}
if (lineAttrTable != null) {
Iterator attri = lineAttrTable.getAttributes();
while (attri.hasNext()) {
AttributeDef lineattr = (AttributeDef) attri.next();
valuei = recConv.addAttrValue(iomObj, ili2sqlName.mapGeometryAsTable(attrDef), sqlId, sqlTableName, ps, valuei, lineattr, null);
}
}
if (createStdCols) {
// T_LastChange
ps.setTimestamp(valuei, today);
valuei++;
// T_CreateDate
ps.setTimestamp(valuei, today);
valuei++;
// T_User
ps.setString(valuei, dbusr);
valuei++;
}
ps.executeUpdate();
} finally {
ps.close();
}
}
use of ch.interlis.ili2c.metamodel.Table 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);
}
}
}
def = (Topic) def.getExtending();
}
return visitedStructs;
}
use of ch.interlis.ili2c.metamodel.Table in project ili2db by claeis.
the class Ili2cUtility method isPureChbaseCatalogueRef.
public static boolean isPureChbaseCatalogueRef(TransferDescription td, AttributeDef attr) {
Type typeo = attr.getDomain();
if (typeo instanceof CompositionType) {
CompositionType type = (CompositionType) typeo;
Table struct = type.getComponentType();
Table root = (Table) struct.getRootExtending();
if (root == null) {
root = struct;
}
if (root.getContainer().getScopedName(null).equals(IliNames.CHBASE1_CATALOGUEOBJECTS_CATALOGUES)) {
if (root.getName().equals(IliNames.CHBASE1_CATALOGUEREFERENCE) || root.getName().equals(IliNames.CHBASE1_MANDATORYCATALOGUEREFERENCE)) {
java.util.Iterator it = struct.getAttributesAndRoles2();
int c = 0;
while (it.hasNext()) {
it.next();
c++;
}
if (c == 1) {
// only one attribute
return true;
}
}
}
}
return false;
}
use of ch.interlis.ili2c.metamodel.Table in project ili2db by claeis.
the class TransferToXtf method dumpItfTableObject.
private void dumpItfTableObject(IoxWriter out, AttributeDef attr, Long basketSqlId) {
String stmt = createItfLineTableQueryStmt(attr, basketSqlId, geomConv);
String sqlTabName = ili2sqlName.mapGeometryAsTable(attr);
EhiLogger.traceBackendCmd(stmt);
SurfaceOrAreaType type = (SurfaceOrAreaType) attr.getDomainResolvingAliases();
String geomAttrName = ch.interlis.iom_j.itf.ModelUtilities.getHelperTableGeomAttrName(attr);
String refAttrName = null;
if (type instanceof SurfaceType) {
refAttrName = ch.interlis.iom_j.itf.ModelUtilities.getHelperTableMainTableRef(attr);
}
java.sql.PreparedStatement dbstmt = null;
try {
dbstmt = conn.prepareStatement(stmt);
dbstmt.clearParameters();
int paramIdx = 1;
if (basketSqlId != null) {
dbstmt.setLong(paramIdx++, basketSqlId);
}
java.sql.ResultSet rs = dbstmt.executeQuery();
while (rs.next()) {
int valuei = 1;
long sqlid = rs.getLong(valuei);
valuei++;
String sqlIliTid = null;
if (writeIliTid) {
sqlIliTid = rs.getString(valuei);
valuei++;
} else {
sqlIliTid = Long.toString(sqlid);
}
Viewable aclass = (Viewable) attr.getContainer();
Iom_jObject iomObj;
iomObj = new Iom_jObject(aclass.getScopedName(null) + "_" + attr.getName(), sqlIliTid);
// geomAttr
Object geomobj = rs.getObject(valuei);
valuei++;
if (!rs.wasNull()) {
try {
boolean is3D = false;
IomObject polyline = geomConv.toIomPolyline(geomobj, ili2sqlName.getSqlColNameItfLineTableGeomAttr(attr, sqlTabName), is3D);
iomObj.addattrobj(geomAttrName, polyline);
} catch (ConverterException ex) {
EhiLogger.logError("Object " + sqlid + ": failed to convert polyline", ex);
}
}
// is of type SURFACE?
if (type instanceof SurfaceType) {
// -> mainTable
IomObject ref = iomObj.addattrobj(refAttrName, "REF");
long refSqlId = rs.getLong(valuei);
if (sqlidPool.containsSqlid(refSqlId)) {
String refTid = sqlidPool.getXtfid(refSqlId);
ref.setobjectrefoid(refTid);
} else {
EhiLogger.logError("unknown referenced object " + attr.getContainer().getScopedName(null) + " sqlid " + refSqlId + " referenced from " + sqlTabName + " " + colT_ID + " " + sqlid);
}
valuei++;
}
Table lineAttrTable = type.getLineAttributeStructure();
if (lineAttrTable != null) {
Iterator attri = lineAttrTable.getAttributes();
while (attri.hasNext()) {
AttributeDef lineattr = (AttributeDef) attri.next();
valuei = recConv.addAttrValue(rs, valuei, sqlid, iomObj, lineattr, null, class2wrapper.get(lineAttrTable), null);
}
}
if (out != null) {
// write object
ObjectEvent objEvent = new ObjectEvent(iomObj);
if (languageFilter != null) {
objEvent = (ObjectEvent) languageFilter.filter(objEvent);
}
if (exportBaseModelFilter != null) {
objEvent = (ObjectEvent) exportBaseModelFilter.filter(objEvent);
}
if (validator != null)
validator.validate(objEvent);
out.write(objEvent);
}
}
} catch (java.sql.SQLException ex) {
EhiLogger.logError("failed to query " + attr.getScopedName(null), ex);
} catch (ch.interlis.iox.IoxException ex) {
EhiLogger.logError("failed to write " + attr.getScopedName(null), ex);
} finally {
if (dbstmt != null) {
try {
dbstmt.close();
} catch (java.sql.SQLException ex) {
EhiLogger.logError("failed to close query of " + attr.getScopedName(null), ex);
}
}
}
}
use of ch.interlis.ili2c.metamodel.Table in project ili2db by claeis.
the class FromXtfRecordConverter method getMultiPointAttrDef.
protected AttributeDef getMultiPointAttrDef(Type type, MultiPointMapping attrMapping) {
Table multiPointType = ((CompositionType) type).getComponentType();
Table pointStructureType = ((CompositionType) ((AttributeDef) multiPointType.getElement(AttributeDef.class, attrMapping.getBagOfPointsAttrName())).getDomain()).getComponentType();
AttributeDef coordAttr = (AttributeDef) pointStructureType.getElement(AttributeDef.class, attrMapping.getPointAttrName());
return coordAttr;
}
Aggregations