001// license-header java merge-point 002// 003// Attention: Generated code! Do not modify by hand! 004// Generated by: hibernate/HibernateSearchParameter.vsl in andromda-spring-cartridge. 005// 006package fr.ifremer.adagio.core.dao; 007 008/* 009 * #%L 010 * SIH-Adagio :: Core for Allegro 011 * $Id:$ 012 * $HeadURL:$ 013 * %% 014 * Copyright (C) 2012 - 2014 Ifremer 015 * %% 016 * This program is free software: you can redistribute it and/or modify 017 * it under the terms of the GNU Affero General Public License as published by 018 * the Free Software Foundation, either version 3 of the License, or 019 * (at your option) any later version. 020 * 021 * This program is distributed in the hope that it will be useful, 022 * but WITHOUT ANY WARRANTY; without even the implied warranty of 023 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 024 * GNU General Public License for more details. 025 * 026 * You should have received a copy of the GNU Affero General Public License 027 * along with this program. If not, see <http://www.gnu.org/licenses/>. 028 * #L% 029 */ 030 031import java.util.regex.Pattern; 032import org.hibernate.criterion.MatchMode; 033 034/** 035 * A <code>CriteriaSearchParameter</code> represents a parameter for a <code>CriteriaSearch</code>. 036 * <br> 037 * <br> 038 * The <code>parameterValue</code> is the actual value to be searched for. 039 * <br> 040 * <br> 041 * The <code>parameterPattern</code> describes the actual parameter which shall be considered for 042 * the search. It contains the dot-separated path and the name of the parameter starting at the 043 * rootEntity of the actual <code>CriteriaSearch</code>. The pattern of a the street of an address 044 * of a person would look like <i>address.street </i> (assuming the entity structure to be 045 * <code>aPerson.getAddress().getStreet()</code>). 046 * <br> 047 * <br> 048 * Usually, if a parameter is <code>null</code> (or if the parameter is of type <code>String</code> 049 * and empty), it is not considered for a search. If <code>searchIfNull</code> is <code>true</code> 050 * it is explicitly searched for the parameter to be null (or empty if the parameter is of type 051 * <code>String</code>).<br> 052 * <br> 053 * The <code>comparator</code> defines the comparator for the parameter. For parameters of type 054 * <code>String</code> the default comparator is the <code>LIKE_COMPARATOR</code>. The 055 * <code>EQUAL_COMPARATOR</code> is default for other parameters. 056 * 057 * @author Stefan Reichert 058 * @author Peter Friese 059 * @author Chad Brandon 060 */ 061public class CriteriaSearchParameter 062 extends SearchParameter 063{ 064 /** Compiled pattern \\. */ 065 public static final Pattern PATTERN = Pattern.compile("\\."); 066 067 /** Order relevance not set */ 068 public static final int RELEVANCE_UNSET = -1; 069 070 private Object parameterValue; 071 private String parameterPattern; 072 private MatchMode matchMode = null; 073 private int orderDirection = ORDER_UNSET; 074 private int orderRelevance = RELEVANCE_UNSET; 075 076 /** 077 * Constructor for CriteriaSearchParameter. Sets <code>searchIfNull</code> to 078 * <code>false</code> and uses the <code>EQUAL_COMPARATOR</code>. 079 * 080 * @param parameterValueIn The actual value of the parameter. 081 * @param parameterPatternIn The pattern of this parameter (dot-separated path e.g. person.address.street). 082 */ 083 public CriteriaSearchParameter(Object parameterValueIn, String parameterPatternIn) 084 { 085 this(parameterValueIn, parameterPatternIn, false, EQUAL_COMPARATOR); 086 } 087 088 /** 089 * Constructor for CriteriaSearchParameter for a <code>String</code> parameter. 090 * Sets <code>searchIfNull</code> to <code>false</code> and uses the 091 * <code>LIKE_COMPARATOR</code>. 092 * 093 * @param parameterValueIn The actual value of the parameter. 094 * @param parameterPatternIn The pattern of this parameter (dot-separated path e.g. person.address.street). 095 */ 096 public CriteriaSearchParameter(String parameterValueIn, String parameterPatternIn) 097 { 098 this(parameterValueIn, parameterPatternIn, false, LIKE_COMPARATOR); 099 } 100 101 /** 102 * Constructor for CriteriaSearchParameter for a <code>String[]</code> parameter. 103 * Sets <code>searchIfNull</code> to <code>false</code> and uses the 104 * <code>LIKE_COMPARATOR</code>. 105 * 106 * @param parameterValueIn The actual value of the parameter. 107 * @param parameterPatternIn The pattern of this parameter (dot-separated path e.g. person.address.street). 108 */ 109 public CriteriaSearchParameter(String[] parameterValueIn, String parameterPatternIn) 110 { 111 this(parameterValueIn, parameterPatternIn, false, LIKE_COMPARATOR); 112 } 113 114 /** 115 * Constructor for CriteriaSearchParameter. Sets <code>searchIfNull</code> to <code>false</code>. 116 * 117 * @param parameterValueIn The actual value of the parameter. 118 * @param parameterPatternIn The pattern of this parameter (dot-separated path e.g. person.address.street). 119 * @param comparatorIn 120 */ 121 public CriteriaSearchParameter(Object parameterValueIn, String parameterPatternIn, int comparatorIn) 122 { 123 this(parameterValueIn, parameterPatternIn, false, comparatorIn); 124 } 125 126 /** 127 * Constructor for CriteriaSearchParameter. 128 * 129 * @param parameterValueIn The actual value of the parameter. 130 * @param parameterPatternIn The pattern of this parameter (dot-separated path e.g. person.address.street). 131 * @param searchIfNull Indicates whether the query should contain an 132 * <code>IS NULL</code> if the parameter is <code>null</code>. 133 */ 134 public CriteriaSearchParameter( 135 Object parameterValueIn, 136 String parameterPatternIn, 137 boolean searchIfNull) 138 { 139 this(parameterValueIn, parameterPatternIn, searchIfNull, EQUAL_COMPARATOR); 140 } 141 142 /** 143 * Constructor for CriteriaSearchParameter. 144 * 145 * @param parameterValueIn The actual value of the parameter. 146 * @param parameterPatternIn The pattern of this parameter (dot-separated path e.g. person.address.street). 147 * @param searchIfNull Indicates whether the query should contain an 148 * <code>IS NULL</code> if the parameter is <code>null</code>. 149 */ 150 public CriteriaSearchParameter( 151 String parameterValueIn, 152 String parameterPatternIn, 153 boolean searchIfNull) 154 { 155 this(parameterValueIn, parameterPatternIn, searchIfNull, LIKE_COMPARATOR); 156 } 157 158 /** 159 * Constructor for CriteriaSearchParameter. 160 * 161 * @param parameterValueIn The actual value of the parameter. 162 * @param parameterPatternIn The pattern of this parameter (dot-separated path e.g. person.address.street). 163 * @param searchIfNull Indicates whether the query should contain an 164 * <code>IS NULL</code> if the parameter is <code>null</code>. 165 */ 166 public CriteriaSearchParameter( 167 String[] parameterValueIn, 168 String parameterPatternIn, 169 boolean searchIfNull) 170 { 171 this(parameterValueIn, parameterPatternIn, searchIfNull, LIKE_COMPARATOR); 172 } 173 174 /** 175 * Constructor for CriteriaSearchParameter. 176 * 177 * @param parameterValueIn The actual value of the parameter. 178 * @param parameterPatternIn The pattern of this parameter (dot-separated path e.g. person.address.street). 179 * @param searchIfNull Indicates whether the query should contain an 180 * <code>IS NULL</code> if the parameter is <code>null</code>. 181 * @param comparatorIn Indicates what comparator is to be used (e.g. like, =, <, ...). 182 */ 183 public CriteriaSearchParameter( 184 Object parameterValueIn, 185 String parameterPatternIn, 186 boolean searchIfNull, 187 int comparatorIn) 188 { 189 super(parameterPatternIn, parameterValueIn); 190 this.parameterValue = parameterValueIn; 191 this.parameterPattern = parameterPatternIn; 192 super.setSearchIfNull(searchIfNull); 193 this.setComparator(comparatorIn); 194 } 195 196 /** 197 * Constructor for CriteriaSearchParameter. 198 * 199 * @param parameterValueIn The actual value of the parameter. 200 * @param parameterPatternIn The pattern of this parameter (dot-separated path e.g. person.address.street). 201 * @param searchIfNull Indicates whether the query should contain an 202 * <code>IS NULL</code> if the parameter is <code>null</code>. 203 * @param matchModeIn The hibernate matchmode to be used in string comparisons. 204 */ 205 public CriteriaSearchParameter( 206 Object parameterValueIn, 207 String parameterPatternIn, 208 boolean searchIfNull, 209 MatchMode matchModeIn) 210 { 211 this(parameterValueIn, parameterPatternIn, searchIfNull); 212 this.matchMode = matchModeIn; 213 } 214 215 /** 216 * Constructor for CriteriaSearchParameter. 217 * 218 * @param parameterValueIn The actual value of the parameter. 219 * @param parameterPatternIn The pattern of this parameter (dot-separated path e.g. person.address.street). 220 * @param searchIfNull Indicates whether the query should contain an 221 * <code>IS NULL</code> if the parameter is <code>null</code>. 222 * @param matchModeIn The hibernate matchmode to be used in string comparisons. 223 */ 224 public CriteriaSearchParameter( 225 String parameterValueIn, 226 String parameterPatternIn, 227 boolean searchIfNull, 228 MatchMode matchModeIn) 229 { 230 this(parameterValueIn, parameterPatternIn, searchIfNull); 231 this.matchMode = matchModeIn; 232 } 233 234 /** 235 * Constructor for CriteriaSearchParameter. 236 * 237 * @param parameterValueIn The actual value of the parameter. 238 * @param parameterPatternIn The pattern of this parameter (dot-separated path e.g. person.address.street). 239 * @param searchIfNull Indicates whether the query should contain an 240 * <code>IS NULL</code> if the parameter is <code>null</code>. 241 * @param matchModeIn The hibernate matchmode to be used in string comparisons. 242 */ 243 public CriteriaSearchParameter( 244 String[] parameterValueIn, 245 String parameterPatternIn, 246 boolean searchIfNull, 247 MatchMode matchModeIn) 248 { 249 this(parameterValueIn, parameterPatternIn, searchIfNull); 250 this.matchMode = matchModeIn; 251 } 252 253 /** 254 * Constructor for CriteriaSearchParameter. 255 * 256 * @param parameterValueIn The actual value of the parameter. 257 * @param parameterPatternIn The pattern of this parameter (dot-separated path e.g. person.address.street). 258 * @param searchIfNull Indicates whether the query should contain an 259 * <code>IS NULL</code> if the parameter is <code>null</code>. 260 * @param comparatorIn Indicates what comparator is to be used (e.g. like, =, <, ...). 261 * @param matchModeIn The hibernate matchmode to be used in string comparisons. 262 */ 263 public CriteriaSearchParameter( 264 String parameterValueIn, 265 String parameterPatternIn, 266 boolean searchIfNull, 267 int comparatorIn, 268 MatchMode matchModeIn) 269 { 270 this(parameterValueIn, parameterPatternIn, searchIfNull, comparatorIn); 271 this.matchMode = matchModeIn; 272 } 273 274 /** 275 * Constructor for CriteriaSearchParameter. 276 * 277 * @param parameterValueIn The actual value of the parameter. 278 * @param parameterPatternIn The pattern of this parameter (dot-separated path e.g. person.address.street). 279 * @param comparatorIn Indicates what comparator is to be used (e.g. like, =, <, ...). 280 * @param matchModeIn The hibernate matchmode to be used in string comparisons. 281 */ 282 public CriteriaSearchParameter( 283 Object parameterValueIn, 284 String parameterPatternIn, 285 int comparatorIn, 286 MatchMode matchModeIn) 287 { 288 this(parameterValueIn, parameterPatternIn, comparatorIn); 289 this.matchMode = matchModeIn; 290 } 291 292 /** 293 * Constructor for CriteriaSearchParameter. 294 * 295 * @param parameterValueIn The actual value of the parameter. 296 * @param parameterPatternIn The pattern of this parameter (dot-separated path e.g. person.address.street). 297 * @param matchModeIn The hibernate matchmode to be used in string comparisons. 298 */ 299 public CriteriaSearchParameter( 300 Object parameterValueIn, 301 String parameterPatternIn, 302 MatchMode matchModeIn) 303 { 304 this(parameterValueIn, parameterPatternIn); 305 this.matchMode = matchModeIn; 306 } 307 308 /** 309 * Constructor for CriteriaSearchParameter. 310 * 311 * @param parameterValueIn The actual value of the parameter. 312 * @param parameterPatternIn The pattern of this parameter (dot-separated path e.g. person.address.street). 313 * @param matchModeIn The hibernate matchmode to be used in string comparisons. 314 */ 315 public CriteriaSearchParameter( 316 String parameterValueIn, 317 String parameterPatternIn, 318 MatchMode matchModeIn) 319 { 320 this(parameterValueIn, parameterPatternIn); 321 this.matchMode = matchModeIn; 322 } 323 324 325 /** 326 * Constructor for CriteriaSearchParameter. 327 * 328 * @param parameterValueIn The actual value of the parameter. 329 * @param parameterPatternIn The pattern of this parameter (dot-separated path e.g. person.address.street). 330 * @param matchModeIn The hibernate matchmode to be used in string comparisons. 331 */ 332 public CriteriaSearchParameter( 333 String[] parameterValueIn, 334 String parameterPatternIn, 335 MatchMode matchModeIn) 336 { 337 this(parameterValueIn, parameterPatternIn); 338 this.matchMode = matchModeIn; 339 } 340 341 /** 342 * @return The pattern of this parameter (dot-separated path e.g. person.address.street). 343 */ 344 public String getParameterPattern() 345 { 346 return this.parameterPattern; 347 } 348 349 /** 350 * Sets the pattern of this parameter. 351 * 352 * @param parameterPatternIn The pattern of this parameter (dot-separated path e.g. person.address.street). 353 */ 354 public void setParameterPattern(String parameterPatternIn) 355 { 356 this.parameterPattern = parameterPatternIn; 357 } 358 359 /** 360 * Parse the parameter pattern and return the last part of the name. 361 * 362 * @param parameterPatternIn The parameter pattern. 363 * @return The last part of the parameter pattern, i.e. the attribute name. 364 */ 365 private String parseParameterName(String parameterPatternIn) 366 { 367 // parsing the pattern of the parameter 368 String[] path = CriteriaSearchParameter.PATTERN.split(parameterPatternIn); 369 return path[path.length - 1]; 370 } 371 372 /** 373 * @return The last part of the parameter pattern, i.e. the attribute name. 374 */ 375 public String getParameterName() 376 { 377 return parseParameterName(this.parameterPattern); 378 } 379 380 /** 381 * @return The value of this parameter. 382 */ 383 public Object getParameterValue() 384 { 385 return this.parameterValue; 386 } 387 388 /** 389 * Sets the value of this parameter. 390 * 391 * @param parameterValueIn The value of this parameter. 392 */ 393 public void setParameterValue(Object parameterValueIn) 394 { 395 this.parameterValue = parameterValueIn; 396 } 397 398 /** 399 * @return The hibernate matchmode of this parameter. 400 */ 401 public MatchMode getMatchMode() 402 { 403 return this.matchMode; 404 } 405 406 /** 407 * Sets the hibernate matchmode of this parameter. 408 * 409 * @param matchModeIn The hibernate matchmode. 410 */ 411 public void setMatchMode(MatchMode matchModeIn) 412 { 413 this.matchMode = matchModeIn; 414 } 415 416 /** 417 * @return The order (ascending or descending) for this parameter. 418 * @see SearchParameter#ORDER_ASC 419 * @see SearchParameter#ORDER_DESC 420 * @see SearchParameter#ORDER_UNSET 421 */ 422 public int getOrderDirection() 423 { 424 return this.orderDirection; 425 } 426 427 /** 428 * Sets the ordering for this parameter. 429 * 430 * @param orderDirectionIn The ordering for this parameter. 431 */ 432 public void setOrderDirection(int orderDirectionIn) 433 { 434 this.orderDirection = orderDirectionIn; 435 } 436 437 /** 438 * @return The relevance for this parameter. 439 * @see SearchParameter#ORDER_UNSET 440 */ 441 public int getOrderRelevance() 442 { 443 return this.orderRelevance; 444 } 445 446 /** 447 * Sets the ordering relevance for this parameter. 448 * 449 * @param relevanceIn The ordering relevance for this parameter. 450 */ 451 public void setOrderRelevance(int relevanceIn) 452 { 453 this.orderRelevance = relevanceIn; 454 } 455 456 private static final long serialVersionUID = 1L; 457}