001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.dao.orm.hibernate;
016    
017    import com.liferay.portal.kernel.dao.orm.Criterion;
018    import com.liferay.portal.kernel.dao.orm.DynamicQuery;
019    import com.liferay.portal.kernel.dao.orm.Order;
020    import com.liferay.portal.kernel.dao.orm.Projection;
021    import com.liferay.portal.kernel.dao.orm.Property;
022    import com.liferay.portal.kernel.util.ListUtil;
023    import com.liferay.portal.kernel.util.ProxyUtil;
024    import com.liferay.portal.security.lang.DoPrivilegedHandler;
025    
026    import java.util.Collection;
027    
028    /**
029     * @author Brian Wing Shun Chan
030     */
031    public class PropertyImpl extends ProjectionImpl implements Property {
032    
033            public PropertyImpl(org.hibernate.criterion.Property property) {
034                    super(property);
035    
036                    _property = property;
037            }
038    
039            @Override
040            public Order asc() {
041                    return new OrderImpl(_property.asc());
042            }
043    
044            @Override
045            public Projection avg() {
046                    return new ProjectionImpl(_property.avg());
047            }
048    
049            @Override
050            public Criterion between(Object min, Object max) {
051                    return new CriterionImpl(_property.between(min, max));
052            }
053    
054            @Override
055            public Projection count() {
056                    return new ProjectionImpl(_property.count());
057            }
058    
059            @Override
060            public Order desc() {
061                    return new OrderImpl(_property.desc());
062            }
063    
064            @Override
065            public Criterion eq(DynamicQuery subselect) {
066                    DynamicQueryImpl dynamicQueryImpl = getDynamicQueryImpl(subselect);
067    
068                    return new CriterionImpl(
069                            _property.eq(dynamicQueryImpl.getDetachedCriteria()));
070            }
071    
072            @Override
073            public Criterion eq(Object value) {
074                    return new CriterionImpl(_property.eq(value));
075            }
076    
077            @Override
078            public Criterion eqAll(DynamicQuery subselect) {
079                    DynamicQueryImpl dynamicQueryImpl = getDynamicQueryImpl(subselect);
080    
081                    return new CriterionImpl(
082                            _property.eqAll(dynamicQueryImpl.getDetachedCriteria()));
083            }
084    
085            @Override
086            public Criterion eqProperty(Property other) {
087                    PropertyImpl propertyImpl = (PropertyImpl)other;
088    
089                    return new CriterionImpl(
090                            _property.eqProperty(propertyImpl.getWrappedProperty()));
091            }
092    
093            @Override
094            public Criterion eqProperty(String other) {
095                    return new CriterionImpl(_property.eqProperty(other));
096            }
097    
098            @Override
099            public Criterion ge(DynamicQuery subselect) {
100                    DynamicQueryImpl dynamicQueryImpl = getDynamicQueryImpl(subselect);
101    
102                    return new CriterionImpl(
103                            _property.ge(dynamicQueryImpl.getDetachedCriteria()));
104            }
105    
106            @Override
107            public Criterion ge(Object value) {
108                    return new CriterionImpl(_property.ge(value));
109            }
110    
111            @Override
112            public Criterion geAll(DynamicQuery subselect) {
113                    DynamicQueryImpl dynamicQueryImpl = getDynamicQueryImpl(subselect);
114    
115                    return new CriterionImpl(
116                            _property.geAll(dynamicQueryImpl.getDetachedCriteria()));
117            }
118    
119            @Override
120            public Criterion geProperty(Property other) {
121                    PropertyImpl propertyImpl = (PropertyImpl)other;
122    
123                    return new CriterionImpl(
124                            _property.geProperty(propertyImpl.getWrappedProperty()));
125            }
126    
127            @Override
128            public Criterion geProperty(String other) {
129                    return new CriterionImpl(_property.geProperty(other));
130            }
131    
132            @Override
133            public Criterion geSome(DynamicQuery subselect) {
134                    DynamicQueryImpl dynamicQueryImpl = getDynamicQueryImpl(subselect);
135    
136                    return new CriterionImpl(
137                            _property.geSome(dynamicQueryImpl.getDetachedCriteria()));
138            }
139    
140            @Override
141            public Property getProperty(String propertyName) {
142                    return new PropertyImpl(_property.getProperty(propertyName));
143            }
144    
145            public org.hibernate.criterion.Property getWrappedProperty() {
146                    return _property;
147            }
148    
149            @Override
150            public Projection group() {
151                    return new ProjectionImpl(_property.group());
152            }
153    
154            @Override
155            public Criterion gt(DynamicQuery subselect) {
156                    DynamicQueryImpl dynamicQueryImpl = getDynamicQueryImpl(subselect);
157    
158                    return new CriterionImpl(
159                            _property.gt(dynamicQueryImpl.getDetachedCriteria()));
160            }
161    
162            @Override
163            public Criterion gt(Object value) {
164                    return new CriterionImpl(_property.gt(value));
165            }
166    
167            @Override
168            public Criterion gtAll(DynamicQuery subselect) {
169                    DynamicQueryImpl dynamicQueryImpl = getDynamicQueryImpl(subselect);
170    
171                    return new CriterionImpl(
172                            _property.gtAll(dynamicQueryImpl.getDetachedCriteria()));
173            }
174    
175            @Override
176            public Criterion gtProperty(Property other) {
177                    PropertyImpl propertyImpl = (PropertyImpl)other;
178    
179                    return new CriterionImpl(
180                            _property.gtProperty(propertyImpl.getWrappedProperty()));
181            }
182    
183            @Override
184            public Criterion gtProperty(String other) {
185                    return new CriterionImpl(_property.gtProperty(other));
186            }
187    
188            @Override
189            public Criterion gtSome(DynamicQuery subselect) {
190                    DynamicQueryImpl dynamicQueryImpl = getDynamicQueryImpl(subselect);
191    
192                    return new CriterionImpl(
193                            _property.gtSome(dynamicQueryImpl.getDetachedCriteria()));
194            }
195    
196            @Override
197            public Criterion in(char[] values) {
198                    return in(ListUtil.toList(values));
199            }
200    
201            @Override
202            public Criterion in(Collection<?> values) {
203                    return new CriterionImpl(_property.in(values));
204            }
205    
206            @Override
207            public Criterion in(double[] values) {
208                    return in(ListUtil.toList(values));
209            }
210    
211            @Override
212            public Criterion in(DynamicQuery subselect) {
213                    DynamicQueryImpl dynamicQueryImpl = getDynamicQueryImpl(subselect);
214    
215                    return new CriterionImpl(
216                            _property.in(dynamicQueryImpl.getDetachedCriteria()));
217            }
218    
219            @Override
220            public Criterion in(float[] values) {
221                    return in(ListUtil.toList(values));
222            }
223    
224            @Override
225            public Criterion in(int[] values) {
226                    return in(ListUtil.toList(values));
227            }
228    
229            @Override
230            public Criterion in(long[] values) {
231                    return in(ListUtil.toList(values));
232            }
233    
234            @Override
235            public Criterion in(Object[] values) {
236                    return new CriterionImpl(_property.in(values));
237            }
238    
239            @Override
240            public Criterion in(short[] values) {
241                    return in(ListUtil.toList(values));
242            }
243    
244            @Override
245            public Criterion isEmpty() {
246                    return new CriterionImpl(_property.isEmpty());
247            }
248    
249            @Override
250            public Criterion isNotEmpty() {
251                    return new CriterionImpl(_property.isNotEmpty());
252            }
253    
254            @Override
255            public Criterion isNotNull() {
256                    return new CriterionImpl(_property.isNotNull());
257            }
258    
259            @Override
260            public Criterion isNull() {
261                    return new CriterionImpl(_property.isNull());
262            }
263    
264            @Override
265            public Criterion le(DynamicQuery subselect) {
266                    DynamicQueryImpl dynamicQueryImpl = getDynamicQueryImpl(subselect);
267    
268                    return new CriterionImpl(
269                            _property.le(dynamicQueryImpl.getDetachedCriteria()));
270            }
271    
272            @Override
273            public Criterion le(Object value) {
274                    return new CriterionImpl(_property.le(value));
275            }
276    
277            @Override
278            public Criterion leAll(DynamicQuery subselect) {
279                    DynamicQueryImpl dynamicQueryImpl = getDynamicQueryImpl(subselect);
280    
281                    return new CriterionImpl(
282                            _property.leAll(dynamicQueryImpl.getDetachedCriteria()));
283            }
284    
285            @Override
286            public Criterion leProperty(Property other) {
287                    PropertyImpl propertyImpl = (PropertyImpl)other;
288    
289                    return new CriterionImpl(
290                            _property.leProperty(propertyImpl.getWrappedProperty()));
291            }
292    
293            @Override
294            public Criterion leProperty(String other) {
295                    return new CriterionImpl(_property.leProperty(other));
296            }
297    
298            @Override
299            public Criterion leSome(DynamicQuery subselect) {
300                    DynamicQueryImpl dynamicQueryImpl = getDynamicQueryImpl(subselect);
301    
302                    return new CriterionImpl(
303                            _property.leSome(dynamicQueryImpl.getDetachedCriteria()));
304            }
305    
306            @Override
307            public Criterion like(Object value) {
308                    return new CriterionImpl(_property.like(value));
309            }
310    
311            @Override
312            public Criterion lt(DynamicQuery subselect) {
313                    DynamicQueryImpl dynamicQueryImpl = getDynamicQueryImpl(subselect);
314    
315                    return new CriterionImpl(
316                            _property.lt(dynamicQueryImpl.getDetachedCriteria()));
317            }
318    
319            @Override
320            public Criterion lt(Object value) {
321                    return new CriterionImpl(_property.lt(value));
322            }
323    
324            @Override
325            public Criterion ltAll(DynamicQuery subselect) {
326                    DynamicQueryImpl dynamicQueryImpl = getDynamicQueryImpl(subselect);
327    
328                    return new CriterionImpl(
329                            _property.ltAll(dynamicQueryImpl.getDetachedCriteria()));
330            }
331    
332            @Override
333            public Criterion ltProperty(Property other) {
334                    PropertyImpl propertyImpl = (PropertyImpl)other;
335    
336                    return new CriterionImpl(
337                            _property.ltProperty(propertyImpl.getWrappedProperty()));
338            }
339    
340            @Override
341            public Criterion ltProperty(String other) {
342                    return new CriterionImpl(_property.ltProperty(other));
343            }
344    
345            @Override
346            public Criterion ltSome(DynamicQuery subselect) {
347                    DynamicQueryImpl dynamicQueryImpl = getDynamicQueryImpl(subselect);
348    
349                    return new CriterionImpl(
350                            _property.ltSome(dynamicQueryImpl.getDetachedCriteria()));
351            }
352    
353            @Override
354            public Projection max() {
355                    return new ProjectionImpl(_property.max());
356            }
357    
358            @Override
359            public Projection min() {
360                    return new ProjectionImpl(_property.min());
361            }
362    
363            @Override
364            public Criterion ne(DynamicQuery subselect) {
365                    DynamicQueryImpl dynamicQueryImpl = getDynamicQueryImpl(subselect);
366    
367                    return new CriterionImpl(
368                            _property.ne(dynamicQueryImpl.getDetachedCriteria()));
369            }
370    
371            @Override
372            public Criterion ne(Object value) {
373                    return new CriterionImpl(_property.ne(value));
374            }
375    
376            @Override
377            public Criterion neProperty(Property other) {
378                    PropertyImpl propertyImpl = (PropertyImpl)other;
379    
380                    return new CriterionImpl(
381                            _property.neProperty(propertyImpl.getWrappedProperty()));
382            }
383    
384            @Override
385            public Criterion neProperty(String other) {
386                    return new CriterionImpl(_property.neProperty(other));
387            }
388    
389            @Override
390            public Criterion notIn(DynamicQuery subselect) {
391                    DynamicQueryImpl dynamicQueryImpl = getDynamicQueryImpl(subselect);
392    
393                    return new CriterionImpl(
394                            _property.notIn(dynamicQueryImpl.getDetachedCriteria()));
395            }
396    
397            protected DynamicQueryImpl getDynamicQueryImpl(DynamicQuery subselect) {
398                    if (subselect instanceof DynamicQueryImpl) {
399                            return (DynamicQueryImpl)subselect;
400                    }
401    
402                    if (ProxyUtil.isProxyClass(subselect.getClass())) {
403                            DoPrivilegedHandler doPrivilegedHandler =
404                                    (DoPrivilegedHandler)ProxyUtil.getInvocationHandler(subselect);
405    
406                            return (DynamicQueryImpl)doPrivilegedHandler.getActualBean();
407                    }
408    
409                    throw new IllegalArgumentException("Uanble to unwrap " + subselect);
410            }
411    
412            private final org.hibernate.criterion.Property _property;
413    
414    }