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.NoSuchPortletException;
26  import com.liferay.portal.SystemException;
27  import com.liferay.portal.kernel.annotation.BeanReference;
28  import com.liferay.portal.kernel.dao.orm.DynamicQuery;
29  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
30  import com.liferay.portal.kernel.dao.orm.Query;
31  import com.liferay.portal.kernel.dao.orm.QueryPos;
32  import com.liferay.portal.kernel.dao.orm.QueryUtil;
33  import com.liferay.portal.kernel.dao.orm.Session;
34  import com.liferay.portal.kernel.log.Log;
35  import com.liferay.portal.kernel.log.LogFactoryUtil;
36  import com.liferay.portal.kernel.util.GetterUtil;
37  import com.liferay.portal.kernel.util.OrderByComparator;
38  import com.liferay.portal.kernel.util.StringPool;
39  import com.liferay.portal.kernel.util.StringUtil;
40  import com.liferay.portal.model.ModelListener;
41  import com.liferay.portal.model.Portlet;
42  import com.liferay.portal.model.impl.PortletImpl;
43  import com.liferay.portal.model.impl.PortletModelImpl;
44  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
45  
46  import java.util.ArrayList;
47  import java.util.Collections;
48  import java.util.Iterator;
49  import java.util.List;
50  
51  /**
52   * <a href="PortletPersistenceImpl.java.html"><b><i>View Source</i></b></a>
53   *
54   * @author Brian Wing Shun Chan
55   *
56   */
57  public class PortletPersistenceImpl extends BasePersistenceImpl
58      implements PortletPersistence {
59      public Portlet create(long id) {
60          Portlet portlet = new PortletImpl();
61  
62          portlet.setNew(true);
63          portlet.setPrimaryKey(id);
64  
65          return portlet;
66      }
67  
68      public Portlet remove(long id)
69          throws NoSuchPortletException, SystemException {
70          Session session = null;
71  
72          try {
73              session = openSession();
74  
75              Portlet portlet = (Portlet)session.get(PortletImpl.class,
76                      new Long(id));
77  
78              if (portlet == null) {
79                  if (_log.isWarnEnabled()) {
80                      _log.warn("No Portlet exists with the primary key " + id);
81                  }
82  
83                  throw new NoSuchPortletException(
84                      "No Portlet exists with the primary key " + id);
85              }
86  
87              return remove(portlet);
88          }
89          catch (NoSuchPortletException nsee) {
90              throw nsee;
91          }
92          catch (Exception e) {
93              throw processException(e);
94          }
95          finally {
96              closeSession(session);
97          }
98      }
99  
100     public Portlet remove(Portlet portlet) throws SystemException {
101         for (ModelListener listener : listeners) {
102             listener.onBeforeRemove(portlet);
103         }
104 
105         portlet = removeImpl(portlet);
106 
107         for (ModelListener listener : listeners) {
108             listener.onAfterRemove(portlet);
109         }
110 
111         return portlet;
112     }
113 
114     protected Portlet removeImpl(Portlet portlet) throws SystemException {
115         Session session = null;
116 
117         try {
118             session = openSession();
119 
120             if (BatchSessionUtil.isEnabled()) {
121                 Object staleObject = session.get(PortletImpl.class,
122                         portlet.getPrimaryKeyObj());
123 
124                 if (staleObject != null) {
125                     session.evict(staleObject);
126                 }
127             }
128 
129             session.delete(portlet);
130 
131             session.flush();
132 
133             return portlet;
134         }
135         catch (Exception e) {
136             throw processException(e);
137         }
138         finally {
139             closeSession(session);
140 
141             FinderCacheUtil.clearCache(Portlet.class.getName());
142         }
143     }
144 
145     /**
146      * @deprecated Use <code>update(Portlet portlet, boolean merge)</code>.
147      */
148     public Portlet update(Portlet portlet) throws SystemException {
149         if (_log.isWarnEnabled()) {
150             _log.warn(
151                 "Using the deprecated update(Portlet portlet) method. Use update(Portlet portlet, boolean merge) instead.");
152         }
153 
154         return update(portlet, false);
155     }
156 
157     /**
158      * Add, update, or merge, the entity. This method also calls the model
159      * listeners to trigger the proper events associated with adding, deleting,
160      * or updating an entity.
161      *
162      * @param        portlet the entity to add, update, or merge
163      * @param        merge boolean value for whether to merge the entity. The
164      *                default value is false. Setting merge to true is more
165      *                expensive and should only be true when portlet is
166      *                transient. See LEP-5473 for a detailed discussion of this
167      *                method.
168      * @return        true if the portlet can be displayed via Ajax
169      */
170     public Portlet update(Portlet portlet, boolean merge)
171         throws SystemException {
172         boolean isNew = portlet.isNew();
173 
174         for (ModelListener listener : listeners) {
175             if (isNew) {
176                 listener.onBeforeCreate(portlet);
177             }
178             else {
179                 listener.onBeforeUpdate(portlet);
180             }
181         }
182 
183         portlet = updateImpl(portlet, merge);
184 
185         for (ModelListener listener : listeners) {
186             if (isNew) {
187                 listener.onAfterCreate(portlet);
188             }
189             else {
190                 listener.onAfterUpdate(portlet);
191             }
192         }
193 
194         return portlet;
195     }
196 
197     public Portlet updateImpl(com.liferay.portal.model.Portlet portlet,
198         boolean merge) throws SystemException {
199         Session session = null;
200 
201         try {
202             session = openSession();
203 
204             BatchSessionUtil.update(session, portlet, merge);
205 
206             portlet.setNew(false);
207 
208             return portlet;
209         }
210         catch (Exception e) {
211             throw processException(e);
212         }
213         finally {
214             closeSession(session);
215 
216             FinderCacheUtil.clearCache(Portlet.class.getName());
217         }
218     }
219 
220     public Portlet findByPrimaryKey(long id)
221         throws NoSuchPortletException, SystemException {
222         Portlet portlet = fetchByPrimaryKey(id);
223 
224         if (portlet == null) {
225             if (_log.isWarnEnabled()) {
226                 _log.warn("No Portlet exists with the primary key " + id);
227             }
228 
229             throw new NoSuchPortletException(
230                 "No Portlet exists with the primary key " + id);
231         }
232 
233         return portlet;
234     }
235 
236     public Portlet fetchByPrimaryKey(long id) throws SystemException {
237         Session session = null;
238 
239         try {
240             session = openSession();
241 
242             return (Portlet)session.get(PortletImpl.class, new Long(id));
243         }
244         catch (Exception e) {
245             throw processException(e);
246         }
247         finally {
248             closeSession(session);
249         }
250     }
251 
252     public List<Portlet> findByCompanyId(long companyId)
253         throws SystemException {
254         boolean finderClassNameCacheEnabled = PortletModelImpl.CACHE_ENABLED;
255         String finderClassName = Portlet.class.getName();
256         String finderMethodName = "findByCompanyId";
257         String[] finderParams = new String[] { Long.class.getName() };
258         Object[] finderArgs = new Object[] { new Long(companyId) };
259 
260         Object result = null;
261 
262         if (finderClassNameCacheEnabled) {
263             result = FinderCacheUtil.getResult(finderClassName,
264                     finderMethodName, finderParams, finderArgs, this);
265         }
266 
267         if (result == null) {
268             Session session = null;
269 
270             try {
271                 session = openSession();
272 
273                 StringBuilder query = new StringBuilder();
274 
275                 query.append("FROM com.liferay.portal.model.Portlet WHERE ");
276 
277                 query.append("companyId = ?");
278 
279                 query.append(" ");
280 
281                 Query q = session.createQuery(query.toString());
282 
283                 QueryPos qPos = QueryPos.getInstance(q);
284 
285                 qPos.add(companyId);
286 
287                 List<Portlet> list = q.list();
288 
289                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
290                     finderClassName, finderMethodName, finderParams,
291                     finderArgs, list);
292 
293                 return list;
294             }
295             catch (Exception e) {
296                 throw processException(e);
297             }
298             finally {
299                 closeSession(session);
300             }
301         }
302         else {
303             return (List<Portlet>)result;
304         }
305     }
306 
307     public List<Portlet> findByCompanyId(long companyId, int start, int end)
308         throws SystemException {
309         return findByCompanyId(companyId, start, end, null);
310     }
311 
312     public List<Portlet> findByCompanyId(long companyId, int start, int end,
313         OrderByComparator obc) throws SystemException {
314         boolean finderClassNameCacheEnabled = PortletModelImpl.CACHE_ENABLED;
315         String finderClassName = Portlet.class.getName();
316         String finderMethodName = "findByCompanyId";
317         String[] finderParams = new String[] {
318                 Long.class.getName(),
319                 
320                 "java.lang.Integer", "java.lang.Integer",
321                 "com.liferay.portal.kernel.util.OrderByComparator"
322             };
323         Object[] finderArgs = new Object[] {
324                 new Long(companyId),
325                 
326                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
327             };
328 
329         Object result = null;
330 
331         if (finderClassNameCacheEnabled) {
332             result = FinderCacheUtil.getResult(finderClassName,
333                     finderMethodName, finderParams, finderArgs, this);
334         }
335 
336         if (result == null) {
337             Session session = null;
338 
339             try {
340                 session = openSession();
341 
342                 StringBuilder query = new StringBuilder();
343 
344                 query.append("FROM com.liferay.portal.model.Portlet WHERE ");
345 
346                 query.append("companyId = ?");
347 
348                 query.append(" ");
349 
350                 if (obc != null) {
351                     query.append("ORDER BY ");
352                     query.append(obc.getOrderBy());
353                 }
354 
355                 Query q = session.createQuery(query.toString());
356 
357                 QueryPos qPos = QueryPos.getInstance(q);
358 
359                 qPos.add(companyId);
360 
361                 List<Portlet> list = (List<Portlet>)QueryUtil.list(q,
362                         getDialect(), start, end);
363 
364                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
365                     finderClassName, finderMethodName, finderParams,
366                     finderArgs, list);
367 
368                 return list;
369             }
370             catch (Exception e) {
371                 throw processException(e);
372             }
373             finally {
374                 closeSession(session);
375             }
376         }
377         else {
378             return (List<Portlet>)result;
379         }
380     }
381 
382     public Portlet findByCompanyId_First(long companyId, OrderByComparator obc)
383         throws NoSuchPortletException, SystemException {
384         List<Portlet> list = findByCompanyId(companyId, 0, 1, obc);
385 
386         if (list.size() == 0) {
387             StringBuilder msg = new StringBuilder();
388 
389             msg.append("No Portlet exists with the key {");
390 
391             msg.append("companyId=" + companyId);
392 
393             msg.append(StringPool.CLOSE_CURLY_BRACE);
394 
395             throw new NoSuchPortletException(msg.toString());
396         }
397         else {
398             return list.get(0);
399         }
400     }
401 
402     public Portlet findByCompanyId_Last(long companyId, OrderByComparator obc)
403         throws NoSuchPortletException, SystemException {
404         int count = countByCompanyId(companyId);
405 
406         List<Portlet> list = findByCompanyId(companyId, count - 1, count, obc);
407 
408         if (list.size() == 0) {
409             StringBuilder msg = new StringBuilder();
410 
411             msg.append("No Portlet exists with the key {");
412 
413             msg.append("companyId=" + companyId);
414 
415             msg.append(StringPool.CLOSE_CURLY_BRACE);
416 
417             throw new NoSuchPortletException(msg.toString());
418         }
419         else {
420             return list.get(0);
421         }
422     }
423 
424     public Portlet[] findByCompanyId_PrevAndNext(long id, long companyId,
425         OrderByComparator obc) throws NoSuchPortletException, SystemException {
426         Portlet portlet = findByPrimaryKey(id);
427 
428         int count = countByCompanyId(companyId);
429 
430         Session session = null;
431 
432         try {
433             session = openSession();
434 
435             StringBuilder query = new StringBuilder();
436 
437             query.append("FROM com.liferay.portal.model.Portlet WHERE ");
438 
439             query.append("companyId = ?");
440 
441             query.append(" ");
442 
443             if (obc != null) {
444                 query.append("ORDER BY ");
445                 query.append(obc.getOrderBy());
446             }
447 
448             Query q = session.createQuery(query.toString());
449 
450             QueryPos qPos = QueryPos.getInstance(q);
451 
452             qPos.add(companyId);
453 
454             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, portlet);
455 
456             Portlet[] array = new PortletImpl[3];
457 
458             array[0] = (Portlet)objArray[0];
459             array[1] = (Portlet)objArray[1];
460             array[2] = (Portlet)objArray[2];
461 
462             return array;
463         }
464         catch (Exception e) {
465             throw processException(e);
466         }
467         finally {
468             closeSession(session);
469         }
470     }
471 
472     public Portlet findByC_P(long companyId, String portletId)
473         throws NoSuchPortletException, SystemException {
474         Portlet portlet = fetchByC_P(companyId, portletId);
475 
476         if (portlet == null) {
477             StringBuilder msg = new StringBuilder();
478 
479             msg.append("No Portlet exists with the key {");
480 
481             msg.append("companyId=" + companyId);
482 
483             msg.append(", ");
484             msg.append("portletId=" + portletId);
485 
486             msg.append(StringPool.CLOSE_CURLY_BRACE);
487 
488             if (_log.isWarnEnabled()) {
489                 _log.warn(msg.toString());
490             }
491 
492             throw new NoSuchPortletException(msg.toString());
493         }
494 
495         return portlet;
496     }
497 
498     public Portlet fetchByC_P(long companyId, String portletId)
499         throws SystemException {
500         boolean finderClassNameCacheEnabled = PortletModelImpl.CACHE_ENABLED;
501         String finderClassName = Portlet.class.getName();
502         String finderMethodName = "fetchByC_P";
503         String[] finderParams = new String[] {
504                 Long.class.getName(), String.class.getName()
505             };
506         Object[] finderArgs = new Object[] { new Long(companyId), portletId };
507 
508         Object result = null;
509 
510         if (finderClassNameCacheEnabled) {
511             result = FinderCacheUtil.getResult(finderClassName,
512                     finderMethodName, finderParams, finderArgs, this);
513         }
514 
515         if (result == null) {
516             Session session = null;
517 
518             try {
519                 session = openSession();
520 
521                 StringBuilder query = new StringBuilder();
522 
523                 query.append("FROM com.liferay.portal.model.Portlet WHERE ");
524 
525                 query.append("companyId = ?");
526 
527                 query.append(" AND ");
528 
529                 if (portletId == null) {
530                     query.append("portletId IS NULL");
531                 }
532                 else {
533                     query.append("portletId = ?");
534                 }
535 
536                 query.append(" ");
537 
538                 Query q = session.createQuery(query.toString());
539 
540                 QueryPos qPos = QueryPos.getInstance(q);
541 
542                 qPos.add(companyId);
543 
544                 if (portletId != null) {
545                     qPos.add(portletId);
546                 }
547 
548                 List<Portlet> list = q.list();
549 
550                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
551                     finderClassName, finderMethodName, finderParams,
552                     finderArgs, list);
553 
554                 if (list.size() == 0) {
555                     return null;
556                 }
557                 else {
558                     return list.get(0);
559                 }
560             }
561             catch (Exception e) {
562                 throw processException(e);
563             }
564             finally {
565                 closeSession(session);
566             }
567         }
568         else {
569             List<Portlet> list = (List<Portlet>)result;
570 
571             if (list.size() == 0) {
572                 return null;
573             }
574             else {
575                 return list.get(0);
576             }
577         }
578     }
579 
580     public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
581         throws SystemException {
582         Session session = null;
583 
584         try {
585             session = openSession();
586 
587             dynamicQuery.compile(session);
588 
589             return dynamicQuery.list();
590         }
591         catch (Exception e) {
592             throw processException(e);
593         }
594         finally {
595             closeSession(session);
596         }
597     }
598 
599     public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
600         int start, int end) throws SystemException {
601         Session session = null;
602 
603         try {
604             session = openSession();
605 
606             dynamicQuery.setLimit(start, end);
607 
608             dynamicQuery.compile(session);
609 
610             return dynamicQuery.list();
611         }
612         catch (Exception e) {
613             throw processException(e);
614         }
615         finally {
616             closeSession(session);
617         }
618     }
619 
620     public List<Portlet> findAll() throws SystemException {
621         return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
622     }
623 
624     public List<Portlet> findAll(int start, int end) throws SystemException {
625         return findAll(start, end, null);
626     }
627 
628     public List<Portlet> findAll(int start, int end, OrderByComparator obc)
629         throws SystemException {
630         boolean finderClassNameCacheEnabled = PortletModelImpl.CACHE_ENABLED;
631         String finderClassName = Portlet.class.getName();
632         String finderMethodName = "findAll";
633         String[] finderParams = new String[] {
634                 "java.lang.Integer", "java.lang.Integer",
635                 "com.liferay.portal.kernel.util.OrderByComparator"
636             };
637         Object[] finderArgs = new Object[] {
638                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
639             };
640 
641         Object result = null;
642 
643         if (finderClassNameCacheEnabled) {
644             result = FinderCacheUtil.getResult(finderClassName,
645                     finderMethodName, finderParams, finderArgs, this);
646         }
647 
648         if (result == null) {
649             Session session = null;
650 
651             try {
652                 session = openSession();
653 
654                 StringBuilder query = new StringBuilder();
655 
656                 query.append("FROM com.liferay.portal.model.Portlet ");
657 
658                 if (obc != null) {
659                     query.append("ORDER BY ");
660                     query.append(obc.getOrderBy());
661                 }
662 
663                 Query q = session.createQuery(query.toString());
664 
665                 List<Portlet> list = null;
666 
667                 if (obc == null) {
668                     list = (List<Portlet>)QueryUtil.list(q, getDialect(),
669                             start, end, false);
670 
671                     Collections.sort(list);
672                 }
673                 else {
674                     list = (List<Portlet>)QueryUtil.list(q, getDialect(),
675                             start, end);
676                 }
677 
678                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
679                     finderClassName, finderMethodName, finderParams,
680                     finderArgs, list);
681 
682                 return list;
683             }
684             catch (Exception e) {
685                 throw processException(e);
686             }
687             finally {
688                 closeSession(session);
689             }
690         }
691         else {
692             return (List<Portlet>)result;
693         }
694     }
695 
696     public void removeByCompanyId(long companyId) throws SystemException {
697         for (Portlet portlet : findByCompanyId(companyId)) {
698             remove(portlet);
699         }
700     }
701 
702     public void removeByC_P(long companyId, String portletId)
703         throws NoSuchPortletException, SystemException {
704         Portlet portlet = findByC_P(companyId, portletId);
705 
706         remove(portlet);
707     }
708 
709     public void removeAll() throws SystemException {
710         for (Portlet portlet : findAll()) {
711             remove(portlet);
712         }
713     }
714 
715     public int countByCompanyId(long companyId) throws SystemException {
716         boolean finderClassNameCacheEnabled = PortletModelImpl.CACHE_ENABLED;
717         String finderClassName = Portlet.class.getName();
718         String finderMethodName = "countByCompanyId";
719         String[] finderParams = new String[] { Long.class.getName() };
720         Object[] finderArgs = new Object[] { new Long(companyId) };
721 
722         Object result = null;
723 
724         if (finderClassNameCacheEnabled) {
725             result = FinderCacheUtil.getResult(finderClassName,
726                     finderMethodName, finderParams, finderArgs, this);
727         }
728 
729         if (result == null) {
730             Session session = null;
731 
732             try {
733                 session = openSession();
734 
735                 StringBuilder query = new StringBuilder();
736 
737                 query.append("SELECT COUNT(*) ");
738                 query.append("FROM com.liferay.portal.model.Portlet WHERE ");
739 
740                 query.append("companyId = ?");
741 
742                 query.append(" ");
743 
744                 Query q = session.createQuery(query.toString());
745 
746                 QueryPos qPos = QueryPos.getInstance(q);
747 
748                 qPos.add(companyId);
749 
750                 Long count = null;
751 
752                 Iterator<Long> itr = q.list().iterator();
753 
754                 if (itr.hasNext()) {
755                     count = itr.next();
756                 }
757 
758                 if (count == null) {
759                     count = new Long(0);
760                 }
761 
762                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
763                     finderClassName, finderMethodName, finderParams,
764                     finderArgs, count);
765 
766                 return count.intValue();
767             }
768             catch (Exception e) {
769                 throw processException(e);
770             }
771             finally {
772                 closeSession(session);
773             }
774         }
775         else {
776             return ((Long)result).intValue();
777         }
778     }
779 
780     public int countByC_P(long companyId, String portletId)
781         throws SystemException {
782         boolean finderClassNameCacheEnabled = PortletModelImpl.CACHE_ENABLED;
783         String finderClassName = Portlet.class.getName();
784         String finderMethodName = "countByC_P";
785         String[] finderParams = new String[] {
786                 Long.class.getName(), String.class.getName()
787             };
788         Object[] finderArgs = new Object[] { new Long(companyId), portletId };
789 
790         Object result = null;
791 
792         if (finderClassNameCacheEnabled) {
793             result = FinderCacheUtil.getResult(finderClassName,
794                     finderMethodName, finderParams, finderArgs, this);
795         }
796 
797         if (result == null) {
798             Session session = null;
799 
800             try {
801                 session = openSession();
802 
803                 StringBuilder query = new StringBuilder();
804 
805                 query.append("SELECT COUNT(*) ");
806                 query.append("FROM com.liferay.portal.model.Portlet WHERE ");
807 
808                 query.append("companyId = ?");
809 
810                 query.append(" AND ");
811 
812                 if (portletId == null) {
813                     query.append("portletId IS NULL");
814                 }
815                 else {
816                     query.append("portletId = ?");
817                 }
818 
819                 query.append(" ");
820 
821                 Query q = session.createQuery(query.toString());
822 
823                 QueryPos qPos = QueryPos.getInstance(q);
824 
825                 qPos.add(companyId);
826 
827                 if (portletId != null) {
828                     qPos.add(portletId);
829                 }
830 
831                 Long count = null;
832 
833                 Iterator<Long> itr = q.list().iterator();
834 
835                 if (itr.hasNext()) {
836                     count = itr.next();
837                 }
838 
839                 if (count == null) {
840                     count = new Long(0);
841                 }
842 
843                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
844                     finderClassName, finderMethodName, finderParams,
845                     finderArgs, count);
846 
847                 return count.intValue();
848             }
849             catch (Exception e) {
850                 throw processException(e);
851             }
852             finally {
853                 closeSession(session);
854             }
855         }
856         else {
857             return ((Long)result).intValue();
858         }
859     }
860 
861     public int countAll() throws SystemException {
862         boolean finderClassNameCacheEnabled = PortletModelImpl.CACHE_ENABLED;
863         String finderClassName = Portlet.class.getName();
864         String finderMethodName = "countAll";
865         String[] finderParams = new String[] {  };
866         Object[] finderArgs = new Object[] {  };
867 
868         Object result = null;
869 
870         if (finderClassNameCacheEnabled) {
871             result = FinderCacheUtil.getResult(finderClassName,
872                     finderMethodName, finderParams, finderArgs, this);
873         }
874 
875         if (result == null) {
876             Session session = null;
877 
878             try {
879                 session = openSession();
880 
881                 Query q = session.createQuery(
882                         "SELECT COUNT(*) FROM com.liferay.portal.model.Portlet");
883 
884                 Long count = null;
885 
886                 Iterator<Long> itr = q.list().iterator();
887 
888                 if (itr.hasNext()) {
889                     count = itr.next();
890                 }
891 
892                 if (count == null) {
893                     count = new Long(0);
894                 }
895 
896                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
897                     finderClassName, finderMethodName, finderParams,
898                     finderArgs, count);
899 
900                 return count.intValue();
901             }
902             catch (Exception e) {
903                 throw processException(e);
904             }
905             finally {
906                 closeSession(session);
907             }
908         }
909         else {
910             return ((Long)result).intValue();
911         }
912     }
913 
914     public void afterPropertiesSet() {
915         String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
916                     com.liferay.portal.util.PropsUtil.get(
917                         "value.object.listener.com.liferay.portal.model.Portlet")));
918 
919         if (listenerClassNames.length > 0) {
920             try {
921                 List<ModelListener> listenersList = new ArrayList<ModelListener>();
922 
923                 for (String listenerClassName : listenerClassNames) {
924                     listenersList.add((ModelListener)Class.forName(
925                             listenerClassName).newInstance());
926                 }
927 
928                 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
929             }
930             catch (Exception e) {
931                 _log.error(e);
932             }
933         }
934     }
935 
936     @BeanReference(name = "com.liferay.portal.service.persistence.AccountPersistence.impl")
937     protected com.liferay.portal.service.persistence.AccountPersistence accountPersistence;
938     @BeanReference(name = "com.liferay.portal.service.persistence.AddressPersistence.impl")
939     protected com.liferay.portal.service.persistence.AddressPersistence addressPersistence;
940     @BeanReference(name = "com.liferay.portal.service.persistence.ClassNamePersistence.impl")
941     protected com.liferay.portal.service.persistence.ClassNamePersistence classNamePersistence;
942     @BeanReference(name = "com.liferay.portal.service.persistence.CompanyPersistence.impl")
943     protected com.liferay.portal.service.persistence.CompanyPersistence companyPersistence;
944     @BeanReference(name = "com.liferay.portal.service.persistence.ContactPersistence.impl")
945     protected com.liferay.portal.service.persistence.ContactPersistence contactPersistence;
946     @BeanReference(name = "com.liferay.portal.service.persistence.CountryPersistence.impl")
947     protected com.liferay.portal.service.persistence.CountryPersistence countryPersistence;
948     @BeanReference(name = "com.liferay.portal.service.persistence.EmailAddressPersistence.impl")
949     protected com.liferay.portal.service.persistence.EmailAddressPersistence emailAddressPersistence;
950     @BeanReference(name = "com.liferay.portal.service.persistence.GroupPersistence.impl")
951     protected com.liferay.portal.service.persistence.GroupPersistence groupPersistence;
952     @BeanReference(name = "com.liferay.portal.service.persistence.ImagePersistence.impl")
953     protected com.liferay.portal.service.persistence.ImagePersistence imagePersistence;
954     @BeanReference(name = "com.liferay.portal.service.persistence.LayoutPersistence.impl")
955     protected com.liferay.portal.service.persistence.LayoutPersistence layoutPersistence;
956     @BeanReference(name = "com.liferay.portal.service.persistence.LayoutSetPersistence.impl")
957     protected com.liferay.portal.service.persistence.LayoutSetPersistence layoutSetPersistence;
958     @BeanReference(name = "com.liferay.portal.service.persistence.ListTypePersistence.impl")
959     protected com.liferay.portal.service.persistence.ListTypePersistence listTypePersistence;
960     @BeanReference(name = "com.liferay.portal.service.persistence.MembershipRequestPersistence.impl")
961     protected com.liferay.portal.service.persistence.MembershipRequestPersistence membershipRequestPersistence;
962     @BeanReference(name = "com.liferay.portal.service.persistence.OrganizationPersistence.impl")
963     protected com.liferay.portal.service.persistence.OrganizationPersistence organizationPersistence;
964     @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupPermissionPersistence.impl")
965     protected com.liferay.portal.service.persistence.OrgGroupPermissionPersistence orgGroupPermissionPersistence;
966     @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupRolePersistence.impl")
967     protected com.liferay.portal.service.persistence.OrgGroupRolePersistence orgGroupRolePersistence;
968     @BeanReference(name = "com.liferay.portal.service.persistence.OrgLaborPersistence.impl")
969     protected com.liferay.portal.service.persistence.OrgLaborPersistence orgLaborPersistence;
970     @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyPersistence.impl")
971     protected com.liferay.portal.service.persistence.PasswordPolicyPersistence passwordPolicyPersistence;
972     @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyRelPersistence.impl")
973     protected com.liferay.portal.service.persistence.PasswordPolicyRelPersistence passwordPolicyRelPersistence;
974     @BeanReference(name = "com.liferay.portal.service.persistence.PasswordTrackerPersistence.impl")
975     protected com.liferay.portal.service.persistence.PasswordTrackerPersistence passwordTrackerPersistence;
976     @BeanReference(name = "com.liferay.portal.service.persistence.PermissionPersistence.impl")
977     protected com.liferay.portal.service.persistence.PermissionPersistence permissionPersistence;
978     @BeanReference(name = "com.liferay.portal.service.persistence.PhonePersistence.impl")
979     protected com.liferay.portal.service.persistence.PhonePersistence phonePersistence;
980     @BeanReference(name = "com.liferay.portal.service.persistence.PluginSettingPersistence.impl")
981     protected com.liferay.portal.service.persistence.PluginSettingPersistence pluginSettingPersistence;
982     @BeanReference(name = "com.liferay.portal.service.persistence.PortletPersistence.impl")
983     protected com.liferay.portal.service.persistence.PortletPersistence portletPersistence;
984     @BeanReference(name = "com.liferay.portal.service.persistence.PortletPreferencesPersistence.impl")
985     protected com.liferay.portal.service.persistence.PortletPreferencesPersistence portletPreferencesPersistence;
986     @BeanReference(name = "com.liferay.portal.service.persistence.RegionPersistence.impl")
987     protected com.liferay.portal.service.persistence.RegionPersistence regionPersistence;
988     @BeanReference(name = "com.liferay.portal.service.persistence.ReleasePersistence.impl")
989     protected com.liferay.portal.service.persistence.ReleasePersistence releasePersistence;
990     @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence.impl")
991     protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
992     @BeanReference(name = "com.liferay.portal.service.persistence.ResourceCodePersistence.impl")
993     protected com.liferay.portal.service.persistence.ResourceCodePersistence resourceCodePersistence;
994     @BeanReference(name = "com.liferay.portal.service.persistence.RolePersistence.impl")
995     protected com.liferay.portal.service.persistence.RolePersistence rolePersistence;
996     @BeanReference(name = "com.liferay.portal.service.persistence.ServiceComponentPersistence.impl")
997     protected com.liferay.portal.service.persistence.ServiceComponentPersistence serviceComponentPersistence;
998     @BeanReference(name = "com.liferay.portal.service.persistence.PortletItemPersistence.impl")
999     protected com.liferay.portal.service.persistence.PortletItemPersistence portletItemPersistence;
1000    @BeanReference(name = "com.liferay.portal.service.persistence.SubscriptionPersistence.impl")
1001    protected com.liferay.portal.service.persistence.SubscriptionPersistence subscriptionPersistence;
1002    @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence.impl")
1003    protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
1004    @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupPersistence.impl")
1005    protected com.liferay.portal.service.persistence.UserGroupPersistence userGroupPersistence;
1006    @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupRolePersistence.impl")
1007    protected com.liferay.portal.service.persistence.UserGroupRolePersistence userGroupRolePersistence;
1008    @BeanReference(name = "com.liferay.portal.service.persistence.UserIdMapperPersistence.impl")
1009    protected com.liferay.portal.service.persistence.UserIdMapperPersistence userIdMapperPersistence;
1010    @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPersistence.impl")
1011    protected com.liferay.portal.service.persistence.UserTrackerPersistence userTrackerPersistence;
1012    @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPathPersistence.impl")
1013    protected com.liferay.portal.service.persistence.UserTrackerPathPersistence userTrackerPathPersistence;
1014    @BeanReference(name = "com.liferay.portal.service.persistence.WebDAVPropsPersistence.impl")
1015    protected com.liferay.portal.service.persistence.WebDAVPropsPersistence webDAVPropsPersistence;
1016    @BeanReference(name = "com.liferay.portal.service.persistence.WebsitePersistence.impl")
1017    protected com.liferay.portal.service.persistence.WebsitePersistence websitePersistence;
1018    private static Log _log = LogFactoryUtil.getLog(PortletPersistenceImpl.class);
1019}