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.NoSuchPortletPreferencesException;
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.PortletPreferences;
40  import com.liferay.portal.model.impl.PortletPreferencesImpl;
41  import com.liferay.portal.model.impl.PortletPreferencesModelImpl;
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="PortletPreferencesPersistenceImpl.java.html"><b><i>View Source</i></b></a>
54   *
55   * @author Brian Wing Shun Chan
56   *
57   */
58  public class PortletPreferencesPersistenceImpl extends BasePersistenceImpl
59      implements PortletPreferencesPersistence {
60      public PortletPreferences create(long portletPreferencesId) {
61          PortletPreferences portletPreferences = new PortletPreferencesImpl();
62  
63          portletPreferences.setNew(true);
64          portletPreferences.setPrimaryKey(portletPreferencesId);
65  
66          return portletPreferences;
67      }
68  
69      public PortletPreferences remove(long portletPreferencesId)
70          throws NoSuchPortletPreferencesException, SystemException {
71          Session session = null;
72  
73          try {
74              session = openSession();
75  
76              PortletPreferences portletPreferences = (PortletPreferences)session.get(PortletPreferencesImpl.class,
77                      new Long(portletPreferencesId));
78  
79              if (portletPreferences == null) {
80                  if (_log.isWarnEnabled()) {
81                      _log.warn(
82                          "No PortletPreferences exists with the primary key " +
83                          portletPreferencesId);
84                  }
85  
86                  throw new NoSuchPortletPreferencesException(
87                      "No PortletPreferences exists with the primary key " +
88                      portletPreferencesId);
89              }
90  
91              return remove(portletPreferences);
92          }
93          catch (NoSuchPortletPreferencesException nsee) {
94              throw nsee;
95          }
96          catch (Exception e) {
97              throw processException(e);
98          }
99          finally {
100             closeSession(session);
101         }
102     }
103 
104     public PortletPreferences remove(PortletPreferences portletPreferences)
105         throws SystemException {
106         if (_listeners.length > 0) {
107             for (ModelListener listener : _listeners) {
108                 listener.onBeforeRemove(portletPreferences);
109             }
110         }
111 
112         portletPreferences = removeImpl(portletPreferences);
113 
114         if (_listeners.length > 0) {
115             for (ModelListener listener : _listeners) {
116                 listener.onAfterRemove(portletPreferences);
117             }
118         }
119 
120         return portletPreferences;
121     }
122 
123     protected PortletPreferences removeImpl(
124         PortletPreferences portletPreferences) throws SystemException {
125         Session session = null;
126 
127         try {
128             session = openSession();
129 
130             session.delete(portletPreferences);
131 
132             session.flush();
133 
134             return portletPreferences;
135         }
136         catch (Exception e) {
137             throw processException(e);
138         }
139         finally {
140             closeSession(session);
141 
142             FinderCacheUtil.clearCache(PortletPreferences.class.getName());
143         }
144     }
145 
146     /**
147      * @deprecated Use <code>update(PortletPreferences portletPreferences, boolean merge)</code>.
148      */
149     public PortletPreferences update(PortletPreferences portletPreferences)
150         throws SystemException {
151         if (_log.isWarnEnabled()) {
152             _log.warn(
153                 "Using the deprecated update(PortletPreferences portletPreferences) method. Use update(PortletPreferences portletPreferences, boolean merge) instead.");
154         }
155 
156         return update(portletPreferences, false);
157     }
158 
159     /**
160      * Add, update, or merge, the entity. This method also calls the model
161      * listeners to trigger the proper events associated with adding, deleting,
162      * or updating an entity.
163      *
164      * @param        portletPreferences the entity to add, update, or merge
165      * @param        merge boolean value for whether to merge the entity. The
166      *                default value is false. Setting merge to true is more
167      *                expensive and should only be true when portletPreferences is
168      *                transient. See LEP-5473 for a detailed discussion of this
169      *                method.
170      * @return        true if the portlet can be displayed via Ajax
171      */
172     public PortletPreferences update(PortletPreferences portletPreferences,
173         boolean merge) throws SystemException {
174         boolean isNew = portletPreferences.isNew();
175 
176         if (_listeners.length > 0) {
177             for (ModelListener listener : _listeners) {
178                 if (isNew) {
179                     listener.onBeforeCreate(portletPreferences);
180                 }
181                 else {
182                     listener.onBeforeUpdate(portletPreferences);
183                 }
184             }
185         }
186 
187         portletPreferences = updateImpl(portletPreferences, merge);
188 
189         if (_listeners.length > 0) {
190             for (ModelListener listener : _listeners) {
191                 if (isNew) {
192                     listener.onAfterCreate(portletPreferences);
193                 }
194                 else {
195                     listener.onAfterUpdate(portletPreferences);
196                 }
197             }
198         }
199 
200         return portletPreferences;
201     }
202 
203     public PortletPreferences updateImpl(
204         com.liferay.portal.model.PortletPreferences portletPreferences,
205         boolean merge) throws SystemException {
206         Session session = null;
207 
208         try {
209             session = openSession();
210 
211             if (merge) {
212                 session.merge(portletPreferences);
213             }
214             else {
215                 if (portletPreferences.isNew()) {
216                     session.save(portletPreferences);
217                 }
218             }
219 
220             session.flush();
221 
222             portletPreferences.setNew(false);
223 
224             return portletPreferences;
225         }
226         catch (Exception e) {
227             throw processException(e);
228         }
229         finally {
230             closeSession(session);
231 
232             FinderCacheUtil.clearCache(PortletPreferences.class.getName());
233         }
234     }
235 
236     public PortletPreferences findByPrimaryKey(long portletPreferencesId)
237         throws NoSuchPortletPreferencesException, SystemException {
238         PortletPreferences portletPreferences = fetchByPrimaryKey(portletPreferencesId);
239 
240         if (portletPreferences == null) {
241             if (_log.isWarnEnabled()) {
242                 _log.warn("No PortletPreferences exists with the primary key " +
243                     portletPreferencesId);
244             }
245 
246             throw new NoSuchPortletPreferencesException(
247                 "No PortletPreferences exists with the primary key " +
248                 portletPreferencesId);
249         }
250 
251         return portletPreferences;
252     }
253 
254     public PortletPreferences fetchByPrimaryKey(long portletPreferencesId)
255         throws SystemException {
256         Session session = null;
257 
258         try {
259             session = openSession();
260 
261             return (PortletPreferences)session.get(PortletPreferencesImpl.class,
262                 new Long(portletPreferencesId));
263         }
264         catch (Exception e) {
265             throw processException(e);
266         }
267         finally {
268             closeSession(session);
269         }
270     }
271 
272     public List<PortletPreferences> findByPlid(long plid)
273         throws SystemException {
274         boolean finderClassNameCacheEnabled = PortletPreferencesModelImpl.CACHE_ENABLED;
275         String finderClassName = PortletPreferences.class.getName();
276         String finderMethodName = "findByPlid";
277         String[] finderParams = new String[] { Long.class.getName() };
278         Object[] finderArgs = new Object[] { new Long(plid) };
279 
280         Object result = null;
281 
282         if (finderClassNameCacheEnabled) {
283             result = FinderCacheUtil.getResult(finderClassName,
284                     finderMethodName, finderParams, finderArgs, this);
285         }
286 
287         if (result == null) {
288             Session session = null;
289 
290             try {
291                 session = openSession();
292 
293                 StringBuilder query = new StringBuilder();
294 
295                 query.append(
296                     "FROM com.liferay.portal.model.PortletPreferences WHERE ");
297 
298                 query.append("plid = ?");
299 
300                 query.append(" ");
301 
302                 Query q = session.createQuery(query.toString());
303 
304                 QueryPos qPos = QueryPos.getInstance(q);
305 
306                 qPos.add(plid);
307 
308                 List<PortletPreferences> list = q.list();
309 
310                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
311                     finderClassName, finderMethodName, finderParams,
312                     finderArgs, list);
313 
314                 return list;
315             }
316             catch (Exception e) {
317                 throw processException(e);
318             }
319             finally {
320                 closeSession(session);
321             }
322         }
323         else {
324             return (List<PortletPreferences>)result;
325         }
326     }
327 
328     public List<PortletPreferences> findByPlid(long plid, int start, int end)
329         throws SystemException {
330         return findByPlid(plid, start, end, null);
331     }
332 
333     public List<PortletPreferences> findByPlid(long plid, int start, int end,
334         OrderByComparator obc) throws SystemException {
335         boolean finderClassNameCacheEnabled = PortletPreferencesModelImpl.CACHE_ENABLED;
336         String finderClassName = PortletPreferences.class.getName();
337         String finderMethodName = "findByPlid";
338         String[] finderParams = new String[] {
339                 Long.class.getName(),
340                 
341                 "java.lang.Integer", "java.lang.Integer",
342                 "com.liferay.portal.kernel.util.OrderByComparator"
343             };
344         Object[] finderArgs = new Object[] {
345                 new Long(plid),
346                 
347                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
348             };
349 
350         Object result = null;
351 
352         if (finderClassNameCacheEnabled) {
353             result = FinderCacheUtil.getResult(finderClassName,
354                     finderMethodName, finderParams, finderArgs, this);
355         }
356 
357         if (result == null) {
358             Session session = null;
359 
360             try {
361                 session = openSession();
362 
363                 StringBuilder query = new StringBuilder();
364 
365                 query.append(
366                     "FROM com.liferay.portal.model.PortletPreferences WHERE ");
367 
368                 query.append("plid = ?");
369 
370                 query.append(" ");
371 
372                 if (obc != null) {
373                     query.append("ORDER BY ");
374                     query.append(obc.getOrderBy());
375                 }
376 
377                 Query q = session.createQuery(query.toString());
378 
379                 QueryPos qPos = QueryPos.getInstance(q);
380 
381                 qPos.add(plid);
382 
383                 List<PortletPreferences> list = (List<PortletPreferences>)QueryUtil.list(q,
384                         getDialect(), start, end);
385 
386                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
387                     finderClassName, finderMethodName, finderParams,
388                     finderArgs, list);
389 
390                 return list;
391             }
392             catch (Exception e) {
393                 throw processException(e);
394             }
395             finally {
396                 closeSession(session);
397             }
398         }
399         else {
400             return (List<PortletPreferences>)result;
401         }
402     }
403 
404     public PortletPreferences findByPlid_First(long plid, OrderByComparator obc)
405         throws NoSuchPortletPreferencesException, SystemException {
406         List<PortletPreferences> list = findByPlid(plid, 0, 1, obc);
407 
408         if (list.size() == 0) {
409             StringBuilder msg = new StringBuilder();
410 
411             msg.append("No PortletPreferences exists with the key {");
412 
413             msg.append("plid=" + plid);
414 
415             msg.append(StringPool.CLOSE_CURLY_BRACE);
416 
417             throw new NoSuchPortletPreferencesException(msg.toString());
418         }
419         else {
420             return list.get(0);
421         }
422     }
423 
424     public PortletPreferences findByPlid_Last(long plid, OrderByComparator obc)
425         throws NoSuchPortletPreferencesException, SystemException {
426         int count = countByPlid(plid);
427 
428         List<PortletPreferences> list = findByPlid(plid, count - 1, count, obc);
429 
430         if (list.size() == 0) {
431             StringBuilder msg = new StringBuilder();
432 
433             msg.append("No PortletPreferences exists with the key {");
434 
435             msg.append("plid=" + plid);
436 
437             msg.append(StringPool.CLOSE_CURLY_BRACE);
438 
439             throw new NoSuchPortletPreferencesException(msg.toString());
440         }
441         else {
442             return list.get(0);
443         }
444     }
445 
446     public PortletPreferences[] findByPlid_PrevAndNext(
447         long portletPreferencesId, long plid, OrderByComparator obc)
448         throws NoSuchPortletPreferencesException, SystemException {
449         PortletPreferences portletPreferences = findByPrimaryKey(portletPreferencesId);
450 
451         int count = countByPlid(plid);
452 
453         Session session = null;
454 
455         try {
456             session = openSession();
457 
458             StringBuilder query = new StringBuilder();
459 
460             query.append(
461                 "FROM com.liferay.portal.model.PortletPreferences WHERE ");
462 
463             query.append("plid = ?");
464 
465             query.append(" ");
466 
467             if (obc != null) {
468                 query.append("ORDER BY ");
469                 query.append(obc.getOrderBy());
470             }
471 
472             Query q = session.createQuery(query.toString());
473 
474             QueryPos qPos = QueryPos.getInstance(q);
475 
476             qPos.add(plid);
477 
478             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
479                     portletPreferences);
480 
481             PortletPreferences[] array = new PortletPreferencesImpl[3];
482 
483             array[0] = (PortletPreferences)objArray[0];
484             array[1] = (PortletPreferences)objArray[1];
485             array[2] = (PortletPreferences)objArray[2];
486 
487             return array;
488         }
489         catch (Exception e) {
490             throw processException(e);
491         }
492         finally {
493             closeSession(session);
494         }
495     }
496 
497     public List<PortletPreferences> findByP_P(long plid, String portletId)
498         throws SystemException {
499         boolean finderClassNameCacheEnabled = PortletPreferencesModelImpl.CACHE_ENABLED;
500         String finderClassName = PortletPreferences.class.getName();
501         String finderMethodName = "findByP_P";
502         String[] finderParams = new String[] {
503                 Long.class.getName(), String.class.getName()
504             };
505         Object[] finderArgs = new Object[] { new Long(plid), portletId };
506 
507         Object result = null;
508 
509         if (finderClassNameCacheEnabled) {
510             result = FinderCacheUtil.getResult(finderClassName,
511                     finderMethodName, finderParams, finderArgs, this);
512         }
513 
514         if (result == null) {
515             Session session = null;
516 
517             try {
518                 session = openSession();
519 
520                 StringBuilder query = new StringBuilder();
521 
522                 query.append(
523                     "FROM com.liferay.portal.model.PortletPreferences WHERE ");
524 
525                 query.append("plid = ?");
526 
527                 query.append(" AND ");
528 
529                 if (portletId == null) {
530                     query.append("portletId IS NULL");
531                 }
532                 else {
533                     query.append("portletId = ?");
534                 }
535 
536                 query.append(" ");
537 
538                 Query q = session.createQuery(query.toString());
539 
540                 QueryPos qPos = QueryPos.getInstance(q);
541 
542                 qPos.add(plid);
543 
544                 if (portletId != null) {
545                     qPos.add(portletId);
546                 }
547 
548                 List<PortletPreferences> list = q.list();
549 
550                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
551                     finderClassName, finderMethodName, finderParams,
552                     finderArgs, list);
553 
554                 return list;
555             }
556             catch (Exception e) {
557                 throw processException(e);
558             }
559             finally {
560                 closeSession(session);
561             }
562         }
563         else {
564             return (List<PortletPreferences>)result;
565         }
566     }
567 
568     public List<PortletPreferences> findByP_P(long plid, String portletId,
569         int start, int end) throws SystemException {
570         return findByP_P(plid, portletId, start, end, null);
571     }
572 
573     public List<PortletPreferences> findByP_P(long plid, String portletId,
574         int start, int end, OrderByComparator obc) throws SystemException {
575         boolean finderClassNameCacheEnabled = PortletPreferencesModelImpl.CACHE_ENABLED;
576         String finderClassName = PortletPreferences.class.getName();
577         String finderMethodName = "findByP_P";
578         String[] finderParams = new String[] {
579                 Long.class.getName(), String.class.getName(),
580                 
581                 "java.lang.Integer", "java.lang.Integer",
582                 "com.liferay.portal.kernel.util.OrderByComparator"
583             };
584         Object[] finderArgs = new Object[] {
585                 new Long(plid),
586                 
587                 portletId,
588                 
589                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
590             };
591 
592         Object result = null;
593 
594         if (finderClassNameCacheEnabled) {
595             result = FinderCacheUtil.getResult(finderClassName,
596                     finderMethodName, finderParams, finderArgs, this);
597         }
598 
599         if (result == null) {
600             Session session = null;
601 
602             try {
603                 session = openSession();
604 
605                 StringBuilder query = new StringBuilder();
606 
607                 query.append(
608                     "FROM com.liferay.portal.model.PortletPreferences WHERE ");
609 
610                 query.append("plid = ?");
611 
612                 query.append(" AND ");
613 
614                 if (portletId == null) {
615                     query.append("portletId IS NULL");
616                 }
617                 else {
618                     query.append("portletId = ?");
619                 }
620 
621                 query.append(" ");
622 
623                 if (obc != null) {
624                     query.append("ORDER BY ");
625                     query.append(obc.getOrderBy());
626                 }
627 
628                 Query q = session.createQuery(query.toString());
629 
630                 QueryPos qPos = QueryPos.getInstance(q);
631 
632                 qPos.add(plid);
633 
634                 if (portletId != null) {
635                     qPos.add(portletId);
636                 }
637 
638                 List<PortletPreferences> list = (List<PortletPreferences>)QueryUtil.list(q,
639                         getDialect(), start, end);
640 
641                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
642                     finderClassName, finderMethodName, finderParams,
643                     finderArgs, list);
644 
645                 return list;
646             }
647             catch (Exception e) {
648                 throw processException(e);
649             }
650             finally {
651                 closeSession(session);
652             }
653         }
654         else {
655             return (List<PortletPreferences>)result;
656         }
657     }
658 
659     public PortletPreferences findByP_P_First(long plid, String portletId,
660         OrderByComparator obc)
661         throws NoSuchPortletPreferencesException, SystemException {
662         List<PortletPreferences> list = findByP_P(plid, portletId, 0, 1, obc);
663 
664         if (list.size() == 0) {
665             StringBuilder msg = new StringBuilder();
666 
667             msg.append("No PortletPreferences exists with the key {");
668 
669             msg.append("plid=" + plid);
670 
671             msg.append(", ");
672             msg.append("portletId=" + portletId);
673 
674             msg.append(StringPool.CLOSE_CURLY_BRACE);
675 
676             throw new NoSuchPortletPreferencesException(msg.toString());
677         }
678         else {
679             return list.get(0);
680         }
681     }
682 
683     public PortletPreferences findByP_P_Last(long plid, String portletId,
684         OrderByComparator obc)
685         throws NoSuchPortletPreferencesException, SystemException {
686         int count = countByP_P(plid, portletId);
687 
688         List<PortletPreferences> list = findByP_P(plid, portletId, count - 1,
689                 count, obc);
690 
691         if (list.size() == 0) {
692             StringBuilder msg = new StringBuilder();
693 
694             msg.append("No PortletPreferences exists with the key {");
695 
696             msg.append("plid=" + plid);
697 
698             msg.append(", ");
699             msg.append("portletId=" + portletId);
700 
701             msg.append(StringPool.CLOSE_CURLY_BRACE);
702 
703             throw new NoSuchPortletPreferencesException(msg.toString());
704         }
705         else {
706             return list.get(0);
707         }
708     }
709 
710     public PortletPreferences[] findByP_P_PrevAndNext(
711         long portletPreferencesId, long plid, String portletId,
712         OrderByComparator obc)
713         throws NoSuchPortletPreferencesException, SystemException {
714         PortletPreferences portletPreferences = findByPrimaryKey(portletPreferencesId);
715 
716         int count = countByP_P(plid, portletId);
717 
718         Session session = null;
719 
720         try {
721             session = openSession();
722 
723             StringBuilder query = new StringBuilder();
724 
725             query.append(
726                 "FROM com.liferay.portal.model.PortletPreferences WHERE ");
727 
728             query.append("plid = ?");
729 
730             query.append(" AND ");
731 
732             if (portletId == null) {
733                 query.append("portletId IS NULL");
734             }
735             else {
736                 query.append("portletId = ?");
737             }
738 
739             query.append(" ");
740 
741             if (obc != null) {
742                 query.append("ORDER BY ");
743                 query.append(obc.getOrderBy());
744             }
745 
746             Query q = session.createQuery(query.toString());
747 
748             QueryPos qPos = QueryPos.getInstance(q);
749 
750             qPos.add(plid);
751 
752             if (portletId != null) {
753                 qPos.add(portletId);
754             }
755 
756             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
757                     portletPreferences);
758 
759             PortletPreferences[] array = new PortletPreferencesImpl[3];
760 
761             array[0] = (PortletPreferences)objArray[0];
762             array[1] = (PortletPreferences)objArray[1];
763             array[2] = (PortletPreferences)objArray[2];
764 
765             return array;
766         }
767         catch (Exception e) {
768             throw processException(e);
769         }
770         finally {
771             closeSession(session);
772         }
773     }
774 
775     public List<PortletPreferences> findByO_O_P(long ownerId, int ownerType,
776         long plid) throws SystemException {
777         boolean finderClassNameCacheEnabled = PortletPreferencesModelImpl.CACHE_ENABLED;
778         String finderClassName = PortletPreferences.class.getName();
779         String finderMethodName = "findByO_O_P";
780         String[] finderParams = new String[] {
781                 Long.class.getName(), Integer.class.getName(),
782                 Long.class.getName()
783             };
784         Object[] finderArgs = new Object[] {
785                 new Long(ownerId), new Integer(ownerType), new Long(plid)
786             };
787 
788         Object result = null;
789 
790         if (finderClassNameCacheEnabled) {
791             result = FinderCacheUtil.getResult(finderClassName,
792                     finderMethodName, finderParams, finderArgs, this);
793         }
794 
795         if (result == null) {
796             Session session = null;
797 
798             try {
799                 session = openSession();
800 
801                 StringBuilder query = new StringBuilder();
802 
803                 query.append(
804                     "FROM com.liferay.portal.model.PortletPreferences WHERE ");
805 
806                 query.append("ownerId = ?");
807 
808                 query.append(" AND ");
809 
810                 query.append("ownerType = ?");
811 
812                 query.append(" AND ");
813 
814                 query.append("plid = ?");
815 
816                 query.append(" ");
817 
818                 Query q = session.createQuery(query.toString());
819 
820                 QueryPos qPos = QueryPos.getInstance(q);
821 
822                 qPos.add(ownerId);
823 
824                 qPos.add(ownerType);
825 
826                 qPos.add(plid);
827 
828                 List<PortletPreferences> list = q.list();
829 
830                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
831                     finderClassName, finderMethodName, finderParams,
832                     finderArgs, list);
833 
834                 return list;
835             }
836             catch (Exception e) {
837                 throw processException(e);
838             }
839             finally {
840                 closeSession(session);
841             }
842         }
843         else {
844             return (List<PortletPreferences>)result;
845         }
846     }
847 
848     public List<PortletPreferences> findByO_O_P(long ownerId, int ownerType,
849         long plid, int start, int end) throws SystemException {
850         return findByO_O_P(ownerId, ownerType, plid, start, end, null);
851     }
852 
853     public List<PortletPreferences> findByO_O_P(long ownerId, int ownerType,
854         long plid, int start, int end, OrderByComparator obc)
855         throws SystemException {
856         boolean finderClassNameCacheEnabled = PortletPreferencesModelImpl.CACHE_ENABLED;
857         String finderClassName = PortletPreferences.class.getName();
858         String finderMethodName = "findByO_O_P";
859         String[] finderParams = new String[] {
860                 Long.class.getName(), Integer.class.getName(),
861                 Long.class.getName(),
862                 
863                 "java.lang.Integer", "java.lang.Integer",
864                 "com.liferay.portal.kernel.util.OrderByComparator"
865             };
866         Object[] finderArgs = new Object[] {
867                 new Long(ownerId), new Integer(ownerType), new Long(plid),
868                 
869                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
870             };
871 
872         Object result = null;
873 
874         if (finderClassNameCacheEnabled) {
875             result = FinderCacheUtil.getResult(finderClassName,
876                     finderMethodName, finderParams, finderArgs, this);
877         }
878 
879         if (result == null) {
880             Session session = null;
881 
882             try {
883                 session = openSession();
884 
885                 StringBuilder query = new StringBuilder();
886 
887                 query.append(
888                     "FROM com.liferay.portal.model.PortletPreferences WHERE ");
889 
890                 query.append("ownerId = ?");
891 
892                 query.append(" AND ");
893 
894                 query.append("ownerType = ?");
895 
896                 query.append(" AND ");
897 
898                 query.append("plid = ?");
899 
900                 query.append(" ");
901 
902                 if (obc != null) {
903                     query.append("ORDER BY ");
904                     query.append(obc.getOrderBy());
905                 }
906 
907                 Query q = session.createQuery(query.toString());
908 
909                 QueryPos qPos = QueryPos.getInstance(q);
910 
911                 qPos.add(ownerId);
912 
913                 qPos.add(ownerType);
914 
915                 qPos.add(plid);
916 
917                 List<PortletPreferences> list = (List<PortletPreferences>)QueryUtil.list(q,
918                         getDialect(), start, end);
919 
920                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
921                     finderClassName, finderMethodName, finderParams,
922                     finderArgs, list);
923 
924                 return list;
925             }
926             catch (Exception e) {
927                 throw processException(e);
928             }
929             finally {
930                 closeSession(session);
931             }
932         }
933         else {
934             return (List<PortletPreferences>)result;
935         }
936     }
937 
938     public PortletPreferences findByO_O_P_First(long ownerId, int ownerType,
939         long plid, OrderByComparator obc)
940         throws NoSuchPortletPreferencesException, SystemException {
941         List<PortletPreferences> list = findByO_O_P(ownerId, ownerType, plid,
942                 0, 1, obc);
943 
944         if (list.size() == 0) {
945             StringBuilder msg = new StringBuilder();
946 
947             msg.append("No PortletPreferences exists with the key {");
948 
949             msg.append("ownerId=" + ownerId);
950 
951             msg.append(", ");
952             msg.append("ownerType=" + ownerType);
953 
954             msg.append(", ");
955             msg.append("plid=" + plid);
956 
957             msg.append(StringPool.CLOSE_CURLY_BRACE);
958 
959             throw new NoSuchPortletPreferencesException(msg.toString());
960         }
961         else {
962             return list.get(0);
963         }
964     }
965 
966     public PortletPreferences findByO_O_P_Last(long ownerId, int ownerType,
967         long plid, OrderByComparator obc)
968         throws NoSuchPortletPreferencesException, SystemException {
969         int count = countByO_O_P(ownerId, ownerType, plid);
970 
971         List<PortletPreferences> list = findByO_O_P(ownerId, ownerType, plid,
972                 count - 1, count, obc);
973 
974         if (list.size() == 0) {
975             StringBuilder msg = new StringBuilder();
976 
977             msg.append("No PortletPreferences exists with the key {");
978 
979             msg.append("ownerId=" + ownerId);
980 
981             msg.append(", ");
982             msg.append("ownerType=" + ownerType);
983 
984             msg.append(", ");
985             msg.append("plid=" + plid);
986 
987             msg.append(StringPool.CLOSE_CURLY_BRACE);
988 
989             throw new NoSuchPortletPreferencesException(msg.toString());
990         }
991         else {
992             return list.get(0);
993         }
994     }
995 
996     public PortletPreferences[] findByO_O_P_PrevAndNext(
997         long portletPreferencesId, long ownerId, int ownerType, long plid,
998         OrderByComparator obc)
999         throws NoSuchPortletPreferencesException, SystemException {
1000        PortletPreferences portletPreferences = findByPrimaryKey(portletPreferencesId);
1001
1002        int count = countByO_O_P(ownerId, ownerType, plid);
1003
1004        Session session = null;
1005
1006        try {
1007            session = openSession();
1008
1009            StringBuilder query = new StringBuilder();
1010
1011            query.append(
1012                "FROM com.liferay.portal.model.PortletPreferences WHERE ");
1013
1014            query.append("ownerId = ?");
1015
1016            query.append(" AND ");
1017
1018            query.append("ownerType = ?");
1019
1020            query.append(" AND ");
1021
1022            query.append("plid = ?");
1023
1024            query.append(" ");
1025
1026            if (obc != null) {
1027                query.append("ORDER BY ");
1028                query.append(obc.getOrderBy());
1029            }
1030
1031            Query q = session.createQuery(query.toString());
1032
1033            QueryPos qPos = QueryPos.getInstance(q);
1034
1035            qPos.add(ownerId);
1036
1037            qPos.add(ownerType);
1038
1039            qPos.add(plid);
1040
1041            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1042                    portletPreferences);
1043
1044            PortletPreferences[] array = new PortletPreferencesImpl[3];
1045
1046            array[0] = (PortletPreferences)objArray[0];
1047            array[1] = (PortletPreferences)objArray[1];
1048            array[2] = (PortletPreferences)objArray[2];
1049
1050            return array;
1051        }
1052        catch (Exception e) {
1053            throw processException(e);
1054        }
1055        finally {
1056            closeSession(session);
1057        }
1058    }
1059
1060    public PortletPreferences findByO_O_P_P(long ownerId, int ownerType,
1061        long plid, String portletId)
1062        throws NoSuchPortletPreferencesException, SystemException {
1063        PortletPreferences portletPreferences = fetchByO_O_P_P(ownerId,
1064                ownerType, plid, portletId);
1065
1066        if (portletPreferences == null) {
1067            StringBuilder msg = new StringBuilder();
1068
1069            msg.append("No PortletPreferences exists with the key {");
1070
1071            msg.append("ownerId=" + ownerId);
1072
1073            msg.append(", ");
1074            msg.append("ownerType=" + ownerType);
1075
1076            msg.append(", ");
1077            msg.append("plid=" + plid);
1078
1079            msg.append(", ");
1080            msg.append("portletId=" + portletId);
1081
1082            msg.append(StringPool.CLOSE_CURLY_BRACE);
1083
1084            if (_log.isWarnEnabled()) {
1085                _log.warn(msg.toString());
1086            }
1087
1088            throw new NoSuchPortletPreferencesException(msg.toString());
1089        }
1090
1091        return portletPreferences;
1092    }
1093
1094    public PortletPreferences fetchByO_O_P_P(long ownerId, int ownerType,
1095        long plid, String portletId) throws SystemException {
1096        boolean finderClassNameCacheEnabled = PortletPreferencesModelImpl.CACHE_ENABLED;
1097        String finderClassName = PortletPreferences.class.getName();
1098        String finderMethodName = "fetchByO_O_P_P";
1099        String[] finderParams = new String[] {
1100                Long.class.getName(), Integer.class.getName(),
1101                Long.class.getName(), String.class.getName()
1102            };
1103        Object[] finderArgs = new Object[] {
1104                new Long(ownerId), new Integer(ownerType), new Long(plid),
1105                
1106                portletId
1107            };
1108
1109        Object result = null;
1110
1111        if (finderClassNameCacheEnabled) {
1112            result = FinderCacheUtil.getResult(finderClassName,
1113                    finderMethodName, finderParams, finderArgs, this);
1114        }
1115
1116        if (result == null) {
1117            Session session = null;
1118
1119            try {
1120                session = openSession();
1121
1122                StringBuilder query = new StringBuilder();
1123
1124                query.append(
1125                    "FROM com.liferay.portal.model.PortletPreferences WHERE ");
1126
1127                query.append("ownerId = ?");
1128
1129                query.append(" AND ");
1130
1131                query.append("ownerType = ?");
1132
1133                query.append(" AND ");
1134
1135                query.append("plid = ?");
1136
1137                query.append(" AND ");
1138
1139                if (portletId == null) {
1140                    query.append("portletId IS NULL");
1141                }
1142                else {
1143                    query.append("portletId = ?");
1144                }
1145
1146                query.append(" ");
1147
1148                Query q = session.createQuery(query.toString());
1149
1150                QueryPos qPos = QueryPos.getInstance(q);
1151
1152                qPos.add(ownerId);
1153
1154                qPos.add(ownerType);
1155
1156                qPos.add(plid);
1157
1158                if (portletId != null) {
1159                    qPos.add(portletId);
1160                }
1161
1162                List<PortletPreferences> list = q.list();
1163
1164                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1165                    finderClassName, finderMethodName, finderParams,
1166                    finderArgs, list);
1167
1168                if (list.size() == 0) {
1169                    return null;
1170                }
1171                else {
1172                    return list.get(0);
1173                }
1174            }
1175            catch (Exception e) {
1176                throw processException(e);
1177            }
1178            finally {
1179                closeSession(session);
1180            }
1181        }
1182        else {
1183            List<PortletPreferences> list = (List<PortletPreferences>)result;
1184
1185            if (list.size() == 0) {
1186                return null;
1187            }
1188            else {
1189                return list.get(0);
1190            }
1191        }
1192    }
1193
1194    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
1195        throws SystemException {
1196        Session session = null;
1197
1198        try {
1199            session = openSession();
1200
1201            dynamicQuery.compile(session);
1202
1203            return dynamicQuery.list();
1204        }
1205        catch (Exception e) {
1206            throw processException(e);
1207        }
1208        finally {
1209            closeSession(session);
1210        }
1211    }
1212
1213    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
1214        int start, int end) throws SystemException {
1215        Session session = null;
1216
1217        try {
1218            session = openSession();
1219
1220            dynamicQuery.setLimit(start, end);
1221
1222            dynamicQuery.compile(session);
1223
1224            return dynamicQuery.list();
1225        }
1226        catch (Exception e) {
1227            throw processException(e);
1228        }
1229        finally {
1230            closeSession(session);
1231        }
1232    }
1233
1234    public List<PortletPreferences> findAll() throws SystemException {
1235        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1236    }
1237
1238    public List<PortletPreferences> findAll(int start, int end)
1239        throws SystemException {
1240        return findAll(start, end, null);
1241    }
1242
1243    public List<PortletPreferences> findAll(int start, int end,
1244        OrderByComparator obc) throws SystemException {
1245        boolean finderClassNameCacheEnabled = PortletPreferencesModelImpl.CACHE_ENABLED;
1246        String finderClassName = PortletPreferences.class.getName();
1247        String finderMethodName = "findAll";
1248        String[] finderParams = new String[] {
1249                "java.lang.Integer", "java.lang.Integer",
1250                "com.liferay.portal.kernel.util.OrderByComparator"
1251            };
1252        Object[] finderArgs = new Object[] {
1253                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1254            };
1255
1256        Object result = null;
1257
1258        if (finderClassNameCacheEnabled) {
1259            result = FinderCacheUtil.getResult(finderClassName,
1260                    finderMethodName, finderParams, finderArgs, this);
1261        }
1262
1263        if (result == null) {
1264            Session session = null;
1265
1266            try {
1267                session = openSession();
1268
1269                StringBuilder query = new StringBuilder();
1270
1271                query.append(
1272                    "FROM com.liferay.portal.model.PortletPreferences ");
1273
1274                if (obc != null) {
1275                    query.append("ORDER BY ");
1276                    query.append(obc.getOrderBy());
1277                }
1278
1279                Query q = session.createQuery(query.toString());
1280
1281                List<PortletPreferences> list = (List<PortletPreferences>)QueryUtil.list(q,
1282                        getDialect(), start, end);
1283
1284                if (obc == null) {
1285                    Collections.sort(list);
1286                }
1287
1288                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1289                    finderClassName, finderMethodName, finderParams,
1290                    finderArgs, list);
1291
1292                return list;
1293            }
1294            catch (Exception e) {
1295                throw processException(e);
1296            }
1297            finally {
1298                closeSession(session);
1299            }
1300        }
1301        else {
1302            return (List<PortletPreferences>)result;
1303        }
1304    }
1305
1306    public void removeByPlid(long plid) throws SystemException {
1307        for (PortletPreferences portletPreferences : findByPlid(plid)) {
1308            remove(portletPreferences);
1309        }
1310    }
1311
1312    public void removeByP_P(long plid, String portletId)
1313        throws SystemException {
1314        for (PortletPreferences portletPreferences : findByP_P(plid, portletId)) {
1315            remove(portletPreferences);
1316        }
1317    }
1318
1319    public void removeByO_O_P(long ownerId, int ownerType, long plid)
1320        throws SystemException {
1321        for (PortletPreferences portletPreferences : findByO_O_P(ownerId,
1322                ownerType, plid)) {
1323            remove(portletPreferences);
1324        }
1325    }
1326
1327    public void removeByO_O_P_P(long ownerId, int ownerType, long plid,
1328        String portletId)
1329        throws NoSuchPortletPreferencesException, SystemException {
1330        PortletPreferences portletPreferences = findByO_O_P_P(ownerId,
1331                ownerType, plid, portletId);
1332
1333        remove(portletPreferences);
1334    }
1335
1336    public void removeAll() throws SystemException {
1337        for (PortletPreferences portletPreferences : findAll()) {
1338            remove(portletPreferences);
1339        }
1340    }
1341
1342    public int countByPlid(long plid) throws SystemException {
1343        boolean finderClassNameCacheEnabled = PortletPreferencesModelImpl.CACHE_ENABLED;
1344        String finderClassName = PortletPreferences.class.getName();
1345        String finderMethodName = "countByPlid";
1346        String[] finderParams = new String[] { Long.class.getName() };
1347        Object[] finderArgs = new Object[] { new Long(plid) };
1348
1349        Object result = null;
1350
1351        if (finderClassNameCacheEnabled) {
1352            result = FinderCacheUtil.getResult(finderClassName,
1353                    finderMethodName, finderParams, finderArgs, this);
1354        }
1355
1356        if (result == null) {
1357            Session session = null;
1358
1359            try {
1360                session = openSession();
1361
1362                StringBuilder query = new StringBuilder();
1363
1364                query.append("SELECT COUNT(*) ");
1365                query.append(
1366                    "FROM com.liferay.portal.model.PortletPreferences WHERE ");
1367
1368                query.append("plid = ?");
1369
1370                query.append(" ");
1371
1372                Query q = session.createQuery(query.toString());
1373
1374                QueryPos qPos = QueryPos.getInstance(q);
1375
1376                qPos.add(plid);
1377
1378                Long count = null;
1379
1380                Iterator<Long> itr = q.list().iterator();
1381
1382                if (itr.hasNext()) {
1383                    count = itr.next();
1384                }
1385
1386                if (count == null) {
1387                    count = new Long(0);
1388                }
1389
1390                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1391                    finderClassName, finderMethodName, finderParams,
1392                    finderArgs, count);
1393
1394                return count.intValue();
1395            }
1396            catch (Exception e) {
1397                throw processException(e);
1398            }
1399            finally {
1400                closeSession(session);
1401            }
1402        }
1403        else {
1404            return ((Long)result).intValue();
1405        }
1406    }
1407
1408    public int countByP_P(long plid, String portletId)
1409        throws SystemException {
1410        boolean finderClassNameCacheEnabled = PortletPreferencesModelImpl.CACHE_ENABLED;
1411        String finderClassName = PortletPreferences.class.getName();
1412        String finderMethodName = "countByP_P";
1413        String[] finderParams = new String[] {
1414                Long.class.getName(), String.class.getName()
1415            };
1416        Object[] finderArgs = new Object[] { new Long(plid), portletId };
1417
1418        Object result = null;
1419
1420        if (finderClassNameCacheEnabled) {
1421            result = FinderCacheUtil.getResult(finderClassName,
1422                    finderMethodName, finderParams, finderArgs, this);
1423        }
1424
1425        if (result == null) {
1426            Session session = null;
1427
1428            try {
1429                session = openSession();
1430
1431                StringBuilder query = new StringBuilder();
1432
1433                query.append("SELECT COUNT(*) ");
1434                query.append(
1435                    "FROM com.liferay.portal.model.PortletPreferences WHERE ");
1436
1437                query.append("plid = ?");
1438
1439                query.append(" AND ");
1440
1441                if (portletId == null) {
1442                    query.append("portletId IS NULL");
1443                }
1444                else {
1445                    query.append("portletId = ?");
1446                }
1447
1448                query.append(" ");
1449
1450                Query q = session.createQuery(query.toString());
1451
1452                QueryPos qPos = QueryPos.getInstance(q);
1453
1454                qPos.add(plid);
1455
1456                if (portletId != null) {
1457                    qPos.add(portletId);
1458                }
1459
1460                Long count = null;
1461
1462                Iterator<Long> itr = q.list().iterator();
1463
1464                if (itr.hasNext()) {
1465                    count = itr.next();
1466                }
1467
1468                if (count == null) {
1469                    count = new Long(0);
1470                }
1471
1472                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1473                    finderClassName, finderMethodName, finderParams,
1474                    finderArgs, count);
1475
1476                return count.intValue();
1477            }
1478            catch (Exception e) {
1479                throw processException(e);
1480            }
1481            finally {
1482                closeSession(session);
1483            }
1484        }
1485        else {
1486            return ((Long)result).intValue();
1487        }
1488    }
1489
1490    public int countByO_O_P(long ownerId, int ownerType, long plid)
1491        throws SystemException {
1492        boolean finderClassNameCacheEnabled = PortletPreferencesModelImpl.CACHE_ENABLED;
1493        String finderClassName = PortletPreferences.class.getName();
1494        String finderMethodName = "countByO_O_P";
1495        String[] finderParams = new String[] {
1496                Long.class.getName(), Integer.class.getName(),
1497                Long.class.getName()
1498            };
1499        Object[] finderArgs = new Object[] {
1500                new Long(ownerId), new Integer(ownerType), new Long(plid)
1501            };
1502
1503        Object result = null;
1504
1505        if (finderClassNameCacheEnabled) {
1506            result = FinderCacheUtil.getResult(finderClassName,
1507                    finderMethodName, finderParams, finderArgs, this);
1508        }
1509
1510        if (result == null) {
1511            Session session = null;
1512
1513            try {
1514                session = openSession();
1515
1516                StringBuilder query = new StringBuilder();
1517
1518                query.append("SELECT COUNT(*) ");
1519                query.append(
1520                    "FROM com.liferay.portal.model.PortletPreferences WHERE ");
1521
1522                query.append("ownerId = ?");
1523
1524                query.append(" AND ");
1525
1526                query.append("ownerType = ?");
1527
1528                query.append(" AND ");
1529
1530                query.append("plid = ?");
1531
1532                query.append(" ");
1533
1534                Query q = session.createQuery(query.toString());
1535
1536                QueryPos qPos = QueryPos.getInstance(q);
1537
1538                qPos.add(ownerId);
1539
1540                qPos.add(ownerType);
1541
1542                qPos.add(plid);
1543
1544                Long count = null;
1545
1546                Iterator<Long> itr = q.list().iterator();
1547
1548                if (itr.hasNext()) {
1549                    count = itr.next();
1550                }
1551
1552                if (count == null) {
1553                    count = new Long(0);
1554                }
1555
1556                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1557                    finderClassName, finderMethodName, finderParams,
1558                    finderArgs, count);
1559
1560                return count.intValue();
1561            }
1562            catch (Exception e) {
1563                throw processException(e);
1564            }
1565            finally {
1566                closeSession(session);
1567            }
1568        }
1569        else {
1570            return ((Long)result).intValue();
1571        }
1572    }
1573
1574    public int countByO_O_P_P(long ownerId, int ownerType, long plid,
1575        String portletId) throws SystemException {
1576        boolean finderClassNameCacheEnabled = PortletPreferencesModelImpl.CACHE_ENABLED;
1577        String finderClassName = PortletPreferences.class.getName();
1578        String finderMethodName = "countByO_O_P_P";
1579        String[] finderParams = new String[] {
1580                Long.class.getName(), Integer.class.getName(),
1581                Long.class.getName(), String.class.getName()
1582            };
1583        Object[] finderArgs = new Object[] {
1584                new Long(ownerId), new Integer(ownerType), new Long(plid),
1585                
1586                portletId
1587            };
1588
1589        Object result = null;
1590
1591        if (finderClassNameCacheEnabled) {
1592            result = FinderCacheUtil.getResult(finderClassName,
1593                    finderMethodName, finderParams, finderArgs, this);
1594        }
1595
1596        if (result == null) {
1597            Session session = null;
1598
1599            try {
1600                session = openSession();
1601
1602                StringBuilder query = new StringBuilder();
1603
1604                query.append("SELECT COUNT(*) ");
1605                query.append(
1606                    "FROM com.liferay.portal.model.PortletPreferences WHERE ");
1607
1608                query.append("ownerId = ?");
1609
1610                query.append(" AND ");
1611
1612                query.append("ownerType = ?");
1613
1614                query.append(" AND ");
1615
1616                query.append("plid = ?");
1617
1618                query.append(" AND ");
1619
1620                if (portletId == null) {
1621                    query.append("portletId IS NULL");
1622                }
1623                else {
1624                    query.append("portletId = ?");
1625                }
1626
1627                query.append(" ");
1628
1629                Query q = session.createQuery(query.toString());
1630
1631                QueryPos qPos = QueryPos.getInstance(q);
1632
1633                qPos.add(ownerId);
1634
1635                qPos.add(ownerType);
1636
1637                qPos.add(plid);
1638
1639                if (portletId != null) {
1640                    qPos.add(portletId);
1641                }
1642
1643                Long count = null;
1644
1645                Iterator<Long> itr = q.list().iterator();
1646
1647                if (itr.hasNext()) {
1648                    count = itr.next();
1649                }
1650
1651                if (count == null) {
1652                    count = new Long(0);
1653                }
1654
1655                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1656                    finderClassName, finderMethodName, finderParams,
1657                    finderArgs, count);
1658
1659                return count.intValue();
1660            }
1661            catch (Exception e) {
1662                throw processException(e);
1663            }
1664            finally {
1665                closeSession(session);
1666            }
1667        }
1668        else {
1669            return ((Long)result).intValue();
1670        }
1671    }
1672
1673    public int countAll() throws SystemException {
1674        boolean finderClassNameCacheEnabled = PortletPreferencesModelImpl.CACHE_ENABLED;
1675        String finderClassName = PortletPreferences.class.getName();
1676        String finderMethodName = "countAll";
1677        String[] finderParams = new String[] {  };
1678        Object[] finderArgs = new Object[] {  };
1679
1680        Object result = null;
1681
1682        if (finderClassNameCacheEnabled) {
1683            result = FinderCacheUtil.getResult(finderClassName,
1684                    finderMethodName, finderParams, finderArgs, this);
1685        }
1686
1687        if (result == null) {
1688            Session session = null;
1689
1690            try {
1691                session = openSession();
1692
1693                Query q = session.createQuery(
1694                        "SELECT COUNT(*) FROM com.liferay.portal.model.PortletPreferences");
1695
1696                Long count = null;
1697
1698                Iterator<Long> itr = q.list().iterator();
1699
1700                if (itr.hasNext()) {
1701                    count = itr.next();
1702                }
1703
1704                if (count == null) {
1705                    count = new Long(0);
1706                }
1707
1708                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1709                    finderClassName, finderMethodName, finderParams,
1710                    finderArgs, count);
1711
1712                return count.intValue();
1713            }
1714            catch (Exception e) {
1715                throw processException(e);
1716            }
1717            finally {
1718                closeSession(session);
1719            }
1720        }
1721        else {
1722            return ((Long)result).intValue();
1723        }
1724    }
1725
1726    public void registerListener(ModelListener listener) {
1727        List<ModelListener> listeners = ListUtil.fromArray(_listeners);
1728
1729        listeners.add(listener);
1730
1731        _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1732    }
1733
1734    public void unregisterListener(ModelListener listener) {
1735        List<ModelListener> listeners = ListUtil.fromArray(_listeners);
1736
1737        listeners.remove(listener);
1738
1739        _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1740    }
1741
1742    public void afterPropertiesSet() {
1743        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1744                    com.liferay.portal.util.PropsUtil.get(
1745                        "value.object.listener.com.liferay.portal.model.PortletPreferences")));
1746
1747        if (listenerClassNames.length > 0) {
1748            try {
1749                List<ModelListener> listeners = new ArrayList<ModelListener>();
1750
1751                for (String listenerClassName : listenerClassNames) {
1752                    listeners.add((ModelListener)Class.forName(
1753                            listenerClassName).newInstance());
1754                }
1755
1756                _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1757            }
1758            catch (Exception e) {
1759                _log.error(e);
1760            }
1761        }
1762    }
1763
1764    private static Log _log = LogFactory.getLog(PortletPreferencesPersistenceImpl.class);
1765    private ModelListener[] _listeners = new ModelListener[0];
1766}