All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sap.cds.jdbc.postgresql.PostgreSqlPredicateMapper Maven / Gradle / Ivy

There is a newer version: 3.4.0
Show newest version
/************************************************************************
 * © 2020-2023 SAP SE or an SAP affiliate company. All rights reserved. *
 ************************************************************************/
package com.sap.cds.jdbc.postgresql;

import com.sap.cds.impl.parser.builder.ExpressionBuilder;
import com.sap.cds.impl.parser.token.CqnPlainImpl;
import com.sap.cds.jdbc.spi.PredicateMapper;
import com.sap.cds.ql.Predicate;
import com.sap.cds.ql.Value;
import com.sap.cds.ql.cqn.CqnComparisonPredicate.Operator;
import com.sap.cds.ql.cqn.CqnPlain;
import com.sap.cds.ql.cqn.CqnPredicate;
import com.sap.cds.ql.cqn.Modifier;
import com.sap.cds.ql.impl.ExpressionVisitor;
import com.sap.cds.ql.impl.LeanModifier;

public class PostgreSqlPredicateMapper implements PredicateMapper {

	private static final CqnPlain IS_NOT_DISTINCT_FROM = CqnPlainImpl.plain("is not distinct from");
	private static final CqnPlain IS_DISTINCT_FROM = CqnPlainImpl.plain("is distinct from");

	@Override
	public CqnPredicate apply(CqnPredicate pred) {
		Modifier m = new LeanModifier() {

			@Override
			public Predicate comparison(Value lhs, Operator op, Value rhs) {
				if (!rhs.isNullValue()) {
					if (op == Operator.IS) {
						return ExpressionBuilder.create(lhs, IS_NOT_DISTINCT_FROM, rhs).predicate();
					}
					if (op == Operator.IS_NOT) {
						return ExpressionBuilder.create(lhs, IS_DISTINCT_FROM, rhs).predicate();
					}
				}
				return LeanModifier.super.comparison(lhs, op, rhs);
			}

		};

		return ExpressionVisitor.copy(pred, m);
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy