Search in sources :

Example 6 with ModelAlias

use of org.apache.ofbiz.entity.model.ModelViewEntity.ModelAlias in project ofbiz-framework by apache.

the class EntityConditionBase method getColName.

protected String getColName(Map<String, String> tableAliases, ModelEntity modelEntity, ModelField modelField, String fieldName, boolean includeTableNamePrefix, Datasource datasourceInfo) {
    if (modelEntity == null || modelField == null) {
        return fieldName;
    }
    // if this is a view entity and we are configured to alias the views, use the alias here instead of the composite (ie table.column) field name
    if (datasourceInfo != null && datasourceInfo.getAliasViewColumns() && modelEntity instanceof ModelViewEntity) {
        ModelViewEntity modelViewEntity = (ModelViewEntity) modelEntity;
        ModelAlias modelAlias = modelViewEntity.getAlias(fieldName);
        if (modelAlias != null) {
            return modelAlias.getColAlias();
        }
    }
    String colName = getColName(modelField, fieldName);
    if (includeTableNamePrefix && datasourceInfo != null) {
        String tableName = modelEntity.getTableName(datasourceInfo);
        if (tableAliases.containsKey(tableName)) {
            tableName = tableAliases.get(tableName);
        }
        colName = tableName + "." + colName;
    }
    return colName;
}
Also used : ModelViewEntity(org.apache.ofbiz.entity.model.ModelViewEntity) ModelAlias(org.apache.ofbiz.entity.model.ModelViewEntity.ModelAlias)

Example 7 with ModelAlias

use of org.apache.ofbiz.entity.model.ModelViewEntity.ModelAlias in project ofbiz-framework by apache.

the class EntityFieldValue method init.

public void init(String fieldName, String entityAlias, List<String> entityAliasStack, ModelViewEntity modelViewEntity) {
    this.fieldName = fieldName;
    this.entityAlias = entityAlias;
    if (UtilValidate.isNotEmpty(entityAliasStack)) {
        this.entityAliasStack = new LinkedList<>();
        this.entityAliasStack.addAll(entityAliasStack);
    }
    this.modelViewEntity = modelViewEntity;
    if (UtilValidate.isNotEmpty(this.entityAliasStack) && UtilValidate.isEmpty(this.entityAlias)) {
        // look it up on the view entity so it can be part of the big list, this only happens for aliased fields, so find the entity-alias and field-name for the alias
        ModelAlias modelAlias = this.modelViewEntity.getAlias(this.fieldName);
        if (modelAlias != null) {
            this.entityAlias = modelAlias.getEntityAlias();
            this.fieldName = modelAlias.getField();
        }
    // TODO/NOTE: this will ignore function, group-by, etc... should maybe support those in conditions too at some point
    }
}
Also used : ModelAlias(org.apache.ofbiz.entity.model.ModelViewEntity.ModelAlias)

Aggregations

ModelAlias (org.apache.ofbiz.entity.model.ModelViewEntity.ModelAlias)7 ModelViewEntity (org.apache.ofbiz.entity.model.ModelViewEntity)3 ModelEntity (org.apache.ofbiz.entity.model.ModelEntity)2 LinkedList (java.util.LinkedList)1 MissingResourceException (java.util.MissingResourceException)1 ResourceBundle (java.util.ResourceBundle)1 ModelField (org.apache.ofbiz.entity.model.ModelField)1 ModelAliasAll (org.apache.ofbiz.entity.model.ModelViewEntity.ModelAliasAll)1 ModelMemberEntity (org.apache.ofbiz.entity.model.ModelViewEntity.ModelMemberEntity)1 ModelViewLink (org.apache.ofbiz.entity.model.ModelViewEntity.ModelViewLink)1 Element (org.w3c.dom.Element)1