1   /**
2    * Copyright (c) 2000-2008 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_TN_CN =
49          ExpandoValueFinder.class.getName() + ".countByTC_TN_CN";
50  
51      public static String COUNT_BY_TC_TN_C =
52          ExpandoValueFinder.class.getName() + ".countByTC_TN_C";
53  
54      public static String COUNT_BY_TC_TN_CN_D =
55          ExpandoValueFinder.class.getName() + ".countByTC_TN_CN_D";
56  
57      public static String FIND_BY_TC_TN_CN =
58          ExpandoValueFinder.class.getName() + ".findByTC_TN_CN";
59  
60      public static String FIND_BY_TC_TN_C =
61          ExpandoValueFinder.class.getName() + ".findByTC_TN_C";
62  
63      public static String FIND_BY_TC_TN_CN_C =
64          ExpandoValueFinder.class.getName() + ".findByTC_TN_CN_C";
65  
66      public static String FIND_BY_TC_TN_CN_D =
67          ExpandoValueFinder.class.getName() + ".findByTC_TN_CN_D";
68  
69      public int countByTC_TN_CN(
70              long classNameId, String tableName, String columnName)
71          throws SystemException {
72  
73          Session session = null;
74  
75          try {
76              session = openSession();
77  
78              String sql = CustomSQLUtil.get(COUNT_BY_TC_TN_CN);
79  
80              SQLQuery q = session.createSQLQuery(sql);
81  
82              q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
83  
84              QueryPos qPos = QueryPos.getInstance(q);
85  
86              qPos.add(classNameId);
87              qPos.add(tableName);
88              qPos.add(columnName);
89  
90              Iterator<Long> itr = q.list().iterator();
91  
92              if (itr.hasNext()) {
93                  Long count = itr.next();
94  
95                  if (count != null) {
96                      return count.intValue();
97                  }
98              }
99  
100             return 0;
101         }
102         catch (Exception e) {
103             throw new SystemException(e);
104         }
105         finally {
106             closeSession(session);
107         }
108     }
109 
110     public int countByTC_TN_C(
111             long classNameId, String tableName, long classPK)
112         throws SystemException {
113 
114         Session session = null;
115 
116         try {
117             session = openSession();
118 
119             String sql = CustomSQLUtil.get(COUNT_BY_TC_TN_C);
120 
121             SQLQuery q = session.createSQLQuery(sql);
122 
123             q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
124 
125             QueryPos qPos = QueryPos.getInstance(q);
126 
127             qPos.add(classNameId);
128             qPos.add(tableName);
129             qPos.add(classPK);
130 
131             Iterator<Long> itr = q.list().iterator();
132 
133             if (itr.hasNext()) {
134                 Long count = itr.next();
135 
136                 if (count != null) {
137                     return count.intValue();
138                 }
139             }
140 
141             return 0;
142         }
143         catch (Exception e) {
144             throw new SystemException(e);
145         }
146         finally {
147             closeSession(session);
148         }
149     }
150 
151     public int countByTC_TN_CN_D(
152             long classNameId, String tableName, String columnName, String data)
153         throws SystemException {
154 
155         Session session = null;
156 
157         try {
158             session = openSession();
159 
160             String sql = CustomSQLUtil.get(COUNT_BY_TC_TN_CN_D);
161 
162             SQLQuery q = session.createSQLQuery(sql);
163 
164             q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
165 
166             QueryPos qPos = QueryPos.getInstance(q);
167 
168             qPos.add(classNameId);
169             qPos.add(tableName);
170             qPos.add(columnName);
171             qPos.add(data);
172 
173             Iterator<Long> itr = q.list().iterator();
174 
175             if (itr.hasNext()) {
176                 Long count = itr.next();
177 
178                 if (count != null) {
179                     return count.intValue();
180                 }
181             }
182 
183             return 0;
184         }
185         catch (Exception e) {
186             throw new SystemException(e);
187         }
188         finally {
189             closeSession(session);
190         }
191     }
192 
193     public List<ExpandoValue> findByTC_TN_CN(
194             long classNameId, String tableName, String columnName, int start,
195             int end)
196         throws SystemException {
197 
198         Session session = null;
199 
200         try {
201             session = openSession();
202 
203             String sql = CustomSQLUtil.get(FIND_BY_TC_TN_CN);
204 
205             SQLQuery q = session.createSQLQuery(sql);
206 
207             q.addEntity("ExpandoValue", ExpandoValueImpl.class);
208 
209             QueryPos qPos = QueryPos.getInstance(q);
210 
211             qPos.add(classNameId);
212             qPos.add(tableName);
213             qPos.add(columnName);
214 
215             return (List<ExpandoValue>)QueryUtil.list(
216                 q, getDialect(), start, end);
217         }
218         catch (Exception e) {
219             throw new SystemException(e);
220         }
221         finally {
222             closeSession(session);
223         }
224     }
225 
226     public List<ExpandoValue> findByTC_TN_C(
227             long classNameId, String tableName, long classPK, int start,
228             int end)
229         throws SystemException {
230 
231         Session session = null;
232 
233         try {
234             session = openSession();
235 
236             String sql = CustomSQLUtil.get(FIND_BY_TC_TN_C);
237 
238             SQLQuery q = session.createSQLQuery(sql);
239 
240             q.addEntity("ExpandoValue", ExpandoValueImpl.class);
241 
242             QueryPos qPos = QueryPos.getInstance(q);
243 
244             qPos.add(classNameId);
245             qPos.add(tableName);
246             qPos.add(classPK);
247 
248             return (List<ExpandoValue>)QueryUtil.list(
249                 q, getDialect(), start, end);
250         }
251         catch (Exception e) {
252             throw new SystemException(e);
253         }
254         finally {
255             closeSession(session);
256         }
257     }
258 
259     public ExpandoValue fetchByTC_TN_CN_C(
260             long classNameId, String tableName, String columnName, long classPK)
261         throws SystemException {
262 
263         Session session = null;
264 
265         try {
266             session = openSession();
267 
268             String sql = CustomSQLUtil.get(FIND_BY_TC_TN_CN_C);
269 
270             SQLQuery q = session.createSQLQuery(sql);
271 
272             q.addEntity("ExpandoValue", ExpandoValueImpl.class);
273 
274             QueryPos qPos = QueryPos.getInstance(q);
275 
276             qPos.add(classNameId);
277             qPos.add(tableName);
278             qPos.add(columnName);
279             qPos.add(classPK);
280 
281             return (ExpandoValue)q.uniqueResult();
282         }
283         catch (Exception e) {
284             throw new SystemException(e);
285         }
286         finally {
287             closeSession(session);
288         }
289     }
290 
291     public List<ExpandoValue> findByTC_TN_CN_D(
292             long classNameId, String tableName, String columnName, String data,
293             int start, int end)
294         throws SystemException {
295 
296         Session session = null;
297 
298         try {
299             session = openSession();
300 
301             String sql = CustomSQLUtil.get(FIND_BY_TC_TN_CN_D);
302 
303             SQLQuery q = session.createSQLQuery(sql);
304 
305             q.addEntity("ExpandoValue", ExpandoValueImpl.class);
306 
307             QueryPos qPos = QueryPos.getInstance(q);
308 
309             qPos.add(classNameId);
310             qPos.add(tableName);
311             qPos.add(columnName);
312             qPos.add(data);
313 
314             return (List<ExpandoValue>)QueryUtil.list(
315                 q, getDialect(), start, end);
316         }
317         catch (Exception e) {
318             throw new SystemException(e);
319         }
320         finally {
321             closeSession(session);
322         }
323     }
324 
325 }