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