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