use of com.evolveum.midpoint.repo.sql.query2.definition.JpaAnyReferenceDefinition in project midpoint by Evolveum.
the class JpaAnyContainerDefinition method nextLinkDefinition.
@Override
public DataSearchResult nextLinkDefinition(ItemPath path, ItemDefinition itemDefinition, PrismContext prismContext) throws QueryException {
if (ItemPath.asSingleName(path) == null) {
throw new QueryException("Couldn't resolve paths other than those in the form of single name in extension/attributes container: " + path);
}
if (itemDefinition == null) {
throw new QueryException("Couldn't resolve dynamically defined item path '" + path + "' without proper definition");
}
CollectionSpecification collSpec = itemDefinition.isSingleValue() ? null : new CollectionSpecification();
// longs, strings, ...
String jpaName;
JpaDataNodeDefinition jpaNodeDefinition;
if (itemDefinition instanceof PrismPropertyDefinition) {
try {
jpaName = RAnyConverter.getAnySetType(itemDefinition, prismContext);
} catch (SchemaException e) {
throw new QueryException(e.getMessage(), e);
}
// TODO
jpaNodeDefinition = new JpaAnyPropertyDefinition(Object.class, null);
} else if (itemDefinition instanceof PrismReferenceDefinition) {
jpaName = "references";
jpaNodeDefinition = new JpaAnyReferenceDefinition(Object.class, RObject.class);
} else {
throw new QueryException("Unsupported 'any' item: " + itemDefinition);
}
JpaLinkDefinition<?> linkDefinition = new JpaAnyItemLinkDefinition(itemDefinition.getName(), jpaName, collSpec, getOwnerType(), jpaNodeDefinition);
return new DataSearchResult<>(linkDefinition, ItemPath.EMPTY_PATH);
}
use of com.evolveum.midpoint.repo.sql.query2.definition.JpaAnyReferenceDefinition in project midpoint by Evolveum.
the class ReferenceRestriction method createRefCondition.
private Condition createRefCondition(RootHibernateQuery hibernateQuery, Collection<String> oids, QName relation, QName targetType) {
String hqlPath = hqlDataInstance.getHqlPath();
final String TARGET_OID_HQL_PROPERTY, RELATION_HQL_PROPERTY, TARGET_TYPE_HQL_PROPERTY;
if (linkDefinition.getTargetDefinition() instanceof JpaAnyReferenceDefinition) {
TARGET_OID_HQL_PROPERTY = ROExtReference.F_TARGET_OID;
RELATION_HQL_PROPERTY = ROExtReference.F_RELATION;
TARGET_TYPE_HQL_PROPERTY = ROExtReference.F_TARGET_TYPE;
} else {
TARGET_OID_HQL_PROPERTY = RObjectReference.F_TARGET_OID;
RELATION_HQL_PROPERTY = RObjectReference.F_RELATION;
TARGET_TYPE_HQL_PROPERTY = RObjectReference.F_TARGET_TYPE;
}
AndCondition conjunction = hibernateQuery.createAnd();
conjunction.add(hibernateQuery.createEqOrInOrNull(hqlDataInstance.getHqlPath() + "." + TARGET_OID_HQL_PROPERTY, oids));
if (ObjectTypeUtil.isDefaultRelation(relation)) {
// Return references without relation or with "member" relation
conjunction.add(hibernateQuery.createIn(hqlPath + "." + RELATION_HQL_PROPERTY, Arrays.asList(RUtil.QNAME_DELIMITER, qnameToString(SchemaConstants.ORG_DEFAULT))));
} else if (QNameUtil.match(relation, PrismConstants.Q_ANY)) {
// Return all relations => no restriction
} else {
// return references with specific relation
List<String> relationsToTest = new ArrayList<>();
relationsToTest.add(qnameToString(relation));
if (QNameUtil.noNamespace(relation)) {
relationsToTest.add(qnameToString(QNameUtil.setNamespaceIfMissing(relation, SchemaConstants.NS_ORG, null)));
} else if (SchemaConstants.NS_ORG.equals(relation.getNamespaceURI())) {
relationsToTest.add(qnameToString(new QName(relation.getLocalPart())));
} else {
// non-empty non-standard NS => nothing to add
}
conjunction.add(hibernateQuery.createEqOrInOrNull(hqlPath + "." + RELATION_HQL_PROPERTY, relationsToTest));
}
if (targetType != null) {
conjunction.add(handleEqInOrNull(hibernateQuery, hqlPath + "." + TARGET_TYPE_HQL_PROPERTY, ClassMapper.getHQLTypeForQName(targetType)));
}
return conjunction;
}
Aggregations