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