View Javadoc
1   // license-header java merge-point
2   //
3   // Attention: Generated code! Do not modify by hand!
4   // Generated by: hibernate/HibernateSearchParameter.vsl in andromda-spring-cartridge.
5   //
6   package fr.ifremer.quadrige3.core.dao;
7   
8   /*-
9    * #%L
10   * Quadrige3 Core :: Client API
11   * %%
12   * Copyright (C) 2017 - 2024 Ifremer
13   * %%
14   * This program is free software: you can redistribute it and/or modify
15   * it under the terms of the GNU Affero General Public License as published by
16   * the Free Software Foundation, either version 3 of the License, or
17   * (at your option) any later version.
18   * 
19   * This program is distributed in the hope that it will be useful,
20   * but WITHOUT ANY WARRANTY; without even the implied warranty of
21   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22   * GNU General Public License for more details.
23   * 
24   * You should have received a copy of the GNU Affero General Public License
25   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
26   * #L%
27   */
28  import java.util.regex.Pattern;
29  import org.hibernate.criterion.MatchMode;
30  
31  /**
32   * A <code>CriteriaSearchParameter</code> represents a parameter for a <code>CriteriaSearch</code>.
33   * <br>
34   * <br>
35   * The <code>parameterValue</code> is the actual value to be searched for.
36   * <br>
37   * <br>
38   * The <code>parameterPattern</code> describes the actual parameter which shall be considered for
39   * the search. It contains the dot-separated path and the name of the parameter starting at the
40   * rootEntity of the actual <code>CriteriaSearch</code>. The pattern of a the street of an address
41   * of a person would look like <i>address.street </i> (assuming the entity structure to be
42   * <code>aPerson.getAddress().getStreet()</code>).
43   * <br>
44   * <br>
45   * Usually, if a parameter is <code>null</code> (or if the parameter is of type <code>String</code>
46   * and empty), it is not considered for a search. If <code>searchIfNull</code> is <code>true</code>
47   * it is explicitly searched for the parameter to be null (or empty if the parameter is of type
48   * <code>String</code>).<br>
49   * <br>
50   * The <code>comparator</code> defines the comparator for the parameter. For parameters of type
51   * <code>String</code> the default comparator is the <code>LIKE_COMPARATOR</code>. The
52   * <code>EQUAL_COMPARATOR</code> is default for other parameters.
53   *
54   * @author Stefan Reichert
55   * @author Peter Friese
56   * @author Chad Brandon
57   */
58  public class CriteriaSearchParameter
59      extends SearchParameter
60  {
61      /** Compiled pattern \\. */
62      public static final Pattern PATTERN = Pattern.compile("\\.");
63  
64      /** Order relevance not set */
65      public static final int RELEVANCE_UNSET = -1;
66  
67      private Object parameterValue;
68      private String parameterPattern;
69      private MatchMode matchMode = null;
70      private int orderDirection = ORDER_UNSET;
71      private int orderRelevance = RELEVANCE_UNSET;
72  
73      /**
74       * Constructor for CriteriaSearchParameter. Sets <code>searchIfNull</code> to
75       * <code>false</code> and uses the <code>EQUAL_COMPARATOR</code>.
76       *
77       * @param parameterValueIn The actual value of the parameter.
78       * @param parameterPatternIn The pattern of this parameter (dot-separated path e.g. person.address.street).
79       */
80      public CriteriaSearchParameter(Object parameterValueIn, String parameterPatternIn)
81      {
82          this(parameterValueIn, parameterPatternIn, false, EQUAL_COMPARATOR);
83      }
84  
85      /**
86       * Constructor for CriteriaSearchParameter for a <code>String</code> parameter.
87       * Sets <code>searchIfNull</code> to <code>false</code> and uses the
88       * <code>LIKE_COMPARATOR</code>.
89       *
90       * @param parameterValueIn The actual value of the parameter.
91       * @param parameterPatternIn The pattern of this parameter (dot-separated path e.g. person.address.street).
92       */
93      public CriteriaSearchParameter(String parameterValueIn, String parameterPatternIn)
94      {
95          this(parameterValueIn, parameterPatternIn, false, LIKE_COMPARATOR);
96      }
97  
98      /**
99       * Constructor for CriteriaSearchParameter for a <code>String[]</code> parameter.
100      * Sets <code>searchIfNull</code> to <code>false</code> and uses the
101      * <code>LIKE_COMPARATOR</code>.
102      *
103      * @param parameterValueIn The actual value of the parameter.
104      * @param parameterPatternIn The pattern of this parameter (dot-separated path e.g. person.address.street).
105      */
106     public CriteriaSearchParameter(String[] parameterValueIn, String parameterPatternIn)
107     {
108         this(parameterValueIn, parameterPatternIn, false, LIKE_COMPARATOR);
109     }
110 
111     /**
112      * Constructor for CriteriaSearchParameter. Sets <code>searchIfNull</code> to <code>false</code>.
113      *
114      * @param parameterValueIn The actual value of the parameter.
115      * @param parameterPatternIn The pattern of this parameter (dot-separated path e.g. person.address.street).
116      * @param comparatorIn
117      */
118     public CriteriaSearchParameter(Object parameterValueIn, String parameterPatternIn, int comparatorIn)
119     {
120         this(parameterValueIn, parameterPatternIn, false, comparatorIn);
121     }
122 
123     /**
124      * Constructor for CriteriaSearchParameter.
125      *
126      * @param parameterValueIn The actual value of the parameter.
127      * @param parameterPatternIn The pattern of this parameter (dot-separated path e.g. person.address.street).
128      * @param searchIfNull Indicates whether the query should contain an
129      *     <code>IS NULL</code> if the parameter is <code>null</code>.
130      */
131     public CriteriaSearchParameter(
132         Object parameterValueIn,
133         String parameterPatternIn,
134         boolean searchIfNull)
135     {
136         this(parameterValueIn, parameterPatternIn, searchIfNull, EQUAL_COMPARATOR);
137     }
138 
139     /**
140      * Constructor for CriteriaSearchParameter.
141      *
142      * @param parameterValueIn The actual value of the parameter.
143      * @param parameterPatternIn The pattern of this parameter (dot-separated path e.g. person.address.street).
144      * @param searchIfNull Indicates whether the query should contain an
145      *     <code>IS NULL</code> if the parameter is <code>null</code>.
146      */
147     public CriteriaSearchParameter(
148         String parameterValueIn,
149         String parameterPatternIn,
150         boolean searchIfNull)
151     {
152         this(parameterValueIn, parameterPatternIn, searchIfNull, LIKE_COMPARATOR);
153     }
154 
155     /**
156      * Constructor for CriteriaSearchParameter.
157      *
158      * @param parameterValueIn The actual value of the parameter.
159      * @param parameterPatternIn The pattern of this parameter (dot-separated path e.g. person.address.street).
160      * @param searchIfNull Indicates whether the query should contain an
161      *     <code>IS NULL</code> if the parameter is <code>null</code>.
162      */
163     public CriteriaSearchParameter(
164         String[] parameterValueIn,
165         String parameterPatternIn,
166         boolean searchIfNull)
167     {
168         this(parameterValueIn, parameterPatternIn, searchIfNull, LIKE_COMPARATOR);
169     }
170 
171     /**
172      * Constructor for CriteriaSearchParameter.
173      *
174      * @param parameterValueIn The actual value of the parameter.
175      * @param parameterPatternIn The pattern of this parameter (dot-separated path e.g. person.address.street).
176      * @param searchIfNull Indicates whether the query should contain an
177      *     <code>IS NULL</code> if the parameter is <code>null</code>.
178      * @param comparatorIn Indicates what comparator is to be used (e.g. like, =, <, ...).
179      */
180     public CriteriaSearchParameter(
181         Object parameterValueIn,
182         String parameterPatternIn,
183         boolean searchIfNull,
184         int comparatorIn)
185     {
186         super(parameterPatternIn, parameterValueIn);
187         this.parameterValue = parameterValueIn;
188         this.parameterPattern = parameterPatternIn;
189         super.setSearchIfNull(searchIfNull);
190         this.setComparator(comparatorIn);
191     }
192 
193     /**
194      * Constructor for CriteriaSearchParameter.
195      *
196      * @param parameterValueIn The actual value of the parameter.
197      * @param parameterPatternIn The pattern of this parameter (dot-separated path e.g. person.address.street).
198      * @param searchIfNull Indicates whether the query should contain an
199      *     <code>IS NULL</code> if the parameter is <code>null</code>.
200      * @param matchModeIn The hibernate matchmode to be used in string comparisons.
201      */
202     public CriteriaSearchParameter(
203         Object parameterValueIn,
204         String parameterPatternIn,
205         boolean searchIfNull,
206         MatchMode matchModeIn)
207     {
208          this(parameterValueIn, parameterPatternIn, searchIfNull);
209          this.matchMode = matchModeIn;
210     }
211 
212     /**
213      * Constructor for CriteriaSearchParameter.
214      *
215      * @param parameterValueIn The actual value of the parameter.
216      * @param parameterPatternIn The pattern of this parameter (dot-separated path e.g. person.address.street).
217      * @param searchIfNull Indicates whether the query should contain an
218      *     <code>IS NULL</code> if the parameter is <code>null</code>.
219      * @param matchModeIn The hibernate matchmode to be used in string comparisons.
220      */
221     public CriteriaSearchParameter(
222         String parameterValueIn,
223         String parameterPatternIn,
224         boolean searchIfNull,
225         MatchMode matchModeIn)
226     {
227         this(parameterValueIn, parameterPatternIn, searchIfNull);
228         this.matchMode = matchModeIn;
229     }
230 
231     /**
232      * Constructor for CriteriaSearchParameter.
233      *
234      * @param parameterValueIn The actual value of the parameter.
235      * @param parameterPatternIn The pattern of this parameter (dot-separated path e.g. person.address.street).
236      * @param searchIfNull Indicates whether the query should contain an
237      *     <code>IS NULL</code> if the parameter is <code>null</code>.
238      * @param matchModeIn The hibernate matchmode to be used in string comparisons.
239      */
240     public CriteriaSearchParameter(
241         String[] parameterValueIn,
242         String parameterPatternIn,
243         boolean searchIfNull,
244         MatchMode matchModeIn)
245     {
246         this(parameterValueIn, parameterPatternIn, searchIfNull);
247         this.matchMode = matchModeIn;
248     }
249 
250     /**
251      * Constructor for CriteriaSearchParameter.
252      *
253      * @param parameterValueIn The actual value of the parameter.
254      * @param parameterPatternIn The pattern of this parameter (dot-separated path e.g. person.address.street).
255      * @param searchIfNull Indicates whether the query should contain an
256      *     <code>IS NULL</code> if the parameter is <code>null</code>.
257      * @param comparatorIn Indicates what comparator is to be used (e.g. like, =, <, ...).
258      * @param matchModeIn The hibernate matchmode to be used in string comparisons.
259      */
260     public CriteriaSearchParameter(
261         String parameterValueIn,
262         String parameterPatternIn,
263         boolean searchIfNull,
264         int comparatorIn,
265         MatchMode matchModeIn)
266     {
267         this(parameterValueIn, parameterPatternIn, searchIfNull, comparatorIn);
268         this.matchMode = matchModeIn;
269     }
270 
271     /**
272      * Constructor for CriteriaSearchParameter.
273      *
274      * @param parameterValueIn The actual value of the parameter.
275      * @param parameterPatternIn The pattern of this parameter (dot-separated path e.g. person.address.street).
276      * @param comparatorIn Indicates what comparator is to be used (e.g. like, =, <, ...).
277      * @param matchModeIn The hibernate matchmode to be used in string comparisons.
278      */
279     public CriteriaSearchParameter(
280         Object parameterValueIn,
281         String parameterPatternIn,
282         int comparatorIn,
283         MatchMode matchModeIn)
284     {
285         this(parameterValueIn, parameterPatternIn, comparatorIn);
286         this.matchMode = matchModeIn;
287     }
288 
289     /**
290      * Constructor for CriteriaSearchParameter.
291      *
292      * @param parameterValueIn The actual value of the parameter.
293      * @param parameterPatternIn The pattern of this parameter (dot-separated path e.g. person.address.street).
294      * @param matchModeIn The hibernate matchmode to be used in string comparisons.
295      */
296     public CriteriaSearchParameter(
297         Object parameterValueIn,
298         String parameterPatternIn,
299         MatchMode matchModeIn)
300     {
301         this(parameterValueIn, parameterPatternIn);
302         this.matchMode = matchModeIn;
303     }
304 
305     /**
306      * Constructor for CriteriaSearchParameter.
307      *
308      * @param parameterValueIn The actual value of the parameter.
309      * @param parameterPatternIn The pattern of this parameter (dot-separated path e.g. person.address.street).
310      * @param matchModeIn The hibernate matchmode to be used in string comparisons.
311      */
312     public CriteriaSearchParameter(
313         String parameterValueIn,
314         String parameterPatternIn,
315         MatchMode matchModeIn)
316     {
317         this(parameterValueIn, parameterPatternIn);
318         this.matchMode = matchModeIn;
319     }
320 
321 
322     /**
323      * Constructor for CriteriaSearchParameter.
324      *
325      * @param parameterValueIn The actual value of the parameter.
326      * @param parameterPatternIn The pattern of this parameter (dot-separated path e.g. person.address.street).
327      * @param matchModeIn The hibernate matchmode to be used in string comparisons.
328      */
329     public CriteriaSearchParameter(
330         String[] parameterValueIn,
331         String parameterPatternIn,
332         MatchMode matchModeIn)
333     {
334         this(parameterValueIn, parameterPatternIn);
335         this.matchMode = matchModeIn;
336     }
337 
338     /**
339      * @return The pattern of this parameter (dot-separated path e.g. person.address.street).
340      */
341     public String getParameterPattern()
342     {
343         return this.parameterPattern;
344     }
345 
346     /**
347      * Sets the pattern of this parameter.
348      *
349      * @param parameterPatternIn The pattern of this parameter (dot-separated path e.g. person.address.street).
350      */
351     public void setParameterPattern(String parameterPatternIn)
352     {
353         this.parameterPattern = parameterPatternIn;
354     }
355 
356     /**
357      * Parse the parameter pattern and return the last part of the name.
358      *
359      * @param parameterPatternIn The parameter pattern.
360      * @return The last part of the parameter pattern, i.e. the attribute name.
361      */
362     private String parseParameterName(String parameterPatternIn)
363     {
364         // parsing the pattern of the parameter
365         String[] path = CriteriaSearchParameter.PATTERN.split(parameterPatternIn);
366         return path[path.length - 1];
367     }
368 
369     /**
370      * @return The last part of the parameter pattern, i.e. the attribute name.
371      */
372     public String getParameterName()
373     {
374         return parseParameterName(this.parameterPattern);
375     }
376 
377     /**
378      * @return The value of this parameter.
379      */
380     public Object getParameterValue()
381     {
382         return this.parameterValue;
383     }
384 
385     /**
386      * Sets the value of this parameter.
387      *
388      * @param parameterValueIn The value of this parameter.
389      */
390     public void setParameterValue(Object parameterValueIn)
391     {
392         this.parameterValue = parameterValueIn;
393     }
394 
395     /**
396      * @return The hibernate matchmode of this parameter.
397      */
398     public MatchMode getMatchMode()
399     {
400         return this.matchMode;
401     }
402 
403     /**
404      * Sets the hibernate matchmode of this parameter.
405      *
406      * @param matchModeIn The hibernate matchmode.
407      */
408     public void setMatchMode(MatchMode matchModeIn)
409     {
410         this.matchMode = matchModeIn;
411     }
412 
413     /**
414      * @return The order (ascending or descending) for this parameter.
415      * @see SearchParameter#ORDER_ASC
416      * @see SearchParameter#ORDER_DESC
417      * @see SearchParameter#ORDER_UNSET
418      */
419     public int getOrderDirection()
420     {
421         return this.orderDirection;
422     }
423 
424     /**
425      * Sets the ordering for this parameter.
426      *
427      * @param orderDirectionIn The ordering for this parameter.
428      */
429     public void setOrderDirection(int orderDirectionIn)
430     {
431         this.orderDirection = orderDirectionIn;
432     }
433 
434     /**
435      * @return The relevance for this parameter.
436      * @see SearchParameter#ORDER_UNSET
437      */
438     public int getOrderRelevance()
439     {
440         return this.orderRelevance;
441     }
442 
443     /**
444      * Sets the ordering relevance for this parameter.
445      *
446      * @param relevanceIn The ordering relevance for this parameter.
447      */
448     public void setOrderRelevance(int relevanceIn)
449     {
450         this.orderRelevance = relevanceIn;
451     }
452 
453     private static final long serialVersionUID = 1L;
454 }