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

com.sap.cds.jdbc.generic.UnfoldIsOperatorModifier Maven / Gradle / Ivy

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

import static com.sap.cds.impl.builder.model.ComparisonPredicate.eq;
import static com.sap.cds.impl.builder.model.ComparisonPredicate.ne;
import static com.sap.cds.ql.CQL.and;
import static com.sap.cds.ql.CQL.or;

import com.sap.cds.ql.CQL;
import com.sap.cds.ql.Value;
import com.sap.cds.ql.cqn.CqnComparisonPredicate.Operator;
import com.sap.cds.ql.cqn.CqnPredicate;
import com.sap.cds.ql.cqn.Modifier;

public class UnfoldIsOperatorModifier implements Modifier {
	@Override
	public CqnPredicate comparison(Value lhs, Operator op, Value rhs) {
		switch (op) {
			case IS:
				// (a = b AND a IS NOT NULL AND b IS NOT NULL) OR (a IS NULL AND b IS NULL)
				CqnPredicate bothNotNull = and(lhs.isNotNull(), rhs.isNotNull());
				CqnPredicate bothNull = and(lhs.isNull(), rhs.isNull());

				return or(and(eq(lhs, rhs), bothNotNull), bothNull);
			case IS_NOT:
				// ((a <> b OR a IS NULL OR b IS NULL) AND (a IS NOT NULL OR b IS NOT NULL))
				CqnPredicate eitherNull = or(lhs.isNull(), rhs.isNull());
				CqnPredicate eitherNotNull = or(lhs.isNotNull(), rhs.isNotNull());

				return and(or(ne(lhs, rhs), eitherNull), eitherNotNull);
			default:
				return CQL.comparison(lhs, op, rhs);
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy