Search in sources :

Example 1 with KeyValueMetaClass

use of io.jmix.core.impl.keyvalue.KeyValueMetaClass in project jmix by jmix-framework.

the class ValueGroupDatasourceImpl method setup.

@Override
public void setup(DsContext dsContext, DataSupplier dataSupplier, String id, MetaClass metaClass, @Nullable FetchPlan view) {
    this.id = id;
    this.dsContext = dsContext;
    this.dataSupplier = dataSupplier;
    this.metaClass = new KeyValueMetaClass();
}
Also used : KeyValueMetaClass(io.jmix.core.impl.keyvalue.KeyValueMetaClass)

Example 2 with KeyValueMetaClass

use of io.jmix.core.impl.keyvalue.KeyValueMetaClass in project jmix by jmix-framework.

the class ValueHierarchicalDatasourceImpl method setup.

@Override
public void setup(DsContext dsContext, DataSupplier dataSupplier, String id, MetaClass metaClass, @Nullable FetchPlan view) {
    this.id = id;
    this.dsContext = dsContext;
    this.dataSupplier = dataSupplier;
    this.metaClass = new KeyValueMetaClass();
}
Also used : KeyValueMetaClass(io.jmix.core.impl.keyvalue.KeyValueMetaClass)

Example 3 with KeyValueMetaClass

use of io.jmix.core.impl.keyvalue.KeyValueMetaClass in project jmix by jmix-framework.

the class FilterMetadataTools method isKeyValueCrossDataStoreReferenceAllowed.

protected boolean isKeyValueCrossDataStoreReferenceAllowed(MetaPropertyPath propertyPath, String query) {
    MetaClass filterMetaClass = propertyPath.getMetaClass();
    if (!(filterMetaClass instanceof KeyValueMetaClass) || Strings.isNullOrEmpty(query)) {
        return true;
    }
    MetaClass domainMetaClass = propertyPath.getMetaProperty().getDomain();
    MetaClass propertyMetaClass = propertyPath.getMetaProperty().getRange().isClass() ? propertyPath.getMetaProperty().getRange().asClass() : null;
    if (!domainMetaClass.equals(filterMetaClass)) {
        return propertyMetaClass == null || domainMetaClass.getStore().getName().equals(propertyMetaClass.getStore().getName());
    } else if (propertyMetaClass != null) {
        String entityName = query.substring(query.indexOf("from") + 4).trim().split(" ")[0];
        MetaClass mainFromMetaClass = metadata.getClass(entityName);
        return mainFromMetaClass.getStore().getName().equals(propertyMetaClass.getStore().getName()) || propertyMetaClass instanceof KeyValueMetaClass;
    } else {
        return true;
    }
}
Also used : MetaClass(io.jmix.core.metamodel.model.MetaClass) KeyValueMetaClass(io.jmix.core.impl.keyvalue.KeyValueMetaClass) KeyValueMetaClass(io.jmix.core.impl.keyvalue.KeyValueMetaClass)

Example 4 with KeyValueMetaClass

use of io.jmix.core.impl.keyvalue.KeyValueMetaClass in project jmix by jmix-framework.

the class PropertyCondition method updateText.

