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