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