@Override
protected void updateText() {
    Metadata metadata = AppBeans.get(Metadata.class);
    MetadataTools metadataTools = metadata.getTools();
    String nameToUse = !Strings.isNullOrEmpty(propertiesPath) ? propertiesPath : name;
    boolean useCrossDataStoreRefId = false;
    boolean stringType = false;
    String thisStore = metaClass.getStore().getName();
    MetaPropertyPath propertyPath = metaClass.getPropertyPath(name);
    if (propertyPath != null) {
        MetaProperty metaProperty = propertyPath.getMetaProperty();
        String refIdProperty = metadataTools.getCrossDataStoreReferenceIdProperty(thisStore, propertyPath.getMetaProperty());
        if (refIdProperty != null) {
            useCrossDataStoreRefId = true;
            int lastdDot = nameToUse.lastIndexOf('.');
            if (lastdDot == -1) {
                nameToUse = refIdProperty;
            } else {
                nameToUse = nameToUse.substring(0, lastdDot + 1) + refIdProperty;
            }
        }
        stringType = String.class.equals(metaProperty.getJavaType());
    }
    if (operator == Op.DATE_INTERVAL) {
        text = dateIntervalConditionToJpql(nameToUse);
        return;
    }
    StringBuilder sb = new StringBuilder();
    StringBuilder sbJoin = new StringBuilder();
    if (operator == Op.NOT_IN) {
        sb.append("((");
    }
    String path = (metaClass instanceof KeyValueMetaClass && Strings.isNullOrEmpty(propertiesPath)) ? entityAlias : entityAlias + "." + nameToUse;
    String joinAlias = nameToUse.replace(".", "_") + RandomStringUtils.randomAlphabetic(5);
    if (Param.Type.ENTITY == param.getType() && !useCrossDataStoreRefId) {
        String primaryKeyName = metadataTools.getPrimaryKeyName(metadata.getClassNN(param.getJavaClass()));
        if (operator == Op.NOT_IN) {
            sbJoin.append("left join ").append(path).append(" ").append(joinAlias);
            sb.append(joinAlias).append(".").append(primaryKeyName);
        } else {
            sb.append(path).append(".").append(primaryKeyName);
        }
    } else {
        sb.append(path);
    }
    if (operator != Op.NOT_EMPTY) {
        PersistenceManagerClient persistenceManager = AppBeans.get(PersistenceManagerClient.class);
        if (operator == Op.EQUAL && stringType) /*&& persistenceManager.emulateEqualsByLike(thisStore)*/
        {
            sb.append(" ").append(Op.CONTAINS.forJpql());
        } else if (operator == Op.NOT_EQUAL && stringType) /*&& persistenceManager.emulateEqualsByLike(thisStore)*/
        {
            sb.append(" ").append(Op.DOES_NOT_CONTAIN.forJpql());
        } else {
            sb.append(" ").append(operator.forJpql());
        }
    }
    if (!operator.isUnary()) {
        sb.append(" :").append(param.getName());
        if (operator == Op.ENDS_WITH || operator == Op.STARTS_WITH || operator == Op.CONTAINS || operator == Op.DOES_NOT_CONTAIN) {
            CubaProperties properties = AppBeans.get(CubaProperties.class);
            if (properties.getDisableEscapingLikeForDataStores() == null || !properties.getDisableEscapingLikeForDataStores().contains(thisStore)) {
                sb.append(" ESCAPE '").append(QueryUtils.ESCAPE_CHARACTER).append("' ");
            }
        }
        if (operator == Op.NOT_IN) {
            if (Param.Type.ENTITY == param.getType() && !useCrossDataStoreRefId) {
                String primaryKeyName = metadataTools.getPrimaryKeyName(metadata.getClassNN(param.getJavaClass()));
                sb.append(") or (").append(joinAlias).append(".").append(primaryKeyName).append(" is null)) ");
            } else {
                sb.append(") or (").append(path).append(" is null)) ");
            }
        }
    }
    if (operator == Op.NOT_EMPTY) {
        sb.append(BooleanUtils.isTrue((Boolean) param.getValue()) ? " is not null" : " is null");
    }
    text = sb.toString();
    join = sbJoin.toString();
}
Also used : MetadataTools(io.jmix.core.MetadataTools) CubaProperties(com.haulmont.cuba.CubaProperties) KeyValueMetaClass(io.jmix.core.impl.keyvalue.KeyValueMetaClass) Metadata(com.haulmont.cuba.core.global.Metadata) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath) PersistenceManagerClient(com.haulmont.cuba.client.sys.PersistenceManagerClient) MetaProperty(io.jmix.core.metamodel.model.MetaProperty)

Example 5 with KeyValueMetaClass

use of io.jmix.core.impl.keyvalue.KeyValueMetaClass in project jmix by jmix-framework.

the class PropertyCondition method toXml.

@Override
public void toXml(Element element, Param.ValueProperty valueProperty) {
    super.toXml(element, valueProperty);
    element.addAttribute("type", ConditionType.PROPERTY.name());
    element.addAttribute("operatorType", getOperatorType());
    if (metaClass instanceof KeyValueMetaClass) {
        element.addAttribute("entityAlias", entityAlias);
        element.addAttribute("propertiesPath", propertiesPath);
    }
    if (!Strings.isNullOrEmpty(join)) {
        Element joinElement = element.addElement("join");
        joinElement.addCDATA(join);
    }
}
Also used : KeyValueMetaClass(io.jmix.core.impl.keyvalue.KeyValueMetaClass) Element(org.dom4j.Element)

Aggregations

KeyValueMetaClass (io.jmix.core.impl.keyvalue.KeyValueMetaClass)10 MetaClass (io.jmix.core.metamodel.model.MetaClass)3 InstanceContainer (io.jmix.ui.model.InstanceContainer)2 CubaProperties (com.haulmont.cuba.CubaProperties)1 PersistenceManagerClient (com.haulmont.cuba.client.sys.PersistenceManagerClient)1 Metadata (com.haulmont.cuba.core.global.Metadata)1 FetchPlan (io.jmix.core.FetchPlan)1 MetadataTools (io.jmix.core.MetadataTools)1 MetaProperty (io.jmix.core.metamodel.model.MetaProperty)1 MetaPropertyPath (io.jmix.core.metamodel.model.MetaPropertyPath)1 UiEntityAttributeContext (io.jmix.ui.accesscontext.UiEntityAttributeContext)1 EntityTableItems (io.jmix.ui.component.data.meta.EntityTableItems)1 DataComponents (io.jmix.ui.model.DataComponents)1 Element (org.dom4j.Element)1