PL-10551 NPE on browser screen with LOB property

This commit is contained in:
Andrey Subbotin 2018-03-16 18:31:51 +04:00
parent 1be4ec0bf0
commit 2458b2de09
8 changed files with 36 additions and 16 deletions

View File

@ -133,7 +133,7 @@ public class PersistenceManagerClient implements PersistenceManagerService {
@Override
public boolean supportsLobSortingAndFiltering(String storeName) {
return dbmsCache.computeIfAbsent(storeName, s -> {
return storeName == null || dbmsCache.computeIfAbsent(storeName, s -> {
DbmsCacheEntry cacheEntry = new DbmsCacheEntry();
cacheEntry.supportsLobSortingAndFiltering = service.supportsLobSortingAndFiltering(s);
return cacheEntry;

View File

@ -70,6 +70,6 @@ public class PersistenceManagerServiceBean implements PersistenceManagerService
@Override
public boolean supportsLobSortingAndFiltering(String storeName) {
return DbmsSpecificFactory.getDbmsFeatures(storeName).supportsLobSortingAndFiltering();
return storeName == null || DbmsSpecificFactory.getDbmsFeatures(storeName).supportsLobSortingAndFiltering();
}
}

View File

@ -29,5 +29,5 @@ public interface OpManager {
EnumSet<Op> availableOpsForCollectionDynamicAttribute();
EnumSet<Op> availableOps(MetaProperty metaProperty);
EnumSet<Op> availableOps(MetaClass metaClass, MetaProperty metaProperty);
}

View File

@ -16,6 +16,7 @@
package com.haulmont.cuba.core.global.filter;
import com.haulmont.chile.core.model.MetaClass;
import com.haulmont.chile.core.model.MetaProperty;
import com.haulmont.cuba.core.app.PersistenceManagerService;
import com.haulmont.cuba.core.entity.Entity;
@ -70,10 +71,10 @@ public class OpManagerImpl implements OpManager {
}
@Override
public EnumSet<Op> availableOps(MetaProperty metaProperty) {
public EnumSet<Op> availableOps(MetaClass metaClass, MetaProperty metaProperty) {
Class javaClass = metaProperty.getJavaType();
if (String.class.equals(javaClass) && metadataTools.isLob(metaProperty)) {
String storeName = metadata.getTools().getStoreName(metaProperty.getDomain());
String storeName = metadata.getTools().getStoreName(metaClass);
PersistenceManagerService persistenceManagerService = AppBeans.get(PersistenceManagerService.class);
if (!persistenceManagerService.supportsLobSortingAndFiltering(storeName)) {
return EnumSet.of(CONTAINS, DOES_NOT_CONTAIN, NOT_EMPTY, STARTS_WITH, ENDS_WITH);

View File

@ -18,13 +18,14 @@
package com.haulmont.cuba.gui.components.filter.descriptor;
import com.google.common.base.Strings;
import com.haulmont.chile.core.annotations.MetaClass;
import com.haulmont.chile.core.model.MetaClass;
import com.haulmont.chile.core.model.MetaProperty;
import com.haulmont.chile.core.model.MetaPropertyPath;
import com.haulmont.cuba.core.entity.annotation.SystemLevel;
import com.haulmont.cuba.core.global.AppBeans;
import com.haulmont.cuba.core.global.MessageTools;
import com.haulmont.cuba.core.global.Messages;
import com.haulmont.cuba.core.global.MetadataTools;
import com.haulmont.cuba.core.global.filter.Op;
import com.haulmont.cuba.core.global.filter.OpManager;
import com.haulmont.cuba.gui.components.filter.condition.AbstractCondition;
@ -38,7 +39,7 @@ import java.util.EnumSet;
import static org.apache.commons.lang.StringUtils.isBlank;
@MetaClass(name = "sec$PropertyConditionDescriptor")
@com.haulmont.chile.core.annotations.MetaClass(name = "sec$PropertyConditionDescriptor")
@SystemLevel
public class PropertyConditionDescriptor extends AbstractConditionDescriptor {
protected String entityParamWhere;
@ -94,8 +95,16 @@ public class PropertyConditionDescriptor extends AbstractConditionDescriptor {
@Override
public AbstractCondition createCondition() {
OpManager opManager = AppBeans.get(OpManager.class);
MetadataTools metadataTools = AppBeans.get(MetadataTools.class);
PropertyCondition propertyCondition = new PropertyCondition(this, entityAlias);
EnumSet<Op> ops = AppBeans.get(OpManager.class).availableOps(getMetaProperty());
MetaPropertyPath propertyPath = datasourceMetaClass.getPropertyPath(name);
if (propertyPath == null) {
throw new IllegalStateException(String.format("Unable to find property '%s' in entity %s", name, datasourceMetaClass));
}
MetaClass propertyMetaClass = metadataTools.getPropertyEnclosingMetaClass(propertyPath);
EnumSet<Op> ops = opManager.availableOps(propertyMetaClass, propertyPath.getMetaProperty());
propertyCondition.setOperator(ops.iterator().next());
return propertyCondition;
}

View File

@ -17,9 +17,9 @@
package com.haulmont.cuba.gui.components.filter.operationedit;
import com.haulmont.chile.core.model.MetaClass;
import com.haulmont.chile.core.model.MetaProperty;
import com.haulmont.chile.core.model.MetaPropertyPath;
import com.haulmont.cuba.core.global.AppBeans;
import com.haulmont.cuba.core.global.MetadataTools;
import com.haulmont.cuba.core.global.filter.Op;
import com.haulmont.cuba.core.global.filter.OpManager;
import com.haulmont.cuba.gui.components.AbstractAction;
@ -28,6 +28,7 @@ import com.haulmont.cuba.gui.components.PopupButton;
import com.haulmont.cuba.gui.components.filter.condition.AbstractCondition;
import com.haulmont.cuba.gui.xml.layout.ComponentsFactory;
/**
* Operation editor for PropertyCondition. Displays popupButton component for selecting an operation.
*/
@ -42,14 +43,20 @@ public class PropertyOperationEditor extends AbstractOperationEditor {
@Override
protected Component createComponent() {
OpManager opManager = AppBeans.get(OpManager.class);
MetadataTools metadataTools = AppBeans.get(MetadataTools.class);
componentsFactory = AppBeans.get(ComponentsFactory.class);
popupButton = componentsFactory.createComponent(PopupButton.class);
OpManager opManager = AppBeans.get(OpManager.class);
MetaClass metaClass = condition.getDatasource().getMetaClass();
MetaPropertyPath propertyPath = metaClass.getPropertyPath(condition.getName());
MetaProperty metaProperty = propertyPath != null ? propertyPath.getMetaProperty() : null;
for (Op op : opManager.availableOps(metaProperty)) {
if (propertyPath == null) {
throw new IllegalStateException(String.format("Unable to find property '%s' in entity %s",
condition.getName(), metaClass));
}
MetaClass propertyMetaClass = metadataTools.getPropertyEnclosingMetaClass(propertyPath);
for (Op op : opManager.availableOps(propertyMetaClass, propertyPath.getMetaProperty())) {
OperatorChangeAction operatorChangeAction = new OperatorChangeAction(op);
popupButton.addAction(operatorChangeAction);
}

View File

@ -649,7 +649,8 @@ public abstract class AbstractCollectionDatasource<T extends Entity<K>, K>
PersistenceManagerService persistenceManagerService = AppBeans.get(PersistenceManagerClient.NAME);
if (!range.isClass()) {
// a scalar persistent attribute
String storeName = metadata.getTools().getStoreName(metaProperty.getDomain());
MetaClass propertyMetaClass = metadata.getTools().getPropertyEnclosingMetaClass(propertyPath);
String storeName = metadata.getTools().getStoreName(propertyMetaClass);
if (!metadata.getTools().isLob(metaProperty)
|| persistenceManagerService.supportsLobSortingAndFiltering(storeName)) {
sortProperties = new String[1];
@ -663,7 +664,7 @@ public abstract class AbstractCollectionDatasource<T extends Entity<K>, K>
sortProperties = properties.stream()
.filter(prop -> {
if (metadata.getTools().isPersistent(prop)) {
String storeName = metadata.getTools().getStoreName(prop.getDomain());
String storeName = metadata.getTools().getStoreName(range.asClass());
return !metadata.getTools().isLob(prop) ||
persistenceManagerService.supportsLobSortingAndFiltering(storeName);
}

View File

@ -244,8 +244,10 @@ public abstract class WebAbstractTable<T extends com.vaadin.ui.Table & CubaEnhan
if (columnId instanceof MetaPropertyPath) {
PersistenceManagerService persistenceManagerService = AppBeans.get(PersistenceManagerClient.NAME);
MetaProperty metaProperty = ((MetaPropertyPath) columnId).getMetaProperty();
String storeName = metadataTools.getStoreName(metaProperty.getDomain());
MetaPropertyPath propertyPath = (MetaPropertyPath) columnId;
MetaProperty metaProperty = propertyPath.getMetaProperty();
MetaClass propertyMetaClass = metadataTools.getPropertyEnclosingMetaClass(propertyPath);
String storeName = metadataTools.getStoreName(propertyMetaClass);
if (metadataTools.isLob(metaProperty) && !persistenceManagerService.supportsLobSortingAndFiltering(storeName)) {
component.setColumnSortable(columnId, false);
}