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