001
014
015 package com.liferay.portal.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.NoSuchResourceException;
019 import com.liferay.portal.kernel.annotation.BeanReference;
020 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
023 import com.liferay.portal.kernel.dao.orm.FinderPath;
024 import com.liferay.portal.kernel.dao.orm.Query;
025 import com.liferay.portal.kernel.dao.orm.QueryPos;
026 import com.liferay.portal.kernel.dao.orm.QueryUtil;
027 import com.liferay.portal.kernel.dao.orm.Session;
028 import com.liferay.portal.kernel.exception.SystemException;
029 import com.liferay.portal.kernel.log.Log;
030 import com.liferay.portal.kernel.log.LogFactoryUtil;
031 import com.liferay.portal.kernel.util.GetterUtil;
032 import com.liferay.portal.kernel.util.InstanceFactory;
033 import com.liferay.portal.kernel.util.OrderByComparator;
034 import com.liferay.portal.kernel.util.StringBundler;
035 import com.liferay.portal.kernel.util.StringPool;
036 import com.liferay.portal.kernel.util.StringUtil;
037 import com.liferay.portal.kernel.util.Validator;
038 import com.liferay.portal.model.ModelListener;
039 import com.liferay.portal.model.Resource;
040 import com.liferay.portal.model.impl.ResourceImpl;
041 import com.liferay.portal.model.impl.ResourceModelImpl;
042 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
043
044 import java.io.Serializable;
045
046 import java.util.ArrayList;
047 import java.util.Collections;
048 import java.util.List;
049
050
066 public class ResourcePersistenceImpl extends BasePersistenceImpl<Resource>
067 implements ResourcePersistence {
068 public static final String FINDER_CLASS_NAME_ENTITY = ResourceImpl.class.getName();
069 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
070 ".List";
071 public static final FinderPath FINDER_PATH_FIND_BY_CODEID = new FinderPath(ResourceModelImpl.ENTITY_CACHE_ENABLED,
072 ResourceModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
073 "findByCodeId",
074 new String[] {
075 Long.class.getName(),
076
077 "java.lang.Integer", "java.lang.Integer",
078 "com.liferay.portal.kernel.util.OrderByComparator"
079 });
080 public static final FinderPath FINDER_PATH_COUNT_BY_CODEID = new FinderPath(ResourceModelImpl.ENTITY_CACHE_ENABLED,
081 ResourceModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
082 "countByCodeId", new String[] { Long.class.getName() });
083 public static final FinderPath FINDER_PATH_FETCH_BY_C_P = new FinderPath(ResourceModelImpl.ENTITY_CACHE_ENABLED,
084 ResourceModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
085 "fetchByC_P",
086 new String[] { Long.class.getName(), String.class.getName() });
087 public static final FinderPath FINDER_PATH_COUNT_BY_C_P = new FinderPath(ResourceModelImpl.ENTITY_CACHE_ENABLED,
088 ResourceModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
089 "countByC_P",
090 new String[] { Long.class.getName(), String.class.getName() });
091 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(ResourceModelImpl.ENTITY_CACHE_ENABLED,
092 ResourceModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
093 "findAll", new String[0]);
094 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ResourceModelImpl.ENTITY_CACHE_ENABLED,
095 ResourceModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
096 "countAll", new String[0]);
097
098
103 public void cacheResult(Resource resource) {
104 EntityCacheUtil.putResult(ResourceModelImpl.ENTITY_CACHE_ENABLED,
105 ResourceImpl.class, resource.getPrimaryKey(), resource);
106
107 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_P,
108 new Object[] { new Long(resource.getCodeId()), resource.getPrimKey() },
109 resource);
110 }
111
112
117 public void cacheResult(List<Resource> resources) {
118 for (Resource resource : resources) {
119 if (EntityCacheUtil.getResult(
120 ResourceModelImpl.ENTITY_CACHE_ENABLED,
121 ResourceImpl.class, resource.getPrimaryKey(), this) == null) {
122 cacheResult(resource);
123 }
124 }
125 }
126
127
134 public void clearCache() {
135 CacheRegistryUtil.clear(ResourceImpl.class.getName());
136 EntityCacheUtil.clearCache(ResourceImpl.class.getName());
137 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
138 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
139 }
140
141
148 public void clearCache(Resource resource) {
149 EntityCacheUtil.removeResult(ResourceModelImpl.ENTITY_CACHE_ENABLED,
150 ResourceImpl.class, resource.getPrimaryKey());
151
152 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_P,
153 new Object[] { new Long(resource.getCodeId()), resource.getPrimKey() });
154 }
155
156
162 public Resource create(long resourceId) {
163 Resource resource = new ResourceImpl();
164
165 resource.setNew(true);
166 resource.setPrimaryKey(resourceId);
167
168 return resource;
169 }
170
171
179 public Resource remove(Serializable primaryKey)
180 throws NoSuchModelException, SystemException {
181 return remove(((Long)primaryKey).longValue());
182 }
183
184
192 public Resource remove(long resourceId)
193 throws NoSuchResourceException, SystemException {
194 Session session = null;
195
196 try {
197 session = openSession();
198
199 Resource resource = (Resource)session.get(ResourceImpl.class,
200 new Long(resourceId));
201
202 if (resource == null) {
203 if (_log.isWarnEnabled()) {
204 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + resourceId);
205 }
206
207 throw new NoSuchResourceException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
208 resourceId);
209 }
210
211 return remove(resource);
212 }
213 catch (NoSuchResourceException nsee) {
214 throw nsee;
215 }
216 catch (Exception e) {
217 throw processException(e);
218 }
219 finally {
220 closeSession(session);
221 }
222 }
223
224 protected Resource removeImpl(Resource resource) throws SystemException {
225 resource = toUnwrappedModel(resource);
226
227 Session session = null;
228
229 try {
230 session = openSession();
231
232 BatchSessionUtil.delete(session, resource);
233 }
234 catch (Exception e) {
235 throw processException(e);
236 }
237 finally {
238 closeSession(session);
239 }
240
241 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
242
243 ResourceModelImpl resourceModelImpl = (ResourceModelImpl)resource;
244
245 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_P,
246 new Object[] {
247 new Long(resourceModelImpl.getCodeId()),
248
249 resourceModelImpl.getPrimKey()
250 });
251
252 EntityCacheUtil.removeResult(ResourceModelImpl.ENTITY_CACHE_ENABLED,
253 ResourceImpl.class, resource.getPrimaryKey());
254
255 return resource;
256 }
257
258 public Resource updateImpl(com.liferay.portal.model.Resource resource,
259 boolean merge) throws SystemException {
260 resource = toUnwrappedModel(resource);
261
262 boolean isNew = resource.isNew();
263
264 ResourceModelImpl resourceModelImpl = (ResourceModelImpl)resource;
265
266 Session session = null;
267
268 try {
269 session = openSession();
270
271 BatchSessionUtil.update(session, resource, merge);
272
273 resource.setNew(false);
274 }
275 catch (Exception e) {
276 throw processException(e);
277 }
278 finally {
279 closeSession(session);
280 }
281
282 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
283
284 EntityCacheUtil.putResult(ResourceModelImpl.ENTITY_CACHE_ENABLED,
285 ResourceImpl.class, resource.getPrimaryKey(), resource);
286
287 if (!isNew &&
288 ((resource.getCodeId() != resourceModelImpl.getOriginalCodeId()) ||
289 !Validator.equals(resource.getPrimKey(),
290 resourceModelImpl.getOriginalPrimKey()))) {
291 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_P,
292 new Object[] {
293 new Long(resourceModelImpl.getOriginalCodeId()),
294
295 resourceModelImpl.getOriginalPrimKey()
296 });
297 }
298
299 if (isNew ||
300 ((resource.getCodeId() != resourceModelImpl.getOriginalCodeId()) ||
301 !Validator.equals(resource.getPrimKey(),
302 resourceModelImpl.getOriginalPrimKey()))) {
303 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_P,
304 new Object[] {
305 new Long(resource.getCodeId()),
306
307 resource.getPrimKey()
308 }, resource);
309 }
310
311 return resource;
312 }
313
314 protected Resource toUnwrappedModel(Resource resource) {
315 if (resource instanceof ResourceImpl) {
316 return resource;
317 }
318
319 ResourceImpl resourceImpl = new ResourceImpl();
320
321 resourceImpl.setNew(resource.isNew());
322 resourceImpl.setPrimaryKey(resource.getPrimaryKey());
323
324 resourceImpl.setResourceId(resource.getResourceId());
325 resourceImpl.setCodeId(resource.getCodeId());
326 resourceImpl.setPrimKey(resource.getPrimKey());
327
328 return resourceImpl;
329 }
330
331
339 public Resource findByPrimaryKey(Serializable primaryKey)
340 throws NoSuchModelException, SystemException {
341 return findByPrimaryKey(((Long)primaryKey).longValue());
342 }
343
344
352 public Resource findByPrimaryKey(long resourceId)
353 throws NoSuchResourceException, SystemException {
354 Resource resource = fetchByPrimaryKey(resourceId);
355
356 if (resource == null) {
357 if (_log.isWarnEnabled()) {
358 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + resourceId);
359 }
360
361 throw new NoSuchResourceException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
362 resourceId);
363 }
364
365 return resource;
366 }
367
368
375 public Resource fetchByPrimaryKey(Serializable primaryKey)
376 throws SystemException {
377 return fetchByPrimaryKey(((Long)primaryKey).longValue());
378 }
379
380
387 public Resource fetchByPrimaryKey(long resourceId)
388 throws SystemException {
389 Resource resource = (Resource)EntityCacheUtil.getResult(ResourceModelImpl.ENTITY_CACHE_ENABLED,
390 ResourceImpl.class, resourceId, this);
391
392 if (resource == null) {
393 Session session = null;
394
395 try {
396 session = openSession();
397
398 resource = (Resource)session.get(ResourceImpl.class,
399 new Long(resourceId));
400 }
401 catch (Exception e) {
402 throw processException(e);
403 }
404 finally {
405 if (resource != null) {
406 cacheResult(resource);
407 }
408
409 closeSession(session);
410 }
411 }
412
413 return resource;
414 }
415
416
423 public List<Resource> findByCodeId(long codeId) throws SystemException {
424 return findByCodeId(codeId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
425 }
426
427
440 public List<Resource> findByCodeId(long codeId, int start, int end)
441 throws SystemException {
442 return findByCodeId(codeId, start, end, null);
443 }
444
445
459 public List<Resource> findByCodeId(long codeId, int start, int end,
460 OrderByComparator orderByComparator) throws SystemException {
461 Object[] finderArgs = new Object[] {
462 codeId,
463
464 String.valueOf(start), String.valueOf(end),
465 String.valueOf(orderByComparator)
466 };
467
468 List<Resource> list = (List<Resource>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_CODEID,
469 finderArgs, this);
470
471 if (list == null) {
472 StringBundler query = null;
473
474 if (orderByComparator != null) {
475 query = new StringBundler(3 +
476 (orderByComparator.getOrderByFields().length * 3));
477 }
478 else {
479 query = new StringBundler(2);
480 }
481
482 query.append(_SQL_SELECT_RESOURCE_WHERE);
483
484 query.append(_FINDER_COLUMN_CODEID_CODEID_2);
485
486 if (orderByComparator != null) {
487 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
488 orderByComparator);
489 }
490
491 String sql = query.toString();
492
493 Session session = null;
494
495 try {
496 session = openSession();
497
498 Query q = session.createQuery(sql);
499
500 QueryPos qPos = QueryPos.getInstance(q);
501
502 qPos.add(codeId);
503
504 list = (List<Resource>)QueryUtil.list(q, getDialect(), start,
505 end);
506 }
507 catch (Exception e) {
508 throw processException(e);
509 }
510 finally {
511 if (list == null) {
512 FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_CODEID,
513 finderArgs);
514 }
515 else {
516 cacheResult(list);
517
518 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_CODEID,
519 finderArgs, list);
520 }
521
522 closeSession(session);
523 }
524 }
525
526 return list;
527 }
528
529
542 public Resource findByCodeId_First(long codeId,
543 OrderByComparator orderByComparator)
544 throws NoSuchResourceException, SystemException {
545 List<Resource> list = findByCodeId(codeId, 0, 1, orderByComparator);
546
547 if (list.isEmpty()) {
548 StringBundler msg = new StringBundler(4);
549
550 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
551
552 msg.append("codeId=");
553 msg.append(codeId);
554
555 msg.append(StringPool.CLOSE_CURLY_BRACE);
556
557 throw new NoSuchResourceException(msg.toString());
558 }
559 else {
560 return list.get(0);
561 }
562 }
563
564
577 public Resource findByCodeId_Last(long codeId,
578 OrderByComparator orderByComparator)
579 throws NoSuchResourceException, SystemException {
580 int count = countByCodeId(codeId);
581
582 List<Resource> list = findByCodeId(codeId, count - 1, count,
583 orderByComparator);
584
585 if (list.isEmpty()) {
586 StringBundler msg = new StringBundler(4);
587
588 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
589
590 msg.append("codeId=");
591 msg.append(codeId);
592
593 msg.append(StringPool.CLOSE_CURLY_BRACE);
594
595 throw new NoSuchResourceException(msg.toString());
596 }
597 else {
598 return list.get(0);
599 }
600 }
601
602
616 public Resource[] findByCodeId_PrevAndNext(long resourceId, long codeId,
617 OrderByComparator orderByComparator)
618 throws NoSuchResourceException, SystemException {
619 Resource resource = findByPrimaryKey(resourceId);
620
621 Session session = null;
622
623 try {
624 session = openSession();
625
626 Resource[] array = new ResourceImpl[3];
627
628 array[0] = getByCodeId_PrevAndNext(session, resource, codeId,
629 orderByComparator, true);
630
631 array[1] = resource;
632
633 array[2] = getByCodeId_PrevAndNext(session, resource, codeId,
634 orderByComparator, false);
635
636 return array;
637 }
638 catch (Exception e) {
639 throw processException(e);
640 }
641 finally {
642 closeSession(session);
643 }
644 }
645
646 protected Resource getByCodeId_PrevAndNext(Session session,
647 Resource resource, long codeId, OrderByComparator orderByComparator,
648 boolean previous) {
649 StringBundler query = null;
650
651 if (orderByComparator != null) {
652 query = new StringBundler(6 +
653 (orderByComparator.getOrderByFields().length * 6));
654 }
655 else {
656 query = new StringBundler(3);
657 }
658
659 query.append(_SQL_SELECT_RESOURCE_WHERE);
660
661 query.append(_FINDER_COLUMN_CODEID_CODEID_2);
662
663 if (orderByComparator != null) {
664 String[] orderByFields = orderByComparator.getOrderByFields();
665
666 if (orderByFields.length > 0) {
667 query.append(WHERE_AND);
668 }
669
670 for (int i = 0; i < orderByFields.length; i++) {
671 query.append(_ORDER_BY_ENTITY_ALIAS);
672 query.append(orderByFields[i]);
673
674 if ((i + 1) < orderByFields.length) {
675 if (orderByComparator.isAscending() ^ previous) {
676 query.append(WHERE_GREATER_THAN_HAS_NEXT);
677 }
678 else {
679 query.append(WHERE_LESSER_THAN_HAS_NEXT);
680 }
681 }
682 else {
683 if (orderByComparator.isAscending() ^ previous) {
684 query.append(WHERE_GREATER_THAN);
685 }
686 else {
687 query.append(WHERE_LESSER_THAN);
688 }
689 }
690 }
691
692 query.append(ORDER_BY_CLAUSE);
693
694 for (int i = 0; i < orderByFields.length; i++) {
695 query.append(_ORDER_BY_ENTITY_ALIAS);
696 query.append(orderByFields[i]);
697
698 if ((i + 1) < orderByFields.length) {
699 if (orderByComparator.isAscending() ^ previous) {
700 query.append(ORDER_BY_ASC_HAS_NEXT);
701 }
702 else {
703 query.append(ORDER_BY_DESC_HAS_NEXT);
704 }
705 }
706 else {
707 if (orderByComparator.isAscending() ^ previous) {
708 query.append(ORDER_BY_ASC);
709 }
710 else {
711 query.append(ORDER_BY_DESC);
712 }
713 }
714 }
715 }
716
717 String sql = query.toString();
718
719 Query q = session.createQuery(sql);
720
721 q.setFirstResult(0);
722 q.setMaxResults(2);
723
724 QueryPos qPos = QueryPos.getInstance(q);
725
726 qPos.add(codeId);
727
728 if (orderByComparator != null) {
729 Object[] values = orderByComparator.getOrderByValues(resource);
730
731 for (Object value : values) {
732 qPos.add(value);
733 }
734 }
735
736 List<Resource> list = q.list();
737
738 if (list.size() == 2) {
739 return list.get(1);
740 }
741 else {
742 return null;
743 }
744 }
745
746
755 public Resource findByC_P(long codeId, String primKey)
756 throws NoSuchResourceException, SystemException {
757 Resource resource = fetchByC_P(codeId, primKey);
758
759 if (resource == null) {
760 StringBundler msg = new StringBundler(6);
761
762 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
763
764 msg.append("codeId=");
765 msg.append(codeId);
766
767 msg.append(", primKey=");
768 msg.append(primKey);
769
770 msg.append(StringPool.CLOSE_CURLY_BRACE);
771
772 if (_log.isWarnEnabled()) {
773 _log.warn(msg.toString());
774 }
775
776 throw new NoSuchResourceException(msg.toString());
777 }
778
779 return resource;
780 }
781
782
790 public Resource fetchByC_P(long codeId, String primKey)
791 throws SystemException {
792 return fetchByC_P(codeId, primKey, true);
793 }
794
795
803 public Resource fetchByC_P(long codeId, String primKey,
804 boolean retrieveFromCache) throws SystemException {
805 Object[] finderArgs = new Object[] { codeId, primKey };
806
807 Object result = null;
808
809 if (retrieveFromCache) {
810 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_P,
811 finderArgs, this);
812 }
813
814 if (result == null) {
815 StringBundler query = new StringBundler(3);
816
817 query.append(_SQL_SELECT_RESOURCE_WHERE);
818
819 query.append(_FINDER_COLUMN_C_P_CODEID_2);
820
821 if (primKey == null) {
822 query.append(_FINDER_COLUMN_C_P_PRIMKEY_1);
823 }
824 else {
825 if (primKey.equals(StringPool.BLANK)) {
826 query.append(_FINDER_COLUMN_C_P_PRIMKEY_3);
827 }
828 else {
829 query.append(_FINDER_COLUMN_C_P_PRIMKEY_2);
830 }
831 }
832
833 String sql = query.toString();
834
835 Session session = null;
836
837 try {
838 session = openSession();
839
840 Query q = session.createQuery(sql);
841
842 QueryPos qPos = QueryPos.getInstance(q);
843
844 qPos.add(codeId);
845
846 if (primKey != null) {
847 qPos.add(primKey);
848 }
849
850 List<Resource> list = q.list();
851
852 result = list;
853
854 Resource resource = null;
855
856 if (list.isEmpty()) {
857 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_P,
858 finderArgs, list);
859 }
860 else {
861 resource = list.get(0);
862
863 cacheResult(resource);
864
865 if ((resource.getCodeId() != codeId) ||
866 (resource.getPrimKey() == null) ||
867 !resource.getPrimKey().equals(primKey)) {
868 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_P,
869 finderArgs, resource);
870 }
871 }
872
873 return resource;
874 }
875 catch (Exception e) {
876 throw processException(e);
877 }
878 finally {
879 if (result == null) {
880 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_P,
881 finderArgs);
882 }
883
884 closeSession(session);
885 }
886 }
887 else {
888 if (result instanceof List<?>) {
889 return null;
890 }
891 else {
892 return (Resource)result;
893 }
894 }
895 }
896
897
903 public List<Resource> findAll() throws SystemException {
904 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
905 }
906
907
919 public List<Resource> findAll(int start, int end) throws SystemException {
920 return findAll(start, end, null);
921 }
922
923
936 public List<Resource> findAll(int start, int end,
937 OrderByComparator orderByComparator) throws SystemException {
938 Object[] finderArgs = new Object[] {
939 String.valueOf(start), String.valueOf(end),
940 String.valueOf(orderByComparator)
941 };
942
943 List<Resource> list = (List<Resource>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
944 finderArgs, this);
945
946 if (list == null) {
947 StringBundler query = null;
948 String sql = null;
949
950 if (orderByComparator != null) {
951 query = new StringBundler(2 +
952 (orderByComparator.getOrderByFields().length * 3));
953
954 query.append(_SQL_SELECT_RESOURCE);
955
956 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
957 orderByComparator);
958
959 sql = query.toString();
960 }
961 else {
962 sql = _SQL_SELECT_RESOURCE;
963 }
964
965 Session session = null;
966
967 try {
968 session = openSession();
969
970 Query q = session.createQuery(sql);
971
972 if (orderByComparator == null) {
973 list = (List<Resource>)QueryUtil.list(q, getDialect(),
974 start, end, false);
975
976 Collections.sort(list);
977 }
978 else {
979 list = (List<Resource>)QueryUtil.list(q, getDialect(),
980 start, end);
981 }
982 }
983 catch (Exception e) {
984 throw processException(e);
985 }
986 finally {
987 if (list == null) {
988 FinderCacheUtil.removeResult(FINDER_PATH_FIND_ALL,
989 finderArgs);
990 }
991 else {
992 cacheResult(list);
993
994 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs,
995 list);
996 }
997
998 closeSession(session);
999 }
1000 }
1001
1002 return list;
1003 }
1004
1005
1011 public void removeByCodeId(long codeId) throws SystemException {
1012 for (Resource resource : findByCodeId(codeId)) {
1013 remove(resource);
1014 }
1015 }
1016
1017
1024 public void removeByC_P(long codeId, String primKey)
1025 throws NoSuchResourceException, SystemException {
1026 Resource resource = findByC_P(codeId, primKey);
1027
1028 remove(resource);
1029 }
1030
1031
1036 public void removeAll() throws SystemException {
1037 for (Resource resource : findAll()) {
1038 remove(resource);
1039 }
1040 }
1041
1042
1049 public int countByCodeId(long codeId) throws SystemException {
1050 Object[] finderArgs = new Object[] { codeId };
1051
1052 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_CODEID,
1053 finderArgs, this);
1054
1055 if (count == null) {
1056 StringBundler query = new StringBundler(2);
1057
1058 query.append(_SQL_COUNT_RESOURCE_WHERE);
1059
1060 query.append(_FINDER_COLUMN_CODEID_CODEID_2);
1061
1062 String sql = query.toString();
1063
1064 Session session = null;
1065
1066 try {
1067 session = openSession();
1068
1069 Query q = session.createQuery(sql);
1070
1071 QueryPos qPos = QueryPos.getInstance(q);
1072
1073 qPos.add(codeId);
1074
1075 count = (Long)q.uniqueResult();
1076 }
1077 catch (Exception e) {
1078 throw processException(e);
1079 }
1080 finally {
1081 if (count == null) {
1082 count = Long.valueOf(0);
1083 }
1084
1085 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_CODEID,
1086 finderArgs, count);
1087
1088 closeSession(session);
1089 }
1090 }
1091
1092 return count.intValue();
1093 }
1094
1095
1103 public int countByC_P(long codeId, String primKey)
1104 throws SystemException {
1105 Object[] finderArgs = new Object[] { codeId, primKey };
1106
1107 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_P,
1108 finderArgs, this);
1109
1110 if (count == null) {
1111 StringBundler query = new StringBundler(3);
1112
1113 query.append(_SQL_COUNT_RESOURCE_WHERE);
1114
1115 query.append(_FINDER_COLUMN_C_P_CODEID_2);
1116
1117 if (primKey == null) {
1118 query.append(_FINDER_COLUMN_C_P_PRIMKEY_1);
1119 }
1120 else {
1121 if (primKey.equals(StringPool.BLANK)) {
1122 query.append(_FINDER_COLUMN_C_P_PRIMKEY_3);
1123 }
1124 else {
1125 query.append(_FINDER_COLUMN_C_P_PRIMKEY_2);
1126 }
1127 }
1128
1129 String sql = query.toString();
1130
1131 Session session = null;
1132
1133 try {
1134 session = openSession();
1135
1136 Query q = session.createQuery(sql);
1137
1138 QueryPos qPos = QueryPos.getInstance(q);
1139
1140 qPos.add(codeId);
1141
1142 if (primKey != null) {
1143 qPos.add(primKey);
1144 }
1145
1146 count = (Long)q.uniqueResult();
1147 }
1148 catch (Exception e) {
1149 throw processException(e);
1150 }
1151 finally {
1152 if (count == null) {
1153 count = Long.valueOf(0);
1154 }
1155
1156 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_P, finderArgs,
1157 count);
1158
1159 closeSession(session);
1160 }
1161 }
1162
1163 return count.intValue();
1164 }
1165
1166
1172 public int countAll() throws SystemException {
1173 Object[] finderArgs = new Object[0];
1174
1175 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1176 finderArgs, this);
1177
1178 if (count == null) {
1179 Session session = null;
1180
1181 try {
1182 session = openSession();
1183
1184 Query q = session.createQuery(_SQL_COUNT_RESOURCE);
1185
1186 count = (Long)q.uniqueResult();
1187 }
1188 catch (Exception e) {
1189 throw processException(e);
1190 }
1191 finally {
1192 if (count == null) {
1193 count = Long.valueOf(0);
1194 }
1195
1196 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1197 count);
1198
1199 closeSession(session);
1200 }
1201 }
1202
1203 return count.intValue();
1204 }
1205
1206
1209 public void afterPropertiesSet() {
1210 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1211 com.liferay.portal.util.PropsUtil.get(
1212 "value.object.listener.com.liferay.portal.model.Resource")));
1213
1214 if (listenerClassNames.length > 0) {
1215 try {
1216 List<ModelListener<Resource>> listenersList = new ArrayList<ModelListener<Resource>>();
1217
1218 for (String listenerClassName : listenerClassNames) {
1219 listenersList.add((ModelListener<Resource>)InstanceFactory.newInstance(
1220 listenerClassName));
1221 }
1222
1223 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1224 }
1225 catch (Exception e) {
1226 _log.error(e);
1227 }
1228 }
1229 }
1230
1231 public void destroy() {
1232 EntityCacheUtil.removeCache(ResourceImpl.class.getName());
1233 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1234 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
1235 }
1236
1237 @BeanReference(type = AccountPersistence.class)
1238 protected AccountPersistence accountPersistence;
1239 @BeanReference(type = AddressPersistence.class)
1240 protected AddressPersistence addressPersistence;
1241 @BeanReference(type = BrowserTrackerPersistence.class)
1242 protected BrowserTrackerPersistence browserTrackerPersistence;
1243 @BeanReference(type = ClassNamePersistence.class)
1244 protected ClassNamePersistence classNamePersistence;
1245 @BeanReference(type = ClusterGroupPersistence.class)
1246 protected ClusterGroupPersistence clusterGroupPersistence;
1247 @BeanReference(type = CompanyPersistence.class)
1248 protected CompanyPersistence companyPersistence;
1249 @BeanReference(type = ContactPersistence.class)
1250 protected ContactPersistence contactPersistence;
1251 @BeanReference(type = CountryPersistence.class)
1252 protected CountryPersistence countryPersistence;
1253 @BeanReference(type = EmailAddressPersistence.class)
1254 protected EmailAddressPersistence emailAddressPersistence;
1255 @BeanReference(type = GroupPersistence.class)
1256 protected GroupPersistence groupPersistence;
1257 @BeanReference(type = ImagePersistence.class)
1258 protected ImagePersistence imagePersistence;
1259 @BeanReference(type = LayoutPersistence.class)
1260 protected LayoutPersistence layoutPersistence;
1261 @BeanReference(type = LayoutPrototypePersistence.class)
1262 protected LayoutPrototypePersistence layoutPrototypePersistence;
1263 @BeanReference(type = LayoutSetPersistence.class)
1264 protected LayoutSetPersistence layoutSetPersistence;
1265 @BeanReference(type = LayoutSetPrototypePersistence.class)
1266 protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
1267 @BeanReference(type = ListTypePersistence.class)
1268 protected ListTypePersistence listTypePersistence;
1269 @BeanReference(type = LockPersistence.class)
1270 protected LockPersistence lockPersistence;
1271 @BeanReference(type = MembershipRequestPersistence.class)
1272 protected MembershipRequestPersistence membershipRequestPersistence;
1273 @BeanReference(type = OrganizationPersistence.class)
1274 protected OrganizationPersistence organizationPersistence;
1275 @BeanReference(type = OrgGroupPermissionPersistence.class)
1276 protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1277 @BeanReference(type = OrgGroupRolePersistence.class)
1278 protected OrgGroupRolePersistence orgGroupRolePersistence;
1279 @BeanReference(type = OrgLaborPersistence.class)
1280 protected OrgLaborPersistence orgLaborPersistence;
1281 @BeanReference(type = PasswordPolicyPersistence.class)
1282 protected PasswordPolicyPersistence passwordPolicyPersistence;
1283 @BeanReference(type = PasswordPolicyRelPersistence.class)
1284 protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1285 @BeanReference(type = PasswordTrackerPersistence.class)
1286 protected PasswordTrackerPersistence passwordTrackerPersistence;
1287 @BeanReference(type = PermissionPersistence.class)
1288 protected PermissionPersistence permissionPersistence;
1289 @BeanReference(type = PhonePersistence.class)
1290 protected PhonePersistence phonePersistence;
1291 @BeanReference(type = PluginSettingPersistence.class)
1292 protected PluginSettingPersistence pluginSettingPersistence;
1293 @BeanReference(type = PortletPersistence.class)
1294 protected PortletPersistence portletPersistence;
1295 @BeanReference(type = PortletItemPersistence.class)
1296 protected PortletItemPersistence portletItemPersistence;
1297 @BeanReference(type = PortletPreferencesPersistence.class)
1298 protected PortletPreferencesPersistence portletPreferencesPersistence;
1299 @BeanReference(type = RegionPersistence.class)
1300 protected RegionPersistence regionPersistence;
1301 @BeanReference(type = ReleasePersistence.class)
1302 protected ReleasePersistence releasePersistence;
1303 @BeanReference(type = ResourcePersistence.class)
1304 protected ResourcePersistence resourcePersistence;
1305 @BeanReference(type = ResourceActionPersistence.class)
1306 protected ResourceActionPersistence resourceActionPersistence;
1307 @BeanReference(type = ResourceCodePersistence.class)
1308 protected ResourceCodePersistence resourceCodePersistence;
1309 @BeanReference(type = ResourcePermissionPersistence.class)
1310 protected ResourcePermissionPersistence resourcePermissionPersistence;
1311 @BeanReference(type = RolePersistence.class)
1312 protected RolePersistence rolePersistence;
1313 @BeanReference(type = ServiceComponentPersistence.class)
1314 protected ServiceComponentPersistence serviceComponentPersistence;
1315 @BeanReference(type = ShardPersistence.class)
1316 protected ShardPersistence shardPersistence;
1317 @BeanReference(type = SubscriptionPersistence.class)
1318 protected SubscriptionPersistence subscriptionPersistence;
1319 @BeanReference(type = TicketPersistence.class)
1320 protected TicketPersistence ticketPersistence;
1321 @BeanReference(type = TeamPersistence.class)
1322 protected TeamPersistence teamPersistence;
1323 @BeanReference(type = UserPersistence.class)
1324 protected UserPersistence userPersistence;
1325 @BeanReference(type = UserGroupPersistence.class)
1326 protected UserGroupPersistence userGroupPersistence;
1327 @BeanReference(type = UserGroupGroupRolePersistence.class)
1328 protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1329 @BeanReference(type = UserGroupRolePersistence.class)
1330 protected UserGroupRolePersistence userGroupRolePersistence;
1331 @BeanReference(type = UserIdMapperPersistence.class)
1332 protected UserIdMapperPersistence userIdMapperPersistence;
1333 @BeanReference(type = UserTrackerPersistence.class)
1334 protected UserTrackerPersistence userTrackerPersistence;
1335 @BeanReference(type = UserTrackerPathPersistence.class)
1336 protected UserTrackerPathPersistence userTrackerPathPersistence;
1337 @BeanReference(type = WebDAVPropsPersistence.class)
1338 protected WebDAVPropsPersistence webDAVPropsPersistence;
1339 @BeanReference(type = WebsitePersistence.class)
1340 protected WebsitePersistence websitePersistence;
1341 @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
1342 protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1343 @BeanReference(type = WorkflowInstanceLinkPersistence.class)
1344 protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1345 private static final String _SQL_SELECT_RESOURCE = "SELECT resource FROM Resource resource";
1346 private static final String _SQL_SELECT_RESOURCE_WHERE = "SELECT resource FROM Resource resource WHERE ";
1347 private static final String _SQL_COUNT_RESOURCE = "SELECT COUNT(resource) FROM Resource resource";
1348 private static final String _SQL_COUNT_RESOURCE_WHERE = "SELECT COUNT(resource) FROM Resource resource WHERE ";
1349 private static final String _FINDER_COLUMN_CODEID_CODEID_2 = "resource.codeId = ?";
1350 private static final String _FINDER_COLUMN_C_P_CODEID_2 = "resource.codeId = ? AND ";
1351 private static final String _FINDER_COLUMN_C_P_PRIMKEY_1 = "resource.primKey IS NULL";
1352 private static final String _FINDER_COLUMN_C_P_PRIMKEY_2 = "resource.primKey = ?";
1353 private static final String _FINDER_COLUMN_C_P_PRIMKEY_3 = "(resource.primKey IS NULL OR resource.primKey = ?)";
1354 private static final String _ORDER_BY_ENTITY_ALIAS = "resource.";
1355 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Resource exists with the primary key ";
1356 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Resource exists with the key {";
1357 private static Log _log = LogFactoryUtil.getLog(ResourcePersistenceImpl.class);
1358 }