use of org.jowidgets.cap.service.jpa.api.query.PropertyMapQueryPath in project jo-client-platform by jo-source.
the class CriteriaQueryCreator method createQueryPathGenericArithmeticFilterPredicate.
@SuppressWarnings("unchecked")
private Predicate createQueryPathGenericArithmeticFilterPredicate(final CriteriaBuilder criteriaBuilder, final Root<?> bean, final CriteriaQuery<?> query, final IArithmeticFilter filter) {
final Class<Object> javaType = (Class<Object>) bean.getJavaType();
final Subquery<Object> subquery = query.subquery(javaType);
final Root<Object> subqueryRoot = subquery.from(javaType);
subquery.select(subqueryRoot.get(IBean.ID_PROPERTY));
final boolean existanceFilter = ArithmeticOperator.EMPTY == filter.getOperator();
final Path<?> joinQueryPath = getJoinQueryPath(subqueryRoot, filter.getPropertyName());
final Predicate predicate = createArithmeticFilterPredicate(criteriaBuilder, subqueryRoot, subquery, filter, joinQueryPath, existanceFilter);
final PropertyMapQueryPath propertyMapQueryPath = bean.getJavaType().getAnnotation(PropertyMapQueryPath.class);
if (IPropertyMap.class.isAssignableFrom(bean.getJavaType()) && joinQueryPath.getParentPath() != null && joinQueryPath.getParentPath().getAlias() != null && propertyMapQueryPath != null && joinQueryPath.getParentPath().getAlias().equals(PROPERTY_MAP_JOIN_ALIAS)) {
final Predicate propertyMapPredicate = criteriaBuilder.equal(joinQueryPath.getParentPath().get(propertyMapQueryPath.propertyNamePath()), filter.getPropertyName());
subquery.where(predicate, propertyMapPredicate);
} else {
subquery.where(predicate);
}
if (filter.isInverted() && !existanceFilter) {
return criteriaBuilder.not(bean.get(IBean.ID_PROPERTY).in(subquery));
} else {
return bean.get(IBean.ID_PROPERTY).in(subquery);
}
}
use of org.jowidgets.cap.service.jpa.api.query.PropertyMapQueryPath in project jo-client-platform by jo-source.
the class CriteriaQueryCreator method getJoinQueryPath.
private Path<?> getJoinQueryPath(final Root<?> bean, final String propertyName) {
final QueryPath queryPath = getQueryPathAnno(bean, propertyName);
if (queryPath != null) {
Path<?> parentPath = bean;
Type<?> type = bean.getModel();
for (final String pathSegment : queryPath.path()) {
final Attribute<?, ?> attribute;
if (type != null && type instanceof ManagedType) {
attribute = ((ManagedType<?>) type).getAttribute(pathSegment);
type = getType(attribute);
} else {
attribute = null;
}
if (isJoinableType(attribute) && parentPath instanceof From) {
final From<?, ?> from = (From<?, ?>) parentPath;
parentPath = from.join(pathSegment, JoinType.LEFT);
} else {
parentPath = parentPath.get(pathSegment);
}
}
return parentPath;
} else if (IPropertyMap.class.isAssignableFrom(bean.getJavaType())) {
final PropertyMapQueryPath propertyMapQueryPath = bean.getJavaType().getAnnotation(PropertyMapQueryPath.class);
if (propertyMapQueryPath != null) {
Path<?> parentPath = bean;
Type<?> type = bean.getModel();
for (final String pathSegment : propertyMapQueryPath.path()) {
final Attribute<?, ?> attribute;
if (type != null && type instanceof ManagedType) {
attribute = ((ManagedType<?>) type).getAttribute(pathSegment);
type = getType(attribute);
} else {
attribute = null;
}
if (isJoinableType(attribute) && parentPath instanceof From) {
final From<?, ?> from = (From<?, ?>) parentPath;
parentPath = from.join(pathSegment, JoinType.LEFT);
} else {
parentPath = parentPath.get(pathSegment);
}
}
parentPath.alias(PROPERTY_MAP_JOIN_ALIAS);
return parentPath.get(propertyMapQueryPath.valuePath());
}
}
return null;
}
use of org.jowidgets.cap.service.jpa.api.query.PropertyMapQueryPath in project jo-client-platform by jo-source.
the class CriteriaQueryCreator method isJoinQueryPath.
private boolean isJoinQueryPath(final Root<?> bean, final String propertyName) {
final QueryPath queryPath = getQueryPathAnno(bean, propertyName);
if (queryPath != null) {
for (final String pathSegment : queryPath.path()) {
Path<?> path = bean;
Type<?> type = bean.getModel();
final Attribute<?, ?> attribute;
if (type != null && type instanceof ManagedType) {
attribute = ((ManagedType<?>) type).getAttribute(pathSegment);
type = getType(attribute);
} else {
attribute = null;
}
if (isJoinableType(attribute)) {
return true;
} else {
path = path.get(pathSegment);
}
}
} else {
try {
bean.get(propertyName);
return false;
} catch (final IllegalArgumentException illegalArgumentException) {
if (IPropertyMap.class.isAssignableFrom(bean.getJavaType())) {
final PropertyMapQueryPath propertyMapQueryPath = bean.getJavaType().getAnnotation(PropertyMapQueryPath.class);
if (propertyMapQueryPath != null) {
return true;
}
}
}
}
return false;
}
Aggregations