View Javadoc
1   package org.synchronoss.cpo.core;
2   
3   /*-
4    * [[
5    * core
6    * ==
7    * Copyright (C) 2003 - 2026 Exaxis LLC, Synchronoss Technologies Inc
8    * ==
9    * This program is free software: you can redistribute it and/or modify
10   * it under the terms of the GNU Lesser General Public License as
11   * published by the Free Software Foundation, either version 3 of the
12   * License, or (at your option) any later version.
13   *
14   * This program is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   * GNU General Lesser Public License for more details.
18   *
19   * You should have received a copy of the GNU General Lesser Public
20   * License along with this program.  If not, see
21   * <http://www.gnu.org/licenses/lgpl-3.0.html>.
22   * ]]
23   */
24  
25  import org.synchronoss.cpo.core.enums.Comparison;
26  import org.synchronoss.cpo.core.enums.Logical;
27  
28  /**
29   * `CpoWhere` is an interface for specifying the where clause to filter objects that are returned
30   * from the Datasource.
31   *
32   * <p>A `CpoWhere` node is either a *leaf*, comparing an attribute to a value or another attribute,
33   * or a *branch*, formed by chaining leaves/branches together with {@link #addWhere(CpoWhere)} and a
34   * {@link Logical} operator. Use {@link #isLeaf()} to tell which kind a given instance is.
35   *
36   * @author david berry
37   */
38  public interface CpoWhere {
39  
40    /**
41     * Sets the {@link Comparison} operator (e.g. equals, greater-than) used to compare the attribute
42     * against the value or right-hand attribute.
43     *
44     * @param comparison the comparison operator for this where clause
45     */
46    void setComparison(Comparison comparison);
47  
48    /**
49     * Gets the {@link Comparison} operator used to compare the attribute against the value or
50     * right-hand attribute.
51     *
52     * @return the comparison operator for this where clause
53     */
54    Comparison getComparison();
55  
56    /**
57     * Sets the {@link Logical} operator (e.g. AND, OR) used to join this where clause with the next
58     * one added via {@link #addWhere(CpoWhere)}.
59     *
60     * @param logical the logical operator joining this clause to the next
61     */
62    void setLogical(Logical logical);
63  
64    /**
65     * Gets the {@link Logical} operator used to join this where clause with the next one added via
66     * {@link #addWhere(CpoWhere)}.
67     *
68     * @return the logical operator joining this clause to the next
69     */
70    Logical getLogical();
71  
72    /**
73     * Sets the name of the bean attribute on the left-hand side of the comparison.
74     *
75     * @param attr the attribute name
76     */
77    void setAttribute(String attr);
78  
79    /**
80     * Gets the name of the bean attribute on the left-hand side of the comparison.
81     *
82     * @return the attribute name
83     */
84    String getAttribute();
85  
86    /**
87     * Sets the name of the bean attribute to compare against, when comparing two attributes rather
88     * than an attribute and a literal value.
89     *
90     * @param attr the right-hand attribute name
91     */
92    void setRightAttribute(String attr);
93  
94    /**
95     * Gets the name of the bean attribute to compare against, when comparing two attributes rather
96     * than an attribute and a literal value.
97     *
98     * @return the right-hand attribute name
99     */
100   String getRightAttribute();
101 
102   /**
103    * Sets the literal value to compare the attribute against.
104    *
105    * @param val the comparison value
106    */
107   void setValue(Object val);
108 
109   /**
110    * Gets the literal value the attribute is compared against.
111    *
112    * @return the comparison value
113    */
114   Object getValue();
115 
116   /**
117    * Gets whether this where clause's comparison result is negated.
118    *
119    * @return `true` if the comparison is negated (NOT), `false` otherwise
120    */
121   boolean getNot();
122 
123   /**
124    * Sets whether this where clause's comparison result should be negated.
125    *
126    * @param b `true` to negate the comparison (NOT), `false` otherwise
127    */
128   void setNot(boolean b);
129 
130   /**
131    * Chains another where clause onto this one, joined by this instance's {@link Logical} operator,
132    * turning this instance into a branch node.
133    *
134    * @param cw the where clause to add
135    * @throws CpoException if the where clause cannot be added
136    */
137   void addWhere(CpoWhere cw) throws CpoException;
138 
139   /**
140    * Sets a native datastore function (e.g. `UPPER`) to apply to the left-hand attribute before
141    * comparison.
142    *
143    * @param s the function expression to apply to the attribute
144    */
145   void setAttributeFunction(String s);
146 
147   /**
148    * Gets the native datastore function applied to the left-hand attribute before comparison.
149    *
150    * @return the function expression applied to the attribute
151    */
152   String getAttributeFunction();
153 
154   /**
155    * Sets a native datastore function (e.g. `UPPER`) to apply to the comparison value before
156    * comparison.
157    *
158    * @param s the function expression to apply to the value
159    */
160   void setValueFunction(String s);
161 
162   /**
163    * Gets the native datastore function applied to the comparison value before comparison.
164    *
165    * @return the function expression applied to the value
166    */
167   String getValueFunction();
168 
169   /**
170    * Sets a native datastore function (e.g. `UPPER`) to apply to the right-hand attribute before
171    * comparison.
172    *
173    * @param s the function expression to apply to the right-hand attribute
174    */
175   void setRightAttributeFunction(String s);
176 
177   /**
178    * Gets the native datastore function applied to the right-hand attribute before comparison.
179    *
180    * @return the function expression applied to the right-hand attribute
181    */
182   String getRightAttributeFunction();
183 
184   /**
185    * Sets a literal, unescaped value to use in place of a bound comparison value, inserted directly
186    * into the native expression.
187    *
188    * @param staticValue the static (literal) value text
189    */
190   void setStaticValue(String staticValue);
191 
192   /**
193    * Gets the literal, unescaped value used in place of a bound comparison value.
194    *
195    * @return the static (literal) value text
196    */
197   String getStaticValue();
198 
199   /**
200    * Gets whether this instance is a leaf node (a single comparison) rather than a branch node
201    * formed by {@link #addWhere(CpoWhere)}.
202    *
203    * @return `true` if this is a leaf comparison node, `false` if it is a branch
204    */
205   boolean isLeaf();
206 
207   /**
208    * Gets a string representing the name of this instance of the CpoOrderBy
209    *
210    * @return String The name of the CpoOrderBy
211    */
212   String getName();
213 
214   /**
215    * Sets a string representing the name of this instance of the CpoOrderBy
216    *
217    * @param s The name of the CpoOrderBy
218    */
219   void setName(String s);
220 }