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