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.bean.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.CacheModel;
039 import com.liferay.portal.model.ModelListener;
040 import com.liferay.portal.model.Resource;
041 import com.liferay.portal.model.impl.ResourceImpl;
042 import com.liferay.portal.model.impl.ResourceModelImpl;
043 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
044
045 import java.io.Serializable;
046
047 import java.util.ArrayList;
048 import java.util.Collections;
049 import java.util.List;
050
051
063 public class ResourcePersistenceImpl extends BasePersistenceImpl<Resource>
064 implements ResourcePersistence {
065
070 public static final String FINDER_CLASS_NAME_ENTITY = ResourceImpl.class.getName();
071 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
072 ".List1";
073 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
074 ".List2";
075 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_CODEID = new FinderPath(ResourceModelImpl.ENTITY_CACHE_ENABLED,
076 ResourceModelImpl.FINDER_CACHE_ENABLED, ResourceImpl.class,
077 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCodeId",
078 new String[] {
079 Long.class.getName(),
080
081 "java.lang.Integer", "java.lang.Integer",
082 "com.liferay.portal.kernel.util.OrderByComparator"
083 });
084 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CODEID =
085 new FinderPath(ResourceModelImpl.ENTITY_CACHE_ENABLED,
086 ResourceModelImpl.FINDER_CACHE_ENABLED, ResourceImpl.class,
087 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCodeId",
088 new String[] { Long.class.getName() },
089 ResourceModelImpl.CODEID_COLUMN_BITMASK);
090 public static final FinderPath FINDER_PATH_COUNT_BY_CODEID = new FinderPath(ResourceModelImpl.ENTITY_CACHE_ENABLED,
091 ResourceModelImpl.FINDER_CACHE_ENABLED, Long.class,
092 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCodeId",
093 new String[] { Long.class.getName() });
094 public static final FinderPath FINDER_PATH_FETCH_BY_C_P = new FinderPath(ResourceModelImpl.ENTITY_CACHE_ENABLED,
095 ResourceModelImpl.FINDER_CACHE_ENABLED, ResourceImpl.class,
096 FINDER_CLASS_NAME_ENTITY, "fetchByC_P",
097 new String[] { Long.class.getName(), String.class.getName() },
098 ResourceModelImpl.CODEID_COLUMN_BITMASK |
099 ResourceModelImpl.PRIMKEY_COLUMN_BITMASK);
100 public static final FinderPath FINDER_PATH_COUNT_BY_C_P = new FinderPath(ResourceModelImpl.ENTITY_CACHE_ENABLED,
101 ResourceModelImpl.FINDER_CACHE_ENABLED, Long.class,
102 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_P",
103 new String[] { Long.class.getName(), String.class.getName() });
104 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(ResourceModelImpl.ENTITY_CACHE_ENABLED,
105 ResourceModelImpl.FINDER_CACHE_ENABLED, ResourceImpl.class,
106 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
107 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ResourceModelImpl.ENTITY_CACHE_ENABLED,
108 ResourceModelImpl.FINDER_CACHE_ENABLED, ResourceImpl.class,
109 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
110 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ResourceModelImpl.ENTITY_CACHE_ENABLED,
111 ResourceModelImpl.FINDER_CACHE_ENABLED, Long.class,
112 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
113
114
119 public void cacheResult(Resource resource) {
120 EntityCacheUtil.putResult(ResourceModelImpl.ENTITY_CACHE_ENABLED,
121 ResourceImpl.class, resource.getPrimaryKey(), resource);
122
123 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_P,
124 new Object[] {
125 Long.valueOf(resource.getCodeId()),
126
127 resource.getPrimKey()
128 }, resource);
129
130 resource.resetOriginalValues();
131 }
132
133
138 public void cacheResult(List<Resource> resources) {
139 for (Resource resource : resources) {
140 if (EntityCacheUtil.getResult(
141 ResourceModelImpl.ENTITY_CACHE_ENABLED,
142 ResourceImpl.class, resource.getPrimaryKey()) == null) {
143 cacheResult(resource);
144 }
145 else {
146 resource.resetOriginalValues();
147 }
148 }
149 }
150
151
158 @Override
159 public void clearCache() {
160 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
161 CacheRegistryUtil.clear(ResourceImpl.class.getName());
162 }
163
164 EntityCacheUtil.clearCache(ResourceImpl.class.getName());
165
166 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
167 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
168 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
169 }
170
171
178 @Override
179 public void clearCache(Resource resource) {
180 EntityCacheUtil.removeResult(ResourceModelImpl.ENTITY_CACHE_ENABLED,
181 ResourceImpl.class, resource.getPrimaryKey());
182
183 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
184 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
185
186 clearUniqueFindersCache(resource);
187 }
188
189 @Override
190 public void clearCache(List<Resource> resources) {
191 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
192 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
193
194 for (Resource resource : resources) {
195 EntityCacheUtil.removeResult(ResourceModelImpl.ENTITY_CACHE_ENABLED,
196 ResourceImpl.class, resource.getPrimaryKey());
197
198 clearUniqueFindersCache(resource);
199 }
200 }
201
202 protected void clearUniqueFindersCache(Resource resource) {
203 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_P,
204 new Object[] {
205 Long.valueOf(resource.getCodeId()),
206
207 resource.getPrimKey()
208 });
209 }
210
211
217 public Resource create(long resourceId) {
218 Resource resource = new ResourceImpl();
219
220 resource.setNew(true);
221 resource.setPrimaryKey(resourceId);
222
223 return resource;
224 }
225
226
234 public Resource remove(long resourceId)
235 throws NoSuchResourceException, SystemException {
236 return remove(Long.valueOf(resourceId));
237 }
238
239
247 @Override
248 public Resource remove(Serializable primaryKey)
249 throws NoSuchResourceException, SystemException {
250 Session session = null;
251
252 try {
253 session = openSession();
254
255 Resource resource = (Resource)session.get(ResourceImpl.class,
256 primaryKey);
257
258 if (resource == null) {
259 if (_log.isWarnEnabled()) {
260 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
261 }
262
263 throw new NoSuchResourceException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
264 primaryKey);
265 }
266
267 return remove(resource);
268 }
269 catch (NoSuchResourceException nsee) {
270 throw nsee;
271 }
272 catch (Exception e) {
273 throw processException(e);
274 }
275 finally {
276 closeSession(session);
277 }
278 }
279
280 @Override
281 protected Resource removeImpl(Resource resource) throws SystemException {
282 resource = toUnwrappedModel(resource);
283
284 Session session = null;
285
286 try {
287 session = openSession();
288
289 BatchSessionUtil.delete(session, resource);
290 }
291 catch (Exception e) {
292 throw processException(e);
293 }
294 finally {
295 closeSession(session);
296 }
297
298 clearCache(resource);
299
300 return resource;
301 }
302
303 @Override
304 public Resource updateImpl(com.liferay.portal.model.Resource resource,
305 boolean merge) throws SystemException {
306 resource = toUnwrappedModel(resource);
307
308 boolean isNew = resource.isNew();
309
310 ResourceModelImpl resourceModelImpl = (ResourceModelImpl)resource;
311
312 Session session = null;
313
314 try {
315 session = openSession();
316
317 BatchSessionUtil.update(session, resource, merge);
318
319 resource.setNew(false);
320 }
321 catch (Exception e) {
322 throw processException(e);
323 }
324 finally {
325 closeSession(session);
326 }
327
328 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
329
330 if (isNew || !ResourceModelImpl.COLUMN_BITMASK_ENABLED) {
331 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
332 }
333 else {
334 if ((resourceModelImpl.getColumnBitmask() &
335 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CODEID.getColumnBitmask()) != 0) {
336 Object[] args = new Object[] {
337 Long.valueOf(resourceModelImpl.getOriginalCodeId())
338 };
339
340 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_CODEID, args);
341 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CODEID,
342 args);
343
344 args = new Object[] { Long.valueOf(resourceModelImpl.getCodeId()) };
345
346 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_CODEID, args);
347 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CODEID,
348 args);
349 }
350 }
351
352 EntityCacheUtil.putResult(ResourceModelImpl.ENTITY_CACHE_ENABLED,
353 ResourceImpl.class, resource.getPrimaryKey(), resource);
354
355 if (isNew) {
356 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_P,
357 new Object[] {
358 Long.valueOf(resource.getCodeId()),
359
360 resource.getPrimKey()
361 }, resource);
362 }
363 else {
364 if ((resourceModelImpl.getColumnBitmask() &
365 FINDER_PATH_FETCH_BY_C_P.getColumnBitmask()) != 0) {
366 Object[] args = new Object[] {
367 Long.valueOf(resourceModelImpl.getOriginalCodeId()),
368
369 resourceModelImpl.getOriginalPrimKey()
370 };
371
372 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_P, args);
373 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_P, args);
374
375 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_P,
376 new Object[] {
377 Long.valueOf(resource.getCodeId()),
378
379 resource.getPrimKey()
380 }, resource);
381 }
382 }
383
384 return resource;
385 }
386
387 protected Resource toUnwrappedModel(Resource resource) {
388 if (resource instanceof ResourceImpl) {
389 return resource;
390 }
391
392 ResourceImpl resourceImpl = new ResourceImpl();
393
394 resourceImpl.setNew(resource.isNew());
395 resourceImpl.setPrimaryKey(resource.getPrimaryKey());
396
397 resourceImpl.setResourceId(resource.getResourceId());
398 resourceImpl.setCodeId(resource.getCodeId());
399 resourceImpl.setPrimKey(resource.getPrimKey());
400
401 return resourceImpl;
402 }
403
404
412 @Override
413 public Resource findByPrimaryKey(Serializable primaryKey)
414 throws NoSuchModelException, SystemException {
415 return findByPrimaryKey(((Long)primaryKey).longValue());
416 }
417
418
426 public Resource findByPrimaryKey(long resourceId)
427 throws NoSuchResourceException, SystemException {
428 Resource resource = fetchByPrimaryKey(resourceId);
429
430 if (resource == null) {
431 if (_log.isWarnEnabled()) {
432 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + resourceId);
433 }
434
435 throw new NoSuchResourceException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
436 resourceId);
437 }
438
439 return resource;
440 }
441
442
449 @Override
450 public Resource fetchByPrimaryKey(Serializable primaryKey)
451 throws SystemException {
452 return fetchByPrimaryKey(((Long)primaryKey).longValue());
453 }
454
455
462 public Resource fetchByPrimaryKey(long resourceId)
463 throws SystemException {
464 Resource resource = (Resource)EntityCacheUtil.getResult(ResourceModelImpl.ENTITY_CACHE_ENABLED,
465 ResourceImpl.class, resourceId);
466
467 if (resource == _nullResource) {
468 return null;
469 }
470
471 if (resource == null) {
472 Session session = null;
473
474 boolean hasException = false;
475
476 try {
477 session = openSession();
478
479 resource = (Resource)session.get(ResourceImpl.class,
480 Long.valueOf(resourceId));
481 }
482 catch (Exception e) {
483 hasException = true;
484
485 throw processException(e);
486 }
487 finally {
488 if (resource != null) {
489 cacheResult(resource);
490 }
491 else if (!hasException) {
492 EntityCacheUtil.putResult(ResourceModelImpl.ENTITY_CACHE_ENABLED,
493 ResourceImpl.class, resourceId, _nullResource);
494 }
495
496 closeSession(session);
497 }
498 }
499
500 return resource;
501 }
502
503
510 public List<Resource> findByCodeId(long codeId) throws SystemException {
511 return findByCodeId(codeId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
512 }
513
514
527 public List<Resource> findByCodeId(long codeId, int start, int end)
528 throws SystemException {
529 return findByCodeId(codeId, start, end, null);
530 }
531
532
546 public List<Resource> findByCodeId(long codeId, int start, int end,
547 OrderByComparator orderByComparator) throws SystemException {
548 FinderPath finderPath = null;
549 Object[] finderArgs = null;
550
551 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
552 (orderByComparator == null)) {
553 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CODEID;
554 finderArgs = new Object[] { codeId };
555 }
556 else {
557 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_CODEID;
558 finderArgs = new Object[] { codeId, start, end, orderByComparator };
559 }
560
561 List<Resource> list = (List<Resource>)FinderCacheUtil.getResult(finderPath,
562 finderArgs, this);
563
564 if ((list != null) && !list.isEmpty()) {
565 for (Resource resource : list) {
566 if ((codeId != resource.getCodeId())) {
567 list = null;
568
569 break;
570 }
571 }
572 }
573
574 if (list == null) {
575 StringBundler query = null;
576
577 if (orderByComparator != null) {
578 query = new StringBundler(3 +
579 (orderByComparator.getOrderByFields().length * 3));
580 }
581 else {
582 query = new StringBundler(2);
583 }
584
585 query.append(_SQL_SELECT_RESOURCE_WHERE);
586
587 query.append(_FINDER_COLUMN_CODEID_CODEID_2);
588
589 if (orderByComparator != null) {
590 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
591 orderByComparator);
592 }
593
594 String sql = query.toString();
595
596 Session session = null;
597
598 try {
599 session = openSession();
600
601 Query q = session.createQuery(sql);
602
603 QueryPos qPos = QueryPos.getInstance(q);
604
605 qPos.add(codeId);
606
607 list = (List<Resource>)QueryUtil.list(q, getDialect(), start,
608 end);
609 }
610 catch (Exception e) {
611 throw processException(e);
612 }
613 finally {
614 if (list == null) {
615 FinderCacheUtil.removeResult(finderPath, finderArgs);
616 }
617 else {
618 cacheResult(list);
619
620 FinderCacheUtil.putResult(finderPath, finderArgs, list);
621 }
622
623 closeSession(session);
624 }
625 }
626
627 return list;
628 }
629
630
643 public Resource findByCodeId_First(long codeId,
644 OrderByComparator orderByComparator)
645 throws NoSuchResourceException, SystemException {
646 List<Resource> list = findByCodeId(codeId, 0, 1, orderByComparator);
647
648 if (list.isEmpty()) {
649 StringBundler msg = new StringBundler(4);
650
651 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
652
653 msg.append("codeId=");
654 msg.append(codeId);
655
656 msg.append(StringPool.CLOSE_CURLY_BRACE);
657
658 throw new NoSuchResourceException(msg.toString());
659 }
660 else {
661 return list.get(0);
662 }
663 }
664
665
678 public Resource findByCodeId_Last(long codeId,
679 OrderByComparator orderByComparator)
680 throws NoSuchResourceException, SystemException {
681 int count = countByCodeId(codeId);
682
683 List<Resource> list = findByCodeId(codeId, count - 1, count,
684 orderByComparator);
685
686 if (list.isEmpty()) {
687 StringBundler msg = new StringBundler(4);
688
689 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
690
691 msg.append("codeId=");
692 msg.append(codeId);
693
694 msg.append(StringPool.CLOSE_CURLY_BRACE);
695
696 throw new NoSuchResourceException(msg.toString());
697 }
698 else {
699 return list.get(0);
700 }
701 }
702
703
717 public Resource[] findByCodeId_PrevAndNext(long resourceId, long codeId,
718 OrderByComparator orderByComparator)
719 throws NoSuchResourceException, SystemException {
720 Resource resource = findByPrimaryKey(resourceId);
721
722 Session session = null;
723
724 try {
725 session = openSession();
726
727 Resource[] array = new ResourceImpl[3];
728
729 array[0] = getByCodeId_PrevAndNext(session, resource, codeId,
730 orderByComparator, true);
731
732 array[1] = resource;
733
734 array[2] = getByCodeId_PrevAndNext(session, resource, codeId,
735 orderByComparator, false);
736
737 return array;
738 }
739 catch (Exception e) {
740 throw processException(e);
741 }
742 finally {
743 closeSession(session);
744 }
745 }
746
747 protected Resource getByCodeId_PrevAndNext(Session session,
748 Resource resource, long codeId, OrderByComparator orderByComparator,
749 boolean previous) {
750 StringBundler query = null;
751
752 if (orderByComparator != null) {
753 query = new StringBundler(6 +
754 (orderByComparator.getOrderByFields().length * 6));
755 }
756 else {
757 query = new StringBundler(3);
758 }
759
760 query.append(_SQL_SELECT_RESOURCE_WHERE);
761
762 query.append(_FINDER_COLUMN_CODEID_CODEID_2);
763
764 if (orderByComparator != null) {
765 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
766
767 if (orderByConditionFields.length > 0) {
768 query.append(WHERE_AND);
769 }
770
771 for (int i = 0; i < orderByConditionFields.length; i++) {
772 query.append(_ORDER_BY_ENTITY_ALIAS);
773 query.append(orderByConditionFields[i]);
774
775 if ((i + 1) < orderByConditionFields.length) {
776 if (orderByComparator.isAscending() ^ previous) {
777 query.append(WHERE_GREATER_THAN_HAS_NEXT);
778 }
779 else {
780 query.append(WHERE_LESSER_THAN_HAS_NEXT);
781 }
782 }
783 else {
784 if (orderByComparator.isAscending() ^ previous) {
785 query.append(WHERE_GREATER_THAN);
786 }
787 else {
788 query.append(WHERE_LESSER_THAN);
789 }
790 }
791 }
792
793 query.append(ORDER_BY_CLAUSE);
794
795 String[] orderByFields = orderByComparator.getOrderByFields();
796
797 for (int i = 0; i < orderByFields.length; i++) {
798 query.append(_ORDER_BY_ENTITY_ALIAS);
799 query.append(orderByFields[i]);
800
801 if ((i + 1) < orderByFields.length) {
802 if (orderByComparator.isAscending() ^ previous) {
803 query.append(ORDER_BY_ASC_HAS_NEXT);
804 }
805 else {
806 query.append(ORDER_BY_DESC_HAS_NEXT);
807 }
808 }
809 else {
810 if (orderByComparator.isAscending() ^ previous) {
811 query.append(ORDER_BY_ASC);
812 }
813 else {
814 query.append(ORDER_BY_DESC);
815 }
816 }
817 }
818 }
819
820 String sql = query.toString();
821
822 Query q = session.createQuery(sql);
823
824 q.setFirstResult(0);
825 q.setMaxResults(2);
826
827 QueryPos qPos = QueryPos.getInstance(q);
828
829 qPos.add(codeId);
830
831 if (orderByComparator != null) {
832 Object[] values = orderByComparator.getOrderByConditionValues(resource);
833
834 for (Object value : values) {
835 qPos.add(value);
836 }
837 }
838
839 List<Resource> list = q.list();
840
841 if (list.size() == 2) {
842 return list.get(1);
843 }
844 else {
845 return null;
846 }
847 }
848
849
858 public Resource findByC_P(long codeId, String primKey)
859 throws NoSuchResourceException, SystemException {
860 Resource resource = fetchByC_P(codeId, primKey);
861
862 if (resource == null) {
863 StringBundler msg = new StringBundler(6);
864
865 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
866
867 msg.append("codeId=");
868 msg.append(codeId);
869
870 msg.append(", primKey=");
871 msg.append(primKey);
872
873 msg.append(StringPool.CLOSE_CURLY_BRACE);
874
875 if (_log.isWarnEnabled()) {
876 _log.warn(msg.toString());
877 }
878
879 throw new NoSuchResourceException(msg.toString());
880 }
881
882 return resource;
883 }
884
885
893 public Resource fetchByC_P(long codeId, String primKey)
894 throws SystemException {
895 return fetchByC_P(codeId, primKey, true);
896 }
897
898
907 public Resource fetchByC_P(long codeId, String primKey,
908 boolean retrieveFromCache) throws SystemException {
909 Object[] finderArgs = new Object[] { codeId, primKey };
910
911 Object result = null;
912
913 if (retrieveFromCache) {
914 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_P,
915 finderArgs, this);
916 }
917
918 if (result instanceof Resource) {
919 Resource resource = (Resource)result;
920
921 if ((codeId != resource.getCodeId()) ||
922 !Validator.equals(primKey, resource.getPrimKey())) {
923 result = null;
924 }
925 }
926
927 if (result == null) {
928 StringBundler query = new StringBundler(3);
929
930 query.append(_SQL_SELECT_RESOURCE_WHERE);
931
932 query.append(_FINDER_COLUMN_C_P_CODEID_2);
933
934 if (primKey == null) {
935 query.append(_FINDER_COLUMN_C_P_PRIMKEY_1);
936 }
937 else {
938 if (primKey.equals(StringPool.BLANK)) {
939 query.append(_FINDER_COLUMN_C_P_PRIMKEY_3);
940 }
941 else {
942 query.append(_FINDER_COLUMN_C_P_PRIMKEY_2);
943 }
944 }
945
946 String sql = query.toString();
947
948 Session session = null;
949
950 try {
951 session = openSession();
952
953 Query q = session.createQuery(sql);
954
955 QueryPos qPos = QueryPos.getInstance(q);
956
957 qPos.add(codeId);
958
959 if (primKey != null) {
960 qPos.add(primKey);
961 }
962
963 List<Resource> list = q.list();
964
965 result = list;
966
967 Resource resource = null;
968
969 if (list.isEmpty()) {
970 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_P,
971 finderArgs, list);
972 }
973 else {
974 resource = list.get(0);
975
976 cacheResult(resource);
977
978 if ((resource.getCodeId() != codeId) ||
979 (resource.getPrimKey() == null) ||
980 !resource.getPrimKey().equals(primKey)) {
981 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_P,
982 finderArgs, resource);
983 }
984 }
985
986 return resource;
987 }
988 catch (Exception e) {
989 throw processException(e);
990 }
991 finally {
992 if (result == null) {
993 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_P,
994 finderArgs);
995 }
996
997 closeSession(session);
998 }
999 }
1000 else {
1001 if (result instanceof List<?>) {
1002 return null;
1003 }
1004 else {
1005 return (Resource)result;
1006 }
1007 }
1008 }
1009
1010
1016 public List<Resource> findAll() throws SystemException {
1017 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1018 }
1019
1020
1032 public List<Resource> findAll(int start, int end) throws SystemException {
1033 return findAll(start, end, null);
1034 }
1035
1036
1049 public List<Resource> findAll(int start, int end,
1050 OrderByComparator orderByComparator) throws SystemException {
1051 FinderPath finderPath = null;
1052 Object[] finderArgs = new Object[] { start, end, orderByComparator };
1053
1054 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1055 (orderByComparator == null)) {
1056 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1057 finderArgs = FINDER_ARGS_EMPTY;
1058 }
1059 else {
1060 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1061 finderArgs = new Object[] { start, end, orderByComparator };
1062 }
1063
1064 List<Resource> list = (List<Resource>)FinderCacheUtil.getResult(finderPath,
1065 finderArgs, this);
1066
1067 if (list == null) {
1068 StringBundler query = null;
1069 String sql = null;
1070
1071 if (orderByComparator != null) {
1072 query = new StringBundler(2 +
1073 (orderByComparator.getOrderByFields().length * 3));
1074
1075 query.append(_SQL_SELECT_RESOURCE);
1076
1077 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1078 orderByComparator);
1079
1080 sql = query.toString();
1081 }
1082 else {
1083 sql = _SQL_SELECT_RESOURCE;
1084 }
1085
1086 Session session = null;
1087
1088 try {
1089 session = openSession();
1090
1091 Query q = session.createQuery(sql);
1092
1093 if (orderByComparator == null) {
1094 list = (List<Resource>)QueryUtil.list(q, getDialect(),
1095 start, end, false);
1096
1097 Collections.sort(list);
1098 }
1099 else {
1100 list = (List<Resource>)QueryUtil.list(q, getDialect(),
1101 start, end);
1102 }
1103 }
1104 catch (Exception e) {
1105 throw processException(e);
1106 }
1107 finally {
1108 if (list == null) {
1109 FinderCacheUtil.removeResult(finderPath, finderArgs);
1110 }
1111 else {
1112 cacheResult(list);
1113
1114 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1115 }
1116
1117 closeSession(session);
1118 }
1119 }
1120
1121 return list;
1122 }
1123
1124
1130 public void removeByCodeId(long codeId) throws SystemException {
1131 for (Resource resource : findByCodeId(codeId)) {
1132 remove(resource);
1133 }
1134 }
1135
1136
1143 public void removeByC_P(long codeId, String primKey)
1144 throws NoSuchResourceException, SystemException {
1145 Resource resource = findByC_P(codeId, primKey);
1146
1147 remove(resource);
1148 }
1149
1150
1155 public void removeAll() throws SystemException {
1156 for (Resource resource : findAll()) {
1157 remove(resource);
1158 }
1159 }
1160
1161
1168 public int countByCodeId(long codeId) throws SystemException {
1169 Object[] finderArgs = new Object[] { codeId };
1170
1171 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_CODEID,
1172 finderArgs, this);
1173
1174 if (count == null) {
1175 StringBundler query = new StringBundler(2);
1176
1177 query.append(_SQL_COUNT_RESOURCE_WHERE);
1178
1179 query.append(_FINDER_COLUMN_CODEID_CODEID_2);
1180
1181 String sql = query.toString();
1182
1183 Session session = null;
1184
1185 try {
1186 session = openSession();
1187
1188 Query q = session.createQuery(sql);
1189
1190 QueryPos qPos = QueryPos.getInstance(q);
1191
1192 qPos.add(codeId);
1193
1194 count = (Long)q.uniqueResult();
1195 }
1196 catch (Exception e) {
1197 throw processException(e);
1198 }
1199 finally {
1200 if (count == null) {
1201 count = Long.valueOf(0);
1202 }
1203
1204 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_CODEID,
1205 finderArgs, count);
1206
1207 closeSession(session);
1208 }
1209 }
1210
1211 return count.intValue();
1212 }
1213
1214
1222 public int countByC_P(long codeId, String primKey)
1223 throws SystemException {
1224 Object[] finderArgs = new Object[] { codeId, primKey };
1225
1226 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_P,
1227 finderArgs, this);
1228
1229 if (count == null) {
1230 StringBundler query = new StringBundler(3);
1231
1232 query.append(_SQL_COUNT_RESOURCE_WHERE);
1233
1234 query.append(_FINDER_COLUMN_C_P_CODEID_2);
1235
1236 if (primKey == null) {
1237 query.append(_FINDER_COLUMN_C_P_PRIMKEY_1);
1238 }
1239 else {
1240 if (primKey.equals(StringPool.BLANK)) {
1241 query.append(_FINDER_COLUMN_C_P_PRIMKEY_3);
1242 }
1243 else {
1244 query.append(_FINDER_COLUMN_C_P_PRIMKEY_2);
1245 }
1246 }
1247
1248 String sql = query.toString();
1249
1250 Session session = null;
1251
1252 try {
1253 session = openSession();
1254
1255 Query q = session.createQuery(sql);
1256
1257 QueryPos qPos = QueryPos.getInstance(q);
1258
1259 qPos.add(codeId);
1260
1261 if (primKey != null) {
1262 qPos.add(primKey);
1263 }
1264
1265 count = (Long)q.uniqueResult();
1266 }
1267 catch (Exception e) {
1268 throw processException(e);
1269 }
1270 finally {
1271 if (count == null) {
1272 count = Long.valueOf(0);
1273 }
1274
1275 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_P, finderArgs,
1276 count);
1277
1278 closeSession(session);
1279 }
1280 }
1281
1282 return count.intValue();
1283 }
1284
1285
1291 public int countAll() throws SystemException {
1292 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1293 FINDER_ARGS_EMPTY, this);
1294
1295 if (count == null) {
1296 Session session = null;
1297
1298 try {
1299 session = openSession();
1300
1301 Query q = session.createQuery(_SQL_COUNT_RESOURCE);
1302
1303 count = (Long)q.uniqueResult();
1304 }
1305 catch (Exception e) {
1306 throw processException(e);
1307 }
1308 finally {
1309 if (count == null) {
1310 count = Long.valueOf(0);
1311 }
1312
1313 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1314 FINDER_ARGS_EMPTY, count);
1315
1316 closeSession(session);
1317 }
1318 }
1319
1320 return count.intValue();
1321 }
1322
1323
1326 public void afterPropertiesSet() {
1327 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1328 com.liferay.portal.util.PropsUtil.get(
1329 "value.object.listener.com.liferay.portal.model.Resource")));
1330
1331 if (listenerClassNames.length > 0) {
1332 try {
1333 List<ModelListener<Resource>> listenersList = new ArrayList<ModelListener<Resource>>();
1334
1335 for (String listenerClassName : listenerClassNames) {
1336 listenersList.add((ModelListener<Resource>)InstanceFactory.newInstance(
1337 listenerClassName));
1338 }
1339
1340 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1341 }
1342 catch (Exception e) {
1343 _log.error(e);
1344 }
1345 }
1346 }
1347
1348 public void destroy() {
1349 EntityCacheUtil.removeCache(ResourceImpl.class.getName());
1350 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1351 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1352 }
1353
1354 @BeanReference(type = AccountPersistence.class)
1355 protected AccountPersistence accountPersistence;
1356 @BeanReference(type = AddressPersistence.class)
1357 protected AddressPersistence addressPersistence;
1358 @BeanReference(type = BrowserTrackerPersistence.class)
1359 protected BrowserTrackerPersistence browserTrackerPersistence;
1360 @BeanReference(type = ClassNamePersistence.class)
1361 protected ClassNamePersistence classNamePersistence;
1362 @BeanReference(type = ClusterGroupPersistence.class)
1363 protected ClusterGroupPersistence clusterGroupPersistence;
1364 @BeanReference(type = CompanyPersistence.class)
1365 protected CompanyPersistence companyPersistence;
1366 @BeanReference(type = ContactPersistence.class)
1367 protected ContactPersistence contactPersistence;
1368 @BeanReference(type = CountryPersistence.class)
1369 protected CountryPersistence countryPersistence;
1370 @BeanReference(type = EmailAddressPersistence.class)
1371 protected EmailAddressPersistence emailAddressPersistence;
1372 @BeanReference(type = GroupPersistence.class)
1373 protected GroupPersistence groupPersistence;
1374 @BeanReference(type = ImagePersistence.class)
1375 protected ImagePersistence imagePersistence;
1376 @BeanReference(type = LayoutPersistence.class)
1377 protected LayoutPersistence layoutPersistence;
1378 @BeanReference(type = LayoutBranchPersistence.class)
1379 protected LayoutBranchPersistence layoutBranchPersistence;
1380 @BeanReference(type = LayoutPrototypePersistence.class)
1381 protected LayoutPrototypePersistence layoutPrototypePersistence;
1382 @BeanReference(type = LayoutRevisionPersistence.class)
1383 protected LayoutRevisionPersistence layoutRevisionPersistence;
1384 @BeanReference(type = LayoutSetPersistence.class)
1385 protected LayoutSetPersistence layoutSetPersistence;
1386 @BeanReference(type = LayoutSetBranchPersistence.class)
1387 protected LayoutSetBranchPersistence layoutSetBranchPersistence;
1388 @BeanReference(type = LayoutSetPrototypePersistence.class)
1389 protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
1390 @BeanReference(type = ListTypePersistence.class)
1391 protected ListTypePersistence listTypePersistence;
1392 @BeanReference(type = LockPersistence.class)
1393 protected LockPersistence lockPersistence;
1394 @BeanReference(type = MembershipRequestPersistence.class)
1395 protected MembershipRequestPersistence membershipRequestPersistence;
1396 @BeanReference(type = OrganizationPersistence.class)
1397 protected OrganizationPersistence organizationPersistence;
1398 @BeanReference(type = OrgGroupPermissionPersistence.class)
1399 protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1400 @BeanReference(type = OrgGroupRolePersistence.class)
1401 protected OrgGroupRolePersistence orgGroupRolePersistence;
1402 @BeanReference(type = OrgLaborPersistence.class)
1403 protected OrgLaborPersistence orgLaborPersistence;
1404 @BeanReference(type = PasswordPolicyPersistence.class)
1405 protected PasswordPolicyPersistence passwordPolicyPersistence;
1406 @BeanReference(type = PasswordPolicyRelPersistence.class)
1407 protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1408 @BeanReference(type = PasswordTrackerPersistence.class)
1409 protected PasswordTrackerPersistence passwordTrackerPersistence;
1410 @BeanReference(type = PermissionPersistence.class)
1411 protected PermissionPersistence permissionPersistence;
1412 @BeanReference(type = PhonePersistence.class)
1413 protected PhonePersistence phonePersistence;
1414 @BeanReference(type = PluginSettingPersistence.class)
1415 protected PluginSettingPersistence pluginSettingPersistence;
1416 @BeanReference(type = PortalPreferencesPersistence.class)
1417 protected PortalPreferencesPersistence portalPreferencesPersistence;
1418 @BeanReference(type = PortletPersistence.class)
1419 protected PortletPersistence portletPersistence;
1420 @BeanReference(type = PortletItemPersistence.class)
1421 protected PortletItemPersistence portletItemPersistence;
1422 @BeanReference(type = PortletPreferencesPersistence.class)
1423 protected PortletPreferencesPersistence portletPreferencesPersistence;
1424 @BeanReference(type = RegionPersistence.class)
1425 protected RegionPersistence regionPersistence;
1426 @BeanReference(type = ReleasePersistence.class)
1427 protected ReleasePersistence releasePersistence;
1428 @BeanReference(type = RepositoryPersistence.class)
1429 protected RepositoryPersistence repositoryPersistence;
1430 @BeanReference(type = RepositoryEntryPersistence.class)
1431 protected RepositoryEntryPersistence repositoryEntryPersistence;
1432 @BeanReference(type = ResourcePersistence.class)
1433 protected ResourcePersistence resourcePersistence;
1434 @BeanReference(type = ResourceActionPersistence.class)
1435 protected ResourceActionPersistence resourceActionPersistence;
1436 @BeanReference(type = ResourceBlockPersistence.class)
1437 protected ResourceBlockPersistence resourceBlockPersistence;
1438 @BeanReference(type = ResourceBlockPermissionPersistence.class)
1439 protected ResourceBlockPermissionPersistence resourceBlockPermissionPersistence;
1440 @BeanReference(type = ResourceCodePersistence.class)
1441 protected ResourceCodePersistence resourceCodePersistence;
1442 @BeanReference(type = ResourcePermissionPersistence.class)
1443 protected ResourcePermissionPersistence resourcePermissionPersistence;
1444 @BeanReference(type = ResourceTypePermissionPersistence.class)
1445 protected ResourceTypePermissionPersistence resourceTypePermissionPersistence;
1446 @BeanReference(type = RolePersistence.class)
1447 protected RolePersistence rolePersistence;
1448 @BeanReference(type = ServiceComponentPersistence.class)
1449 protected ServiceComponentPersistence serviceComponentPersistence;
1450 @BeanReference(type = ShardPersistence.class)
1451 protected ShardPersistence shardPersistence;
1452 @BeanReference(type = SubscriptionPersistence.class)
1453 protected SubscriptionPersistence subscriptionPersistence;
1454 @BeanReference(type = TeamPersistence.class)
1455 protected TeamPersistence teamPersistence;
1456 @BeanReference(type = TicketPersistence.class)
1457 protected TicketPersistence ticketPersistence;
1458 @BeanReference(type = UserPersistence.class)
1459 protected UserPersistence userPersistence;
1460 @BeanReference(type = UserGroupPersistence.class)
1461 protected UserGroupPersistence userGroupPersistence;
1462 @BeanReference(type = UserGroupGroupRolePersistence.class)
1463 protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1464 @BeanReference(type = UserGroupRolePersistence.class)
1465 protected UserGroupRolePersistence userGroupRolePersistence;
1466 @BeanReference(type = UserIdMapperPersistence.class)
1467 protected UserIdMapperPersistence userIdMapperPersistence;
1468 @BeanReference(type = UserNotificationEventPersistence.class)
1469 protected UserNotificationEventPersistence userNotificationEventPersistence;
1470 @BeanReference(type = UserTrackerPersistence.class)
1471 protected UserTrackerPersistence userTrackerPersistence;
1472 @BeanReference(type = UserTrackerPathPersistence.class)
1473 protected UserTrackerPathPersistence userTrackerPathPersistence;
1474 @BeanReference(type = VirtualHostPersistence.class)
1475 protected VirtualHostPersistence virtualHostPersistence;
1476 @BeanReference(type = WebDAVPropsPersistence.class)
1477 protected WebDAVPropsPersistence webDAVPropsPersistence;
1478 @BeanReference(type = WebsitePersistence.class)
1479 protected WebsitePersistence websitePersistence;
1480 @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
1481 protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1482 @BeanReference(type = WorkflowInstanceLinkPersistence.class)
1483 protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1484 private static final String _SQL_SELECT_RESOURCE = "SELECT resource FROM Resource resource";
1485 private static final String _SQL_SELECT_RESOURCE_WHERE = "SELECT resource FROM Resource resource WHERE ";
1486 private static final String _SQL_COUNT_RESOURCE = "SELECT COUNT(resource) FROM Resource resource";
1487 private static final String _SQL_COUNT_RESOURCE_WHERE = "SELECT COUNT(resource) FROM Resource resource WHERE ";
1488 private static final String _FINDER_COLUMN_CODEID_CODEID_2 = "resource.codeId = ?";
1489 private static final String _FINDER_COLUMN_C_P_CODEID_2 = "resource.codeId = ? AND ";
1490 private static final String _FINDER_COLUMN_C_P_PRIMKEY_1 = "resource.primKey IS NULL";
1491 private static final String _FINDER_COLUMN_C_P_PRIMKEY_2 = "resource.primKey = ?";
1492 private static final String _FINDER_COLUMN_C_P_PRIMKEY_3 = "(resource.primKey IS NULL OR resource.primKey = ?)";
1493 private static final String _ORDER_BY_ENTITY_ALIAS = "resource.";
1494 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Resource exists with the primary key ";
1495 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Resource exists with the key {";
1496 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1497 private static Log _log = LogFactoryUtil.getLog(ResourcePersistenceImpl.class);
1498 private static Resource _nullResource = new ResourceImpl() {
1499 @Override
1500 public Object clone() {
1501 return this;
1502 }
1503
1504 @Override
1505 public CacheModel<Resource> toCacheModel() {
1506 return _nullResourceCacheModel;
1507 }
1508 };
1509
1510 private static CacheModel<Resource> _nullResourceCacheModel = new CacheModel<Resource>() {
1511 public Resource toEntityModel() {
1512 return _nullResource;
1513 }
1514 };
1515 }