1   /**
2    * Copyright (c) 2000-2007 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.portal.service.persistence;
24  
25  import com.liferay.portal.NoSuchServiceComponentException;
26  import com.liferay.portal.SystemException;
27  import com.liferay.portal.kernel.dao.DynamicQuery;
28  import com.liferay.portal.kernel.dao.DynamicQueryInitializer;
29  import com.liferay.portal.kernel.util.OrderByComparator;
30  import com.liferay.portal.kernel.util.StringMaker;
31  import com.liferay.portal.kernel.util.StringPool;
32  import com.liferay.portal.model.ServiceComponent;
33  import com.liferay.portal.model.impl.ServiceComponentImpl;
34  import com.liferay.portal.service.persistence.BasePersistence;
35  import com.liferay.portal.spring.hibernate.FinderCache;
36  import com.liferay.portal.spring.hibernate.HibernateUtil;
37  
38  import com.liferay.util.dao.hibernate.QueryUtil;
39  
40  import org.apache.commons.logging.Log;
41  import org.apache.commons.logging.LogFactory;
42  
43  import org.hibernate.Query;
44  import org.hibernate.Session;
45  
46  import java.util.Collections;
47  import java.util.Iterator;
48  import java.util.List;
49  
50  /**
51   * <a href="ServiceComponentPersistenceImpl.java.html"><b><i>View Source</i></b></a>
52   *
53   * @author Brian Wing Shun Chan
54   *
55   */
56  public class ServiceComponentPersistenceImpl extends BasePersistence
57      implements ServiceComponentPersistence {
58      public ServiceComponent create(long serviceComponentId) {
59          ServiceComponent serviceComponent = new ServiceComponentImpl();
60          serviceComponent.setNew(true);
61          serviceComponent.setPrimaryKey(serviceComponentId);
62  
63          return serviceComponent;
64      }
65  
66      public ServiceComponent remove(long serviceComponentId)
67          throws NoSuchServiceComponentException, SystemException {
68          Session session = null;
69  
70          try {
71              session = openSession();
72  
73              ServiceComponent serviceComponent = (ServiceComponent)session.get(ServiceComponentImpl.class,
74                      new Long(serviceComponentId));
75  
76              if (serviceComponent == null) {
77                  if (_log.isWarnEnabled()) {
78                      _log.warn(
79                          "No ServiceComponent exists with the primary key " +
80                          serviceComponentId);
81                  }
82  
83                  throw new NoSuchServiceComponentException(
84                      "No ServiceComponent exists with the primary key " +
85                      serviceComponentId);
86              }
87  
88              return remove(serviceComponent);
89          }
90          catch (NoSuchServiceComponentException nsee) {
91              throw nsee;
92          }
93          catch (Exception e) {
94              throw HibernateUtil.processException(e);
95          }
96          finally {
97              closeSession(session);
98          }
99      }
100 
101     public ServiceComponent remove(ServiceComponent serviceComponent)
102         throws SystemException {
103         Session session = null;
104 
105         try {
106             session = openSession();
107             session.delete(serviceComponent);
108             session.flush();
109 
110             return serviceComponent;
111         }
112         catch (Exception e) {
113             throw HibernateUtil.processException(e);
114         }
115         finally {
116             closeSession(session);
117             FinderCache.clearCache(ServiceComponent.class.getName());
118         }
119     }
120 
121     public ServiceComponent update(
122         com.liferay.portal.model.ServiceComponent serviceComponent)
123         throws SystemException {
124         return update(serviceComponent, false);
125     }
126 
127     public ServiceComponent update(
128         com.liferay.portal.model.ServiceComponent serviceComponent,
129         boolean merge) throws SystemException {
130         Session session = null;
131 
132         try {
133             session = openSession();
134 
135             if (merge) {
136                 session.merge(serviceComponent);
137             }
138             else {
139                 if (serviceComponent.isNew()) {
140                     session.save(serviceComponent);
141                 }
142             }
143 
144             session.flush();
145             serviceComponent.setNew(false);
146 
147             return serviceComponent;
148         }
149         catch (Exception e) {
150             throw HibernateUtil.processException(e);
151         }
152         finally {
153             closeSession(session);
154             FinderCache.clearCache(ServiceComponent.class.getName());
155         }
156     }
157 
158     public ServiceComponent findByPrimaryKey(long serviceComponentId)
159         throws NoSuchServiceComponentException, SystemException {
160         ServiceComponent serviceComponent = fetchByPrimaryKey(serviceComponentId);
161 
162         if (serviceComponent == null) {
163             if (_log.isWarnEnabled()) {
164                 _log.warn("No ServiceComponent exists with the primary key " +
165                     serviceComponentId);
166             }
167 
168             throw new NoSuchServiceComponentException(
169                 "No ServiceComponent exists with the primary key " +
170                 serviceComponentId);
171         }
172 
173         return serviceComponent;
174     }
175 
176     public ServiceComponent fetchByPrimaryKey(long serviceComponentId)
177         throws SystemException {
178         Session session = null;
179 
180         try {
181             session = openSession();
182 
183             return (ServiceComponent)session.get(ServiceComponentImpl.class,
184                 new Long(serviceComponentId));
185         }
186         catch (Exception e) {
187             throw HibernateUtil.processException(e);
188         }
189         finally {
190             closeSession(session);
191         }
192     }
193 
194     public List findByBuildNamespace(String buildNamespace)
195         throws SystemException {
196         String finderClassName = ServiceComponent.class.getName();
197         String finderMethodName = "findByBuildNamespace";
198         String[] finderParams = new String[] { String.class.getName() };
199         Object[] finderArgs = new Object[] { buildNamespace };
200         Object result = FinderCache.getResult(finderClassName,
201                 finderMethodName, finderParams, finderArgs, getSessionFactory());
202 
203         if (result == null) {
204             Session session = null;
205 
206             try {
207                 session = openSession();
208 
209                 StringMaker query = new StringMaker();
210                 query.append(
211                     "FROM com.liferay.portal.model.ServiceComponent WHERE ");
212 
213                 if (buildNamespace == null) {
214                     query.append("buildNamespace IS NULL");
215                 }
216                 else {
217                     query.append("buildNamespace = ?");
218                 }
219 
220                 query.append(" ");
221                 query.append("ORDER BY ");
222                 query.append("buildNamespace DESC").append(", ");
223                 query.append("buildNumber DESC");
224 
225                 Query q = session.createQuery(query.toString());
226                 int queryPos = 0;
227 
228                 if (buildNamespace != null) {
229                     q.setString(queryPos++, buildNamespace);
230                 }
231 
232                 List list = q.list();
233                 FinderCache.putResult(finderClassName, finderMethodName,
234                     finderParams, finderArgs, list);
235 
236                 return list;
237             }
238             catch (Exception e) {
239                 throw HibernateUtil.processException(e);
240             }
241             finally {
242                 closeSession(session);
243             }
244         }
245         else {
246             return (List)result;
247         }
248     }
249 
250     public List findByBuildNamespace(String buildNamespace, int begin, int end)
251         throws SystemException {
252         return findByBuildNamespace(buildNamespace, begin, end, null);
253     }
254 
255     public List findByBuildNamespace(String buildNamespace, int begin, int end,
256         OrderByComparator obc) throws SystemException {
257         String finderClassName = ServiceComponent.class.getName();
258         String finderMethodName = "findByBuildNamespace";
259         String[] finderParams = new String[] {
260                 String.class.getName(), "java.lang.Integer", "java.lang.Integer",
261                 "com.liferay.portal.kernel.util.OrderByComparator"
262             };
263         Object[] finderArgs = new Object[] {
264                 buildNamespace, String.valueOf(begin), String.valueOf(end),
265                 String.valueOf(obc)
266             };
267         Object result = FinderCache.getResult(finderClassName,
268                 finderMethodName, finderParams, finderArgs, getSessionFactory());
269 
270         if (result == null) {
271             Session session = null;
272 
273             try {
274                 session = openSession();
275 
276                 StringMaker query = new StringMaker();
277                 query.append(
278                     "FROM com.liferay.portal.model.ServiceComponent WHERE ");
279 
280                 if (buildNamespace == null) {
281                     query.append("buildNamespace IS NULL");
282                 }
283                 else {
284                     query.append("buildNamespace = ?");
285                 }
286 
287                 query.append(" ");
288 
289                 if (obc != null) {
290                     query.append("ORDER BY ");
291                     query.append(obc.getOrderBy());
292                 }
293                 else {
294                     query.append("ORDER BY ");
295                     query.append("buildNamespace DESC").append(", ");
296                     query.append("buildNumber DESC");
297                 }
298 
299                 Query q = session.createQuery(query.toString());
300                 int queryPos = 0;
301 
302                 if (buildNamespace != null) {
303                     q.setString(queryPos++, buildNamespace);
304                 }
305 
306                 List list = QueryUtil.list(q, getDialect(), begin, end);
307                 FinderCache.putResult(finderClassName, finderMethodName,
308                     finderParams, finderArgs, list);
309 
310                 return list;
311             }
312             catch (Exception e) {
313                 throw HibernateUtil.processException(e);
314             }
315             finally {
316                 closeSession(session);
317             }
318         }
319         else {
320             return (List)result;
321         }
322     }
323 
324     public ServiceComponent findByBuildNamespace_First(String buildNamespace,
325         OrderByComparator obc)
326         throws NoSuchServiceComponentException, SystemException {
327         List list = findByBuildNamespace(buildNamespace, 0, 1, obc);
328 
329         if (list.size() == 0) {
330             StringMaker msg = new StringMaker();
331             msg.append("No ServiceComponent exists with the key ");
332             msg.append(StringPool.OPEN_CURLY_BRACE);
333             msg.append("buildNamespace=");
334             msg.append(buildNamespace);
335             msg.append(StringPool.CLOSE_CURLY_BRACE);
336             throw new NoSuchServiceComponentException(msg.toString());
337         }
338         else {
339             return (ServiceComponent)list.get(0);
340         }
341     }
342 
343     public ServiceComponent findByBuildNamespace_Last(String buildNamespace,
344         OrderByComparator obc)
345         throws NoSuchServiceComponentException, SystemException {
346         int count = countByBuildNamespace(buildNamespace);
347         List list = findByBuildNamespace(buildNamespace, count - 1, count, obc);
348 
349         if (list.size() == 0) {
350             StringMaker msg = new StringMaker();
351             msg.append("No ServiceComponent exists with the key ");
352             msg.append(StringPool.OPEN_CURLY_BRACE);
353             msg.append("buildNamespace=");
354             msg.append(buildNamespace);
355             msg.append(StringPool.CLOSE_CURLY_BRACE);
356             throw new NoSuchServiceComponentException(msg.toString());
357         }
358         else {
359             return (ServiceComponent)list.get(0);
360         }
361     }
362 
363     public ServiceComponent[] findByBuildNamespace_PrevAndNext(
364         long serviceComponentId, String buildNamespace, OrderByComparator obc)
365         throws NoSuchServiceComponentException, SystemException {
366         ServiceComponent serviceComponent = findByPrimaryKey(serviceComponentId);
367         int count = countByBuildNamespace(buildNamespace);
368         Session session = null;
369 
370         try {
371             session = openSession();
372 
373             StringMaker query = new StringMaker();
374             query.append(
375                 "FROM com.liferay.portal.model.ServiceComponent WHERE ");
376 
377             if (buildNamespace == null) {
378                 query.append("buildNamespace IS NULL");
379             }
380             else {
381                 query.append("buildNamespace = ?");
382             }
383 
384             query.append(" ");
385 
386             if (obc != null) {
387                 query.append("ORDER BY ");
388                 query.append(obc.getOrderBy());
389             }
390             else {
391                 query.append("ORDER BY ");
392                 query.append("buildNamespace DESC").append(", ");
393                 query.append("buildNumber DESC");
394             }
395 
396             Query q = session.createQuery(query.toString());
397             int queryPos = 0;
398 
399             if (buildNamespace != null) {
400                 q.setString(queryPos++, buildNamespace);
401             }
402 
403             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
404                     serviceComponent);
405             ServiceComponent[] array = new ServiceComponentImpl[3];
406             array[0] = (ServiceComponent)objArray[0];
407             array[1] = (ServiceComponent)objArray[1];
408             array[2] = (ServiceComponent)objArray[2];
409 
410             return array;
411         }
412         catch (Exception e) {
413             throw HibernateUtil.processException(e);
414         }
415         finally {
416             closeSession(session);
417         }
418     }
419 
420     public ServiceComponent findByBNS_BNU(String buildNamespace,
421         long buildNumber)
422         throws NoSuchServiceComponentException, SystemException {
423         ServiceComponent serviceComponent = fetchByBNS_BNU(buildNamespace,
424                 buildNumber);
425 
426         if (serviceComponent == null) {
427             StringMaker msg = new StringMaker();
428             msg.append("No ServiceComponent exists with the key ");
429             msg.append(StringPool.OPEN_CURLY_BRACE);
430             msg.append("buildNamespace=");
431             msg.append(buildNamespace);
432             msg.append(", ");
433             msg.append("buildNumber=");
434             msg.append(buildNumber);
435             msg.append(StringPool.CLOSE_CURLY_BRACE);
436 
437             if (_log.isWarnEnabled()) {
438                 _log.warn(msg.toString());
439             }
440 
441             throw new NoSuchServiceComponentException(msg.toString());
442         }
443 
444         return serviceComponent;
445     }
446 
447     public ServiceComponent fetchByBNS_BNU(String buildNamespace,
448         long buildNumber) throws SystemException {
449         String finderClassName = ServiceComponent.class.getName();
450         String finderMethodName = "fetchByBNS_BNU";
451         String[] finderParams = new String[] {
452                 String.class.getName(), Long.class.getName()
453             };
454         Object[] finderArgs = new Object[] { buildNamespace, new Long(buildNumber) };
455         Object result = FinderCache.getResult(finderClassName,
456                 finderMethodName, finderParams, finderArgs, getSessionFactory());
457 
458         if (result == null) {
459             Session session = null;
460 
461             try {
462                 session = openSession();
463 
464                 StringMaker query = new StringMaker();
465                 query.append(
466                     "FROM com.liferay.portal.model.ServiceComponent WHERE ");
467 
468                 if (buildNamespace == null) {
469                     query.append("buildNamespace IS NULL");
470                 }
471                 else {
472                     query.append("buildNamespace = ?");
473                 }
474 
475                 query.append(" AND ");
476                 query.append("buildNumber = ?");
477                 query.append(" ");
478                 query.append("ORDER BY ");
479                 query.append("buildNamespace DESC").append(", ");
480                 query.append("buildNumber DESC");
481 
482                 Query q = session.createQuery(query.toString());
483                 int queryPos = 0;
484 
485                 if (buildNamespace != null) {
486                     q.setString(queryPos++, buildNamespace);
487                 }
488 
489                 q.setLong(queryPos++, buildNumber);
490 
491                 List list = q.list();
492                 FinderCache.putResult(finderClassName, finderMethodName,
493                     finderParams, finderArgs, list);
494 
495                 if (list.size() == 0) {
496                     return null;
497                 }
498                 else {
499                     return (ServiceComponent)list.get(0);
500                 }
501             }
502             catch (Exception e) {
503                 throw HibernateUtil.processException(e);
504             }
505             finally {
506                 closeSession(session);
507             }
508         }
509         else {
510             List list = (List)result;
511 
512             if (list.size() == 0) {
513                 return null;
514             }
515             else {
516                 return (ServiceComponent)list.get(0);
517             }
518         }
519     }
520 
521     public List findWithDynamicQuery(DynamicQueryInitializer queryInitializer)
522         throws SystemException {
523         Session session = null;
524 
525         try {
526             session = openSession();
527 
528             DynamicQuery query = queryInitializer.initialize(session);
529 
530             return query.list();
531         }
532         catch (Exception e) {
533             throw HibernateUtil.processException(e);
534         }
535         finally {
536             closeSession(session);
537         }
538     }
539 
540     public List findWithDynamicQuery(DynamicQueryInitializer queryInitializer,
541         int begin, int end) throws SystemException {
542         Session session = null;
543 
544         try {
545             session = openSession();
546 
547             DynamicQuery query = queryInitializer.initialize(session);
548             query.setLimit(begin, end);
549 
550             return query.list();
551         }
552         catch (Exception e) {
553             throw HibernateUtil.processException(e);
554         }
555         finally {
556             closeSession(session);
557         }
558     }
559 
560     public List findAll() throws SystemException {
561         return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
562     }
563 
564     public List findAll(int begin, int end) throws SystemException {
565         return findAll(begin, end, null);
566     }
567 
568     public List findAll(int begin, int end, OrderByComparator obc)
569         throws SystemException {
570         String finderClassName = ServiceComponent.class.getName();
571         String finderMethodName = "findAll";
572         String[] finderParams = new String[] {
573                 "java.lang.Integer", "java.lang.Integer",
574                 "com.liferay.portal.kernel.util.OrderByComparator"
575             };
576         Object[] finderArgs = new Object[] {
577                 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
578             };
579         Object result = FinderCache.getResult(finderClassName,
580                 finderMethodName, finderParams, finderArgs, getSessionFactory());
581 
582         if (result == null) {
583             Session session = null;
584 
585             try {
586                 session = openSession();
587 
588                 StringMaker query = new StringMaker();
589                 query.append("FROM com.liferay.portal.model.ServiceComponent ");
590 
591                 if (obc != null) {
592                     query.append("ORDER BY ");
593                     query.append(obc.getOrderBy());
594                 }
595                 else {
596                     query.append("ORDER BY ");
597                     query.append("buildNamespace DESC").append(", ");
598                     query.append("buildNumber DESC");
599                 }
600 
601                 Query q = session.createQuery(query.toString());
602                 List list = QueryUtil.list(q, getDialect(), begin, end);
603 
604                 if (obc == null) {
605                     Collections.sort(list);
606                 }
607 
608                 FinderCache.putResult(finderClassName, finderMethodName,
609                     finderParams, finderArgs, list);
610 
611                 return list;
612             }
613             catch (Exception e) {
614                 throw HibernateUtil.processException(e);
615             }
616             finally {
617                 closeSession(session);
618             }
619         }
620         else {
621             return (List)result;
622         }
623     }
624 
625     public void removeByBuildNamespace(String buildNamespace)
626         throws SystemException {
627         Iterator itr = findByBuildNamespace(buildNamespace).iterator();
628 
629         while (itr.hasNext()) {
630             ServiceComponent serviceComponent = (ServiceComponent)itr.next();
631             remove(serviceComponent);
632         }
633     }
634 
635     public void removeByBNS_BNU(String buildNamespace, long buildNumber)
636         throws NoSuchServiceComponentException, SystemException {
637         ServiceComponent serviceComponent = findByBNS_BNU(buildNamespace,
638                 buildNumber);
639         remove(serviceComponent);
640     }
641 
642     public void removeAll() throws SystemException {
643         Iterator itr = findAll().iterator();
644 
645         while (itr.hasNext()) {
646             remove((ServiceComponent)itr.next());
647         }
648     }
649 
650     public int countByBuildNamespace(String buildNamespace)
651         throws SystemException {
652         String finderClassName = ServiceComponent.class.getName();
653         String finderMethodName = "countByBuildNamespace";
654         String[] finderParams = new String[] { String.class.getName() };
655         Object[] finderArgs = new Object[] { buildNamespace };
656         Object result = FinderCache.getResult(finderClassName,
657                 finderMethodName, finderParams, finderArgs, getSessionFactory());
658 
659         if (result == null) {
660             Session session = null;
661 
662             try {
663                 session = openSession();
664 
665                 StringMaker query = new StringMaker();
666                 query.append("SELECT COUNT(*) ");
667                 query.append(
668                     "FROM com.liferay.portal.model.ServiceComponent WHERE ");
669 
670                 if (buildNamespace == null) {
671                     query.append("buildNamespace IS NULL");
672                 }
673                 else {
674                     query.append("buildNamespace = ?");
675                 }
676 
677                 query.append(" ");
678 
679                 Query q = session.createQuery(query.toString());
680                 int queryPos = 0;
681 
682                 if (buildNamespace != null) {
683                     q.setString(queryPos++, buildNamespace);
684                 }
685 
686                 Long count = null;
687                 Iterator itr = q.list().iterator();
688 
689                 if (itr.hasNext()) {
690                     count = (Long)itr.next();
691                 }
692 
693                 if (count == null) {
694                     count = new Long(0);
695                 }
696 
697                 FinderCache.putResult(finderClassName, finderMethodName,
698                     finderParams, finderArgs, count);
699 
700                 return count.intValue();
701             }
702             catch (Exception e) {
703                 throw HibernateUtil.processException(e);
704             }
705             finally {
706                 closeSession(session);
707             }
708         }
709         else {
710             return ((Long)result).intValue();
711         }
712     }
713 
714     public int countByBNS_BNU(String buildNamespace, long buildNumber)
715         throws SystemException {
716         String finderClassName = ServiceComponent.class.getName();
717         String finderMethodName = "countByBNS_BNU";
718         String[] finderParams = new String[] {
719                 String.class.getName(), Long.class.getName()
720             };
721         Object[] finderArgs = new Object[] { buildNamespace, new Long(buildNumber) };
722         Object result = FinderCache.getResult(finderClassName,
723                 finderMethodName, finderParams, finderArgs, getSessionFactory());
724 
725         if (result == null) {
726             Session session = null;
727 
728             try {
729                 session = openSession();
730 
731                 StringMaker query = new StringMaker();
732                 query.append("SELECT COUNT(*) ");
733                 query.append(
734                     "FROM com.liferay.portal.model.ServiceComponent WHERE ");
735 
736                 if (buildNamespace == null) {
737                     query.append("buildNamespace IS NULL");
738                 }
739                 else {
740                     query.append("buildNamespace = ?");
741                 }
742 
743                 query.append(" AND ");
744                 query.append("buildNumber = ?");
745                 query.append(" ");
746 
747                 Query q = session.createQuery(query.toString());
748                 int queryPos = 0;
749 
750                 if (buildNamespace != null) {
751                     q.setString(queryPos++, buildNamespace);
752                 }
753 
754                 q.setLong(queryPos++, buildNumber);
755 
756                 Long count = null;
757                 Iterator itr = q.list().iterator();
758 
759                 if (itr.hasNext()) {
760                     count = (Long)itr.next();
761                 }
762 
763                 if (count == null) {
764                     count = new Long(0);
765                 }
766 
767                 FinderCache.putResult(finderClassName, finderMethodName,
768                     finderParams, finderArgs, count);
769 
770                 return count.intValue();
771             }
772             catch (Exception e) {
773                 throw HibernateUtil.processException(e);
774             }
775             finally {
776                 closeSession(session);
777             }
778         }
779         else {
780             return ((Long)result).intValue();
781         }
782     }
783 
784     public int countAll() throws SystemException {
785         String finderClassName = ServiceComponent.class.getName();
786         String finderMethodName = "countAll";
787         String[] finderParams = new String[] {  };
788         Object[] finderArgs = new Object[] {  };
789         Object result = FinderCache.getResult(finderClassName,
790                 finderMethodName, finderParams, finderArgs, getSessionFactory());
791 
792         if (result == null) {
793             Session session = null;
794 
795             try {
796                 session = openSession();
797 
798                 StringMaker query = new StringMaker();
799                 query.append("SELECT COUNT(*) ");
800                 query.append("FROM com.liferay.portal.model.ServiceComponent");
801 
802                 Query q = session.createQuery(query.toString());
803                 Long count = null;
804                 Iterator itr = q.list().iterator();
805 
806                 if (itr.hasNext()) {
807                     count = (Long)itr.next();
808                 }
809 
810                 if (count == null) {
811                     count = new Long(0);
812                 }
813 
814                 FinderCache.putResult(finderClassName, finderMethodName,
815                     finderParams, finderArgs, count);
816 
817                 return count.intValue();
818             }
819             catch (Exception e) {
820                 throw HibernateUtil.processException(e);
821             }
822             finally {
823                 closeSession(session);
824             }
825         }
826         else {
827             return ((Long)result).intValue();
828         }
829     }
830 
831     protected void initDao() {
832     }
833 
834     private static Log _log = LogFactory.getLog(ServiceComponentPersistenceImpl.class);
835 }