use of org.compiere.util.Evaluatee in project metasfresh-webui-api by metasfresh.
the class SqlDocumentQueryBuilder method getSql.
/**
* @return SQL to fully load the documents matched by this query.
*/
public String getSql(final List<Object> outSqlParams) {
final Evaluatee evalCtx = getEvaluationContext();
final IPair<IStringExpression, List<Object>> sqlAndParams = getSqlAndParams();
final String sql = sqlAndParams.getLeft().evaluate(evalCtx, OnVariableNotFound.Fail);
final List<Object> sqlParams = sqlAndParams.getRight();
outSqlParams.addAll(sqlParams);
return sql;
}
use of org.compiere.util.Evaluatee in project metasfresh-webui-api by metasfresh.
the class SqlDocumentQueryBuilder method getSqlWhere.
private String getSqlWhere(final List<Object> sqlParams) {
final IPair<IStringExpression, List<Object>> sqlWhereAndParams = getSqlWhereAndParams();
final Evaluatee evalCtx = getEvaluationContext();
final String sqlWhere = sqlWhereAndParams.getLeft().evaluate(evalCtx, OnVariableNotFound.Fail);
sqlParams.addAll(sqlWhereAndParams.getRight());
return sqlWhere;
}
use of org.compiere.util.Evaluatee in project metasfresh-webui-api by metasfresh.
the class SqlDocumentQueryBuilder method getSqlSelectParentId.
/**
* SQL to fetch the parent's ID based on given child document.
*
* @return SELECT KeyColumnName from ParentTableName WHERE ....
*/
public String getSqlSelectParentId(final List<Object> outSqlParams, final DocumentEntityDescriptor parentEntityDescriptor) {
final String linkColumnName = entityBinding.getLinkColumnName();
final String parentLinkColumnName = entityBinding.getParentLinkColumnName();
if (parentLinkColumnName == null || linkColumnName == null) {
throw new AdempiereException("Selecting parent ID is not possible because this entity does not have a parent link").setParameter("linkColumnName", linkColumnName).setParameter("parentLinkColumnName", parentLinkColumnName).setParameter("entityBinding", entityBinding);
}
//
// SELECT linkColumnName from current(child) tableName
final List<Object> sqlSelectLinkColumnNameParams = new ArrayList<>();
final CompositeStringExpression.Builder sqlSelectLinkColumnName = IStringExpression.composer();
{
final IPair<IStringExpression, List<Object>> sqlWhereAndParams = getSqlWhereAndParams();
final IStringExpression sqlWhere = sqlWhereAndParams.getLeft();
final List<Object> sqlWhereParams = sqlWhereAndParams.getRight();
sqlSelectLinkColumnName.append("SELECT " + linkColumnName).append(// NOTE: we need table alias because the where clause is using it
" FROM " + entityBinding.getTableName() + " " + entityBinding.getTableAlias()).append("\n WHERE ").append(sqlWhere);
sqlSelectLinkColumnNameParams.addAll(sqlWhereParams);
}
//
//
final String parentKeyColumnName = extractSingleKeyColumnName(parentEntityDescriptor);
if (Objects.equals(parentKeyColumnName, parentLinkColumnName)) {
final Evaluatee evalCtx = getEvaluationContext();
final String sql = sqlSelectLinkColumnName.build().evaluate(evalCtx, OnVariableNotFound.Fail);
outSqlParams.addAll(sqlSelectLinkColumnNameParams);
return sql;
} else {
final Evaluatee evalCtx = getEvaluationContext();
final String sql = IStringExpression.composer().append("SELECT " + parentKeyColumnName + " FROM " + parentEntityDescriptor.getTableName()).append("\n WHERE " + parentLinkColumnName + " IN (").append(sqlSelectLinkColumnName).append(")").build().evaluate(evalCtx, OnVariableNotFound.Fail);
outSqlParams.addAll(sqlSelectLinkColumnNameParams);
return sql;
}
}
use of org.compiere.util.Evaluatee in project metasfresh-webui-api by metasfresh.
the class DocumentField method getLookupValuesForQuery.
@Override
public LookupValuesList getLookupValuesForQuery(final String query) {
final LookupDataSource lookupDataSource = getLookupDataSource();
final Evaluatee ctx = getDocument().asEvaluatee();
final LookupValuesList values = lookupDataSource.findEntities(ctx, query);
lookupValuesStaled = false;
return values;
}
Aggregations