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.getOriginalCodeId()),
248
249 resourceModelImpl.getOriginalPrimKey()
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 Session session = null;
473
474 try {
475 session = openSession();
476
477 StringBundler query = null;
478
479 if (orderByComparator != null) {
480 query = new StringBundler(3 +
481 (orderByComparator.getOrderByFields().length * 3));
482 }
483 else {
484 query = new StringBundler(2);
485 }
486
487 query.append(_SQL_SELECT_RESOURCE_WHERE);
488
489 query.append(_FINDER_COLUMN_CODEID_CODEID_2);
490
491 if (orderByComparator != null) {
492 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
493 orderByComparator);
494 }
495
496 String sql = query.toString();
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 list = new ArrayList<Resource>();
513 }
514
515 cacheResult(list);
516
517 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_CODEID,
518 finderArgs, list);
519
520 closeSession(session);
521 }
522 }
523
524 return list;
525 }
526
527
540 public Resource findByCodeId_First(long codeId,
541 OrderByComparator orderByComparator)
542 throws NoSuchResourceException, SystemException {
543 List<Resource> list = findByCodeId(codeId, 0, 1, orderByComparator);
544
545 if (list.isEmpty()) {
546 StringBundler msg = new StringBundler(4);
547
548 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
549
550 msg.append("codeId=");
551 msg.append(codeId);
552
553 msg.append(StringPool.CLOSE_CURLY_BRACE);
554
555 throw new NoSuchResourceException(msg.toString());
556 }
557 else {
558 return list.get(0);
559 }
560 }
561
562
575 public Resource findByCodeId_Last(long codeId,
576 OrderByComparator orderByComparator)
577 throws NoSuchResourceException, SystemException {
578 int count = countByCodeId(codeId);
579
580 List<Resource> list = findByCodeId(codeId, count - 1, count,
581 orderByComparator);
582
583 if (list.isEmpty()) {
584 StringBundler msg = new StringBundler(4);
585
586 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
587
588 msg.append("codeId=");
589 msg.append(codeId);
590
591 msg.append(StringPool.CLOSE_CURLY_BRACE);
592
593 throw new NoSuchResourceException(msg.toString());
594 }
595 else {
596 return list.get(0);
597 }
598 }
599
600
614 public Resource[] findByCodeId_PrevAndNext(long resourceId, long codeId,
615 OrderByComparator orderByComparator)
616 throws NoSuchResourceException, SystemException {
617 Resource resource = findByPrimaryKey(resourceId);
618
619 Session session = null;
620
621 try {
622 session = openSession();
623
624 Resource[] array = new ResourceImpl[3];
625
626 array[0] = getByCodeId_PrevAndNext(session, resource, codeId,
627 orderByComparator, true);
628
629 array[1] = resource;
630
631 array[2] = getByCodeId_PrevAndNext(session, resource, codeId,
632 orderByComparator, false);
633
634 return array;
635 }
636 catch (Exception e) {
637 throw processException(e);
638 }
639 finally {
640 closeSession(session);
641 }
642 }
643
644 protected Resource getByCodeId_PrevAndNext(Session session,
645 Resource resource, long codeId, OrderByComparator orderByComparator,
646 boolean previous) {
647 StringBundler query = null;
648
649 if (orderByComparator != null) {
650 query = new StringBundler(6 +
651 (orderByComparator.getOrderByFields().length * 6));
652 }
653 else {
654 query = new StringBundler(3);
655 }
656
657 query.append(_SQL_SELECT_RESOURCE_WHERE);
658
659 query.append(_FINDER_COLUMN_CODEID_CODEID_2);
660
661 if (orderByComparator != null) {
662 String[] orderByFields = orderByComparator.getOrderByFields();
663
664 if (orderByFields.length > 0) {
665 query.append(WHERE_AND);
666 }
667
668 for (int i = 0; i < orderByFields.length; i++) {
669 query.append(_ORDER_BY_ENTITY_ALIAS);
670 query.append(orderByFields[i]);
671
672 if ((i + 1) < orderByFields.length) {
673 if (orderByComparator.isAscending() ^ previous) {
674 query.append(WHERE_GREATER_THAN_HAS_NEXT);
675 }
676 else {
677 query.append(WHERE_LESSER_THAN_HAS_NEXT);
678 }
679 }
680 else {
681 if (orderByComparator.isAscending() ^ previous) {
682 query.append(WHERE_GREATER_THAN);
683 }
684 else {
685 query.append(WHERE_LESSER_THAN);
686 }
687 }
688 }
689
690 query.append(ORDER_BY_CLAUSE);
691
692 for (int i = 0; i < orderByFields.length; i++) {
693 query.append(_ORDER_BY_ENTITY_ALIAS);
694 query.append(orderByFields[i]);
695
696 if ((i + 1) < orderByFields.length) {
697 if (orderByComparator.isAscending() ^ previous) {
698 query.append(ORDER_BY_ASC_HAS_NEXT);
699 }
700 else {
701 query.append(ORDER_BY_DESC_HAS_NEXT);
702 }
703 }
704 else {
705 if (orderByComparator.isAscending() ^ previous) {
706 query.append(ORDER_BY_ASC);
707 }
708 else {
709 query.append(ORDER_BY_DESC);
710 }
711 }
712 }
713 }
714
715 String sql = query.toString();
716
717 Query q = session.createQuery(sql);
718
719 q.setFirstResult(0);
720 q.setMaxResults(2);
721
722 QueryPos qPos = QueryPos.getInstance(q);
723
724 qPos.add(codeId);
725
726 if (orderByComparator != null) {
727 Object[] values = orderByComparator.getOrderByValues(resource);
728
729 for (Object value : values) {
730 qPos.add(value);
731 }
732 }
733
734 List<Resource> list = q.list();
735
736 if (list.size() == 2) {
737 return list.get(1);
738 }
739 else {
740 return null;
741 }
742 }
743
744
753 public Resource findByC_P(long codeId, String primKey)
754 throws NoSuchResourceException, SystemException {
755 Resource resource = fetchByC_P(codeId, primKey);
756
757 if (resource == null) {
758 StringBundler msg = new StringBundler(6);
759
760 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
761
762 msg.append("codeId=");
763 msg.append(codeId);
764
765 msg.append(", primKey=");
766 msg.append(primKey);
767
768 msg.append(StringPool.CLOSE_CURLY_BRACE);
769
770 if (_log.isWarnEnabled()) {
771 _log.warn(msg.toString());
772 }
773
774 throw new NoSuchResourceException(msg.toString());
775 }
776
777 return resource;
778 }
779
780
788 public Resource fetchByC_P(long codeId, String primKey)
789 throws SystemException {
790 return fetchByC_P(codeId, primKey, true);
791 }
792
793
801 public Resource fetchByC_P(long codeId, String primKey,
802 boolean retrieveFromCache) throws SystemException {
803 Object[] finderArgs = new Object[] { codeId, primKey };
804
805 Object result = null;
806
807 if (retrieveFromCache) {
808 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_P,
809 finderArgs, this);
810 }
811
812 if (result == null) {
813 Session session = null;
814
815 try {
816 session = openSession();
817
818 StringBundler query = new StringBundler(3);
819
820 query.append(_SQL_SELECT_RESOURCE_WHERE);
821
822 query.append(_FINDER_COLUMN_C_P_CODEID_2);
823
824 if (primKey == null) {
825 query.append(_FINDER_COLUMN_C_P_PRIMKEY_1);
826 }
827 else {
828 if (primKey.equals(StringPool.BLANK)) {
829 query.append(_FINDER_COLUMN_C_P_PRIMKEY_3);
830 }
831 else {
832 query.append(_FINDER_COLUMN_C_P_PRIMKEY_2);
833 }
834 }
835
836 String sql = query.toString();
837
838 Query q = session.createQuery(sql);
839
840 QueryPos qPos = QueryPos.getInstance(q);
841
842 qPos.add(codeId);
843
844 if (primKey != null) {
845 qPos.add(primKey);
846 }
847
848 List<Resource> list = q.list();
849
850 result = list;
851
852 Resource resource = null;
853
854 if (list.isEmpty()) {
855 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_P,
856 finderArgs, list);
857 }
858 else {
859 resource = list.get(0);
860
861 cacheResult(resource);
862
863 if ((resource.getCodeId() != codeId) ||
864 (resource.getPrimKey() == null) ||
865 !resource.getPrimKey().equals(primKey)) {
866 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_P,
867 finderArgs, resource);
868 }
869 }
870
871 return resource;
872 }
873 catch (Exception e) {
874 throw processException(e);
875 }
876 finally {
877 if (result == null) {
878 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_P,
879 finderArgs, new ArrayList<Resource>());
880 }
881
882 closeSession(session);
883 }
884 }
885 else {
886 if (result instanceof List<?>) {
887 return null;
888 }
889 else {
890 return (Resource)result;
891 }
892 }
893 }
894
895
901 public List<Resource> findAll() throws SystemException {
902 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
903 }
904
905
917 public List<Resource> findAll(int start, int end) throws SystemException {
918 return findAll(start, end, null);
919 }
920
921
934 public List<Resource> findAll(int start, int end,
935 OrderByComparator orderByComparator) throws SystemException {
936 Object[] finderArgs = new Object[] {
937 String.valueOf(start), String.valueOf(end),
938 String.valueOf(orderByComparator)
939 };
940
941 List<Resource> list = (List<Resource>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
942 finderArgs, this);
943
944 if (list == null) {
945 Session session = null;
946
947 try {
948 session = openSession();
949
950 StringBundler query = null;
951 String sql = null;
952
953 if (orderByComparator != null) {
954 query = new StringBundler(2 +
955 (orderByComparator.getOrderByFields().length * 3));
956
957 query.append(_SQL_SELECT_RESOURCE);
958
959 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
960 orderByComparator);
961
962 sql = query.toString();
963 }
964 else {
965 sql = _SQL_SELECT_RESOURCE;
966 }
967
968 Query q = session.createQuery(sql);
969
970 if (orderByComparator == null) {
971 list = (List<Resource>)QueryUtil.list(q, getDialect(),
972 start, end, false);
973
974 Collections.sort(list);
975 }
976 else {
977 list = (List<Resource>)QueryUtil.list(q, getDialect(),
978 start, end);
979 }
980 }
981 catch (Exception e) {
982 throw processException(e);
983 }
984 finally {
985 if (list == null) {
986 list = new ArrayList<Resource>();
987 }
988
989 cacheResult(list);
990
991 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
992
993 closeSession(session);
994 }
995 }
996
997 return list;
998 }
999
1000
1006 public void removeByCodeId(long codeId) throws SystemException {
1007 for (Resource resource : findByCodeId(codeId)) {
1008 remove(resource);
1009 }
1010 }
1011
1012
1019 public void removeByC_P(long codeId, String primKey)
1020 throws NoSuchResourceException, SystemException {
1021 Resource resource = findByC_P(codeId, primKey);
1022
1023 remove(resource);
1024 }
1025
1026
1031 public void removeAll() throws SystemException {
1032 for (Resource resource : findAll()) {
1033 remove(resource);
1034 }
1035 }
1036
1037
1044 public int countByCodeId(long codeId) throws SystemException {
1045 Object[] finderArgs = new Object[] { codeId };
1046
1047 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_CODEID,
1048 finderArgs, this);
1049
1050 if (count == null) {
1051 Session session = null;
1052
1053 try {
1054 session = openSession();
1055
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 Query q = session.createQuery(sql);
1065
1066 QueryPos qPos = QueryPos.getInstance(q);
1067
1068 qPos.add(codeId);
1069
1070 count = (Long)q.uniqueResult();
1071 }
1072 catch (Exception e) {
1073 throw processException(e);
1074 }
1075 finally {
1076 if (count == null) {
1077 count = Long.valueOf(0);
1078 }
1079
1080 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_CODEID,
1081 finderArgs, count);
1082
1083 closeSession(session);
1084 }
1085 }
1086
1087 return count.intValue();
1088 }
1089
1090
1098 public int countByC_P(long codeId, String primKey)
1099 throws SystemException {
1100 Object[] finderArgs = new Object[] { codeId, primKey };
1101
1102 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_P,
1103 finderArgs, this);
1104
1105 if (count == null) {
1106 Session session = null;
1107
1108 try {
1109 session = openSession();
1110
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 Query q = session.createQuery(sql);
1132
1133 QueryPos qPos = QueryPos.getInstance(q);
1134
1135 qPos.add(codeId);
1136
1137 if (primKey != null) {
1138 qPos.add(primKey);
1139 }
1140
1141 count = (Long)q.uniqueResult();
1142 }
1143 catch (Exception e) {
1144 throw processException(e);
1145 }
1146 finally {
1147 if (count == null) {
1148 count = Long.valueOf(0);
1149 }
1150
1151 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_P, finderArgs,
1152 count);
1153
1154 closeSession(session);
1155 }
1156 }
1157
1158 return count.intValue();
1159 }
1160
1161
1167 public int countAll() throws SystemException {
1168 Object[] finderArgs = new Object[0];
1169
1170 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1171 finderArgs, this);
1172
1173 if (count == null) {
1174 Session session = null;
1175
1176 try {
1177 session = openSession();
1178
1179 Query q = session.createQuery(_SQL_COUNT_RESOURCE);
1180
1181 count = (Long)q.uniqueResult();
1182 }
1183 catch (Exception e) {
1184 throw processException(e);
1185 }
1186 finally {
1187 if (count == null) {
1188 count = Long.valueOf(0);
1189 }
1190
1191 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1192 count);
1193
1194 closeSession(session);
1195 }
1196 }
1197
1198 return count.intValue();
1199 }
1200
1201
1204 public void afterPropertiesSet() {
1205 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1206 com.liferay.portal.util.PropsUtil.get(
1207 "value.object.listener.com.liferay.portal.model.Resource")));
1208
1209 if (listenerClassNames.length > 0) {
1210 try {
1211 List<ModelListener<Resource>> listenersList = new ArrayList<ModelListener<Resource>>();
1212
1213 for (String listenerClassName : listenerClassNames) {
1214 listenersList.add((ModelListener<Resource>)InstanceFactory.newInstance(
1215 listenerClassName));
1216 }
1217
1218 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1219 }
1220 catch (Exception e) {
1221 _log.error(e);
1222 }
1223 }
1224 }
1225
1226 public void destroy() {
1227 EntityCacheUtil.removeCache(ResourceImpl.class.getName());
1228 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1229 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
1230 }
1231
1232 @BeanReference(type = AccountPersistence.class)
1233 protected AccountPersistence accountPersistence;
1234 @BeanReference(type = AddressPersistence.class)
1235 protected AddressPersistence addressPersistence;
1236 @BeanReference(type = BrowserTrackerPersistence.class)
1237 protected BrowserTrackerPersistence browserTrackerPersistence;
1238 @BeanReference(type = ClassNamePersistence.class)
1239 protected ClassNamePersistence classNamePersistence;
1240 @BeanReference(type = ClusterGroupPersistence.class)
1241 protected ClusterGroupPersistence clusterGroupPersistence;
1242 @BeanReference(type = CompanyPersistence.class)
1243 protected CompanyPersistence companyPersistence;
1244 @BeanReference(type = ContactPersistence.class)
1245 protected ContactPersistence contactPersistence;
1246 @BeanReference(type = CountryPersistence.class)
1247 protected CountryPersistence countryPersistence;
1248 @BeanReference(type = EmailAddressPersistence.class)
1249 protected EmailAddressPersistence emailAddressPersistence;
1250 @BeanReference(type = GroupPersistence.class)
1251 protected GroupPersistence groupPersistence;
1252 @BeanReference(type = ImagePersistence.class)
1253 protected ImagePersistence imagePersistence;
1254 @BeanReference(type = LayoutPersistence.class)
1255 protected LayoutPersistence layoutPersistence;
1256 @BeanReference(type = LayoutPrototypePersistence.class)
1257 protected LayoutPrototypePersistence layoutPrototypePersistence;
1258 @BeanReference(type = LayoutSetPersistence.class)
1259 protected LayoutSetPersistence layoutSetPersistence;
1260 @BeanReference(type = LayoutSetPrototypePersistence.class)
1261 protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
1262 @BeanReference(type = ListTypePersistence.class)
1263 protected ListTypePersistence listTypePersistence;
1264 @BeanReference(type = LockPersistence.class)
1265 protected LockPersistence lockPersistence;
1266 @BeanReference(type = MembershipRequestPersistence.class)
1267 protected MembershipRequestPersistence membershipRequestPersistence;
1268 @BeanReference(type = OrganizationPersistence.class)
1269 protected OrganizationPersistence organizationPersistence;
1270 @BeanReference(type = OrgGroupPermissionPersistence.class)
1271 protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1272 @BeanReference(type = OrgGroupRolePersistence.class)
1273 protected OrgGroupRolePersistence orgGroupRolePersistence;
1274 @BeanReference(type = OrgLaborPersistence.class)
1275 protected OrgLaborPersistence orgLaborPersistence;
1276 @BeanReference(type = PasswordPolicyPersistence.class)
1277 protected PasswordPolicyPersistence passwordPolicyPersistence;
1278 @BeanReference(type = PasswordPolicyRelPersistence.class)
1279 protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1280 @BeanReference(type = PasswordTrackerPersistence.class)
1281 protected PasswordTrackerPersistence passwordTrackerPersistence;
1282 @BeanReference(type = PermissionPersistence.class)
1283 protected PermissionPersistence permissionPersistence;
1284 @BeanReference(type = PhonePersistence.class)
1285 protected PhonePersistence phonePersistence;
1286 @BeanReference(type = PluginSettingPersistence.class)
1287 protected PluginSettingPersistence pluginSettingPersistence;
1288 @BeanReference(type = PortletPersistence.class)
1289 protected PortletPersistence portletPersistence;
1290 @BeanReference(type = PortletItemPersistence.class)
1291 protected PortletItemPersistence portletItemPersistence;
1292 @BeanReference(type = PortletPreferencesPersistence.class)
1293 protected PortletPreferencesPersistence portletPreferencesPersistence;
1294 @BeanReference(type = RegionPersistence.class)
1295 protected RegionPersistence regionPersistence;
1296 @BeanReference(type = ReleasePersistence.class)
1297 protected ReleasePersistence releasePersistence;
1298 @BeanReference(type = ResourcePersistence.class)
1299 protected ResourcePersistence resourcePersistence;
1300 @BeanReference(type = ResourceActionPersistence.class)
1301 protected ResourceActionPersistence resourceActionPersistence;
1302 @BeanReference(type = ResourceCodePersistence.class)
1303 protected ResourceCodePersistence resourceCodePersistence;
1304 @BeanReference(type = ResourcePermissionPersistence.class)
1305 protected ResourcePermissionPersistence resourcePermissionPersistence;
1306 @BeanReference(type = RolePersistence.class)
1307 protected RolePersistence rolePersistence;
1308 @BeanReference(type = ServiceComponentPersistence.class)
1309 protected ServiceComponentPersistence serviceComponentPersistence;
1310 @BeanReference(type = ShardPersistence.class)
1311 protected ShardPersistence shardPersistence;
1312 @BeanReference(type = SubscriptionPersistence.class)
1313 protected SubscriptionPersistence subscriptionPersistence;
1314 @BeanReference(type = TicketPersistence.class)
1315 protected TicketPersistence ticketPersistence;
1316 @BeanReference(type = TeamPersistence.class)
1317 protected TeamPersistence teamPersistence;
1318 @BeanReference(type = UserPersistence.class)
1319 protected UserPersistence userPersistence;
1320 @BeanReference(type = UserGroupPersistence.class)
1321 protected UserGroupPersistence userGroupPersistence;
1322 @BeanReference(type = UserGroupGroupRolePersistence.class)
1323 protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1324 @BeanReference(type = UserGroupRolePersistence.class)
1325 protected UserGroupRolePersistence userGroupRolePersistence;
1326 @BeanReference(type = UserIdMapperPersistence.class)
1327 protected UserIdMapperPersistence userIdMapperPersistence;
1328 @BeanReference(type = UserTrackerPersistence.class)
1329 protected UserTrackerPersistence userTrackerPersistence;
1330 @BeanReference(type = UserTrackerPathPersistence.class)
1331 protected UserTrackerPathPersistence userTrackerPathPersistence;
1332 @BeanReference(type = WebDAVPropsPersistence.class)
1333 protected WebDAVPropsPersistence webDAVPropsPersistence;
1334 @BeanReference(type = WebsitePersistence.class)
1335 protected WebsitePersistence websitePersistence;
1336 @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
1337 protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1338 @BeanReference(type = WorkflowInstanceLinkPersistence.class)
1339 protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1340 private static final String _SQL_SELECT_RESOURCE = "SELECT resource FROM Resource resource";
1341 private static final String _SQL_SELECT_RESOURCE_WHERE = "SELECT resource FROM Resource resource WHERE ";
1342 private static final String _SQL_COUNT_RESOURCE = "SELECT COUNT(resource) FROM Resource resource";
1343 private static final String _SQL_COUNT_RESOURCE_WHERE = "SELECT COUNT(resource) FROM Resource resource WHERE ";
1344 private static final String _FINDER_COLUMN_CODEID_CODEID_2 = "resource.codeId = ?";
1345 private static final String _FINDER_COLUMN_C_P_CODEID_2 = "resource.codeId = ? AND ";
1346 private static final String _FINDER_COLUMN_C_P_PRIMKEY_1 = "resource.primKey IS NULL";
1347 private static final String _FINDER_COLUMN_C_P_PRIMKEY_2 = "resource.primKey = ?";
1348 private static final String _FINDER_COLUMN_C_P_PRIMKEY_3 = "(resource.primKey IS NULL OR resource.primKey = ?)";
1349 private static final String _ORDER_BY_ENTITY_ALIAS = "resource.";
1350 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Resource exists with the primary key ";
1351 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Resource exists with the key {";
1352 private static Log _log = LogFactoryUtil.getLog(ResourcePersistenceImpl.class);
1353 }