1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portlet.expando.service.persistence;
24  
25  import com.liferay.portal.SystemException;
26  import com.liferay.portal.kernel.dao.orm.QueryPos;
27  import com.liferay.portal.kernel.dao.orm.QueryUtil;
28  import com.liferay.portal.kernel.dao.orm.SQLQuery;
29  import com.liferay.portal.kernel.dao.orm.Session;
30  import com.liferay.portal.kernel.dao.orm.Type;
31  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
32  import com.liferay.portlet.expando.model.ExpandoValue;
33  import com.liferay.portlet.expando.model.impl.ExpandoValueImpl;
34  import com.liferay.util.dao.orm.CustomSQLUtil;
35  
36  import java.util.Iterator;
37  import java.util.List;
38  
39  /**
40   * <a href="ExpandoValueFinderImpl.java.html"><b><i>View Source</i></b></a>
41   *
42   * @author Raymond Augé
43   *
44   */
45  public class ExpandoValueFinderImpl
46      extends BasePersistenceImpl implements ExpandoValueFinder {
47  
48      public static String COUNT_BY_TC_TC_TN_CN =
49          ExpandoValueFinder.class.getName() + ".countByTC_TC_TN_CN";
50  
51      public static String COUNT_BY_TC_TC_TN_C =
52          ExpandoValueFinder.class.getName() + ".countByTC_TC_TN_C";
53  
54      public static String COUNT_BY_TC_TC_TN_CN_D =
55          ExpandoValueFinder.class.getName() + ".countByTC_TC_TN_CN_D";
56  
57      public static String FIND_BY_TC_TC_TN_CN =
58          ExpandoValueFinder.class.getName() + ".findByTC_TC_TN_CN";
59  
60      public static String FIND_BY_TC_TC_TN_C =
61          ExpandoValueFinder.class.getName() + ".findByTC_TC_TN_C";
62  
63      public static String FIND_BY_TC_TC_TN_CN_C =
64          ExpandoValueFinder.class.getName() + ".findByTC_TC_TN_CN_C";
65  
66      public static String FIND_BY_TC_TC_TN_CN_D =
67          ExpandoValueFinder.class.getName() + ".findByTC_TC_TN_CN_D";
68  
69      public int countByTC_TC_TN_CN(
70              long companyId, long classNameId, String tableName,
71              String columnName)
72          throws SystemException {
73  
74          Session session = null;
75  
76          try {
77              session = openSession();
78  
79              String sql = CustomSQLUtil.get(COUNT_BY_TC_TC_TN_CN);
80  
81              SQLQuery q = session.createSQLQuery(sql);
82  
83              q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
84  
85              QueryPos qPos = QueryPos.getInstance(q);
86  
87              qPos.add(companyId);
88              qPos.add(classNameId);
89              qPos.add(tableName);
90              qPos.add(columnName);
91  
92              Iterator<Long> itr = q.list().iterator();
93  
94              if (itr.hasNext()) {
95                  Long count = itr.next();
96  
97                  if (count != null) {
98                      return count.intValue();
99                  }
100             }
101 
102             return 0;
103         }
104         catch (Exception e) {
105             throw new SystemException(e);
106         }
107         finally {
108             closeSession(session);
109         }
110     }
111 
112     public int countByTC_TC_TN_C(
113             long companyId, long classNameId, String tableName, long classPK)
114         throws SystemException {
115 
116         Session session = null;
117 
118         try {
119             session = openSession();
120 
121             String sql = CustomSQLUtil.get(COUNT_BY_TC_TC_TN_C);
122 
123             SQLQuery q = session.createSQLQuery(sql);
124 
125             q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
126 
127             QueryPos qPos = QueryPos.getInstance(q);
128 
129             qPos.add(companyId);
130             qPos.add(classNameId);
131             qPos.add(tableName);
132             qPos.add(classPK);
133 
134             Iterator<Long> itr = q.list().iterator();
135 
136             if (itr.hasNext()) {
137                 Long count = itr.next();
138 
139                 if (count != null) {
140                     return count.intValue();
141                 }
142             }
143 
144             return 0;
145         }
146         catch (Exception e) {
147             throw new SystemException(e);
148         }
149         finally {
150             closeSession(session);
151         }
152     }
153 
154     public int countByTC_TC_TN_CN_D(
155             long companyId, long classNameId, String tableName,
156             String columnName, String data)
157         throws SystemException {
158 
159         Session session = null;
160 
161         try {
162             session = openSession();
163 
164             String sql = CustomSQLUtil.get(COUNT_BY_TC_TC_TN_CN_D);
165 
166             SQLQuery q = session.createSQLQuery(sql);
167 
168             q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
169 
170             QueryPos qPos = QueryPos.getInstance(q);
171 
172             qPos.add(companyId);
173             qPos.add(classNameId);
174             qPos.add(tableName);
175             qPos.add(columnName);
176             qPos.add(data);
177 
178             Iterator<Long> itr = q.list().iterator();
179 
180             if (itr.hasNext()) {
181                 Long count = itr.next();
182 
183                 if (count != null) {
184                     return count.intValue();
185                 }
186             }
187 
188             return 0;
189         }
190         catch (Exception e) {
191             throw new SystemException(e);
192         }
193         finally {
194             closeSession(session);
195         }
196     }
197 
198     public List<ExpandoValue> findByTC_TC_TN_CN(
199             long companyId, long classNameId, String tableName,
200             String columnName, int start, int end)
201         throws SystemException {
202 
203         Session session = null;
204 
205         try {
206             session = openSession();
207 
208             String sql = CustomSQLUtil.get(FIND_BY_TC_TC_TN_CN);
209 
210             SQLQuery q = session.createSQLQuery(sql);
211 
212             q.addEntity("ExpandoValue", ExpandoValueImpl.class);
213 
214             QueryPos qPos = QueryPos.getInstance(q);
215 
216             qPos.add(companyId);
217             qPos.add(classNameId);
218             qPos.add(tableName);
219             qPos.add(columnName);
220 
221             return (List<ExpandoValue>)QueryUtil.list(
222                 q, getDialect(), start, end);
223         }
224         catch (Exception e) {
225             throw new SystemException(e);
226         }
227         finally {
228             closeSession(session);
229         }
230     }
231 
232     public List<ExpandoValue> findByTC_TC_TN_C(
233             long companyId, long classNameId, String tableName, long classPK,
234             int start, int end)
235         throws SystemException {
236 
237         Session session = null;
238 
239         try {
240             session = openSession();
241 
242             String sql = CustomSQLUtil.get(FIND_BY_TC_TC_TN_C);
243 
244             SQLQuery q = session.createSQLQuery(sql);
245 
246             q.addEntity("ExpandoValue", ExpandoValueImpl.class);
247 
248             QueryPos qPos = QueryPos.getInstance(q);
249 
250             qPos.add(companyId);
251             qPos.add(classNameId);
252             qPos.add(tableName);
253             qPos.add(classPK);
254 
255             return (List<ExpandoValue>)QueryUtil.list(
256                 q, getDialect(), start, end);
257         }
258         catch (Exception e) {
259             throw new SystemException(e);
260         }
261         finally {
262             closeSession(session);
263         }
264     }
265 
266     public ExpandoValue fetchByTC_TC_TN_CN_C(
267             long companyId, long classNameId, String tableName,
268             String columnName, long classPK)
269         throws SystemException {
270 
271         Session session = null;
272 
273         try {
274             session = openSession();
275 
276             String sql = CustomSQLUtil.get(FIND_BY_TC_TC_TN_CN_C);
277 
278             SQLQuery q = session.createSQLQuery(sql);
279 
280             q.addEntity("ExpandoValue", ExpandoValueImpl.class);
281 
282             QueryPos qPos = QueryPos.getInstance(q);
283 
284             qPos.add(companyId);
285             qPos.add(classNameId);
286             qPos.add(tableName);
287             qPos.add(columnName);
288             qPos.add(classPK);
289 
290             return (ExpandoValue)q.uniqueResult();
291         }
292         catch (Exception e) {
293             throw new SystemException(e);
294         }
295         finally {
296             closeSession(session);
297         }
298     }
299 
300     public List<ExpandoValue> findByTC_TC_TN_CN_D(
301             long companyId, long classNameId, String tableName,
302             String columnName, String data, int start, int end)
303         throws SystemException {
304 
305         Session session = null;
306 
307         try {
308             session = openSession();
309 
310             String sql = CustomSQLUtil.get(FIND_BY_TC_TC_TN_CN_D);
311 
312             SQLQuery q = session.createSQLQuery(sql);
313 
314             q.addEntity("ExpandoValue", ExpandoValueImpl.class);
315 
316             QueryPos qPos = QueryPos.getInstance(q);
317 
318             qPos.add(companyId);
319             qPos.add(classNameId);
320             qPos.add(tableName);
321             qPos.add(columnName);
322             qPos.add(data);
323 
324             return (List<ExpandoValue>)QueryUtil.list(
325                 q, getDialect(), start, end);
326         }
327         catch (Exception e) {
328             throw new SystemException(e);
329         }
330         finally {
331             closeSession(session);
332         }
333     }
334 
335 }