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