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