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