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