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