001// license-header java merge-point 002// 003// Attention: Generated code! Do not modify by hand! 004// Generated by: hibernate/search/Search.java.vsl in andromda-spring-cartridge. 005// 006package fr.ifremer.adagio.core.dao; 007 008/* 009 * #%L 010 * SIH-Adagio :: Core 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.io.Serializable; 032import java.util.ArrayList; 033import java.util.Arrays; 034import java.util.Collection; 035 036/** 037 * Stores the information necessary to perform a property search. 038 * 039 * @see PropertySearch 040 */ 041public class Search 042 implements Serializable 043{ 044 private static final long serialVersionUID = 8277265070757689152L; 045 046 /** 047 * Constructs the search object. 048 * 049 * @param parametersIn the parameters to use. 050 * @param pageNumberIn the page number (if paging results). 051 * @param pageSizeIn the page size (if paging results). 052 * @param eagerFetchingIn whether or not the search will eagerly fetch the associations included in the search. 053 */ 054 public Search(SearchParameter[] parametersIn, int pageNumberIn, int pageSizeIn, boolean eagerFetchingIn) 055 { 056 this.pageNumber = pageNumberIn; 057 this.pageSize = pageSizeIn; 058 if (parametersIn != null) 059 { 060 this.parameters.addAll(Arrays.asList(parametersIn)); 061 } 062 this.eagerFetching = eagerFetchingIn; 063 } 064 065 /** 066 * Constructs the search object. 067 * 068 * @param parametersIn the parameters to use. 069 * @param pageNumberIn the page number (if paging results). 070 * @param pageSizeIn the page size (if paging results). 071 */ 072 public Search(SearchParameter[] parametersIn, int pageNumberIn, int pageSizeIn) 073 { 074 this(parametersIn, pageNumberIn, pageSizeIn, false); 075 } 076 077 /** 078 * Constructs the search object. 079 * 080 * @param parametersIn the parameters to use. 081 */ 082 public Search(SearchParameter[] parametersIn) 083 { 084 this(parametersIn, -1, -1, false); 085 } 086 087 /** 088 * Constructs the search object. 089 * 090 * @param parametersIn the parameters to use. 091 * @param eagerFetchingIn whether or not the search will eagerly fetch the associations included in the search. 092 */ 093 public Search(SearchParameter[] parametersIn, boolean eagerFetchingIn) 094 { 095 this(parametersIn, -1, -1, eagerFetchingIn); 096 } 097 098 private int pageNumber; 099 100 /** 101 * Gets the page number (if paging the results). 102 * 103 * @return the page number. 104 */ 105 public int getPageNumber() 106 { 107 return this.pageNumber; 108 } 109 110 /** 111 * Sets the page number (if paging the results). 112 * 113 * @param pageNumberIn the page number (if paging results). 114 * @return the current search instance. 115 */ 116 public Search setPageNumber(int pageNumberIn) 117 { 118 this.pageNumber = pageNumberIn; 119 return this; 120 } 121 122 private int pageSize; 123 124 /** 125 * Gets the size of the page (if paging the results). 126 * 127 * @return the page size. 128 */ 129 public int getPageSize() 130 { 131 return this.pageSize; 132 } 133 134 /** 135 * Sets the size of the page (if paging the results). 136 * 137 * @param pageSizeIn the page size. 138 * @return the current search instance. 139 */ 140 public Search setPageSize(int pageSizeIn) 141 { 142 this.pageSize = pageSizeIn; 143 return this; 144 } 145 146 private Collection<SearchParameter> parameters = new ArrayList<SearchParameter>(); 147 148 /** 149 * Gets the search parameters for this search object.. 150 * @return parameters.toArray(new SearchParameter[this.parameters.size()]) 151 */ 152 public SearchParameter[] getParameters() 153 { 154 return this.parameters.toArray(new SearchParameter[this.parameters.size()]); 155 } 156 157 /** 158 * Sets the search parameters for this search object. 159 * 160 * @param parametersIn 161 * @return the current search instance (this). 162 */ 163 public Search setParameters(SearchParameter[] parametersIn) 164 { 165 this.parameters = new ArrayList<SearchParameter>(Arrays.asList(parametersIn)); 166 return this; 167 } 168 169 /** 170 * Constructs the search object with no parameters. 171 */ 172 public Search() 173 { 174 this(null, -1, -1, false); 175 } 176 177 /** 178 * Adds a search parameter to the search. 179 * 180 * @param searchParameter the search parameter to add. 181 * @return the current search instance. 182 */ 183 public Search addSearchParameter(final SearchParameter searchParameter) 184 { 185 this.parameters.add(searchParameter); 186 return this; 187 } 188 189 private boolean eagerFetching; 190 191 /** 192 * Whether or not eager fetching is enabled (if it is enabled, all associations 193 * queried will be fetched eagerly). 194 * 195 * @return true/false 196 */ 197 public boolean isEagerFetching() 198 { 199 return this.eagerFetching; 200 } 201 202 /** 203 * Sets whether or not eager fetching is enabled (if it is enabled, all associations 204 * queried will be fetched eagerly). 205 * 206 * @param eagerFetchingIn whether or not to eager fetch the results. 207 * @return the current search instance (this). 208 */ 209 public Search setEagerFetching(boolean eagerFetchingIn) 210 { 211 this.eagerFetching = eagerFetchingIn; 212 return this; 213 } 214 215 /** 216 * Adds an "order by" clause for the search with default ascending order. 217 * 218 * @param propertyName the property name to order by. 219 * 220 * @return the current search instance. 221 */ 222 public Search addOrderBy(final String propertyName) 223 { 224 return this.addOrderBy(propertyName, SearchParameter.ORDER_ASC); 225 } 226 227 /** 228 * Adds an "order by" clause for the search. 229 * 230 * @param propertyName the property name to order by. 231 * @param order the order. Use: {@link SearchParameter#ORDER_ASC}, 232 * {@link SearchParameter#ORDER_DESC}, or {@link SearchParameter#ORDER_UNSET}. 233 * 234 * @return the current search instance. 235 */ 236 public Search addOrderBy(final String propertyName, final int order) 237 { 238 this.parameters.add(new SearchParameter(propertyName, null, -1, -1, order)); 239 return this; 240 } 241 242 /** 243 * Adds an "order by" clause for the search. 244 * 245 * @param propertyName the property name to order by. 246 * @param descending true/false; true for descending ordering, false for ascending ordering. 247 * 248 * @return the current search instance. 249 */ 250 public Search addOrderBy(String propertyName, final boolean descending) 251 { 252 this.addOrderBy(propertyName, descending ? SearchParameter.ORDER_DESC : SearchParameter.ORDER_ASC); 253 return this; 254 } 255 256 private boolean useSqlLimiting = false; 257 258 /** 259 * Whether or not to use sql limiting (if paging is being used). If this is set to false, then 260 * paging will be based on the actual entities returned instead of using SQL to limit the results. 261 * 262 * @return true/false 263 */ 264 public boolean isUseSqlLimiting() 265 { 266 return this.useSqlLimiting; 267 } 268 269 /** 270 * Sets whether or not to use sql limiting (if paging is being used). If this is set to false, then 271 * paging will be based on the actual entities returned instead of using SQL to limit the results. 272 * 273 * @param useSqlPaging whether or not to use SQL paging (default is <code>false</code>). 274 * 275 * @return the current search instance. 276 */ 277 public Search setUseSqlLimiting(boolean useSqlPaging) 278 { 279 this.useSqlLimiting = useSqlPaging; 280 return this; 281 } 282}