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