use of org.jkiss.dbeaver.model.struct.DBSAttributeBase in project dbeaver by serge-rider.
the class SQLUtils method appendConditionString.
public static void appendConditionString(@NotNull DBDDataFilter filter, @NotNull DBPDataSource dataSource, @Nullable String conditionTable, @NotNull StringBuilder query, boolean inlineCriteria) {
//$NON-NLS-1$ $NON-NLS-2$
String operator = filter.isAnyConstraint() ? " OR " : " AND ";
boolean hasWhere = false;
for (DBDAttributeConstraint constraint : filter.getConstraints()) {
String condition = getConstraintCondition(dataSource, constraint, inlineCriteria);
if (condition == null) {
continue;
}
if (hasWhere)
query.append(operator);
hasWhere = true;
if (constraint.getEntityAlias() != null) {
query.append(constraint.getEntityAlias()).append('.');
} else if (conditionTable != null) {
query.append(conditionTable).append('.');
}
// Attribute name could be an expression. So check if this is a real attribute
// and generate full/quoted name for it.
String attrName;
DBSAttributeBase cAttr = constraint.getAttribute();
if (cAttr instanceof DBDAttributeBinding) {
DBDAttributeBinding binding = (DBDAttributeBinding) cAttr;
if (binding.getEntityAttribute() != null && binding.getEntityAttribute().getName().equals(binding.getMetaAttribute().getName())) {
attrName = DBUtils.getObjectFullName(dataSource, binding, DBPEvaluationContext.DML);
} else {
// Most likely it is an expression so we don't want to quote it
attrName = binding.getMetaAttribute().getName();
}
} else {
attrName = DBUtils.getObjectFullName(dataSource, cAttr, DBPEvaluationContext.DML);
}
query.append(attrName).append(' ').append(condition);
}
if (!CommonUtils.isEmpty(filter.getWhere())) {
if (hasWhere)
query.append(operator);
query.append(filter.getWhere());
}
}
Aggregations