use of org.jowidgets.cap.service.jpa.api.query.QueryPath 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.QueryPath 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