1 // license-header java merge-point 2 // 3 // Attention: Generated code! Do not modify by hand! 4 // Generated by: hibernate/search/Search.java.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.io.Serializable; 29 import java.util.ArrayList; 30 import java.util.Arrays; 31 import java.util.Collection; 32 33 /** 34 * Stores the information necessary to perform a property search. 35 * 36 * @see PropertySearch 37 */ 38 public class Search 39 implements Serializable 40 { 41 private static final long serialVersionUID = 8277265070757689152L; 42 43 /** 44 * Constructs the search object. 45 * 46 * @param parametersIn the parameters to use. 47 * @param pageNumberIn the page number (if paging results). 48 * @param pageSizeIn the page size (if paging results). 49 * @param eagerFetchingIn whether or not the search will eagerly fetch the associations included in the search. 50 */ 51 public Search(SearchParameter[] parametersIn, int pageNumberIn, int pageSizeIn, boolean eagerFetchingIn) 52 { 53 this.pageNumber = pageNumberIn; 54 this.pageSize = pageSizeIn; 55 if (parametersIn != null) 56 { 57 this.parameters.addAll(Arrays.asList(parametersIn)); 58 } 59 this.eagerFetching = eagerFetchingIn; 60 } 61 62 /** 63 * Constructs the search object. 64 * 65 * @param parametersIn the parameters to use. 66 * @param pageNumberIn the page number (if paging results). 67 * @param pageSizeIn the page size (if paging results). 68 */ 69 public Search(SearchParameter[] parametersIn, int pageNumberIn, int pageSizeIn) 70 { 71 this(parametersIn, pageNumberIn, pageSizeIn, false); 72 } 73 74 /** 75 * Constructs the search object. 76 * 77 * @param parametersIn the parameters to use. 78 */ 79 public Search(SearchParameter[] parametersIn) 80 { 81 this(parametersIn, -1, -1, false); 82 } 83 84 /** 85 * Constructs the search object. 86 * 87 * @param parametersIn the parameters to use. 88 * @param eagerFetchingIn whether or not the search will eagerly fetch the associations included in the search. 89 */ 90 public Search(SearchParameter[] parametersIn, boolean eagerFetchingIn) 91 { 92 this(parametersIn, -1, -1, eagerFetchingIn); 93 } 94 95 private int pageNumber; 96 97 /** 98 * Gets the page number (if paging the results). 99 * 100 * @return the page number. 101 */ 102 public int getPageNumber() 103 { 104 return this.pageNumber; 105 } 106 107 /** 108 * Sets the page number (if paging the results). 109 * 110 * @param pageNumberIn the page number (if paging results). 111 * @return the current search instance. 112 */ 113 public Search setPageNumber(int pageNumberIn) 114 { 115 this.pageNumber = pageNumberIn; 116 return this; 117 } 118 119 private int pageSize; 120 121 /** 122 * Gets the size of the page (if paging the results). 123 * 124 * @return the page size. 125 */ 126 public int getPageSize() 127 { 128 return this.pageSize; 129 } 130 131 /** 132 * Sets the size of the page (if paging the results). 133 * 134 * @param pageSizeIn the page size. 135 * @return the current search instance. 136 */ 137 public Search setPageSize(int pageSizeIn) 138 { 139 this.pageSize = pageSizeIn; 140 return this; 141 } 142 143 private Collection<SearchParameter> parameters = new ArrayList<SearchParameter>(); 144 145 /** 146 * Gets the search parameters for this search object.. 147 * @return parameters.toArray(new SearchParameter[this.parameters.size()]) 148 */ 149 public SearchParameter[] getParameters() 150 { 151 return this.parameters.toArray(new SearchParameter[this.parameters.size()]); 152 } 153 154 /** 155 * Sets the search parameters for this search object. 156 * 157 * @param parametersIn 158 * @return the current search instance (this). 159 */ 160 public Search setParameters(SearchParameter[] parametersIn) 161 { 162 this.parameters = new ArrayList<SearchParameter>(Arrays.asList(parametersIn)); 163 return this; 164 } 165 166 /** 167 * Constructs the search object with no parameters. 168 */ 169 public Search() 170 { 171 this(null, -1, -1, false); 172 } 173 174 /** 175 * Adds a search parameter to the search. 176 * 177 * @param searchParameter the search parameter to add. 178 * @return the current search instance. 179 */ 180 public Search addSearchParameter(final SearchParameter searchParameter) 181 { 182 this.parameters.add(searchParameter); 183 return this; 184 } 185 186 private boolean eagerFetching; 187 188 /** 189 * Whether or not eager fetching is enabled (if it is enabled, all associations 190 * queried will be fetched eagerly). 191 * 192 * @return true/false 193 */ 194 public boolean isEagerFetching() 195 { 196 return this.eagerFetching; 197 } 198 199 /** 200 * Sets whether or not eager fetching is enabled (if it is enabled, all associations 201 * queried will be fetched eagerly). 202 * 203 * @param eagerFetchingIn whether or not to eager fetch the results. 204 * @return the current search instance (this). 205 */ 206 public Search setEagerFetching(boolean eagerFetchingIn) 207 { 208 this.eagerFetching = eagerFetchingIn; 209 return this; 210 } 211 212 /** 213 * Adds an "order by" clause for the search with default ascending order. 214 * 215 * @param propertyName the property name to order by. 216 * 217 * @return the current search instance. 218 */ 219 public Search addOrderBy(final String propertyName) 220 { 221 return this.addOrderBy(propertyName, SearchParameter.ORDER_ASC); 222 } 223 224 /** 225 * Adds an "order by" clause for the search. 226 * 227 * @param propertyName the property name to order by. 228 * @param order the order. Use: {@link SearchParameter#ORDER_ASC}, 229 * {@link SearchParameter#ORDER_DESC}, or {@link SearchParameter#ORDER_UNSET}. 230 * 231 * @return the current search instance. 232 */ 233 public Search addOrderBy(final String propertyName, final int order) 234 { 235 this.parameters.add(new SearchParameter(propertyName, null, -1, -1, order)); 236 return this; 237 } 238 239 /** 240 * Adds an "order by" clause for the search. 241 * 242 * @param propertyName the property name to order by. 243 * @param descending true/false; true for descending ordering, false for ascending ordering. 244 * 245 * @return the current search instance. 246 */ 247 public Search addOrderBy(String propertyName, final boolean descending) 248 { 249 this.addOrderBy(propertyName, descending ? SearchParameter.ORDER_DESC : SearchParameter.ORDER_ASC); 250 return this; 251 } 252 253 private boolean useSqlLimiting = false; 254 255 /** 256 * Whether or not to use sql limiting (if paging is being used). If this is set to false, then 257 * paging will be based on the actual entities returned instead of using SQL to limit the results. 258 * 259 * @return true/false 260 */ 261 public boolean isUseSqlLimiting() 262 { 263 return this.useSqlLimiting; 264 } 265 266 /** 267 * Sets whether or not to use sql limiting (if paging is being used). If this is set to false, then 268 * paging will be based on the actual entities returned instead of using SQL to limit the results. 269 * 270 * @param useSqlPaging whether or not to use SQL paging (default is <code>false</code>). 271 * 272 * @return the current search instance. 273 */ 274 public Search setUseSqlLimiting(boolean useSqlPaging) 275 { 276 this.useSqlLimiting = useSqlPaging; 277 return this; 278 } 279 }