use of com.evolveum.midpoint.repo.sql.query.hqm.RootHibernateQuery in project midpoint by Evolveum.
the class PropertyRestriction method createPropertyVsPropertyCondition.
Condition createPropertyVsPropertyCondition(String leftPropertyValuePath) throws QueryException {
HqlDataInstance rightItem = getItemPathResolver().resolveItemPath(filter.getRightHandSidePath(), filter.getRightHandSideDefinition(), getBaseHqlEntityForChildren(), true);
String rightHqlPath = rightItem.getHqlPath();
RootHibernateQuery hibernateQuery = context.getHibernateQuery();
if (filter instanceof EqualFilter) {
// left = right OR (left IS NULL AND right IS NULL)
Condition condition = hibernateQuery.createCompareXY(leftPropertyValuePath, rightHqlPath, "=", false);
return hibernateQuery.createOr(condition, hibernateQuery.createAnd(hibernateQuery.createIsNull(leftPropertyValuePath), hibernateQuery.createIsNull(rightHqlPath)));
} else if (filter instanceof ComparativeFilter) {
ItemRestrictionOperation operation = findOperationForFilter(filter);
return hibernateQuery.createCompareXY(leftPropertyValuePath, rightHqlPath, operation.symbol(), false);
} else {
throw new QueryException("Right-side ItemPath is supported currently only for EqualFilter or ComparativeFilter, not for " + filter);
}
}
use of com.evolveum.midpoint.repo.sql.query.hqm.RootHibernateQuery in project midpoint by Evolveum.
the class QueryInterpreter method addGrouping.
private void addGrouping(InterpretationContext context, ObjectGrouping grouping) throws QueryException {
ItemPath groupByPath = grouping.getGroupBy();
// TODO if we'd like to have group-by extension properties, we'd need to provide itemDefinition for them
ProperDataSearchResult<?> result = context.getItemPathResolver().findProperDataDefinition(context.getRootEntityDefinition(), groupByPath, null, JpaDataNodeDefinition.class, context.getPrismContext());
if (result == null) {
LOGGER.error("Unknown path '" + groupByPath + "', couldn't find definition for it, " + "list will not be grouped by it.");
return;
}
JpaDataNodeDefinition targetDefinition = result.getLinkDefinition().getTargetDefinition();
if (targetDefinition instanceof JpaAnyContainerDefinition) {
throw new QueryException("Grouping based on extension item or attribute is not supported yet: " + groupByPath);
} else if (targetDefinition instanceof JpaReferenceDefinition) {
throw new QueryException("Grouping based on reference is not supported: " + groupByPath);
} else if (result.getLinkDefinition().isMultivalued()) {
throw new QueryException("Grouping based on multi-valued item is not supported: " + groupByPath);
} else if (targetDefinition instanceof JpaEntityDefinition) {
throw new QueryException("Grouping based on entity is not supported: " + groupByPath);
} else if (!(targetDefinition instanceof JpaPropertyDefinition)) {
throw new IllegalStateException("Unknown item definition type: " + result.getClass());
}
JpaEntityDefinition baseEntityDefinition = result.getEntityDefinition();
JpaPropertyDefinition groupByDefinition = (JpaPropertyDefinition) targetDefinition;
String hqlPropertyPath = context.getItemPathResolver().resolveItemPath(groupByPath, null, context.getPrimaryEntityAlias(), baseEntityDefinition, true).getHqlPath();
if (RPolyString.class.equals(groupByDefinition.getJpaClass())) {
hqlPropertyPath += ".orig";
}
RootHibernateQuery hibernateQuery = context.getHibernateQuery();
hibernateQuery.addGrouping(hqlPropertyPath);
}
use of com.evolveum.midpoint.repo.sql.query.hqm.RootHibernateQuery in project midpoint by Evolveum.
the class ItemPathResolver method addTextInfoJoin.
public String addTextInfoJoin(String currentHqlPath) {
RootHibernateQuery hibernateQuery = context.getHibernateQuery();
String joinedItemJpaName = RObject.F_TEXT_INFO_ITEMS;
String joinedItemFullPath = currentHqlPath + "." + joinedItemJpaName;
String joinedItemAlias = hibernateQuery.createAlias(joinedItemJpaName, false);
hibernateQuery.getPrimaryEntity().addJoin(new JoinSpecification(joinedItemAlias, joinedItemFullPath, null));
return joinedItemAlias;
}
use of com.evolveum.midpoint.repo.sql.query.hqm.RootHibernateQuery in project midpoint by Evolveum.
the class ItemPathResolver method reuseOrAddJoin.
String reuseOrAddJoin(JpaLinkDefinition<?> joinedItemDefinition, String currentHqlPath, boolean reuseMultivaluedJoins) throws QueryException {
RootHibernateQuery hibernateQuery = context.getHibernateQuery();
String joinedItemJpaName = joinedItemDefinition.getJpaName();
String joinedItemFullPath = currentHqlPath + "." + joinedItemJpaName;
String joinedItemAlias;
if (joinedItemDefinition.isMultivalued()) {
if (reuseMultivaluedJoins) {
String existingAlias = findExistingAlias(hibernateQuery, joinedItemDefinition, joinedItemFullPath);
if (existingAlias != null) {
return existingAlias;
} else {
// TODO better explanation
throw new QueryException("Couldn't reuse existing join for " + joinedItemDefinition + " in the context of " + currentHqlPath);
}
}
} else {
/*
* Let's check if we were already here i.e. if we had already created this join.
* This is to avoid useless creation of redundant joins for singleton items.
*
* But how can we be sure that item is singleton if we look only at the last segment (which is single-valued)?
* Imagine we are creating join for single-valued entity of u.abc.(...).xyz.ent where
* ent is single-valued and not embedded (so we are to create something like "left join u.abc.(...).xyz.ent e").
* Then "u" is certainly a single value: either the root object, or some value pointed to by Exists restriction.
* Also, abc, ..., xyz are surely single-valued: otherwise they would be connected by a join. So,
* u.abc.(...).xyz.ent is a singleton.
*
* Look at it in other way: if e.g. xyz was multivalued, then we would have something like:
* left join u.abc.(...).uvw.xyz x
* left join x.ent e
* And, therefore we would not be looking for u.abc.(...).xyz.ent.
*/
String existingAlias = findExistingAlias(hibernateQuery, joinedItemDefinition, joinedItemFullPath);
if (existingAlias != null) {
return existingAlias;
}
}
joinedItemAlias = hibernateQuery.createAlias(joinedItemDefinition);
Condition condition = createJoinCondition(joinedItemAlias, joinedItemDefinition, hibernateQuery);
hibernateQuery.getPrimaryEntity().addJoin(new JoinSpecification(joinedItemAlias, joinedItemFullPath, condition));
return joinedItemAlias;
}
Aggregations