use of ch.interlis.ili2c.metamodel.ViewableTransferElement in project ili2db by claeis.
the class ToXtfRecordConverter method convertRecord.
public Iom_jObject convertRecord(java.sql.ResultSet rs, Viewable aclass1, FixIomObjectRefs fixref, StructWrapper structWrapper, HashMap structelev, ArrayList<StructWrapper> structQueue, long sqlid) throws SQLException {
ViewableWrapper aclass = class2wrapper.get(aclass1);
Iom_jObject iomObj;
int valuei = 1;
valuei++;
if (createTypeDiscriminator || aclass.includesMultipleTypes()) {
// String t_type=rs.getString(valuei);
valuei++;
}
String sqlIliTid = null;
if (structWrapper == null) {
if (!aclass.isStructure()) {
if (createIliTidCol || aclass.getOid() != null) {
sqlIliTid = rs.getString(valuei);
sqlid2xtfid.putSqlid2Xtfid(sqlid, sqlIliTid);
valuei++;
} else {
sqlIliTid = Long.toString(sqlid);
sqlid2xtfid.putSqlid2Xtfid(sqlid, sqlIliTid);
}
}
}
if (structWrapper == null) {
if (!aclass.isStructure()) {
iomObj = new Iom_jObject(aclass1.getScopedName(null), sqlIliTid);
} else {
iomObj = new Iom_jObject(aclass1.getScopedName(null), null);
}
iomObj.setattrvalue(ItfWriter2.INTERNAL_T_ID, Long.toString(sqlid));
fixref.setRoot(iomObj);
} else {
iomObj = (Iom_jObject) structelev.get(Long.toString(sqlid));
if (createGenericStructRef) {
valuei += 4;
} else {
valuei += 2;
}
}
HashSet<AttributeDef> visitedAttrs = new HashSet<AttributeDef>();
for (ViewableWrapper table : aclass.getWrappers()) {
Iterator iter = table.getAttrIterator();
while (iter.hasNext()) {
ViewableTransferElement obj = (ViewableTransferElement) iter.next();
if (obj.obj instanceof AttributeDef) {
AttributeDef attr = (AttributeDef) obj.obj;
AttributeDef baseAttr = attr;
while (true) {
AttributeDef baseAttr1 = (AttributeDef) baseAttr.getExtending();
if (baseAttr1 == null) {
break;
}
baseAttr = baseAttr1;
}
if (!visitedAttrs.contains(baseAttr)) {
visitedAttrs.add(baseAttr);
if (!baseAttr.isTransient()) {
Type proxyType = baseAttr.getDomain();
if (proxyType != null && (proxyType instanceof ObjectType)) {
// skip implicit particles (base-viewables) of views
} else {
valuei = addAttrValue(rs, valuei, sqlid, iomObj, baseAttr, structQueue, table, fixref);
}
}
}
}
if (obj.obj instanceof RoleDef) {
RoleDef role = (RoleDef) obj.obj;
if (role.getExtending() == null) {
String roleName = role.getName();
ArrayList<ViewableWrapper> targetTables = getTargetTables(role.getDestination());
boolean refAlreadyDefined = false;
for (ViewableWrapper targetTable : targetTables) {
String sqlRoleName = ili2sqlName.mapIliRoleDef(role, getSqlType(table.getViewable()).getName(), targetTable.getSqlTablename(), targetTables.size() > 1);
// a role of an embedded association?
if (obj.embedded) {
AssociationDef roleOwner = (AssociationDef) role.getContainer();
if (roleOwner.getDerivedFrom() == null) {
// TODO if(orderPos!=0){
long value = rs.getLong(valuei);
valuei++;
if (!rs.wasNull()) {
if (refAlreadyDefined) {
EhiLogger.logAdaption("Table " + table.getSqlTablename() + "(id " + sqlid + ") more than one value for role " + roleName + "; value of " + sqlRoleName + " ignored");
} else {
IomObject ref = iomObj.addattrobj(roleName, roleOwner.getScopedName(null));
mapSqlid2Xtfid(fixref, value, ref, role.getDestination());
refAlreadyDefined = true;
}
}
}
} else {
// TODO if(orderPos!=0){
long value = rs.getLong(valuei);
valuei++;
if (!rs.wasNull()) {
if (refAlreadyDefined) {
EhiLogger.logAdaption("Table " + table.getSqlTablename() + "(id " + sqlid + ") more than one value for role " + roleName + "; value of " + sqlRoleName + " ignored");
} else {
IomObject ref = iomObj.addattrobj(roleName, "REF");
mapSqlid2Xtfid(fixref, value, ref, role.getDestination());
refAlreadyDefined = true;
}
}
}
}
}
}
}
}
return iomObj;
}
use of ch.interlis.ili2c.metamodel.ViewableTransferElement in project ili2db by claeis.
the class ReduceToBaseModel method translateObject.
private void translateObject(IomObject iomObj) {
Element modelElement = (Element) tag2class.get(iomObj.getobjecttag());
Element destModelEle = getTranslatedElement(modelElement);
if (destModelEle == modelElement) {
// no translation required
return;
}
Viewable aclass = (Viewable) modelElement;
Viewable destClass = (Viewable) destModelEle;
String destName = destClass.getScopedName();
iomObj.setobjecttag(destName);
// handle attrs
Iterator iter = aclass.getAttributesAndRoles2();
while (iter.hasNext()) {
ViewableTransferElement srcProp = (ViewableTransferElement) iter.next();
ViewableTransferElement destProp = (ViewableTransferElement) srctag2destElement.get(((Element) srcProp.obj).getScopedName());
if (destProp == null) {
iomObj.setattrundefined(((Element) srcProp.obj).getName());
} else {
if (srcProp.obj instanceof AttributeDef) {
AttributeDef attr = (AttributeDef) srcProp.obj;
if (!attr.isTransient()) {
Type proxyType = attr.getDomain();
if (proxyType != null && (proxyType instanceof ObjectType)) {
// skip implicit particles (base-viewables) of views
} else {
translateAttrValue(iomObj, attr);
}
}
}
}
}
}
use of ch.interlis.ili2c.metamodel.ViewableTransferElement in project ili2db by claeis.
the class FromXtfRecordConverter method getIomObjectAttrs.
public HashSet getIomObjectAttrs(Viewable aclass) {
HashSet ret = new HashSet();
Iterator iter = aclass.getAttributesAndRoles2();
while (iter.hasNext()) {
ViewableTransferElement obj = (ViewableTransferElement) iter.next();
if (obj.obj instanceof AttributeDef) {
AttributeDef attr = (AttributeDef) obj.obj;
if (!attr.isTransient()) {
Type proxyType = attr.getDomain();
if (proxyType != null && (proxyType instanceof ObjectType)) {
// skip implicit particles (base-viewables) of views
} else {
AttributeDef base = (AttributeDef) attr.getExtending();
while (base != null) {
attr = base;
base = (AttributeDef) attr.getExtending();
}
ret.add(attr);
}
}
}
if (obj.obj instanceof RoleDef) {
RoleDef role = (RoleDef) obj.obj;
if (role.getExtending() == null) {
// a role of an embedded association?
if (obj.embedded) {
AssociationDef roleOwner = (AssociationDef) role.getContainer();
if (roleOwner.getDerivedFrom() == null) {
RoleDef base = (RoleDef) role.getExtending();
while (base != null) {
role = base;
base = (RoleDef) role.getExtending();
}
ret.add(role);
}
} else {
RoleDef base = (RoleDef) role.getExtending();
while (base != null) {
role = base;
base = (RoleDef) role.getExtending();
}
ret.add(role);
}
}
}
}
return ret;
}
use of ch.interlis.ili2c.metamodel.ViewableTransferElement in project ili2db by claeis.
the class FromXtfRecordConverter method writeRecord.
public void writeRecord(long basketSqlId, IomObject iomObj, Viewable iomClass, StructWrapper structEle, ViewableWrapper aclass, String sqlType, long sqlId, boolean updateObj, PreparedStatement ps, ArrayList structQueue) throws SQLException, ConverterException {
int valuei = 1;
if (updateObj) {
// if update, t_id is last param
// ps.setInt(valuei, sqlId);
// valuei++;
} else {
ps.setLong(valuei, sqlId);
valuei++;
}
if (createBasketCol) {
ps.setLong(valuei, basketSqlId);
valuei++;
}
if (createDatasetCol) {
ps.setString(valuei, datasetName);
valuei++;
}
if (!aclass.isSecondaryTable()) {
if (aclass.getExtending() == null) {
if (createTypeDiscriminator || aclass.includesMultipleTypes()) {
ps.setString(valuei, sqlType);
valuei++;
}
// if class
if (structEle == null) {
if (!updateObj) {
if (!aclass.isStructure()) {
if (createIliTidCol || aclass.getOid() != null) {
// import TID from transfer file
if (AbstractRecordConverter.isUuidOid(td, aclass.getOid())) {
Object toInsertUUID = geomConv.fromIomUuid(iomObj.getobjectoid());
ps.setObject(valuei, toInsertUUID);
} else {
ps.setString(valuei, iomObj.getobjectoid());
}
valuei++;
}
}
}
}
// if struct, add ref to parent
if (structEle != null) {
ps.setLong(valuei, structEle.getParentSqlId());
valuei++;
if (createGenericStructRef) {
ps.setString(valuei, structEle.getParentSqlType());
valuei++;
// T_ParentAttr
ps.setString(valuei, structEle.getParentSqlAttr());
valuei++;
}
// T_Seq
ps.setInt(valuei, structEle.getStructi());
valuei++;
}
}
}
HashSet attrs = getIomObjectAttrs(iomClass);
Iterator iter = aclass.getAttrIterator();
while (iter.hasNext()) {
ViewableTransferElement obj = (ViewableTransferElement) iter.next();
if (obj.obj instanceof AttributeDef) {
AttributeDef attr = (AttributeDef) obj.obj;
if (attrs.contains(attr)) {
if (!attr.isTransient()) {
Type proxyType = attr.getDomain();
if (proxyType != null && (proxyType instanceof ObjectType)) {
// skip implicit particles (base-viewables) of views
} else {
valuei = addAttrValue(iomObj, sqlType, sqlId, aclass.getSqlTablename(), ps, valuei, attr, structQueue);
}
}
}
}
if (obj.obj instanceof RoleDef) {
RoleDef role = (RoleDef) obj.obj;
if (role.getExtending() == null) {
if (attrs.contains(role)) {
String refoid = null;
String roleName = role.getName();
// a role of an embedded association?
if (obj.embedded) {
AssociationDef roleOwner = (AssociationDef) role.getContainer();
if (roleOwner.getDerivedFrom() == null) {
// not just a link?
IomObject structvalue = iomObj.getattrobj(roleName, 0);
if (roleOwner.getAttributes().hasNext() || roleOwner.getLightweightAssociations().iterator().hasNext()) {
// TODO handle attributes of link
}
if (structvalue != null) {
refoid = structvalue.getobjectrefoid();
long orderPos = structvalue.getobjectreforderpos();
if (orderPos != 0) {
// refoid,orderPos
// ret.setStringAttribute(roleName, refoid);
// ret.setStringAttribute(roleName+".orderPos", Long.toString(orderPos));
} else {
// refoid
// ret.setStringAttribute(roleName, refoid);
}
} else {
refoid = null;
}
}
} else {
IomObject structvalue = iomObj.getattrobj(roleName, 0);
refoid = structvalue.getobjectrefoid();
long orderPos = structvalue.getobjectreforderpos();
if (orderPos != 0) {
// refoid,orderPos
// ret.setStringAttribute(roleName, refoid);
// ret.setStringAttribute(roleName+".orderPos", Long.toString(orderPos));
} else {
// refoid
// ret.setStringAttribute(roleName, refoid);
}
}
Holder<Integer> valueiRef = new Holder<Integer>(valuei);
setReferenceColumn(ps, role.getDestination(), refoid, valueiRef);
valuei = valueiRef.value;
}
}
}
}
if (createStdCols) {
// T_LastChange
ps.setTimestamp(valuei, today);
valuei++;
// T_CreateDate
if (!updateObj) {
ps.setTimestamp(valuei, today);
valuei++;
}
// T_User
ps.setString(valuei, dbusr);
valuei++;
}
if (updateObj) {
// if update, t_id is last param
ps.setLong(valuei, sqlId);
valuei++;
} else {
// if insert, t_id is first param
// ps.setInt(valuei, sqlId);
// valuei++;
}
}
use of ch.interlis.ili2c.metamodel.ViewableTransferElement in project ili2db by claeis.
the class TransferFromXtf method getAssociationId.
private String getAssociationId(IomObject iomObj, AssociationDef modelele) {
String tag = modelele.getScopedName(null);
String tid;
Iterator<ViewableTransferElement> rolei = modelele.getAttributesAndRoles2();
String sep = "";
tid = "";
while (rolei.hasNext()) {
ViewableTransferElement prop = rolei.next();
if (prop.obj instanceof RoleDef && !prop.embedded) {
String roleName = ((RoleDef) prop.obj).getName();
IomObject refObj = iomObj.getattrobj(roleName, 0);
String ref = null;
if (refObj != null) {
ref = refObj.getobjectrefoid();
}
if (ref != null) {
tid = tid + sep + ref;
sep = ":";
} else {
throw new IllegalStateException("REF required (" + tag + "/" + roleName + ")");
}
}
}
return tid;
}
Aggregations