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