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