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