Search in sources :

Example 6 with DBSAttributeBase

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());
    }
}
Also used : DBSAttributeBase(org.jkiss.dbeaver.model.struct.DBSAttributeBase)

Aggregations

DBSAttributeBase (org.jkiss.dbeaver.model.struct.DBSAttributeBase)6 Table (net.sf.jsqlparser.schema.Table)1 Nullable (org.jkiss.code.Nullable)1 DBDAttributeBinding (org.jkiss.dbeaver.model.data.DBDAttributeBinding)1 DBCExecutionContext (org.jkiss.dbeaver.model.exec.DBCExecutionContext)1 DBSEntityAttribute (org.jkiss.dbeaver.model.struct.DBSEntityAttribute)1 DBSTypedObject (org.jkiss.dbeaver.model.struct.DBSTypedObject)1 Pair (org.jkiss.utils.Pair)1