1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.service.persistence;
16  
17  import com.liferay.portal.NoSuchModelException;
18  import com.liferay.portal.NoSuchPortletItemException;
19  import com.liferay.portal.kernel.annotation.BeanReference;
20  import com.liferay.portal.kernel.cache.CacheRegistry;
21  import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
22  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
23  import com.liferay.portal.kernel.dao.orm.FinderPath;
24  import com.liferay.portal.kernel.dao.orm.Query;
25  import com.liferay.portal.kernel.dao.orm.QueryPos;
26  import com.liferay.portal.kernel.dao.orm.QueryUtil;
27  import com.liferay.portal.kernel.dao.orm.Session;
28  import com.liferay.portal.kernel.exception.SystemException;
29  import com.liferay.portal.kernel.log.Log;
30  import com.liferay.portal.kernel.log.LogFactoryUtil;
31  import com.liferay.portal.kernel.util.GetterUtil;
32  import com.liferay.portal.kernel.util.InstanceFactory;
33  import com.liferay.portal.kernel.util.OrderByComparator;
34  import com.liferay.portal.kernel.util.StringBundler;
35  import com.liferay.portal.kernel.util.StringPool;
36  import com.liferay.portal.kernel.util.StringUtil;
37  import com.liferay.portal.kernel.util.Validator;
38  import com.liferay.portal.model.ModelListener;
39  import com.liferay.portal.model.PortletItem;
40  import com.liferay.portal.model.impl.PortletItemImpl;
41  import com.liferay.portal.model.impl.PortletItemModelImpl;
42  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
43  
44  import java.io.Serializable;
45  
46  import java.util.ArrayList;
47  import java.util.Collections;
48  import java.util.List;
49  
50  /**
51   * <a href="PortletItemPersistenceImpl.java.html"><b><i>View Source</i></b></a>
52   *
53   * <p>
54   * ServiceBuilder generated this class. Modifications in this class will be
55   * overwritten the next time is generated.
56   * </p>
57   *
58   * @author    Brian Wing Shun Chan
59   * @see       PortletItemPersistence
60   * @see       PortletItemUtil
61   * @generated
62   */
63  public class PortletItemPersistenceImpl extends BasePersistenceImpl<PortletItem>
64      implements PortletItemPersistence {
65      public static final String FINDER_CLASS_NAME_ENTITY = PortletItemImpl.class.getName();
66      public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
67          ".List";
68      public static final FinderPath FINDER_PATH_FIND_BY_G_C = new FinderPath(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
69              PortletItemModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
70              "findByG_C",
71              new String[] {
72                  Long.class.getName(), Long.class.getName(),
73                  
74              "java.lang.Integer", "java.lang.Integer",
75                  "com.liferay.portal.kernel.util.OrderByComparator"
76              });
77      public static final FinderPath FINDER_PATH_COUNT_BY_G_C = new FinderPath(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
78              PortletItemModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
79              "countByG_C",
80              new String[] { Long.class.getName(), Long.class.getName() });
81      public static final FinderPath FINDER_PATH_FIND_BY_G_P_C = new FinderPath(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
82              PortletItemModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
83              "findByG_P_C",
84              new String[] {
85                  Long.class.getName(), String.class.getName(),
86                  Long.class.getName(),
87                  
88              "java.lang.Integer", "java.lang.Integer",
89                  "com.liferay.portal.kernel.util.OrderByComparator"
90              });
91      public static final FinderPath FINDER_PATH_COUNT_BY_G_P_C = new FinderPath(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
92              PortletItemModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
93              "countByG_P_C",
94              new String[] {
95                  Long.class.getName(), String.class.getName(),
96                  Long.class.getName()
97              });
98      public static final FinderPath FINDER_PATH_FETCH_BY_G_N_P_C = new FinderPath(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
99              PortletItemModelImpl.FINDER_CACHE_ENABLED,
100             FINDER_CLASS_NAME_ENTITY, "fetchByG_N_P_C",
101             new String[] {
102                 Long.class.getName(), String.class.getName(),
103                 String.class.getName(), Long.class.getName()
104             });
105     public static final FinderPath FINDER_PATH_COUNT_BY_G_N_P_C = new FinderPath(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
106             PortletItemModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
107             "countByG_N_P_C",
108             new String[] {
109                 Long.class.getName(), String.class.getName(),
110                 String.class.getName(), Long.class.getName()
111             });
112     public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
113             PortletItemModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
114             "findAll", new String[0]);
115     public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
116             PortletItemModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
117             "countAll", new String[0]);
118 
119     public void cacheResult(PortletItem portletItem) {
120         EntityCacheUtil.putResult(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
121             PortletItemImpl.class, portletItem.getPrimaryKey(), portletItem);
122 
123         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N_P_C,
124             new Object[] {
125                 new Long(portletItem.getGroupId()),
126                 
127             portletItem.getName(),
128                 
129             portletItem.getPortletId(), new Long(portletItem.getClassNameId())
130             }, portletItem);
131     }
132 
133     public void cacheResult(List<PortletItem> portletItems) {
134         for (PortletItem portletItem : portletItems) {
135             if (EntityCacheUtil.getResult(
136                         PortletItemModelImpl.ENTITY_CACHE_ENABLED,
137                         PortletItemImpl.class, portletItem.getPrimaryKey(), this) == null) {
138                 cacheResult(portletItem);
139             }
140         }
141     }
142 
143     public void clearCache() {
144         CacheRegistry.clear(PortletItemImpl.class.getName());
145         EntityCacheUtil.clearCache(PortletItemImpl.class.getName());
146         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
147         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
148     }
149 
150     public void clearCache(PortletItem portletItem) {
151         EntityCacheUtil.removeResult(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
152             PortletItemImpl.class, portletItem.getPrimaryKey());
153 
154         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N_P_C,
155             new Object[] {
156                 new Long(portletItem.getGroupId()),
157                 
158             portletItem.getName(),
159                 
160             portletItem.getPortletId(), new Long(portletItem.getClassNameId())
161             });
162     }
163 
164     public PortletItem create(long portletItemId) {
165         PortletItem portletItem = new PortletItemImpl();
166 
167         portletItem.setNew(true);
168         portletItem.setPrimaryKey(portletItemId);
169 
170         return portletItem;
171     }
172 
173     public PortletItem remove(Serializable primaryKey)
174         throws NoSuchModelException, SystemException {
175         return remove(((Long)primaryKey).longValue());
176     }
177 
178     public PortletItem remove(long portletItemId)
179         throws NoSuchPortletItemException, SystemException {
180         Session session = null;
181 
182         try {
183             session = openSession();
184 
185             PortletItem portletItem = (PortletItem)session.get(PortletItemImpl.class,
186                     new Long(portletItemId));
187 
188             if (portletItem == null) {
189                 if (_log.isWarnEnabled()) {
190                     _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + portletItemId);
191                 }
192 
193                 throw new NoSuchPortletItemException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
194                     portletItemId);
195             }
196 
197             return remove(portletItem);
198         }
199         catch (NoSuchPortletItemException nsee) {
200             throw nsee;
201         }
202         catch (Exception e) {
203             throw processException(e);
204         }
205         finally {
206             closeSession(session);
207         }
208     }
209 
210     public PortletItem remove(PortletItem portletItem)
211         throws SystemException {
212         for (ModelListener<PortletItem> listener : listeners) {
213             listener.onBeforeRemove(portletItem);
214         }
215 
216         portletItem = removeImpl(portletItem);
217 
218         for (ModelListener<PortletItem> listener : listeners) {
219             listener.onAfterRemove(portletItem);
220         }
221 
222         return portletItem;
223     }
224 
225     protected PortletItem removeImpl(PortletItem portletItem)
226         throws SystemException {
227         portletItem = toUnwrappedModel(portletItem);
228 
229         Session session = null;
230 
231         try {
232             session = openSession();
233 
234             if (portletItem.isCachedModel() || BatchSessionUtil.isEnabled()) {
235                 Object staleObject = session.get(PortletItemImpl.class,
236                         portletItem.getPrimaryKeyObj());
237 
238                 if (staleObject != null) {
239                     session.evict(staleObject);
240                 }
241             }
242 
243             session.delete(portletItem);
244 
245             session.flush();
246         }
247         catch (Exception e) {
248             throw processException(e);
249         }
250         finally {
251             closeSession(session);
252         }
253 
254         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
255 
256         PortletItemModelImpl portletItemModelImpl = (PortletItemModelImpl)portletItem;
257 
258         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N_P_C,
259             new Object[] {
260                 new Long(portletItemModelImpl.getOriginalGroupId()),
261                 
262             portletItemModelImpl.getOriginalName(),
263                 
264             portletItemModelImpl.getOriginalPortletId(),
265                 new Long(portletItemModelImpl.getOriginalClassNameId())
266             });
267 
268         EntityCacheUtil.removeResult(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
269             PortletItemImpl.class, portletItem.getPrimaryKey());
270 
271         return portletItem;
272     }
273 
274     public PortletItem updateImpl(
275         com.liferay.portal.model.PortletItem portletItem, boolean merge)
276         throws SystemException {
277         portletItem = toUnwrappedModel(portletItem);
278 
279         boolean isNew = portletItem.isNew();
280 
281         PortletItemModelImpl portletItemModelImpl = (PortletItemModelImpl)portletItem;
282 
283         Session session = null;
284 
285         try {
286             session = openSession();
287 
288             BatchSessionUtil.update(session, portletItem, merge);
289 
290             portletItem.setNew(false);
291         }
292         catch (Exception e) {
293             throw processException(e);
294         }
295         finally {
296             closeSession(session);
297         }
298 
299         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
300 
301         EntityCacheUtil.putResult(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
302             PortletItemImpl.class, portletItem.getPrimaryKey(), portletItem);
303 
304         if (!isNew &&
305                 ((portletItem.getGroupId() != portletItemModelImpl.getOriginalGroupId()) ||
306                 !Validator.equals(portletItem.getName(),
307                     portletItemModelImpl.getOriginalName()) ||
308                 !Validator.equals(portletItem.getPortletId(),
309                     portletItemModelImpl.getOriginalPortletId()) ||
310                 (portletItem.getClassNameId() != portletItemModelImpl.getOriginalClassNameId()))) {
311             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N_P_C,
312                 new Object[] {
313                     new Long(portletItemModelImpl.getOriginalGroupId()),
314                     
315                 portletItemModelImpl.getOriginalName(),
316                     
317                 portletItemModelImpl.getOriginalPortletId(),
318                     new Long(portletItemModelImpl.getOriginalClassNameId())
319                 });
320         }
321 
322         if (isNew ||
323                 ((portletItem.getGroupId() != portletItemModelImpl.getOriginalGroupId()) ||
324                 !Validator.equals(portletItem.getName(),
325                     portletItemModelImpl.getOriginalName()) ||
326                 !Validator.equals(portletItem.getPortletId(),
327                     portletItemModelImpl.getOriginalPortletId()) ||
328                 (portletItem.getClassNameId() != portletItemModelImpl.getOriginalClassNameId()))) {
329             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N_P_C,
330                 new Object[] {
331                     new Long(portletItem.getGroupId()),
332                     
333                 portletItem.getName(),
334                     
335                 portletItem.getPortletId(),
336                     new Long(portletItem.getClassNameId())
337                 }, portletItem);
338         }
339 
340         return portletItem;
341     }
342 
343     protected PortletItem toUnwrappedModel(PortletItem portletItem) {
344         if (portletItem instanceof PortletItemImpl) {
345             return portletItem;
346         }
347 
348         PortletItemImpl portletItemImpl = new PortletItemImpl();
349 
350         portletItemImpl.setNew(portletItem.isNew());
351         portletItemImpl.setPrimaryKey(portletItem.getPrimaryKey());
352 
353         portletItemImpl.setPortletItemId(portletItem.getPortletItemId());
354         portletItemImpl.setGroupId(portletItem.getGroupId());
355         portletItemImpl.setCompanyId(portletItem.getCompanyId());
356         portletItemImpl.setUserId(portletItem.getUserId());
357         portletItemImpl.setUserName(portletItem.getUserName());
358         portletItemImpl.setCreateDate(portletItem.getCreateDate());
359         portletItemImpl.setModifiedDate(portletItem.getModifiedDate());
360         portletItemImpl.setName(portletItem.getName());
361         portletItemImpl.setPortletId(portletItem.getPortletId());
362         portletItemImpl.setClassNameId(portletItem.getClassNameId());
363 
364         return portletItemImpl;
365     }
366 
367     public PortletItem findByPrimaryKey(Serializable primaryKey)
368         throws NoSuchModelException, SystemException {
369         return findByPrimaryKey(((Long)primaryKey).longValue());
370     }
371 
372     public PortletItem findByPrimaryKey(long portletItemId)
373         throws NoSuchPortletItemException, SystemException {
374         PortletItem portletItem = fetchByPrimaryKey(portletItemId);
375 
376         if (portletItem == null) {
377             if (_log.isWarnEnabled()) {
378                 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + portletItemId);
379             }
380 
381             throw new NoSuchPortletItemException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
382                 portletItemId);
383         }
384 
385         return portletItem;
386     }
387 
388     public PortletItem fetchByPrimaryKey(Serializable primaryKey)
389         throws SystemException {
390         return fetchByPrimaryKey(((Long)primaryKey).longValue());
391     }
392 
393     public PortletItem fetchByPrimaryKey(long portletItemId)
394         throws SystemException {
395         PortletItem portletItem = (PortletItem)EntityCacheUtil.getResult(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
396                 PortletItemImpl.class, portletItemId, this);
397 
398         if (portletItem == null) {
399             Session session = null;
400 
401             try {
402                 session = openSession();
403 
404                 portletItem = (PortletItem)session.get(PortletItemImpl.class,
405                         new Long(portletItemId));
406             }
407             catch (Exception e) {
408                 throw processException(e);
409             }
410             finally {
411                 if (portletItem != null) {
412                     cacheResult(portletItem);
413                 }
414 
415                 closeSession(session);
416             }
417         }
418 
419         return portletItem;
420     }
421 
422     public List<PortletItem> findByG_C(long groupId, long classNameId)
423         throws SystemException {
424         return findByG_C(groupId, classNameId, QueryUtil.ALL_POS,
425             QueryUtil.ALL_POS, null);
426     }
427 
428     public List<PortletItem> findByG_C(long groupId, long classNameId,
429         int start, int end) throws SystemException {
430         return findByG_C(groupId, classNameId, start, end, null);
431     }
432 
433     public List<PortletItem> findByG_C(long groupId, long classNameId,
434         int start, int end, OrderByComparator orderByComparator)
435         throws SystemException {
436         Object[] finderArgs = new Object[] {
437                 new Long(groupId), new Long(classNameId),
438                 
439                 String.valueOf(start), String.valueOf(end),
440                 String.valueOf(orderByComparator)
441             };
442 
443         List<PortletItem> list = (List<PortletItem>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_C,
444                 finderArgs, this);
445 
446         if (list == null) {
447             Session session = null;
448 
449             try {
450                 session = openSession();
451 
452                 StringBundler query = null;
453 
454                 if (orderByComparator != null) {
455                     query = new StringBundler(4 +
456                             (orderByComparator.getOrderByFields().length * 3));
457                 }
458                 else {
459                     query = new StringBundler(3);
460                 }
461 
462                 query.append(_SQL_SELECT_PORTLETITEM_WHERE);
463 
464                 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
465 
466                 query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_2);
467 
468                 if (orderByComparator != null) {
469                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
470                         orderByComparator);
471                 }
472 
473                 String sql = query.toString();
474 
475                 Query q = session.createQuery(sql);
476 
477                 QueryPos qPos = QueryPos.getInstance(q);
478 
479                 qPos.add(groupId);
480 
481                 qPos.add(classNameId);
482 
483                 list = (List<PortletItem>)QueryUtil.list(q, getDialect(),
484                         start, end);
485             }
486             catch (Exception e) {
487                 throw processException(e);
488             }
489             finally {
490                 if (list == null) {
491                     list = new ArrayList<PortletItem>();
492                 }
493 
494                 cacheResult(list);
495 
496                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_C, finderArgs,
497                     list);
498 
499                 closeSession(session);
500             }
501         }
502 
503         return list;
504     }
505 
506     public PortletItem findByG_C_First(long groupId, long classNameId,
507         OrderByComparator orderByComparator)
508         throws NoSuchPortletItemException, SystemException {
509         List<PortletItem> list = findByG_C(groupId, classNameId, 0, 1,
510                 orderByComparator);
511 
512         if (list.isEmpty()) {
513             StringBundler msg = new StringBundler(6);
514 
515             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
516 
517             msg.append("groupId=");
518             msg.append(groupId);
519 
520             msg.append(", classNameId=");
521             msg.append(classNameId);
522 
523             msg.append(StringPool.CLOSE_CURLY_BRACE);
524 
525             throw new NoSuchPortletItemException(msg.toString());
526         }
527         else {
528             return list.get(0);
529         }
530     }
531 
532     public PortletItem findByG_C_Last(long groupId, long classNameId,
533         OrderByComparator orderByComparator)
534         throws NoSuchPortletItemException, SystemException {
535         int count = countByG_C(groupId, classNameId);
536 
537         List<PortletItem> list = findByG_C(groupId, classNameId, count - 1,
538                 count, orderByComparator);
539 
540         if (list.isEmpty()) {
541             StringBundler msg = new StringBundler(6);
542 
543             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
544 
545             msg.append("groupId=");
546             msg.append(groupId);
547 
548             msg.append(", classNameId=");
549             msg.append(classNameId);
550 
551             msg.append(StringPool.CLOSE_CURLY_BRACE);
552 
553             throw new NoSuchPortletItemException(msg.toString());
554         }
555         else {
556             return list.get(0);
557         }
558     }
559 
560     public PortletItem[] findByG_C_PrevAndNext(long portletItemId,
561         long groupId, long classNameId, OrderByComparator orderByComparator)
562         throws NoSuchPortletItemException, SystemException {
563         PortletItem portletItem = findByPrimaryKey(portletItemId);
564 
565         Session session = null;
566 
567         try {
568             session = openSession();
569 
570             PortletItem[] array = new PortletItemImpl[3];
571 
572             array[0] = getByG_C_PrevAndNext(session, portletItem, groupId,
573                     classNameId, orderByComparator, true);
574 
575             array[1] = portletItem;
576 
577             array[2] = getByG_C_PrevAndNext(session, portletItem, groupId,
578                     classNameId, orderByComparator, false);
579 
580             return array;
581         }
582         catch (Exception e) {
583             throw processException(e);
584         }
585         finally {
586             closeSession(session);
587         }
588     }
589 
590     protected PortletItem getByG_C_PrevAndNext(Session session,
591         PortletItem portletItem, long groupId, long classNameId,
592         OrderByComparator orderByComparator, boolean previous) {
593         StringBundler query = null;
594 
595         if (orderByComparator != null) {
596             query = new StringBundler(6 +
597                     (orderByComparator.getOrderByFields().length * 6));
598         }
599         else {
600             query = new StringBundler(3);
601         }
602 
603         query.append(_SQL_SELECT_PORTLETITEM_WHERE);
604 
605         query.append(_FINDER_COLUMN_G_C_GROUPID_2);
606 
607         query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_2);
608 
609         if (orderByComparator != null) {
610             String[] orderByFields = orderByComparator.getOrderByFields();
611 
612             if (orderByFields.length > 0) {
613                 query.append(WHERE_AND);
614             }
615 
616             for (int i = 0; i < orderByFields.length; i++) {
617                 query.append(_ORDER_BY_ENTITY_ALIAS);
618                 query.append(orderByFields[i]);
619 
620                 if ((i + 1) < orderByFields.length) {
621                     if (orderByComparator.isAscending() ^ previous) {
622                         query.append(WHERE_GREATER_THAN_HAS_NEXT);
623                     }
624                     else {
625                         query.append(WHERE_LESSER_THAN_HAS_NEXT);
626                     }
627                 }
628                 else {
629                     if (orderByComparator.isAscending() ^ previous) {
630                         query.append(WHERE_GREATER_THAN);
631                     }
632                     else {
633                         query.append(WHERE_LESSER_THAN);
634                     }
635                 }
636             }
637 
638             query.append(ORDER_BY_CLAUSE);
639 
640             for (int i = 0; i < orderByFields.length; i++) {
641                 query.append(_ORDER_BY_ENTITY_ALIAS);
642                 query.append(orderByFields[i]);
643 
644                 if ((i + 1) < orderByFields.length) {
645                     if (orderByComparator.isAscending() ^ previous) {
646                         query.append(ORDER_BY_ASC_HAS_NEXT);
647                     }
648                     else {
649                         query.append(ORDER_BY_DESC_HAS_NEXT);
650                     }
651                 }
652                 else {
653                     if (orderByComparator.isAscending() ^ previous) {
654                         query.append(ORDER_BY_ASC);
655                     }
656                     else {
657                         query.append(ORDER_BY_DESC);
658                     }
659                 }
660             }
661         }
662 
663         String sql = query.toString();
664 
665         Query q = session.createQuery(sql);
666 
667         q.setFirstResult(0);
668         q.setMaxResults(2);
669 
670         QueryPos qPos = QueryPos.getInstance(q);
671 
672         qPos.add(groupId);
673 
674         qPos.add(classNameId);
675 
676         if (orderByComparator != null) {
677             Object[] values = orderByComparator.getOrderByValues(portletItem);
678 
679             for (Object value : values) {
680                 qPos.add(value);
681             }
682         }
683 
684         List<PortletItem> list = q.list();
685 
686         if (list.size() == 2) {
687             return list.get(1);
688         }
689         else {
690             return null;
691         }
692     }
693 
694     public List<PortletItem> findByG_P_C(long groupId, String portletId,
695         long classNameId) throws SystemException {
696         return findByG_P_C(groupId, portletId, classNameId, QueryUtil.ALL_POS,
697             QueryUtil.ALL_POS, null);
698     }
699 
700     public List<PortletItem> findByG_P_C(long groupId, String portletId,
701         long classNameId, int start, int end) throws SystemException {
702         return findByG_P_C(groupId, portletId, classNameId, start, end, null);
703     }
704 
705     public List<PortletItem> findByG_P_C(long groupId, String portletId,
706         long classNameId, int start, int end,
707         OrderByComparator orderByComparator) throws SystemException {
708         Object[] finderArgs = new Object[] {
709                 new Long(groupId),
710                 
711                 portletId, new Long(classNameId),
712                 
713                 String.valueOf(start), String.valueOf(end),
714                 String.valueOf(orderByComparator)
715             };
716 
717         List<PortletItem> list = (List<PortletItem>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_P_C,
718                 finderArgs, this);
719 
720         if (list == null) {
721             Session session = null;
722 
723             try {
724                 session = openSession();
725 
726                 StringBundler query = null;
727 
728                 if (orderByComparator != null) {
729                     query = new StringBundler(5 +
730                             (orderByComparator.getOrderByFields().length * 3));
731                 }
732                 else {
733                     query = new StringBundler(4);
734                 }
735 
736                 query.append(_SQL_SELECT_PORTLETITEM_WHERE);
737 
738                 query.append(_FINDER_COLUMN_G_P_C_GROUPID_2);
739 
740                 if (portletId == null) {
741                     query.append(_FINDER_COLUMN_G_P_C_PORTLETID_1);
742                 }
743                 else {
744                     if (portletId.equals(StringPool.BLANK)) {
745                         query.append(_FINDER_COLUMN_G_P_C_PORTLETID_3);
746                     }
747                     else {
748                         query.append(_FINDER_COLUMN_G_P_C_PORTLETID_2);
749                     }
750                 }
751 
752                 query.append(_FINDER_COLUMN_G_P_C_CLASSNAMEID_2);
753 
754                 if (orderByComparator != null) {
755                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
756                         orderByComparator);
757                 }
758 
759                 String sql = query.toString();
760 
761                 Query q = session.createQuery(sql);
762 
763                 QueryPos qPos = QueryPos.getInstance(q);
764 
765                 qPos.add(groupId);
766 
767                 if (portletId != null) {
768                     qPos.add(portletId);
769                 }
770 
771                 qPos.add(classNameId);
772 
773                 list = (List<PortletItem>)QueryUtil.list(q, getDialect(),
774                         start, end);
775             }
776             catch (Exception e) {
777                 throw processException(e);
778             }
779             finally {
780                 if (list == null) {
781                     list = new ArrayList<PortletItem>();
782                 }
783 
784                 cacheResult(list);
785 
786                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_P_C,
787                     finderArgs, list);
788 
789                 closeSession(session);
790             }
791         }
792 
793         return list;
794     }
795 
796     public PortletItem findByG_P_C_First(long groupId, String portletId,
797         long classNameId, OrderByComparator orderByComparator)
798         throws NoSuchPortletItemException, SystemException {
799         List<PortletItem> list = findByG_P_C(groupId, portletId, classNameId,
800                 0, 1, orderByComparator);
801 
802         if (list.isEmpty()) {
803             StringBundler msg = new StringBundler(8);
804 
805             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
806 
807             msg.append("groupId=");
808             msg.append(groupId);
809 
810             msg.append(", portletId=");
811             msg.append(portletId);
812 
813             msg.append(", classNameId=");
814             msg.append(classNameId);
815 
816             msg.append(StringPool.CLOSE_CURLY_BRACE);
817 
818             throw new NoSuchPortletItemException(msg.toString());
819         }
820         else {
821             return list.get(0);
822         }
823     }
824 
825     public PortletItem findByG_P_C_Last(long groupId, String portletId,
826         long classNameId, OrderByComparator orderByComparator)
827         throws NoSuchPortletItemException, SystemException {
828         int count = countByG_P_C(groupId, portletId, classNameId);
829 
830         List<PortletItem> list = findByG_P_C(groupId, portletId, classNameId,
831                 count - 1, count, orderByComparator);
832 
833         if (list.isEmpty()) {
834             StringBundler msg = new StringBundler(8);
835 
836             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
837 
838             msg.append("groupId=");
839             msg.append(groupId);
840 
841             msg.append(", portletId=");
842             msg.append(portletId);
843 
844             msg.append(", classNameId=");
845             msg.append(classNameId);
846 
847             msg.append(StringPool.CLOSE_CURLY_BRACE);
848 
849             throw new NoSuchPortletItemException(msg.toString());
850         }
851         else {
852             return list.get(0);
853         }
854     }
855 
856     public PortletItem[] findByG_P_C_PrevAndNext(long portletItemId,
857         long groupId, String portletId, long classNameId,
858         OrderByComparator orderByComparator)
859         throws NoSuchPortletItemException, SystemException {
860         PortletItem portletItem = findByPrimaryKey(portletItemId);
861 
862         Session session = null;
863 
864         try {
865             session = openSession();
866 
867             PortletItem[] array = new PortletItemImpl[3];
868 
869             array[0] = getByG_P_C_PrevAndNext(session, portletItem, groupId,
870                     portletId, classNameId, orderByComparator, true);
871 
872             array[1] = portletItem;
873 
874             array[2] = getByG_P_C_PrevAndNext(session, portletItem, groupId,
875                     portletId, classNameId, orderByComparator, false);
876 
877             return array;
878         }
879         catch (Exception e) {
880             throw processException(e);
881         }
882         finally {
883             closeSession(session);
884         }
885     }
886 
887     protected PortletItem getByG_P_C_PrevAndNext(Session session,
888         PortletItem portletItem, long groupId, String portletId,
889         long classNameId, OrderByComparator orderByComparator, boolean previous) {
890         StringBundler query = null;
891 
892         if (orderByComparator != null) {
893             query = new StringBundler(6 +
894                     (orderByComparator.getOrderByFields().length * 6));
895         }
896         else {
897             query = new StringBundler(3);
898         }
899 
900         query.append(_SQL_SELECT_PORTLETITEM_WHERE);
901 
902         query.append(_FINDER_COLUMN_G_P_C_GROUPID_2);
903 
904         if (portletId == null) {
905             query.append(_FINDER_COLUMN_G_P_C_PORTLETID_1);
906         }
907         else {
908             if (portletId.equals(StringPool.BLANK)) {
909                 query.append(_FINDER_COLUMN_G_P_C_PORTLETID_3);
910             }
911             else {
912                 query.append(_FINDER_COLUMN_G_P_C_PORTLETID_2);
913             }
914         }
915 
916         query.append(_FINDER_COLUMN_G_P_C_CLASSNAMEID_2);
917 
918         if (orderByComparator != null) {
919             String[] orderByFields = orderByComparator.getOrderByFields();
920 
921             if (orderByFields.length > 0) {
922                 query.append(WHERE_AND);
923             }
924 
925             for (int i = 0; i < orderByFields.length; i++) {
926                 query.append(_ORDER_BY_ENTITY_ALIAS);
927                 query.append(orderByFields[i]);
928 
929                 if ((i + 1) < orderByFields.length) {
930                     if (orderByComparator.isAscending() ^ previous) {
931                         query.append(WHERE_GREATER_THAN_HAS_NEXT);
932                     }
933                     else {
934                         query.append(WHERE_LESSER_THAN_HAS_NEXT);
935                     }
936                 }
937                 else {
938                     if (orderByComparator.isAscending() ^ previous) {
939                         query.append(WHERE_GREATER_THAN);
940                     }
941                     else {
942                         query.append(WHERE_LESSER_THAN);
943                     }
944                 }
945             }
946 
947             query.append(ORDER_BY_CLAUSE);
948 
949             for (int i = 0; i < orderByFields.length; i++) {
950                 query.append(_ORDER_BY_ENTITY_ALIAS);
951                 query.append(orderByFields[i]);
952 
953                 if ((i + 1) < orderByFields.length) {
954                     if (orderByComparator.isAscending() ^ previous) {
955                         query.append(ORDER_BY_ASC_HAS_NEXT);
956                     }
957                     else {
958                         query.append(ORDER_BY_DESC_HAS_NEXT);
959                     }
960                 }
961                 else {
962                     if (orderByComparator.isAscending() ^ previous) {
963                         query.append(ORDER_BY_ASC);
964                     }
965                     else {
966                         query.append(ORDER_BY_DESC);
967                     }
968                 }
969             }
970         }
971 
972         String sql = query.toString();
973 
974         Query q = session.createQuery(sql);
975 
976         q.setFirstResult(0);
977         q.setMaxResults(2);
978 
979         QueryPos qPos = QueryPos.getInstance(q);
980 
981         qPos.add(groupId);
982 
983         if (portletId != null) {
984             qPos.add(portletId);
985         }
986 
987         qPos.add(classNameId);
988 
989         if (orderByComparator != null) {
990             Object[] values = orderByComparator.getOrderByValues(portletItem);
991 
992             for (Object value : values) {
993                 qPos.add(value);
994             }
995         }
996 
997         List<PortletItem> list = q.list();
998 
999         if (list.size() == 2) {
1000            return list.get(1);
1001        }
1002        else {
1003            return null;
1004        }
1005    }
1006
1007    public PortletItem findByG_N_P_C(long groupId, String name,
1008        String portletId, long classNameId)
1009        throws NoSuchPortletItemException, SystemException {
1010        PortletItem portletItem = fetchByG_N_P_C(groupId, name, portletId,
1011                classNameId);
1012
1013        if (portletItem == null) {
1014            StringBundler msg = new StringBundler(10);
1015
1016            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1017
1018            msg.append("groupId=");
1019            msg.append(groupId);
1020
1021            msg.append(", name=");
1022            msg.append(name);
1023
1024            msg.append(", portletId=");
1025            msg.append(portletId);
1026
1027            msg.append(", classNameId=");
1028            msg.append(classNameId);
1029
1030            msg.append(StringPool.CLOSE_CURLY_BRACE);
1031
1032            if (_log.isWarnEnabled()) {
1033                _log.warn(msg.toString());
1034            }
1035
1036            throw new NoSuchPortletItemException(msg.toString());
1037        }
1038
1039        return portletItem;
1040    }
1041
1042    public PortletItem fetchByG_N_P_C(long groupId, String name,
1043        String portletId, long classNameId) throws SystemException {
1044        return fetchByG_N_P_C(groupId, name, portletId, classNameId, true);
1045    }
1046
1047    public PortletItem fetchByG_N_P_C(long groupId, String name,
1048        String portletId, long classNameId, boolean retrieveFromCache)
1049        throws SystemException {
1050        Object[] finderArgs = new Object[] {
1051                new Long(groupId),
1052                
1053                name,
1054                
1055                portletId, new Long(classNameId)
1056            };
1057
1058        Object result = null;
1059
1060        if (retrieveFromCache) {
1061            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_N_P_C,
1062                    finderArgs, this);
1063        }
1064
1065        if (result == null) {
1066            Session session = null;
1067
1068            try {
1069                session = openSession();
1070
1071                StringBundler query = new StringBundler(5);
1072
1073                query.append(_SQL_SELECT_PORTLETITEM_WHERE);
1074
1075                query.append(_FINDER_COLUMN_G_N_P_C_GROUPID_2);
1076
1077                if (name == null) {
1078                    query.append(_FINDER_COLUMN_G_N_P_C_NAME_1);
1079                }
1080                else {
1081                    if (name.equals(StringPool.BLANK)) {
1082                        query.append(_FINDER_COLUMN_G_N_P_C_NAME_3);
1083                    }
1084                    else {
1085                        query.append(_FINDER_COLUMN_G_N_P_C_NAME_2);
1086                    }
1087                }
1088
1089                if (portletId == null) {
1090                    query.append(_FINDER_COLUMN_G_N_P_C_PORTLETID_1);
1091                }
1092                else {
1093                    if (portletId.equals(StringPool.BLANK)) {
1094                        query.append(_FINDER_COLUMN_G_N_P_C_PORTLETID_3);
1095                    }
1096                    else {
1097                        query.append(_FINDER_COLUMN_G_N_P_C_PORTLETID_2);
1098                    }
1099                }
1100
1101                query.append(_FINDER_COLUMN_G_N_P_C_CLASSNAMEID_2);
1102
1103                String sql = query.toString();
1104
1105                Query q = session.createQuery(sql);
1106
1107                QueryPos qPos = QueryPos.getInstance(q);
1108
1109                qPos.add(groupId);
1110
1111                if (name != null) {
1112                    qPos.add(name);
1113                }
1114
1115                if (portletId != null) {
1116                    qPos.add(portletId);
1117                }
1118
1119                qPos.add(classNameId);
1120
1121                List<PortletItem> list = q.list();
1122
1123                result = list;
1124
1125                PortletItem portletItem = null;
1126
1127                if (list.isEmpty()) {
1128                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N_P_C,
1129                        finderArgs, list);
1130                }
1131                else {
1132                    portletItem = list.get(0);
1133
1134                    cacheResult(portletItem);
1135
1136                    if ((portletItem.getGroupId() != groupId) ||
1137                            (portletItem.getName() == null) ||
1138                            !portletItem.getName().equals(name) ||
1139                            (portletItem.getPortletId() == null) ||
1140                            !portletItem.getPortletId().equals(portletId) ||
1141                            (portletItem.getClassNameId() != classNameId)) {
1142                        FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N_P_C,
1143                            finderArgs, portletItem);
1144                    }
1145                }
1146
1147                return portletItem;
1148            }
1149            catch (Exception e) {
1150                throw processException(e);
1151            }
1152            finally {
1153                if (result == null) {
1154                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N_P_C,
1155                        finderArgs, new ArrayList<PortletItem>());
1156                }
1157
1158                closeSession(session);
1159            }
1160        }
1161        else {
1162            if (result instanceof List<?>) {
1163                return null;
1164            }
1165            else {
1166                return (PortletItem)result;
1167            }
1168        }
1169    }
1170
1171    public List<PortletItem> findAll() throws SystemException {
1172        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1173    }
1174
1175    public List<PortletItem> findAll(int start, int end)
1176        throws SystemException {
1177        return findAll(start, end, null);
1178    }
1179
1180    public List<PortletItem> findAll(int start, int end,
1181        OrderByComparator orderByComparator) throws SystemException {
1182        Object[] finderArgs = new Object[] {
1183                String.valueOf(start), String.valueOf(end),
1184                String.valueOf(orderByComparator)
1185            };
1186
1187        List<PortletItem> list = (List<PortletItem>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1188                finderArgs, this);
1189
1190        if (list == null) {
1191            Session session = null;
1192
1193            try {
1194                session = openSession();
1195
1196                StringBundler query = null;
1197                String sql = null;
1198
1199                if (orderByComparator != null) {
1200                    query = new StringBundler(2 +
1201                            (orderByComparator.getOrderByFields().length * 3));
1202
1203                    query.append(_SQL_SELECT_PORTLETITEM);
1204
1205                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1206                        orderByComparator);
1207
1208                    sql = query.toString();
1209                }
1210
1211                sql = _SQL_SELECT_PORTLETITEM;
1212
1213                Query q = session.createQuery(sql);
1214
1215                if (orderByComparator == null) {
1216                    list = (List<PortletItem>)QueryUtil.list(q, getDialect(),
1217                            start, end, false);
1218
1219                    Collections.sort(list);
1220                }
1221                else {
1222                    list = (List<PortletItem>)QueryUtil.list(q, getDialect(),
1223                            start, end);
1224                }
1225            }
1226            catch (Exception e) {
1227                throw processException(e);
1228            }
1229            finally {
1230                if (list == null) {
1231                    list = new ArrayList<PortletItem>();
1232                }
1233
1234                cacheResult(list);
1235
1236                FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1237
1238                closeSession(session);
1239            }
1240        }
1241
1242        return list;
1243    }
1244
1245    public void removeByG_C(long groupId, long classNameId)
1246        throws SystemException {
1247        for (PortletItem portletItem : findByG_C(groupId, classNameId)) {
1248            remove(portletItem);
1249        }
1250    }
1251
1252    public void removeByG_P_C(long groupId, String portletId, long classNameId)
1253        throws SystemException {
1254        for (PortletItem portletItem : findByG_P_C(groupId, portletId,
1255                classNameId)) {
1256            remove(portletItem);
1257        }
1258    }
1259
1260    public void removeByG_N_P_C(long groupId, String name, String portletId,
1261        long classNameId) throws NoSuchPortletItemException, SystemException {
1262        PortletItem portletItem = findByG_N_P_C(groupId, name, portletId,
1263                classNameId);
1264
1265        remove(portletItem);
1266    }
1267
1268    public void removeAll() throws SystemException {
1269        for (PortletItem portletItem : findAll()) {
1270            remove(portletItem);
1271        }
1272    }
1273
1274    public int countByG_C(long groupId, long classNameId)
1275        throws SystemException {
1276        Object[] finderArgs = new Object[] {
1277                new Long(groupId), new Long(classNameId)
1278            };
1279
1280        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C,
1281                finderArgs, this);
1282
1283        if (count == null) {
1284            Session session = null;
1285
1286            try {
1287                session = openSession();
1288
1289                StringBundler query = new StringBundler(3);
1290
1291                query.append(_SQL_COUNT_PORTLETITEM_WHERE);
1292
1293                query.append(_FINDER_COLUMN_G_C_GROUPID_2);
1294
1295                query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_2);
1296
1297                String sql = query.toString();
1298
1299                Query q = session.createQuery(sql);
1300
1301                QueryPos qPos = QueryPos.getInstance(q);
1302
1303                qPos.add(groupId);
1304
1305                qPos.add(classNameId);
1306
1307                count = (Long)q.uniqueResult();
1308            }
1309            catch (Exception e) {
1310                throw processException(e);
1311            }
1312            finally {
1313                if (count == null) {
1314                    count = Long.valueOf(0);
1315                }
1316
1317                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C, finderArgs,
1318                    count);
1319
1320                closeSession(session);
1321            }
1322        }
1323
1324        return count.intValue();
1325    }
1326
1327    public int countByG_P_C(long groupId, String portletId, long classNameId)
1328        throws SystemException {
1329        Object[] finderArgs = new Object[] {
1330                new Long(groupId),
1331                
1332                portletId, new Long(classNameId)
1333            };
1334
1335        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_P_C,
1336                finderArgs, this);
1337
1338        if (count == null) {
1339            Session session = null;
1340
1341            try {
1342                session = openSession();
1343
1344                StringBundler query = new StringBundler(4);
1345
1346                query.append(_SQL_COUNT_PORTLETITEM_WHERE);
1347
1348                query.append(_FINDER_COLUMN_G_P_C_GROUPID_2);
1349
1350                if (portletId == null) {
1351                    query.append(_FINDER_COLUMN_G_P_C_PORTLETID_1);
1352                }
1353                else {
1354                    if (portletId.equals(StringPool.BLANK)) {
1355                        query.append(_FINDER_COLUMN_G_P_C_PORTLETID_3);
1356                    }
1357                    else {
1358                        query.append(_FINDER_COLUMN_G_P_C_PORTLETID_2);
1359                    }
1360                }
1361
1362                query.append(_FINDER_COLUMN_G_P_C_CLASSNAMEID_2);
1363
1364                String sql = query.toString();
1365
1366                Query q = session.createQuery(sql);
1367
1368                QueryPos qPos = QueryPos.getInstance(q);
1369
1370                qPos.add(groupId);
1371
1372                if (portletId != null) {
1373                    qPos.add(portletId);
1374                }
1375
1376                qPos.add(classNameId);
1377
1378                count = (Long)q.uniqueResult();
1379            }
1380            catch (Exception e) {
1381                throw processException(e);
1382            }
1383            finally {
1384                if (count == null) {
1385                    count = Long.valueOf(0);
1386                }
1387
1388                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P_C,
1389                    finderArgs, count);
1390
1391                closeSession(session);
1392            }
1393        }
1394
1395        return count.intValue();
1396    }
1397
1398    public int countByG_N_P_C(long groupId, String name, String portletId,
1399        long classNameId) throws SystemException {
1400        Object[] finderArgs = new Object[] {
1401                new Long(groupId),
1402                
1403                name,
1404                
1405                portletId, new Long(classNameId)
1406            };
1407
1408        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_N_P_C,
1409                finderArgs, this);
1410
1411        if (count == null) {
1412            Session session = null;
1413
1414            try {
1415                session = openSession();
1416
1417                StringBundler query = new StringBundler(5);
1418
1419                query.append(_SQL_COUNT_PORTLETITEM_WHERE);
1420
1421                query.append(_FINDER_COLUMN_G_N_P_C_GROUPID_2);
1422
1423                if (name == null) {
1424                    query.append(_FINDER_COLUMN_G_N_P_C_NAME_1);
1425                }
1426                else {
1427                    if (name.equals(StringPool.BLANK)) {
1428                        query.append(_FINDER_COLUMN_G_N_P_C_NAME_3);
1429                    }
1430                    else {
1431                        query.append(_FINDER_COLUMN_G_N_P_C_NAME_2);
1432                    }
1433                }
1434
1435                if (portletId == null) {
1436                    query.append(_FINDER_COLUMN_G_N_P_C_PORTLETID_1);
1437                }
1438                else {
1439                    if (portletId.equals(StringPool.BLANK)) {
1440                        query.append(_FINDER_COLUMN_G_N_P_C_PORTLETID_3);
1441                    }
1442                    else {
1443                        query.append(_FINDER_COLUMN_G_N_P_C_PORTLETID_2);
1444                    }
1445                }
1446
1447                query.append(_FINDER_COLUMN_G_N_P_C_CLASSNAMEID_2);
1448
1449                String sql = query.toString();
1450
1451                Query q = session.createQuery(sql);
1452
1453                QueryPos qPos = QueryPos.getInstance(q);
1454
1455                qPos.add(groupId);
1456
1457                if (name != null) {
1458                    qPos.add(name);
1459                }
1460
1461                if (portletId != null) {
1462                    qPos.add(portletId);
1463                }
1464
1465                qPos.add(classNameId);
1466
1467                count = (Long)q.uniqueResult();
1468            }
1469            catch (Exception e) {
1470                throw processException(e);
1471            }
1472            finally {
1473                if (count == null) {
1474                    count = Long.valueOf(0);
1475                }
1476
1477                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_N_P_C,
1478                    finderArgs, count);
1479
1480                closeSession(session);
1481            }
1482        }
1483
1484        return count.intValue();
1485    }
1486
1487    public int countAll() throws SystemException {
1488        Object[] finderArgs = new Object[0];
1489
1490        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1491                finderArgs, this);
1492
1493        if (count == null) {
1494            Session session = null;
1495
1496            try {
1497                session = openSession();
1498
1499                Query q = session.createQuery(_SQL_COUNT_PORTLETITEM);
1500
1501                count = (Long)q.uniqueResult();
1502            }
1503            catch (Exception e) {
1504                throw processException(e);
1505            }
1506            finally {
1507                if (count == null) {
1508                    count = Long.valueOf(0);
1509                }
1510
1511                FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1512                    count);
1513
1514                closeSession(session);
1515            }
1516        }
1517
1518        return count.intValue();
1519    }
1520
1521    public void afterPropertiesSet() {
1522        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1523                    com.liferay.portal.util.PropsUtil.get(
1524                        "value.object.listener.com.liferay.portal.model.PortletItem")));
1525
1526        if (listenerClassNames.length > 0) {
1527            try {
1528                List<ModelListener<PortletItem>> listenersList = new ArrayList<ModelListener<PortletItem>>();
1529
1530                for (String listenerClassName : listenerClassNames) {
1531                    listenersList.add((ModelListener<PortletItem>)InstanceFactory.newInstance(
1532                            listenerClassName));
1533                }
1534
1535                listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1536            }
1537            catch (Exception e) {
1538                _log.error(e);
1539            }
1540        }
1541    }
1542
1543    @BeanReference(type = AccountPersistence.class)
1544    protected AccountPersistence accountPersistence;
1545    @BeanReference(type = AddressPersistence.class)
1546    protected AddressPersistence addressPersistence;
1547    @BeanReference(type = BrowserTrackerPersistence.class)
1548    protected BrowserTrackerPersistence browserTrackerPersistence;
1549    @BeanReference(type = ClassNamePersistence.class)
1550    protected ClassNamePersistence classNamePersistence;
1551    @BeanReference(type = CompanyPersistence.class)
1552    protected CompanyPersistence companyPersistence;
1553    @BeanReference(type = ContactPersistence.class)
1554    protected ContactPersistence contactPersistence;
1555    @BeanReference(type = CountryPersistence.class)
1556    protected CountryPersistence countryPersistence;
1557    @BeanReference(type = EmailAddressPersistence.class)
1558    protected EmailAddressPersistence emailAddressPersistence;
1559    @BeanReference(type = GroupPersistence.class)
1560    protected GroupPersistence groupPersistence;
1561    @BeanReference(type = ImagePersistence.class)
1562    protected ImagePersistence imagePersistence;
1563    @BeanReference(type = LayoutPersistence.class)
1564    protected LayoutPersistence layoutPersistence;
1565    @BeanReference(type = LayoutPrototypePersistence.class)
1566    protected LayoutPrototypePersistence layoutPrototypePersistence;
1567    @BeanReference(type = LayoutSetPersistence.class)
1568    protected LayoutSetPersistence layoutSetPersistence;
1569    @BeanReference(type = LayoutSetPrototypePersistence.class)
1570    protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
1571    @BeanReference(type = ListTypePersistence.class)
1572    protected ListTypePersistence listTypePersistence;
1573    @BeanReference(type = LockPersistence.class)
1574    protected LockPersistence lockPersistence;
1575    @BeanReference(type = MembershipRequestPersistence.class)
1576    protected MembershipRequestPersistence membershipRequestPersistence;
1577    @BeanReference(type = OrganizationPersistence.class)
1578    protected OrganizationPersistence organizationPersistence;
1579    @BeanReference(type = OrgGroupPermissionPersistence.class)
1580    protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1581    @BeanReference(type = OrgGroupRolePersistence.class)
1582    protected OrgGroupRolePersistence orgGroupRolePersistence;
1583    @BeanReference(type = OrgLaborPersistence.class)
1584    protected OrgLaborPersistence orgLaborPersistence;
1585    @BeanReference(type = PasswordPolicyPersistence.class)
1586    protected PasswordPolicyPersistence passwordPolicyPersistence;
1587    @BeanReference(type = PasswordPolicyRelPersistence.class)
1588    protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1589    @BeanReference(type = PasswordTrackerPersistence.class)
1590    protected PasswordTrackerPersistence passwordTrackerPersistence;
1591    @BeanReference(type = PermissionPersistence.class)
1592    protected PermissionPersistence permissionPersistence;
1593    @BeanReference(type = PhonePersistence.class)
1594    protected PhonePersistence phonePersistence;
1595    @BeanReference(type = PluginSettingPersistence.class)
1596    protected PluginSettingPersistence pluginSettingPersistence;
1597    @BeanReference(type = PortletPersistence.class)
1598    protected PortletPersistence portletPersistence;
1599    @BeanReference(type = PortletItemPersistence.class)
1600    protected PortletItemPersistence portletItemPersistence;
1601    @BeanReference(type = PortletPreferencesPersistence.class)
1602    protected PortletPreferencesPersistence portletPreferencesPersistence;
1603    @BeanReference(type = RegionPersistence.class)
1604    protected RegionPersistence regionPersistence;
1605    @BeanReference(type = ReleasePersistence.class)
1606    protected ReleasePersistence releasePersistence;
1607    @BeanReference(type = ResourcePersistence.class)
1608    protected ResourcePersistence resourcePersistence;
1609    @BeanReference(type = ResourceActionPersistence.class)
1610    protected ResourceActionPersistence resourceActionPersistence;
1611    @BeanReference(type = ResourceCodePersistence.class)
1612    protected ResourceCodePersistence resourceCodePersistence;
1613    @BeanReference(type = ResourcePermissionPersistence.class)
1614    protected ResourcePermissionPersistence resourcePermissionPersistence;
1615    @BeanReference(type = RolePersistence.class)
1616    protected RolePersistence rolePersistence;
1617    @BeanReference(type = ServiceComponentPersistence.class)
1618    protected ServiceComponentPersistence serviceComponentPersistence;
1619    @BeanReference(type = ShardPersistence.class)
1620    protected ShardPersistence shardPersistence;
1621    @BeanReference(type = SubscriptionPersistence.class)
1622    protected SubscriptionPersistence subscriptionPersistence;
1623    @BeanReference(type = TicketPersistence.class)
1624    protected TicketPersistence ticketPersistence;
1625    @BeanReference(type = TeamPersistence.class)
1626    protected TeamPersistence teamPersistence;
1627    @BeanReference(type = UserPersistence.class)
1628    protected UserPersistence userPersistence;
1629    @BeanReference(type = UserGroupPersistence.class)
1630    protected UserGroupPersistence userGroupPersistence;
1631    @BeanReference(type = UserGroupGroupRolePersistence.class)
1632    protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1633    @BeanReference(type = UserGroupRolePersistence.class)
1634    protected UserGroupRolePersistence userGroupRolePersistence;
1635    @BeanReference(type = UserIdMapperPersistence.class)
1636    protected UserIdMapperPersistence userIdMapperPersistence;
1637    @BeanReference(type = UserTrackerPersistence.class)
1638    protected UserTrackerPersistence userTrackerPersistence;
1639    @BeanReference(type = UserTrackerPathPersistence.class)
1640    protected UserTrackerPathPersistence userTrackerPathPersistence;
1641    @BeanReference(type = WebDAVPropsPersistence.class)
1642    protected WebDAVPropsPersistence webDAVPropsPersistence;
1643    @BeanReference(type = WebsitePersistence.class)
1644    protected WebsitePersistence websitePersistence;
1645    @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
1646    protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1647    @BeanReference(type = WorkflowInstanceLinkPersistence.class)
1648    protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1649    private static final String _SQL_SELECT_PORTLETITEM = "SELECT portletItem FROM PortletItem portletItem";
1650    private static final String _SQL_SELECT_PORTLETITEM_WHERE = "SELECT portletItem FROM PortletItem portletItem WHERE ";
1651    private static final String _SQL_COUNT_PORTLETITEM = "SELECT COUNT(portletItem) FROM PortletItem portletItem";
1652    private static final String _SQL_COUNT_PORTLETITEM_WHERE = "SELECT COUNT(portletItem) FROM PortletItem portletItem WHERE ";
1653    private static final String _FINDER_COLUMN_G_C_GROUPID_2 = "portletItem.groupId = ? AND ";
1654    private static final String _FINDER_COLUMN_G_C_CLASSNAMEID_2 = "portletItem.classNameId = ?";
1655    private static final String _FINDER_COLUMN_G_P_C_GROUPID_2 = "portletItem.groupId = ? AND ";
1656    private static final String _FINDER_COLUMN_G_P_C_PORTLETID_1 = "portletItem.portletId IS NULL AND ";
1657    private static final String _FINDER_COLUMN_G_P_C_PORTLETID_2 = "portletItem.portletId = ? AND ";
1658    private static final String _FINDER_COLUMN_G_P_C_PORTLETID_3 = "(portletItem.portletId IS NULL OR portletItem.portletId = ?) AND ";
1659    private static final String _FINDER_COLUMN_G_P_C_CLASSNAMEID_2 = "portletItem.classNameId = ?";
1660    private static final String _FINDER_COLUMN_G_N_P_C_GROUPID_2 = "portletItem.groupId = ? AND ";
1661    private static final String _FINDER_COLUMN_G_N_P_C_NAME_1 = "portletItem.name IS NULL AND ";
1662    private static final String _FINDER_COLUMN_G_N_P_C_NAME_2 = "lower(portletItem.name) = lower(?) AND ";
1663    private static final String _FINDER_COLUMN_G_N_P_C_NAME_3 = "(portletItem.name IS NULL OR lower(portletItem.name) = lower(?)) AND ";
1664    private static final String _FINDER_COLUMN_G_N_P_C_PORTLETID_1 = "portletItem.portletId IS NULL AND ";
1665    private static final String _FINDER_COLUMN_G_N_P_C_PORTLETID_2 = "portletItem.portletId = ? AND ";
1666    private static final String _FINDER_COLUMN_G_N_P_C_PORTLETID_3 = "(portletItem.portletId IS NULL OR portletItem.portletId = ?) AND ";
1667    private static final String _FINDER_COLUMN_G_N_P_C_CLASSNAMEID_2 = "portletItem.classNameId = ?";
1668    private static final String _ORDER_BY_ENTITY_ALIAS = "portletItem.";
1669    private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No PortletItem exists with the primary key ";
1670    private static final String _NO_SUCH_ENTITY_WITH_KEY = "No PortletItem exists with the key {";
1671    private static Log _log = LogFactoryUtil.getLog(PortletItemPersistenceImpl.class);
1672}