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