Skip to content

Commit

Permalink
Generic Repository - Use object reference type hints only when unable…
Browse files Browse the repository at this point in the history
… to resolve in original type
  • Loading branch information
tonydamage committed Sep 28, 2022
1 parent 6163e3e commit dc3fd30
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.evolveum.midpoint.repo.sql.query.QueryDefinitionRegistry;
import com.evolveum.midpoint.repo.sql.query.resolution.DataSearchResult;
import com.evolveum.midpoint.repo.sql.util.ClassMapper;
import com.evolveum.midpoint.repo.sqlbase.QueryException;
import com.evolveum.midpoint.schema.constants.SchemaConstants;

/**
Expand All @@ -47,20 +48,26 @@ protected String getDebugDumpClassName() {
}

@Override
public DataSearchResult<?> nextLinkDefinition(ItemPath path, ItemDefinition itemDefinition, PrismContext prismContext) {
public DataSearchResult<?> nextLinkDefinition(ItemPath path, ItemDefinition itemDefinition, PrismContext prismContext) throws QueryException {
var first = path.first();
var rest = path.rest();
if (ItemPath.isObjectReference(first)) {
// returning artificially created transition definition, used to allow dereferencing target object in a generic way
// Here we could use type hint?
JpaEntityDefinition resolvedEntityDef = referencedEntityDefinition.getResolvedEntityDefinition();
if (first instanceof ObjectReferencePathSegment) {
Optional<QName> typeHint = ((ObjectReferencePathSegment) first).typeHint();

if (typeHint.isPresent()) {
// Now we need to find RObject class for type hint
//Class<? extends RObject> hqlClazz = ClassMapper.getHQLTypeForQName(typeHint.get()).getClazz();
// And now, we somehow need resolvedEntityDefinition

resolvedEntityDef = QueryDefinitionRegistry.getInstance().findEntityDefinition(typeHint.get());
// We have type hint, first lets try resolve in original definition
DataSearchResult<?> nextDef = resolvedEntityDef.nextLinkDefinition(rest, itemDefinition, prismContext);
// If we did not found item using original entity definition, we try to use type hint
if (nextDef == null) {
resolvedEntityDef = QueryDefinitionRegistry.getInstance().findEntityDefinition(typeHint.get());
}
}

}
Expand Down

0 comments on commit dc3fd30

Please sign in to comment.