use of io.jmix.core.metamodel.model.MetaPropertyPath in project jmix by jmix-framework.
the class PropertyConditionGenerator method isCrossDataStoreReference.
protected boolean isCrossDataStoreReference(String property, @Nullable String entityName) {
if (Strings.isNullOrEmpty(entityName)) {
return false;
}
MetaClass metaClass = metadata.getClass(entityName);
MetaPropertyPath mpp = metaClass.getPropertyPath(property);
if (mpp == null) {
return false;
}
return metadataTools.getCrossDataStoreReferenceIdProperty(metaClass.getStore().getName(), mpp.getMetaProperty()) != null;
}
use of io.jmix.core.metamodel.model.MetaPropertyPath in project jmix by jmix-framework.
the class PropertyConditionGenerator method getProperty.
protected String getProperty(String property, @Nullable String entityName) {
if (Strings.isNullOrEmpty(entityName) || !isCrossDataStoreReference(property, entityName)) {
return property;
}
MetaClass metaClass = metadata.getClass(entityName);
MetaPropertyPath mpp = metaClass.getPropertyPath(property);
if (mpp == null) {
return property;
}
String referenceIdProperty = metadataTools.getCrossDataStoreReferenceIdProperty(metaClass.getStore().getName(), mpp.getMetaProperty());
// noinspection ConstantConditions
return property.lastIndexOf(".") > 0 ? property.substring(0, property.lastIndexOf(".") + 1) + referenceIdProperty : referenceIdProperty;
}
use of io.jmix.core.metamodel.model.MetaPropertyPath in project jmix by jmix-framework.
the class SortJpqlGenerator method getUniqueSortExpression.
protected Map<String, Sort.Direction> getUniqueSortExpression(Map<String, Sort.Direction> sortExpressions, MetaClass metaClass, Sort.Direction direction) {
String pkName = metadataTools.getPrimaryKeyName(metaClass);
if (pkName != null) {
MetaProperty idProperty = metaClass.getProperty(pkName);
if (metadataTools.hasCompositePrimaryKey(metaClass)) {
Map<String, Sort.Direction> uniqueSortExpressions = new LinkedHashMap<>();
MetaClass pkMetaClass = idProperty.getRange().asClass();
for (MetaProperty metaProperty : pkMetaClass.getProperties()) {
if (metadataTools.isJpa(metaProperty)) {
MetaPropertyPath idPropertyPath = metaClass.getPropertyPath(String.format("%s.%s", pkName, metaProperty.getName()));
Map<String, Sort.Direction> currentSortExpressions = getPropertySortExpressions(Objects.requireNonNull(idPropertyPath), direction);
if (currentSortExpressions.keySet().stream().noneMatch(sortExpressions::containsKey)) {
uniqueSortExpressions.putAll(currentSortExpressions);
}
}
}
return uniqueSortExpressions;
} else {
MetaPropertyPath idPropertyPath = metaClass.getPropertyPath(pkName);
Map<String, Sort.Direction> uniqueSortExpressions = getPropertySortExpressions(Objects.requireNonNull(idPropertyPath), direction);
if (uniqueSortExpressions.keySet().stream().noneMatch(sortExpressions::containsKey)) {
return uniqueSortExpressions;
}
}
}
return Collections.emptyMap();
}
use of io.jmix.core.metamodel.model.MetaPropertyPath in project jmix by jmix-framework.
the class SortJpqlGenerator method getNotPersistentPropertySortExpression.
protected Map<String, Sort.Direction> getNotPersistentPropertySortExpression(MetaPropertyPath metaPropertyPath, Sort.Direction sortDirection) {
List<String> related = metadataTools.getDependsOnProperties(metaPropertyPath.getMetaProperty());
MetaClass propertyMetaClass = metadataTools.getPropertyEnclosingMetaClass(metaPropertyPath);
if (!related.isEmpty()) {
Map<String, Sort.Direction> sortExpressions = new LinkedHashMap<>(related.size());
for (String item : related) {
MetaProperty metaProperty = propertyMetaClass.getProperty(item);
if (metadataTools.isJpa(metaProperty)) {
List<MetaProperty> metaProperties = Arrays.asList(metaPropertyPath.getMetaProperties());
metaProperties.set(metaProperties.size() - 1, metaProperty);
MetaPropertyPath childPropertyPath = new MetaPropertyPath(metaPropertyPath.getMetaClass(), Iterables.toArray(metaProperties, MetaProperty.class));
sortExpressions.putAll(getPropertySortExpressions(childPropertyPath, sortDirection));
}
}
return sortExpressions;
}
return Collections.emptyMap();
}
use of io.jmix.core.metamodel.model.MetaPropertyPath in project jmix by jmix-framework.
the class SortJpqlGenerator method processQuery.
public String processQuery(String entityName, List<String> valueProperties, String queryString, Sort sort) {
List<Sort.Order> orders = sort.getOrders();
if (orders.isEmpty()) {
return queryString;
}
Sort.Direction defaultSort = Sort.Direction.ASC;
Map<String, Sort.Direction> sortExpressions = new LinkedHashMap<>();
if (entityName != null) {
MetaClass metaClass = metadata.getClass(entityName);
for (Sort.Order order : sort.getOrders()) {
MetaPropertyPath metaPropertyPath = metaClass.getPropertyPath(order.getProperty());
checkNotNullArgument(metaPropertyPath, "Could not resolve property path '%s' in '%s'", order.getProperty(), metaClass);
sortExpressions.putAll(getPropertySortExpressions(metaPropertyPath, order.getDirection()));
}
if (!sortExpressions.isEmpty()) {
sortExpressions.putAll(getUniqueSortExpression(sortExpressions, metaClass, defaultSort));
}
} else if (valueProperties != null) {
List<String> selectedExpressions = queryTransformerFactory.parser(queryString).getSelectedExpressionsList();
for (Sort.Order order : sort.getOrders()) {
sortExpressions.putAll(getValuePropertySortExpression(order.getProperty(), valueProperties, selectedExpressions, order.getDirection()));
}
}
return transformQuery(queryString, sortExpressions, defaultSort);
}
Aggregations