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             if (BatchSessionUtil.isEnabled()) {
130                 Object staleObject = session.get(PluginSettingImpl.class,
131                         pluginSetting.getPrimaryKeyObj());
132 
133                 if (staleObject != null) {
134                     session.evict(staleObject);
135                 }
136             }
137 
138             session.delete(pluginSetting);
139 
140             session.flush();
141 
142             return pluginSetting;
143         }
144         catch (Exception e) {
145             throw processException(e);
146         }
147         finally {
148             closeSession(session);
149 
150             FinderCacheUtil.clearCache(PluginSetting.class.getName());
151         }
152     }
153 
154     /**
155      * @deprecated Use <code>update(PluginSetting pluginSetting, boolean merge)</code>.
156      */
157     public PluginSetting update(PluginSetting pluginSetting)
158         throws SystemException {
159         if (_log.isWarnEnabled()) {
160             _log.warn(
161                 "Using the deprecated update(PluginSetting pluginSetting) method. Use update(PluginSetting pluginSetting, boolean merge) instead.");
162         }
163 
164         return update(pluginSetting, false);
165     }
166 
167     /**
168      * Add, update, or merge, the entity. This method also calls the model
169      * listeners to trigger the proper events associated with adding, deleting,
170      * or updating an entity.
171      *
172      * @param        pluginSetting the entity to add, update, or merge
173      * @param        merge boolean value for whether to merge the entity. The
174      *                default value is false. Setting merge to true is more
175      *                expensive and should only be true when pluginSetting is
176      *                transient. See LEP-5473 for a detailed discussion of this
177      *                method.
178      * @return        true if the portlet can be displayed via Ajax
179      */
180     public PluginSetting update(PluginSetting pluginSetting, boolean merge)
181         throws SystemException {
182         boolean isNew = pluginSetting.isNew();
183 
184         if (_listeners.length > 0) {
185             for (ModelListener listener : _listeners) {
186                 if (isNew) {
187                     listener.onBeforeCreate(pluginSetting);
188                 }
189                 else {
190                     listener.onBeforeUpdate(pluginSetting);
191                 }
192             }
193         }
194 
195         pluginSetting = updateImpl(pluginSetting, merge);
196 
197         if (_listeners.length > 0) {
198             for (ModelListener listener : _listeners) {
199                 if (isNew) {
200                     listener.onAfterCreate(pluginSetting);
201                 }
202                 else {
203                     listener.onAfterUpdate(pluginSetting);
204                 }
205             }
206         }
207 
208         return pluginSetting;
209     }
210 
211     public PluginSetting updateImpl(
212         com.liferay.portal.model.PluginSetting pluginSetting, boolean merge)
213         throws SystemException {
214         Session session = null;
215 
216         try {
217             session = openSession();
218 
219             BatchSessionUtil.update(session, pluginSetting, merge);
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 = null;
718 
719                 if (obc == null) {
720                     list = (List<PluginSetting>)QueryUtil.list(q, getDialect(),
721                             start, end, false);
722 
723                     Collections.sort(list);
724                 }
725                 else {
726                     list = (List<PluginSetting>)QueryUtil.list(q, getDialect(),
727                             start, end);
728                 }
729 
730                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
731                     finderClassName, finderMethodName, finderParams,
732                     finderArgs, list);
733 
734                 return list;
735             }
736             catch (Exception e) {
737                 throw processException(e);
738             }
739             finally {
740                 closeSession(session);
741             }
742         }
743         else {
744             return (List<PluginSetting>)result;
745         }
746     }
747 
748     public void removeByCompanyId(long companyId) throws SystemException {
749         for (PluginSetting pluginSetting : findByCompanyId(companyId)) {
750             remove(pluginSetting);
751         }
752     }
753 
754     public void removeByC_I_T(long companyId, String pluginId, String pluginType)
755         throws NoSuchPluginSettingException, SystemException {
756         PluginSetting pluginSetting = findByC_I_T(companyId, pluginId,
757                 pluginType);
758 
759         remove(pluginSetting);
760     }
761 
762     public void removeAll() throws SystemException {
763         for (PluginSetting pluginSetting : findAll()) {
764             remove(pluginSetting);
765         }
766     }
767 
768     public int countByCompanyId(long companyId) throws SystemException {
769         boolean finderClassNameCacheEnabled = PluginSettingModelImpl.CACHE_ENABLED;
770         String finderClassName = PluginSetting.class.getName();
771         String finderMethodName = "countByCompanyId";
772         String[] finderParams = new String[] { Long.class.getName() };
773         Object[] finderArgs = new Object[] { new Long(companyId) };
774 
775         Object result = null;
776 
777         if (finderClassNameCacheEnabled) {
778             result = FinderCacheUtil.getResult(finderClassName,
779                     finderMethodName, finderParams, finderArgs, this);
780         }
781 
782         if (result == null) {
783             Session session = null;
784 
785             try {
786                 session = openSession();
787 
788                 StringBuilder query = new StringBuilder();
789 
790                 query.append("SELECT COUNT(*) ");
791                 query.append(
792                     "FROM com.liferay.portal.model.PluginSetting WHERE ");
793 
794                 query.append("companyId = ?");
795 
796                 query.append(" ");
797 
798                 Query q = session.createQuery(query.toString());
799 
800                 QueryPos qPos = QueryPos.getInstance(q);
801 
802                 qPos.add(companyId);
803 
804                 Long count = null;
805 
806                 Iterator<Long> itr = q.list().iterator();
807 
808                 if (itr.hasNext()) {
809                     count = itr.next();
810                 }
811 
812                 if (count == null) {
813                     count = new Long(0);
814                 }
815 
816                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
817                     finderClassName, finderMethodName, finderParams,
818                     finderArgs, count);
819 
820                 return count.intValue();
821             }
822             catch (Exception e) {
823                 throw processException(e);
824             }
825             finally {
826                 closeSession(session);
827             }
828         }
829         else {
830             return ((Long)result).intValue();
831         }
832     }
833 
834     public int countByC_I_T(long companyId, String pluginId, String pluginType)
835         throws SystemException {
836         boolean finderClassNameCacheEnabled = PluginSettingModelImpl.CACHE_ENABLED;
837         String finderClassName = PluginSetting.class.getName();
838         String finderMethodName = "countByC_I_T";
839         String[] finderParams = new String[] {
840                 Long.class.getName(), String.class.getName(),
841                 String.class.getName()
842             };
843         Object[] finderArgs = new Object[] {
844                 new Long(companyId),
845                 
846                 pluginId,
847                 
848                 pluginType
849             };
850 
851         Object result = null;
852 
853         if (finderClassNameCacheEnabled) {
854             result = FinderCacheUtil.getResult(finderClassName,
855                     finderMethodName, finderParams, finderArgs, this);
856         }
857 
858         if (result == null) {
859             Session session = null;
860 
861             try {
862                 session = openSession();
863 
864                 StringBuilder query = new StringBuilder();
865 
866                 query.append("SELECT COUNT(*) ");
867                 query.append(
868                     "FROM com.liferay.portal.model.PluginSetting WHERE ");
869 
870                 query.append("companyId = ?");
871 
872                 query.append(" AND ");
873 
874                 if (pluginId == null) {
875                     query.append("pluginId IS NULL");
876                 }
877                 else {
878                     query.append("pluginId = ?");
879                 }
880 
881                 query.append(" AND ");
882 
883                 if (pluginType == null) {
884                     query.append("pluginType IS NULL");
885                 }
886                 else {
887                     query.append("pluginType = ?");
888                 }
889 
890                 query.append(" ");
891 
892                 Query q = session.createQuery(query.toString());
893 
894                 QueryPos qPos = QueryPos.getInstance(q);
895 
896                 qPos.add(companyId);
897 
898                 if (pluginId != null) {
899                     qPos.add(pluginId);
900                 }
901 
902                 if (pluginType != null) {
903                     qPos.add(pluginType);
904                 }
905 
906                 Long count = null;
907 
908                 Iterator<Long> itr = q.list().iterator();
909 
910                 if (itr.hasNext()) {
911                     count = itr.next();
912                 }
913 
914                 if (count == null) {
915                     count = new Long(0);
916                 }
917 
918                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
919                     finderClassName, finderMethodName, finderParams,
920                     finderArgs, count);
921 
922                 return count.intValue();
923             }
924             catch (Exception e) {
925                 throw processException(e);
926             }
927             finally {
928                 closeSession(session);
929             }
930         }
931         else {
932             return ((Long)result).intValue();
933         }
934     }
935 
936     public int countAll() throws SystemException {
937         boolean finderClassNameCacheEnabled = PluginSettingModelImpl.CACHE_ENABLED;
938         String finderClassName = PluginSetting.class.getName();
939         String finderMethodName = "countAll";
940         String[] finderParams = new String[] {  };
941         Object[] finderArgs = new Object[] {  };
942 
943         Object result = null;
944 
945         if (finderClassNameCacheEnabled) {
946             result = FinderCacheUtil.getResult(finderClassName,
947                     finderMethodName, finderParams, finderArgs, this);
948         }
949 
950         if (result == null) {
951             Session session = null;
952 
953             try {
954                 session = openSession();
955 
956                 Query q = session.createQuery(
957                         "SELECT COUNT(*) FROM com.liferay.portal.model.PluginSetting");
958 
959                 Long count = null;
960 
961                 Iterator<Long> itr = q.list().iterator();
962 
963                 if (itr.hasNext()) {
964                     count = itr.next();
965                 }
966 
967                 if (count == null) {
968                     count = new Long(0);
969                 }
970 
971                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
972                     finderClassName, finderMethodName, finderParams,
973                     finderArgs, count);
974 
975                 return count.intValue();
976             }
977             catch (Exception e) {
978                 throw processException(e);
979             }
980             finally {
981                 closeSession(session);
982             }
983         }
984         else {
985             return ((Long)result).intValue();
986         }
987     }
988 
989     public void registerListener(ModelListener listener) {
990         List<ModelListener> listeners = ListUtil.fromArray(_listeners);
991 
992         listeners.add(listener);
993 
994         _listeners = listeners.toArray(new ModelListener[listeners.size()]);
995     }
996 
997     public void unregisterListener(ModelListener listener) {
998         List<ModelListener> listeners = ListUtil.fromArray(_listeners);
999 
1000        listeners.remove(listener);
1001
1002        _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1003    }
1004
1005    public void afterPropertiesSet() {
1006        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1007                    com.liferay.portal.util.PropsUtil.get(
1008                        "value.object.listener.com.liferay.portal.model.PluginSetting")));
1009
1010        if (listenerClassNames.length > 0) {
1011            try {
1012                List<ModelListener> listeners = new ArrayList<ModelListener>();
1013
1014                for (String listenerClassName : listenerClassNames) {
1015                    listeners.add((ModelListener)Class.forName(
1016                            listenerClassName).newInstance());
1017                }
1018
1019                _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1020            }
1021            catch (Exception e) {
1022                _log.error(e);
1023            }
1024        }
1025    }
1026
1027    private static Log _log = LogFactory.getLog(PluginSettingPersistenceImpl.class);
1028    private ModelListener[] _listeners = new ModelListener[0];
1029}