use of javax.persistence.metamodel.Attribute 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;
}
Aggregations