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