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