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