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