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();
}
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();
}
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;
}
}
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();
}
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);
}
}
Aggregations