use of org.apache.ofbiz.entity.model.ModelViewEntity 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;
}
use of org.apache.ofbiz.entity.model.ModelViewEntity in project ofbiz-framework by apache.
the class EntityConditionSubSelect method addSqlValue.
@Override
public void addSqlValue(StringBuilder sql, Map<String, String> tableAliases, ModelEntity parentModelEntity, List<EntityConditionParam> entityConditionParams, boolean includeTableNamePrefix, Datasource datasourceInfo) {
if (localModelEntity instanceof ModelViewEntity && datasourceInfo == null) {
throw new IllegalArgumentException("Call to EntityConditionSubSelect.addSqlValue with datasourceInfo=null which is not allowed because the local entity [" + this.localModelEntity.getEntityName() + "] is a view entity");
}
try {
// add select and where and such, based on local entity not on the main entity
ModelField localModelField = localModelEntity.getField(this.keyFieldName);
if (this.requireAll) {
sql.append(" ALL(");
} else {
sql.append(" ANY(");
}
sql.append("SELECT ");
sql.append(localModelField.getColName());
// FROM clause and when necessary the JOIN or LEFT JOIN clause(s) as well
sql.append(SqlJdbcUtil.makeFromClause(localModelEntity, null, datasourceInfo));
// WHERE clause
StringBuilder whereString = new StringBuilder();
String entityCondWhereString = "";
if (this.whereCond != null) {
entityCondWhereString = this.whereCond.makeWhereString(localModelEntity, entityConditionParams, datasourceInfo);
}
String viewClause = SqlJdbcUtil.makeViewWhereClause(localModelEntity, (datasourceInfo != null ? datasourceInfo.getJoinStyle() : null));
if (viewClause.length() > 0) {
if (entityCondWhereString.length() > 0) {
whereString.append("(");
whereString.append(entityCondWhereString);
whereString.append(") AND ");
}
whereString.append(viewClause);
} else {
whereString.append(entityCondWhereString);
}
if (whereString.length() > 0) {
sql.append(" WHERE ");
sql.append(whereString.toString());
}
sql.append(")");
} catch (GenericEntityException e) {
String errMsg = "Could not generate sub-select SQL: " + e.toString();
Debug.logError(e, errMsg, module);
}
}
Aggregations