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