Skip to content

Method: setExpressionToQuery(StringBuilder, CriteriaParameterFiller)

1: /*
2: * JOPA
3: * Copyright (C) 2024 Czech Technical University in Prague
4: *
5: * This library is free software; you can redistribute it and/or
6: * modify it under the terms of the GNU Lesser General Public
7: * License as published by the Free Software Foundation; either
8: * version 3.0 of the License, or (at your option) any later version.
9: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library.
17: */
18: package cz.cvut.kbss.jopa.query.criteria.expressions;
19:
20: import cz.cvut.kbss.jopa.model.query.criteria.Expression;
21: import cz.cvut.kbss.jopa.model.query.criteria.Predicate;
22: import cz.cvut.kbss.jopa.query.criteria.AbstractPredicate;
23: import cz.cvut.kbss.jopa.query.criteria.CriteriaParameterFiller;
24: import cz.cvut.kbss.jopa.query.soql.SoqlConstants;
25: import cz.cvut.kbss.jopa.model.query.criteria.CriteriaBuilder;
26:
27: import java.util.Collection;
28: import java.util.List;
29:
30: public class IsMemberExpression<Y> extends AbstractPredicate {
31:
32: private final Expression<? extends Collection<Y>> collectionExpression;
33: private final Y value;
34:
35: public IsMemberExpression(Y value, Expression<? extends Collection<Y>> collectionExpression, CriteriaBuilder cb) {
36: super(BooleanOperator.AND, cb);
37: this.value = value;
38: this.collectionExpression = collectionExpression;
39: }
40:
41: @Override
42: public Predicate not() {
43: super.negate();
44: return this;
45: }
46:
47: @Override
48: public List<Expression<Boolean>> getExpressions() {
49: return List.of(this);
50: }
51:
52: @Override
53: public void setExpressionToQuery(StringBuilder query, CriteriaParameterFiller parameterFiller) {
54: final AbstractExpression<?> param = (AbstractExpression<?>) cb.literal(value);
55: param.setExpressionToQuery(query, parameterFiller);
56:• if (negated) {
57: query.append(' ').append(SoqlConstants.NOT);
58: }
59: query.append(' ').append(SoqlConstants.MEMBER_OF).append(' ');
60: ((AbstractExpression<?>) collectionExpression).setExpressionToQuery(query, parameterFiller);
61: }
62: }