use of org.apache.sis.feature.AbstractAssociation in project geotoolkit by Geomatys.
the class DBRelationOperation method apply.
@Override
public Property apply(Feature ftr, ParameterValueGroup pvg) {
final Object key = ftr.getPropertyValue(relation.getCurrentColumn());
final Query qb = new Query();
qb.setTypeName(NamesExt.create(relation.getForeignTable()));
qb.setSelection(relation.toFilter(key));
final FeatureCollection res = store.createSession(false).getFeatureCollection(qb);
final Object value;
if (type.getMaximumOccurs() == 1) {
try (FeatureIterator ite = res.iterator()) {
if (ite.hasNext()) {
value = ite.next();
} else {
value = null;
}
}
} else {
value = res;
}
return new AbstractAssociation(type) {
@Override
public Feature getValue() throws MultiValuedPropertyException {
if (value == null || value instanceof Feature) {
return (Feature) value;
}
throw new MultiValuedPropertyException();
}
@Override
public Collection<Feature> getValues() {
if (value == null) {
return Collections.EMPTY_LIST;
} else if (value instanceof Feature) {
return Arrays.asList((Feature) value);
} else {
return res;
}
}
@Override
public void setValue(Feature value) throws InvalidPropertyValueException {
throw new UnsupportedOperationException("Not supported.");
}
};
}
Aggregations