001    /**
002     * Copyright (c) 2000-2013 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.Conjunction;
018    import com.liferay.portal.kernel.dao.orm.Criterion;
019    import com.liferay.portal.kernel.dao.orm.Disjunction;
020    import com.liferay.portal.kernel.dao.orm.RestrictionsFactory;
021    import com.liferay.portal.kernel.dao.orm.Type;
022    import com.liferay.portal.kernel.security.pacl.DoPrivileged;
023    
024    import java.util.Collection;
025    import java.util.Map;
026    
027    /**
028     * @author Raymond Augé
029     */
030    @DoPrivileged
031    public class RestrictionsFactoryImpl implements RestrictionsFactory {
032    
033            public Criterion allEq(Map<String, Criterion> propertyNameValues) {
034                    return new CriterionImpl(
035                            org.hibernate.criterion.Restrictions.allEq(propertyNameValues));
036            }
037    
038            public Criterion and(Criterion lhs, Criterion rhs) {
039                    CriterionImpl lhsImpl = (CriterionImpl)lhs;
040                    CriterionImpl rhsImpl = (CriterionImpl)rhs;
041    
042                    return new CriterionImpl(
043                            org.hibernate.criterion.Restrictions.and(
044                                    lhsImpl.getWrappedCriterion(), rhsImpl.getWrappedCriterion()));
045            }
046    
047            public Criterion between(String propertyName, Object lo, Object hi) {
048                    return new CriterionImpl(
049                            org.hibernate.criterion.Restrictions.between(propertyName, lo, hi));
050            }
051    
052            public Conjunction conjunction() {
053                    return new ConjunctionImpl(
054                            org.hibernate.criterion.Restrictions.conjunction());
055            }
056    
057            public Disjunction disjunction() {
058                    return new DisjunctionImpl(
059                            org.hibernate.criterion.Restrictions.disjunction());
060            }
061    
062            public Criterion eq(String propertyName, Object value) {
063                    return new CriterionImpl(
064                            org.hibernate.criterion.Restrictions.eq(propertyName, value));
065            }
066    
067            public Criterion eqProperty(String propertyName, String otherPropertyName) {
068                    return new CriterionImpl(
069                            org.hibernate.criterion.Restrictions.eqProperty(
070                                    propertyName, otherPropertyName));
071            }
072    
073            public Criterion ge(String propertyName, Object value) {
074                    return new CriterionImpl(
075                            org.hibernate.criterion.Restrictions.ge(propertyName, value));
076            }
077    
078            public Criterion geProperty(String propertyName, String otherPropertyName) {
079                    return new CriterionImpl(
080                            org.hibernate.criterion.Restrictions.geProperty(
081                                    propertyName, otherPropertyName));
082            }
083    
084            public Criterion gt(String propertyName, Object value) {
085                    return new CriterionImpl(
086                            org.hibernate.criterion.Restrictions.gt(propertyName, value));
087            }
088    
089            public Criterion gtProperty(String propertyName, String otherPropertyName) {
090                    return new CriterionImpl(
091                            org.hibernate.criterion.Restrictions.gtProperty(
092                                    propertyName, otherPropertyName));
093            }
094    
095            public Criterion ilike(String propertyName, Object value) {
096                    return new CriterionImpl(
097                            org.hibernate.criterion.Restrictions.ilike(propertyName, value));
098            }
099    
100            public Criterion in(String propertyName, Collection<Object> values) {
101                    return new CriterionImpl(
102                            org.hibernate.criterion.Restrictions.in(propertyName, values));
103            }
104    
105            public Criterion in(String propertyName, Object[] values) {
106                    return new CriterionImpl(
107                            org.hibernate.criterion.Restrictions.in(propertyName, values));
108            }
109    
110            public Criterion isEmpty(String propertyName) {
111                    return new CriterionImpl(
112                            org.hibernate.criterion.Restrictions.isEmpty(propertyName));
113            }
114    
115            public Criterion isNotEmpty(String propertyName) {
116                    return new CriterionImpl(
117                            org.hibernate.criterion.Restrictions.isNotEmpty(propertyName));
118            }
119    
120            public Criterion isNotNull(String propertyName) {
121                    return new CriterionImpl(
122                            org.hibernate.criterion.Restrictions.isNotNull(propertyName));
123            }
124    
125            public Criterion isNull(String propertyName) {
126                    return new CriterionImpl(
127                            org.hibernate.criterion.Restrictions.isNull(propertyName));
128            }
129    
130            public Criterion le(String propertyName, Object value) {
131                    return new CriterionImpl(
132                            org.hibernate.criterion.Restrictions.le(propertyName, value));
133            }
134    
135            public Criterion leProperty(String propertyName, String otherPropertyName) {
136                    return new CriterionImpl(
137                            org.hibernate.criterion.Restrictions.leProperty(
138                                    propertyName, otherPropertyName));
139            }
140    
141            public Criterion like(String propertyName, Object value) {
142                    return new CriterionImpl(
143                            org.hibernate.criterion.Restrictions.like(propertyName, value));
144            }
145    
146            public Criterion lt(String propertyName, Object value) {
147                    return new CriterionImpl(
148                            org.hibernate.criterion.Restrictions.lt(propertyName, value));
149            }
150    
151            public Criterion ltProperty(String propertyName, String otherPropertyName) {
152                    return new CriterionImpl(
153                            org.hibernate.criterion.Restrictions.ltProperty(
154                                    propertyName, otherPropertyName));
155            }
156    
157            public Criterion ne(String propertyName, Object value) {
158                    return new CriterionImpl(
159                            org.hibernate.criterion.Restrictions.ne(propertyName, value));
160            }
161    
162            public Criterion neProperty(String propertyName, String otherPropertyName) {
163                    return new CriterionImpl(
164                            org.hibernate.criterion.Restrictions.neProperty(
165                                    propertyName, otherPropertyName));
166            }
167    
168            public Criterion not(Criterion expression) {
169                    CriterionImpl expressionImpl = (CriterionImpl)expression;
170    
171                    return new CriterionImpl(
172                            org.hibernate.criterion.Restrictions.not(
173                                    expressionImpl.getWrappedCriterion()));
174            }
175    
176            public Criterion or(Criterion lhs, Criterion rhs) {
177                    CriterionImpl lhsImpl = (CriterionImpl)lhs;
178                    CriterionImpl rhsImpl = (CriterionImpl)rhs;
179    
180                    return new CriterionImpl(
181                            org.hibernate.criterion.Restrictions.or(
182                                    lhsImpl.getWrappedCriterion(), rhsImpl.getWrappedCriterion()));
183            }
184    
185            public Criterion sizeEq(String propertyName, int size) {
186                    return new CriterionImpl(
187                            org.hibernate.criterion.Restrictions.sizeEq(propertyName, size));
188            }
189    
190            public Criterion sizeGe(String propertyName, int size) {
191                    return new CriterionImpl(
192                            org.hibernate.criterion.Restrictions.sizeGe(propertyName, size));
193            }
194    
195            public Criterion sizeGt(String propertyName, int size) {
196                    return new CriterionImpl(
197                            org.hibernate.criterion.Restrictions.sizeGe(propertyName, size));
198            }
199    
200            public Criterion sizeLe(String propertyName, int size) {
201                    return new CriterionImpl(
202                            org.hibernate.criterion.Restrictions.sizeLe(propertyName, size));
203            }
204    
205            public Criterion sizeLt(String propertyName, int size) {
206                    return new CriterionImpl(
207                            org.hibernate.criterion.Restrictions.sizeLt(propertyName, size));
208            }
209    
210            public Criterion sizeNe(String propertyName, int size) {
211                    return new CriterionImpl(
212                            org.hibernate.criterion.Restrictions.sizeNe(propertyName, size));
213            }
214    
215            public Criterion sqlRestriction(String sql) {
216                    return new CriterionImpl(
217                            org.hibernate.criterion.Restrictions.sqlRestriction(sql));
218            }
219    
220            public Criterion sqlRestriction(String sql, Object value, Type type) {
221                    return new CriterionImpl(
222                            org.hibernate.criterion.Restrictions.sqlRestriction(
223                                    sql, value, TypeTranslator.translate(type)));
224            }
225    
226            public Criterion sqlRestriction(String sql, Object[] values, Type[] types) {
227                    org.hibernate.type.Type[] hibernateTypes =
228                            new org.hibernate.type.Type[types.length];
229    
230                    for (int i = 0; i < types.length; i++) {
231                            hibernateTypes[i] = TypeTranslator.translate(types[i]);
232                    }
233    
234                    return new CriterionImpl(
235                            org.hibernate.criterion.Restrictions.sqlRestriction(
236                                    sql, values, hibernateTypes));
237            }
238    
239    }