Search in sources :

Example 1 with PathElAssocRole

use of ch.interlis.ili2c.metamodel.PathElAssocRole in project ili2db by claeis.

the class FromIliRecordConverter method getUniqueAttrs.

private HashSet getUniqueAttrs(UniquenessConstraint cnstr, HashSet wrapperCols) {
    if (cnstr.getLocal()) {
        return null;
    }
    HashSet ret = new HashSet();
    UniqueEl attribs = cnstr.getElements();
    Iterator attri = attribs.iteratorAttribute();
    for (; attri.hasNext(); ) {
        ObjectPath path = (ObjectPath) attri.next();
        PathEl[] pathEles = path.getPathElements();
        if (pathEles.length != 1) {
            return null;
        }
        PathEl pathEle = pathEles[0];
        if (pathEle instanceof AttributeRef) {
            AttributeDef attr = ((AttributeRef) pathEle).getAttr();
            while (attr.getExtending() != null) {
                attr = (AttributeDef) attr.getExtending();
            }
            if (!wrapperCols.contains(attr)) {
                return null;
            }
            ret.add(attr);
        } else if (pathEle instanceof PathElAssocRole) {
            RoleDef role = ((PathElAssocRole) pathEle).getRole();
            while (role.getExtending() != null) {
                role = (RoleDef) role.getExtending();
            }
            if (!wrapperCols.contains(role)) {
                return null;
            }
            ret.add(role);
        } else {
            return null;
        }
    }
    return ret;
}
Also used : ObjectPath(ch.interlis.ili2c.metamodel.ObjectPath) PathElAssocRole(ch.interlis.ili2c.metamodel.PathElAssocRole) AttributeRef(ch.interlis.ili2c.metamodel.AttributeRef) UniqueEl(ch.interlis.ili2c.metamodel.UniqueEl) RoleDef(ch.interlis.ili2c.metamodel.RoleDef) Iterator(java.util.Iterator) AttributeDef(ch.interlis.ili2c.metamodel.AttributeDef) PathEl(ch.interlis.ili2c.metamodel.PathEl) HashSet(java.util.HashSet)

Aggregations

AttributeDef (ch.interlis.ili2c.metamodel.AttributeDef)1 AttributeRef (ch.interlis.ili2c.metamodel.AttributeRef)1 ObjectPath (ch.interlis.ili2c.metamodel.ObjectPath)1 PathEl (ch.interlis.ili2c.metamodel.PathEl)1 PathElAssocRole (ch.interlis.ili2c.metamodel.PathElAssocRole)1 RoleDef (ch.interlis.ili2c.metamodel.RoleDef)1 UniqueEl (ch.interlis.ili2c.metamodel.UniqueEl)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1