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