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