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_WITH_PAGINATION_FIND_BY_PRIMKEY = new FinderPath(ResourceModelImpl.ENTITY_CACHE_ENABLED,
095 ResourceModelImpl.FINDER_CACHE_ENABLED, ResourceImpl.class,
096 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByPrimKey",
097 new String[] {
098 String.class.getName(),
099
100 "java.lang.Integer", "java.lang.Integer",
101 "com.liferay.portal.kernel.util.OrderByComparator"
102 });
103 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PRIMKEY =
104 new FinderPath(ResourceModelImpl.ENTITY_CACHE_ENABLED,
105 ResourceModelImpl.FINDER_CACHE_ENABLED, ResourceImpl.class,
106 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByPrimKey",
107 new String[] { String.class.getName() },
108 ResourceModelImpl.PRIMKEY_COLUMN_BITMASK);
109 public static final FinderPath FINDER_PATH_COUNT_BY_PRIMKEY = new FinderPath(ResourceModelImpl.ENTITY_CACHE_ENABLED,
110 ResourceModelImpl.FINDER_CACHE_ENABLED, Long.class,
111 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByPrimKey",
112 new String[] { String.class.getName() });
113 public static final FinderPath FINDER_PATH_FETCH_BY_C_P = new FinderPath(ResourceModelImpl.ENTITY_CACHE_ENABLED,
114 ResourceModelImpl.FINDER_CACHE_ENABLED, ResourceImpl.class,
115 FINDER_CLASS_NAME_ENTITY, "fetchByC_P",
116 new String[] { Long.class.getName(), String.class.getName() },
117 ResourceModelImpl.CODEID_COLUMN_BITMASK |
118 ResourceModelImpl.PRIMKEY_COLUMN_BITMASK);
119 public static final FinderPath FINDER_PATH_COUNT_BY_C_P = new FinderPath(ResourceModelImpl.ENTITY_CACHE_ENABLED,
120 ResourceModelImpl.FINDER_CACHE_ENABLED, Long.class,
121 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_P",
122 new String[] { Long.class.getName(), String.class.getName() });
123 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(ResourceModelImpl.ENTITY_CACHE_ENABLED,
124 ResourceModelImpl.FINDER_CACHE_ENABLED, ResourceImpl.class,
125 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
126 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ResourceModelImpl.ENTITY_CACHE_ENABLED,
127 ResourceModelImpl.FINDER_CACHE_ENABLED, ResourceImpl.class,
128 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
129 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ResourceModelImpl.ENTITY_CACHE_ENABLED,
130 ResourceModelImpl.FINDER_CACHE_ENABLED, Long.class,
131 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
132
133
138 public void cacheResult(Resource resource) {
139 EntityCacheUtil.putResult(ResourceModelImpl.ENTITY_CACHE_ENABLED,
140 ResourceImpl.class, resource.getPrimaryKey(), resource);
141
142 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_P,
143 new Object[] {
144 Long.valueOf(resource.getCodeId()),
145
146 resource.getPrimKey()
147 }, resource);
148
149 resource.resetOriginalValues();
150 }
151
152
157 public void cacheResult(List<Resource> resources) {
158 for (Resource resource : resources) {
159 if (EntityCacheUtil.getResult(
160 ResourceModelImpl.ENTITY_CACHE_ENABLED,
161 ResourceImpl.class, resource.getPrimaryKey()) == null) {
162 cacheResult(resource);
163 }
164 else {
165 resource.resetOriginalValues();
166 }
167 }
168 }
169
170
177 @Override
178 public void clearCache() {
179 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
180 CacheRegistryUtil.clear(ResourceImpl.class.getName());
181 }
182
183 EntityCacheUtil.clearCache(ResourceImpl.class.getName());
184
185 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
186 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
187 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
188 }
189
190
197 @Override
198 public void clearCache(Resource resource) {
199 EntityCacheUtil.removeResult(ResourceModelImpl.ENTITY_CACHE_ENABLED,
200 ResourceImpl.class, resource.getPrimaryKey());
201
202 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
203 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
204
205 clearUniqueFindersCache(resource);
206 }
207
208 @Override
209 public void clearCache(List<Resource> resources) {
210 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
211 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
212
213 for (Resource resource : resources) {
214 EntityCacheUtil.removeResult(ResourceModelImpl.ENTITY_CACHE_ENABLED,
215 ResourceImpl.class, resource.getPrimaryKey());
216
217 clearUniqueFindersCache(resource);
218 }
219 }
220
221 protected void cacheUniqueFindersCache(Resource resource) {
222 if (resource.isNew()) {
223 Object[] args = new Object[] {
224 Long.valueOf(resource.getCodeId()),
225
226 resource.getPrimKey()
227 };
228
229 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_P, args,
230 Long.valueOf(1));
231 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_P, args, resource);
232 }
233 else {
234 ResourceModelImpl resourceModelImpl = (ResourceModelImpl)resource;
235
236 if ((resourceModelImpl.getColumnBitmask() &
237 FINDER_PATH_FETCH_BY_C_P.getColumnBitmask()) != 0) {
238 Object[] args = new Object[] {
239 Long.valueOf(resource.getCodeId()),
240
241 resource.getPrimKey()
242 };
243
244 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_P, args,
245 Long.valueOf(1));
246 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_P, args,
247 resource);
248 }
249 }
250 }
251
252 protected void clearUniqueFindersCache(Resource resource) {
253 ResourceModelImpl resourceModelImpl = (ResourceModelImpl)resource;
254
255 Object[] args = new Object[] {
256 Long.valueOf(resource.getCodeId()),
257
258 resource.getPrimKey()
259 };
260
261 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_P, args);
262 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_P, args);
263
264 if ((resourceModelImpl.getColumnBitmask() &
265 FINDER_PATH_FETCH_BY_C_P.getColumnBitmask()) != 0) {
266 args = new Object[] {
267 Long.valueOf(resourceModelImpl.getOriginalCodeId()),
268
269 resourceModelImpl.getOriginalPrimKey()
270 };
271
272 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_P, args);
273 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_P, args);
274 }
275 }
276
277
283 public Resource create(long resourceId) {
284 Resource resource = new ResourceImpl();
285
286 resource.setNew(true);
287 resource.setPrimaryKey(resourceId);
288
289 return resource;
290 }
291
292
300 public Resource remove(long resourceId)
301 throws NoSuchResourceException, SystemException {
302 return remove(Long.valueOf(resourceId));
303 }
304
305
313 @Override
314 public Resource remove(Serializable primaryKey)
315 throws NoSuchResourceException, SystemException {
316 Session session = null;
317
318 try {
319 session = openSession();
320
321 Resource resource = (Resource)session.get(ResourceImpl.class,
322 primaryKey);
323
324 if (resource == null) {
325 if (_log.isWarnEnabled()) {
326 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
327 }
328
329 throw new NoSuchResourceException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
330 primaryKey);
331 }
332
333 return remove(resource);
334 }
335 catch (NoSuchResourceException nsee) {
336 throw nsee;
337 }
338 catch (Exception e) {
339 throw processException(e);
340 }
341 finally {
342 closeSession(session);
343 }
344 }
345
346 @Override
347 protected Resource removeImpl(Resource resource) throws SystemException {
348 resource = toUnwrappedModel(resource);
349
350 Session session = null;
351
352 try {
353 session = openSession();
354
355 BatchSessionUtil.delete(session, resource);
356 }
357 catch (Exception e) {
358 throw processException(e);
359 }
360 finally {
361 closeSession(session);
362 }
363
364 clearCache(resource);
365
366 return resource;
367 }
368
369 @Override
370 public Resource updateImpl(com.liferay.portal.model.Resource resource,
371 boolean merge) throws SystemException {
372 resource = toUnwrappedModel(resource);
373
374 boolean isNew = resource.isNew();
375
376 ResourceModelImpl resourceModelImpl = (ResourceModelImpl)resource;
377
378 Session session = null;
379
380 try {
381 session = openSession();
382
383 BatchSessionUtil.update(session, resource, merge);
384
385 resource.setNew(false);
386 }
387 catch (Exception e) {
388 throw processException(e);
389 }
390 finally {
391 closeSession(session);
392 }
393
394 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
395
396 if (isNew || !ResourceModelImpl.COLUMN_BITMASK_ENABLED) {
397 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
398 }
399
400 else {
401 if ((resourceModelImpl.getColumnBitmask() &
402 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CODEID.getColumnBitmask()) != 0) {
403 Object[] args = new Object[] {
404 Long.valueOf(resourceModelImpl.getOriginalCodeId())
405 };
406
407 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_CODEID, args);
408 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CODEID,
409 args);
410
411 args = new Object[] { Long.valueOf(resourceModelImpl.getCodeId()) };
412
413 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_CODEID, args);
414 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CODEID,
415 args);
416 }
417
418 if ((resourceModelImpl.getColumnBitmask() &
419 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PRIMKEY.getColumnBitmask()) != 0) {
420 Object[] args = new Object[] {
421 resourceModelImpl.getOriginalPrimKey()
422 };
423
424 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_PRIMKEY, args);
425 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PRIMKEY,
426 args);
427
428 args = new Object[] { resourceModelImpl.getPrimKey() };
429
430 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_PRIMKEY, args);
431 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PRIMKEY,
432 args);
433 }
434 }
435
436 EntityCacheUtil.putResult(ResourceModelImpl.ENTITY_CACHE_ENABLED,
437 ResourceImpl.class, resource.getPrimaryKey(), resource);
438
439 clearUniqueFindersCache(resource);
440 cacheUniqueFindersCache(resource);
441
442 return resource;
443 }
444
445 protected Resource toUnwrappedModel(Resource resource) {
446 if (resource instanceof ResourceImpl) {
447 return resource;
448 }
449
450 ResourceImpl resourceImpl = new ResourceImpl();
451
452 resourceImpl.setNew(resource.isNew());
453 resourceImpl.setPrimaryKey(resource.getPrimaryKey());
454
455 resourceImpl.setResourceId(resource.getResourceId());
456 resourceImpl.setCodeId(resource.getCodeId());
457 resourceImpl.setPrimKey(resource.getPrimKey());
458
459 return resourceImpl;
460 }
461
462
470 @Override
471 public Resource findByPrimaryKey(Serializable primaryKey)
472 throws NoSuchModelException, SystemException {
473 return findByPrimaryKey(((Long)primaryKey).longValue());
474 }
475
476
484 public Resource findByPrimaryKey(long resourceId)
485 throws NoSuchResourceException, SystemException {
486 Resource resource = fetchByPrimaryKey(resourceId);
487
488 if (resource == null) {
489 if (_log.isWarnEnabled()) {
490 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + resourceId);
491 }
492
493 throw new NoSuchResourceException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
494 resourceId);
495 }
496
497 return resource;
498 }
499
500
507 @Override
508 public Resource fetchByPrimaryKey(Serializable primaryKey)
509 throws SystemException {
510 return fetchByPrimaryKey(((Long)primaryKey).longValue());
511 }
512
513
520 public Resource fetchByPrimaryKey(long resourceId)
521 throws SystemException {
522 Resource resource = (Resource)EntityCacheUtil.getResult(ResourceModelImpl.ENTITY_CACHE_ENABLED,
523 ResourceImpl.class, resourceId);
524
525 if (resource == _nullResource) {
526 return null;
527 }
528
529 if (resource == null) {
530 Session session = null;
531
532 boolean hasException = false;
533
534 try {
535 session = openSession();
536
537 resource = (Resource)session.get(ResourceImpl.class,
538 Long.valueOf(resourceId));
539 }
540 catch (Exception e) {
541 hasException = true;
542
543 throw processException(e);
544 }
545 finally {
546 if (resource != null) {
547 cacheResult(resource);
548 }
549 else if (!hasException) {
550 EntityCacheUtil.putResult(ResourceModelImpl.ENTITY_CACHE_ENABLED,
551 ResourceImpl.class, resourceId, _nullResource);
552 }
553
554 closeSession(session);
555 }
556 }
557
558 return resource;
559 }
560
561
568 public List<Resource> findByCodeId(long codeId) throws SystemException {
569 return findByCodeId(codeId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
570 }
571
572
585 public List<Resource> findByCodeId(long codeId, int start, int end)
586 throws SystemException {
587 return findByCodeId(codeId, start, end, null);
588 }
589
590
604 public List<Resource> findByCodeId(long codeId, int start, int end,
605 OrderByComparator orderByComparator) throws SystemException {
606 FinderPath finderPath = null;
607 Object[] finderArgs = null;
608
609 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
610 (orderByComparator == null)) {
611 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CODEID;
612 finderArgs = new Object[] { codeId };
613 }
614 else {
615 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_CODEID;
616 finderArgs = new Object[] { codeId, start, end, orderByComparator };
617 }
618
619 List<Resource> list = (List<Resource>)FinderCacheUtil.getResult(finderPath,
620 finderArgs, this);
621
622 if ((list != null) && !list.isEmpty()) {
623 for (Resource resource : list) {
624 if ((codeId != resource.getCodeId())) {
625 list = null;
626
627 break;
628 }
629 }
630 }
631
632 if (list == null) {
633 StringBundler query = null;
634
635 if (orderByComparator != null) {
636 query = new StringBundler(3 +
637 (orderByComparator.getOrderByFields().length * 3));
638 }
639 else {
640 query = new StringBundler(2);
641 }
642
643 query.append(_SQL_SELECT_RESOURCE_WHERE);
644
645 query.append(_FINDER_COLUMN_CODEID_CODEID_2);
646
647 if (orderByComparator != null) {
648 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
649 orderByComparator);
650 }
651
652 String sql = query.toString();
653
654 Session session = null;
655
656 try {
657 session = openSession();
658
659 Query q = session.createQuery(sql);
660
661 QueryPos qPos = QueryPos.getInstance(q);
662
663 qPos.add(codeId);
664
665 list = (List<Resource>)QueryUtil.list(q, getDialect(), start,
666 end);
667 }
668 catch (Exception e) {
669 throw processException(e);
670 }
671 finally {
672 if (list == null) {
673 FinderCacheUtil.removeResult(finderPath, finderArgs);
674 }
675 else {
676 cacheResult(list);
677
678 FinderCacheUtil.putResult(finderPath, finderArgs, list);
679 }
680
681 closeSession(session);
682 }
683 }
684
685 return list;
686 }
687
688
697 public Resource findByCodeId_First(long codeId,
698 OrderByComparator orderByComparator)
699 throws NoSuchResourceException, SystemException {
700 Resource resource = fetchByCodeId_First(codeId, orderByComparator);
701
702 if (resource != null) {
703 return resource;
704 }
705
706 StringBundler msg = new StringBundler(4);
707
708 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
709
710 msg.append("codeId=");
711 msg.append(codeId);
712
713 msg.append(StringPool.CLOSE_CURLY_BRACE);
714
715 throw new NoSuchResourceException(msg.toString());
716 }
717
718
726 public Resource fetchByCodeId_First(long codeId,
727 OrderByComparator orderByComparator) throws SystemException {
728 List<Resource> list = findByCodeId(codeId, 0, 1, orderByComparator);
729
730 if (!list.isEmpty()) {
731 return list.get(0);
732 }
733
734 return null;
735 }
736
737
746 public Resource findByCodeId_Last(long codeId,
747 OrderByComparator orderByComparator)
748 throws NoSuchResourceException, SystemException {
749 Resource resource = fetchByCodeId_Last(codeId, orderByComparator);
750
751 if (resource != null) {
752 return resource;
753 }
754
755 StringBundler msg = new StringBundler(4);
756
757 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
758
759 msg.append("codeId=");
760 msg.append(codeId);
761
762 msg.append(StringPool.CLOSE_CURLY_BRACE);
763
764 throw new NoSuchResourceException(msg.toString());
765 }
766
767
775 public Resource fetchByCodeId_Last(long codeId,
776 OrderByComparator orderByComparator) throws SystemException {
777 int count = countByCodeId(codeId);
778
779 List<Resource> list = findByCodeId(codeId, count - 1, count,
780 orderByComparator);
781
782 if (!list.isEmpty()) {
783 return list.get(0);
784 }
785
786 return null;
787 }
788
789
799 public Resource[] findByCodeId_PrevAndNext(long resourceId, long codeId,
800 OrderByComparator orderByComparator)
801 throws NoSuchResourceException, SystemException {
802 Resource resource = findByPrimaryKey(resourceId);
803
804 Session session = null;
805
806 try {
807 session = openSession();
808
809 Resource[] array = new ResourceImpl[3];
810
811 array[0] = getByCodeId_PrevAndNext(session, resource, codeId,
812 orderByComparator, true);
813
814 array[1] = resource;
815
816 array[2] = getByCodeId_PrevAndNext(session, resource, codeId,
817 orderByComparator, false);
818
819 return array;
820 }
821 catch (Exception e) {
822 throw processException(e);
823 }
824 finally {
825 closeSession(session);
826 }
827 }
828
829 protected Resource getByCodeId_PrevAndNext(Session session,
830 Resource resource, long codeId, OrderByComparator orderByComparator,
831 boolean previous) {
832 StringBundler query = null;
833
834 if (orderByComparator != null) {
835 query = new StringBundler(6 +
836 (orderByComparator.getOrderByFields().length * 6));
837 }
838 else {
839 query = new StringBundler(3);
840 }
841
842 query.append(_SQL_SELECT_RESOURCE_WHERE);
843
844 query.append(_FINDER_COLUMN_CODEID_CODEID_2);
845
846 if (orderByComparator != null) {
847 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
848
849 if (orderByConditionFields.length > 0) {
850 query.append(WHERE_AND);
851 }
852
853 for (int i = 0; i < orderByConditionFields.length; i++) {
854 query.append(_ORDER_BY_ENTITY_ALIAS);
855 query.append(orderByConditionFields[i]);
856
857 if ((i + 1) < orderByConditionFields.length) {
858 if (orderByComparator.isAscending() ^ previous) {
859 query.append(WHERE_GREATER_THAN_HAS_NEXT);
860 }
861 else {
862 query.append(WHERE_LESSER_THAN_HAS_NEXT);
863 }
864 }
865 else {
866 if (orderByComparator.isAscending() ^ previous) {
867 query.append(WHERE_GREATER_THAN);
868 }
869 else {
870 query.append(WHERE_LESSER_THAN);
871 }
872 }
873 }
874
875 query.append(ORDER_BY_CLAUSE);
876
877 String[] orderByFields = orderByComparator.getOrderByFields();
878
879 for (int i = 0; i < orderByFields.length; i++) {
880 query.append(_ORDER_BY_ENTITY_ALIAS);
881 query.append(orderByFields[i]);
882
883 if ((i + 1) < orderByFields.length) {
884 if (orderByComparator.isAscending() ^ previous) {
885 query.append(ORDER_BY_ASC_HAS_NEXT);
886 }
887 else {
888 query.append(ORDER_BY_DESC_HAS_NEXT);
889 }
890 }
891 else {
892 if (orderByComparator.isAscending() ^ previous) {
893 query.append(ORDER_BY_ASC);
894 }
895 else {
896 query.append(ORDER_BY_DESC);
897 }
898 }
899 }
900 }
901
902 String sql = query.toString();
903
904 Query q = session.createQuery(sql);
905
906 q.setFirstResult(0);
907 q.setMaxResults(2);
908
909 QueryPos qPos = QueryPos.getInstance(q);
910
911 qPos.add(codeId);
912
913 if (orderByComparator != null) {
914 Object[] values = orderByComparator.getOrderByConditionValues(resource);
915
916 for (Object value : values) {
917 qPos.add(value);
918 }
919 }
920
921 List<Resource> list = q.list();
922
923 if (list.size() == 2) {
924 return list.get(1);
925 }
926 else {
927 return null;
928 }
929 }
930
931
938 public List<Resource> findByPrimKey(String primKey)
939 throws SystemException {
940 return findByPrimKey(primKey, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
941 }
942
943
956 public List<Resource> findByPrimKey(String primKey, int start, int end)
957 throws SystemException {
958 return findByPrimKey(primKey, start, end, null);
959 }
960
961
975 public List<Resource> findByPrimKey(String primKey, int start, int end,
976 OrderByComparator orderByComparator) throws SystemException {
977 FinderPath finderPath = null;
978 Object[] finderArgs = null;
979
980 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
981 (orderByComparator == null)) {
982 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PRIMKEY;
983 finderArgs = new Object[] { primKey };
984 }
985 else {
986 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_PRIMKEY;
987 finderArgs = new Object[] { primKey, start, end, orderByComparator };
988 }
989
990 List<Resource> list = (List<Resource>)FinderCacheUtil.getResult(finderPath,
991 finderArgs, this);
992
993 if ((list != null) && !list.isEmpty()) {
994 for (Resource resource : list) {
995 if (!Validator.equals(primKey, resource.getPrimKey())) {
996 list = null;
997
998 break;
999 }
1000 }
1001 }
1002
1003 if (list == null) {
1004 StringBundler query = null;
1005
1006 if (orderByComparator != null) {
1007 query = new StringBundler(3 +
1008 (orderByComparator.getOrderByFields().length * 3));
1009 }
1010 else {
1011 query = new StringBundler(2);
1012 }
1013
1014 query.append(_SQL_SELECT_RESOURCE_WHERE);
1015
1016 if (primKey == null) {
1017 query.append(_FINDER_COLUMN_PRIMKEY_PRIMKEY_1);
1018 }
1019 else {
1020 if (primKey.equals(StringPool.BLANK)) {
1021 query.append(_FINDER_COLUMN_PRIMKEY_PRIMKEY_3);
1022 }
1023 else {
1024 query.append(_FINDER_COLUMN_PRIMKEY_PRIMKEY_2);
1025 }
1026 }
1027
1028 if (orderByComparator != null) {
1029 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1030 orderByComparator);
1031 }
1032
1033 String sql = query.toString();
1034
1035 Session session = null;
1036
1037 try {
1038 session = openSession();
1039
1040 Query q = session.createQuery(sql);
1041
1042 QueryPos qPos = QueryPos.getInstance(q);
1043
1044 if (primKey != null) {
1045 qPos.add(primKey);
1046 }
1047
1048 list = (List<Resource>)QueryUtil.list(q, getDialect(), start,
1049 end);
1050 }
1051 catch (Exception e) {
1052 throw processException(e);
1053 }
1054 finally {
1055 if (list == null) {
1056 FinderCacheUtil.removeResult(finderPath, finderArgs);
1057 }
1058 else {
1059 cacheResult(list);
1060
1061 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1062 }
1063
1064 closeSession(session);
1065 }
1066 }
1067
1068 return list;
1069 }
1070
1071
1080 public Resource findByPrimKey_First(String primKey,
1081 OrderByComparator orderByComparator)
1082 throws NoSuchResourceException, SystemException {
1083 Resource resource = fetchByPrimKey_First(primKey, orderByComparator);
1084
1085 if (resource != null) {
1086 return resource;
1087 }
1088
1089 StringBundler msg = new StringBundler(4);
1090
1091 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1092
1093 msg.append("primKey=");
1094 msg.append(primKey);
1095
1096 msg.append(StringPool.CLOSE_CURLY_BRACE);
1097
1098 throw new NoSuchResourceException(msg.toString());
1099 }
1100
1101
1109 public Resource fetchByPrimKey_First(String primKey,
1110 OrderByComparator orderByComparator) throws SystemException {
1111 List<Resource> list = findByPrimKey(primKey, 0, 1, orderByComparator);
1112
1113 if (!list.isEmpty()) {
1114 return list.get(0);
1115 }
1116
1117 return null;
1118 }
1119
1120
1129 public Resource findByPrimKey_Last(String primKey,
1130 OrderByComparator orderByComparator)
1131 throws NoSuchResourceException, SystemException {
1132 Resource resource = fetchByPrimKey_Last(primKey, orderByComparator);
1133
1134 if (resource != null) {
1135 return resource;
1136 }
1137
1138 StringBundler msg = new StringBundler(4);
1139
1140 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1141
1142 msg.append("primKey=");
1143 msg.append(primKey);
1144
1145 msg.append(StringPool.CLOSE_CURLY_BRACE);
1146
1147 throw new NoSuchResourceException(msg.toString());
1148 }
1149
1150
1158 public Resource fetchByPrimKey_Last(String primKey,
1159 OrderByComparator orderByComparator) throws SystemException {
1160 int count = countByPrimKey(primKey);
1161
1162 List<Resource> list = findByPrimKey(primKey, count - 1, count,
1163 orderByComparator);
1164
1165 if (!list.isEmpty()) {
1166 return list.get(0);
1167 }
1168
1169 return null;
1170 }
1171
1172
1182 public Resource[] findByPrimKey_PrevAndNext(long resourceId,
1183 String primKey, OrderByComparator orderByComparator)
1184 throws NoSuchResourceException, SystemException {
1185 Resource resource = findByPrimaryKey(resourceId);
1186
1187 Session session = null;
1188
1189 try {
1190 session = openSession();
1191
1192 Resource[] array = new ResourceImpl[3];
1193
1194 array[0] = getByPrimKey_PrevAndNext(session, resource, primKey,
1195 orderByComparator, true);
1196
1197 array[1] = resource;
1198
1199 array[2] = getByPrimKey_PrevAndNext(session, resource, primKey,
1200 orderByComparator, false);
1201
1202 return array;
1203 }
1204 catch (Exception e) {
1205 throw processException(e);
1206 }
1207 finally {
1208 closeSession(session);
1209 }
1210 }
1211
1212 protected Resource getByPrimKey_PrevAndNext(Session session,
1213 Resource resource, String primKey, OrderByComparator orderByComparator,
1214 boolean previous) {
1215 StringBundler query = null;
1216
1217 if (orderByComparator != null) {
1218 query = new StringBundler(6 +
1219 (orderByComparator.getOrderByFields().length * 6));
1220 }
1221 else {
1222 query = new StringBundler(3);
1223 }
1224
1225 query.append(_SQL_SELECT_RESOURCE_WHERE);
1226
1227 if (primKey == null) {
1228 query.append(_FINDER_COLUMN_PRIMKEY_PRIMKEY_1);
1229 }
1230 else {
1231 if (primKey.equals(StringPool.BLANK)) {
1232 query.append(_FINDER_COLUMN_PRIMKEY_PRIMKEY_3);
1233 }
1234 else {
1235 query.append(_FINDER_COLUMN_PRIMKEY_PRIMKEY_2);
1236 }
1237 }
1238
1239 if (orderByComparator != null) {
1240 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1241
1242 if (orderByConditionFields.length > 0) {
1243 query.append(WHERE_AND);
1244 }
1245
1246 for (int i = 0; i < orderByConditionFields.length; i++) {
1247 query.append(_ORDER_BY_ENTITY_ALIAS);
1248 query.append(orderByConditionFields[i]);
1249
1250 if ((i + 1) < orderByConditionFields.length) {
1251 if (orderByComparator.isAscending() ^ previous) {
1252 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1253 }
1254 else {
1255 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1256 }
1257 }
1258 else {
1259 if (orderByComparator.isAscending() ^ previous) {
1260 query.append(WHERE_GREATER_THAN);
1261 }
1262 else {
1263 query.append(WHERE_LESSER_THAN);
1264 }
1265 }
1266 }
1267
1268 query.append(ORDER_BY_CLAUSE);
1269
1270 String[] orderByFields = orderByComparator.getOrderByFields();
1271
1272 for (int i = 0; i < orderByFields.length; i++) {
1273 query.append(_ORDER_BY_ENTITY_ALIAS);
1274 query.append(orderByFields[i]);
1275
1276 if ((i + 1) < orderByFields.length) {
1277 if (orderByComparator.isAscending() ^ previous) {
1278 query.append(ORDER_BY_ASC_HAS_NEXT);
1279 }
1280 else {
1281 query.append(ORDER_BY_DESC_HAS_NEXT);
1282 }
1283 }
1284 else {
1285 if (orderByComparator.isAscending() ^ previous) {
1286 query.append(ORDER_BY_ASC);
1287 }
1288 else {
1289 query.append(ORDER_BY_DESC);
1290 }
1291 }
1292 }
1293 }
1294
1295 String sql = query.toString();
1296
1297 Query q = session.createQuery(sql);
1298
1299 q.setFirstResult(0);
1300 q.setMaxResults(2);
1301
1302 QueryPos qPos = QueryPos.getInstance(q);
1303
1304 if (primKey != null) {
1305 qPos.add(primKey);
1306 }
1307
1308 if (orderByComparator != null) {
1309 Object[] values = orderByComparator.getOrderByConditionValues(resource);
1310
1311 for (Object value : values) {
1312 qPos.add(value);
1313 }
1314 }
1315
1316 List<Resource> list = q.list();
1317
1318 if (list.size() == 2) {
1319 return list.get(1);
1320 }
1321 else {
1322 return null;
1323 }
1324 }
1325
1326
1335 public Resource findByC_P(long codeId, String primKey)
1336 throws NoSuchResourceException, SystemException {
1337 Resource resource = fetchByC_P(codeId, primKey);
1338
1339 if (resource == null) {
1340 StringBundler msg = new StringBundler(6);
1341
1342 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1343
1344 msg.append("codeId=");
1345 msg.append(codeId);
1346
1347 msg.append(", primKey=");
1348 msg.append(primKey);
1349
1350 msg.append(StringPool.CLOSE_CURLY_BRACE);
1351
1352 if (_log.isWarnEnabled()) {
1353 _log.warn(msg.toString());
1354 }
1355
1356 throw new NoSuchResourceException(msg.toString());
1357 }
1358
1359 return resource;
1360 }
1361
1362
1370 public Resource fetchByC_P(long codeId, String primKey)
1371 throws SystemException {
1372 return fetchByC_P(codeId, primKey, true);
1373 }
1374
1375
1384 public Resource fetchByC_P(long codeId, String primKey,
1385 boolean retrieveFromCache) throws SystemException {
1386 Object[] finderArgs = new Object[] { codeId, primKey };
1387
1388 Object result = null;
1389
1390 if (retrieveFromCache) {
1391 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_P,
1392 finderArgs, this);
1393 }
1394
1395 if (result instanceof Resource) {
1396 Resource resource = (Resource)result;
1397
1398 if ((codeId != resource.getCodeId()) ||
1399 !Validator.equals(primKey, resource.getPrimKey())) {
1400 result = null;
1401 }
1402 }
1403
1404 if (result == null) {
1405 StringBundler query = new StringBundler(3);
1406
1407 query.append(_SQL_SELECT_RESOURCE_WHERE);
1408
1409 query.append(_FINDER_COLUMN_C_P_CODEID_2);
1410
1411 if (primKey == null) {
1412 query.append(_FINDER_COLUMN_C_P_PRIMKEY_1);
1413 }
1414 else {
1415 if (primKey.equals(StringPool.BLANK)) {
1416 query.append(_FINDER_COLUMN_C_P_PRIMKEY_3);
1417 }
1418 else {
1419 query.append(_FINDER_COLUMN_C_P_PRIMKEY_2);
1420 }
1421 }
1422
1423 String sql = query.toString();
1424
1425 Session session = null;
1426
1427 try {
1428 session = openSession();
1429
1430 Query q = session.createQuery(sql);
1431
1432 QueryPos qPos = QueryPos.getInstance(q);
1433
1434 qPos.add(codeId);
1435
1436 if (primKey != null) {
1437 qPos.add(primKey);
1438 }
1439
1440 List<Resource> list = q.list();
1441
1442 result = list;
1443
1444 Resource resource = null;
1445
1446 if (list.isEmpty()) {
1447 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_P,
1448 finderArgs, list);
1449 }
1450 else {
1451 resource = list.get(0);
1452
1453 cacheResult(resource);
1454
1455 if ((resource.getCodeId() != codeId) ||
1456 (resource.getPrimKey() == null) ||
1457 !resource.getPrimKey().equals(primKey)) {
1458 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_P,
1459 finderArgs, resource);
1460 }
1461 }
1462
1463 return resource;
1464 }
1465 catch (Exception e) {
1466 throw processException(e);
1467 }
1468 finally {
1469 if (result == null) {
1470 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_P,
1471 finderArgs);
1472 }
1473
1474 closeSession(session);
1475 }
1476 }
1477 else {
1478 if (result instanceof List<?>) {
1479 return null;
1480 }
1481 else {
1482 return (Resource)result;
1483 }
1484 }
1485 }
1486
1487
1493 public List<Resource> findAll() throws SystemException {
1494 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1495 }
1496
1497
1509 public List<Resource> findAll(int start, int end) throws SystemException {
1510 return findAll(start, end, null);
1511 }
1512
1513
1526 public List<Resource> findAll(int start, int end,
1527 OrderByComparator orderByComparator) throws SystemException {
1528 FinderPath finderPath = null;
1529 Object[] finderArgs = new Object[] { start, end, orderByComparator };
1530
1531 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1532 (orderByComparator == null)) {
1533 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1534 finderArgs = FINDER_ARGS_EMPTY;
1535 }
1536 else {
1537 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1538 finderArgs = new Object[] { start, end, orderByComparator };
1539 }
1540
1541 List<Resource> list = (List<Resource>)FinderCacheUtil.getResult(finderPath,
1542 finderArgs, this);
1543
1544 if (list == null) {
1545 StringBundler query = null;
1546 String sql = null;
1547
1548 if (orderByComparator != null) {
1549 query = new StringBundler(2 +
1550 (orderByComparator.getOrderByFields().length * 3));
1551
1552 query.append(_SQL_SELECT_RESOURCE);
1553
1554 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1555 orderByComparator);
1556
1557 sql = query.toString();
1558 }
1559 else {
1560 sql = _SQL_SELECT_RESOURCE;
1561 }
1562
1563 Session session = null;
1564
1565 try {
1566 session = openSession();
1567
1568 Query q = session.createQuery(sql);
1569
1570 if (orderByComparator == null) {
1571 list = (List<Resource>)QueryUtil.list(q, getDialect(),
1572 start, end, false);
1573
1574 Collections.sort(list);
1575 }
1576 else {
1577 list = (List<Resource>)QueryUtil.list(q, getDialect(),
1578 start, end);
1579 }
1580 }
1581 catch (Exception e) {
1582 throw processException(e);
1583 }
1584 finally {
1585 if (list == null) {
1586 FinderCacheUtil.removeResult(finderPath, finderArgs);
1587 }
1588 else {
1589 cacheResult(list);
1590
1591 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1592 }
1593
1594 closeSession(session);
1595 }
1596 }
1597
1598 return list;
1599 }
1600
1601
1607 public void removeByCodeId(long codeId) throws SystemException {
1608 for (Resource resource : findByCodeId(codeId)) {
1609 remove(resource);
1610 }
1611 }
1612
1613
1619 public void removeByPrimKey(String primKey) throws SystemException {
1620 for (Resource resource : findByPrimKey(primKey)) {
1621 remove(resource);
1622 }
1623 }
1624
1625
1633 public Resource removeByC_P(long codeId, String primKey)
1634 throws NoSuchResourceException, SystemException {
1635 Resource resource = findByC_P(codeId, primKey);
1636
1637 return remove(resource);
1638 }
1639
1640
1645 public void removeAll() throws SystemException {
1646 for (Resource resource : findAll()) {
1647 remove(resource);
1648 }
1649 }
1650
1651
1658 public int countByCodeId(long codeId) throws SystemException {
1659 Object[] finderArgs = new Object[] { codeId };
1660
1661 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_CODEID,
1662 finderArgs, this);
1663
1664 if (count == null) {
1665 StringBundler query = new StringBundler(2);
1666
1667 query.append(_SQL_COUNT_RESOURCE_WHERE);
1668
1669 query.append(_FINDER_COLUMN_CODEID_CODEID_2);
1670
1671 String sql = query.toString();
1672
1673 Session session = null;
1674
1675 try {
1676 session = openSession();
1677
1678 Query q = session.createQuery(sql);
1679
1680 QueryPos qPos = QueryPos.getInstance(q);
1681
1682 qPos.add(codeId);
1683
1684 count = (Long)q.uniqueResult();
1685 }
1686 catch (Exception e) {
1687 throw processException(e);
1688 }
1689 finally {
1690 if (count == null) {
1691 count = Long.valueOf(0);
1692 }
1693
1694 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_CODEID,
1695 finderArgs, count);
1696
1697 closeSession(session);
1698 }
1699 }
1700
1701 return count.intValue();
1702 }
1703
1704
1711 public int countByPrimKey(String primKey) throws SystemException {
1712 Object[] finderArgs = new Object[] { primKey };
1713
1714 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_PRIMKEY,
1715 finderArgs, this);
1716
1717 if (count == null) {
1718 StringBundler query = new StringBundler(2);
1719
1720 query.append(_SQL_COUNT_RESOURCE_WHERE);
1721
1722 if (primKey == null) {
1723 query.append(_FINDER_COLUMN_PRIMKEY_PRIMKEY_1);
1724 }
1725 else {
1726 if (primKey.equals(StringPool.BLANK)) {
1727 query.append(_FINDER_COLUMN_PRIMKEY_PRIMKEY_3);
1728 }
1729 else {
1730 query.append(_FINDER_COLUMN_PRIMKEY_PRIMKEY_2);
1731 }
1732 }
1733
1734 String sql = query.toString();
1735
1736 Session session = null;
1737
1738 try {
1739 session = openSession();
1740
1741 Query q = session.createQuery(sql);
1742
1743 QueryPos qPos = QueryPos.getInstance(q);
1744
1745 if (primKey != null) {
1746 qPos.add(primKey);
1747 }
1748
1749 count = (Long)q.uniqueResult();
1750 }
1751 catch (Exception e) {
1752 throw processException(e);
1753 }
1754 finally {
1755 if (count == null) {
1756 count = Long.valueOf(0);
1757 }
1758
1759 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_PRIMKEY,
1760 finderArgs, count);
1761
1762 closeSession(session);
1763 }
1764 }
1765
1766 return count.intValue();
1767 }
1768
1769
1777 public int countByC_P(long codeId, String primKey)
1778 throws SystemException {
1779 Object[] finderArgs = new Object[] { codeId, primKey };
1780
1781 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_P,
1782 finderArgs, this);
1783
1784 if (count == null) {
1785 StringBundler query = new StringBundler(3);
1786
1787 query.append(_SQL_COUNT_RESOURCE_WHERE);
1788
1789 query.append(_FINDER_COLUMN_C_P_CODEID_2);
1790
1791 if (primKey == null) {
1792 query.append(_FINDER_COLUMN_C_P_PRIMKEY_1);
1793 }
1794 else {
1795 if (primKey.equals(StringPool.BLANK)) {
1796 query.append(_FINDER_COLUMN_C_P_PRIMKEY_3);
1797 }
1798 else {
1799 query.append(_FINDER_COLUMN_C_P_PRIMKEY_2);
1800 }
1801 }
1802
1803 String sql = query.toString();
1804
1805 Session session = null;
1806
1807 try {
1808 session = openSession();
1809
1810 Query q = session.createQuery(sql);
1811
1812 QueryPos qPos = QueryPos.getInstance(q);
1813
1814 qPos.add(codeId);
1815
1816 if (primKey != null) {
1817 qPos.add(primKey);
1818 }
1819
1820 count = (Long)q.uniqueResult();
1821 }
1822 catch (Exception e) {
1823 throw processException(e);
1824 }
1825 finally {
1826 if (count == null) {
1827 count = Long.valueOf(0);
1828 }
1829
1830 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_P, finderArgs,
1831 count);
1832
1833 closeSession(session);
1834 }
1835 }
1836
1837 return count.intValue();
1838 }
1839
1840
1846 public int countAll() throws SystemException {
1847 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1848 FINDER_ARGS_EMPTY, this);
1849
1850 if (count == null) {
1851 Session session = null;
1852
1853 try {
1854 session = openSession();
1855
1856 Query q = session.createQuery(_SQL_COUNT_RESOURCE);
1857
1858 count = (Long)q.uniqueResult();
1859 }
1860 catch (Exception e) {
1861 throw processException(e);
1862 }
1863 finally {
1864 if (count == null) {
1865 count = Long.valueOf(0);
1866 }
1867
1868 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1869 FINDER_ARGS_EMPTY, count);
1870
1871 closeSession(session);
1872 }
1873 }
1874
1875 return count.intValue();
1876 }
1877
1878
1881 public void afterPropertiesSet() {
1882 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1883 com.liferay.portal.util.PropsUtil.get(
1884 "value.object.listener.com.liferay.portal.model.Resource")));
1885
1886 if (listenerClassNames.length > 0) {
1887 try {
1888 List<ModelListener<Resource>> listenersList = new ArrayList<ModelListener<Resource>>();
1889
1890 for (String listenerClassName : listenerClassNames) {
1891 Class<?> clazz = getClass();
1892
1893 listenersList.add((ModelListener<Resource>)InstanceFactory.newInstance(
1894 clazz.getClassLoader(), listenerClassName));
1895 }
1896
1897 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1898 }
1899 catch (Exception e) {
1900 _log.error(e);
1901 }
1902 }
1903 }
1904
1905 public void destroy() {
1906 EntityCacheUtil.removeCache(ResourceImpl.class.getName());
1907 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1908 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1909 }
1910
1911 @BeanReference(type = AccountPersistence.class)
1912 protected AccountPersistence accountPersistence;
1913 @BeanReference(type = AddressPersistence.class)
1914 protected AddressPersistence addressPersistence;
1915 @BeanReference(type = BrowserTrackerPersistence.class)
1916 protected BrowserTrackerPersistence browserTrackerPersistence;
1917 @BeanReference(type = ClassNamePersistence.class)
1918 protected ClassNamePersistence classNamePersistence;
1919 @BeanReference(type = ClusterGroupPersistence.class)
1920 protected ClusterGroupPersistence clusterGroupPersistence;
1921 @BeanReference(type = CompanyPersistence.class)
1922 protected CompanyPersistence companyPersistence;
1923 @BeanReference(type = ContactPersistence.class)
1924 protected ContactPersistence contactPersistence;
1925 @BeanReference(type = CountryPersistence.class)
1926 protected CountryPersistence countryPersistence;
1927 @BeanReference(type = EmailAddressPersistence.class)
1928 protected EmailAddressPersistence emailAddressPersistence;
1929 @BeanReference(type = GroupPersistence.class)
1930 protected GroupPersistence groupPersistence;
1931 @BeanReference(type = ImagePersistence.class)
1932 protected ImagePersistence imagePersistence;
1933 @BeanReference(type = LayoutPersistence.class)
1934 protected LayoutPersistence layoutPersistence;
1935 @BeanReference(type = LayoutBranchPersistence.class)
1936 protected LayoutBranchPersistence layoutBranchPersistence;
1937 @BeanReference(type = LayoutPrototypePersistence.class)
1938 protected LayoutPrototypePersistence layoutPrototypePersistence;
1939 @BeanReference(type = LayoutRevisionPersistence.class)
1940 protected LayoutRevisionPersistence layoutRevisionPersistence;
1941 @BeanReference(type = LayoutSetPersistence.class)
1942 protected LayoutSetPersistence layoutSetPersistence;
1943 @BeanReference(type = LayoutSetBranchPersistence.class)
1944 protected LayoutSetBranchPersistence layoutSetBranchPersistence;
1945 @BeanReference(type = LayoutSetPrototypePersistence.class)
1946 protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
1947 @BeanReference(type = ListTypePersistence.class)
1948 protected ListTypePersistence listTypePersistence;
1949 @BeanReference(type = LockPersistence.class)
1950 protected LockPersistence lockPersistence;
1951 @BeanReference(type = MembershipRequestPersistence.class)
1952 protected MembershipRequestPersistence membershipRequestPersistence;
1953 @BeanReference(type = OrganizationPersistence.class)
1954 protected OrganizationPersistence organizationPersistence;
1955 @BeanReference(type = OrgGroupPermissionPersistence.class)
1956 protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1957 @BeanReference(type = OrgGroupRolePersistence.class)
1958 protected OrgGroupRolePersistence orgGroupRolePersistence;
1959 @BeanReference(type = OrgLaborPersistence.class)
1960 protected OrgLaborPersistence orgLaborPersistence;
1961 @BeanReference(type = PasswordPolicyPersistence.class)
1962 protected PasswordPolicyPersistence passwordPolicyPersistence;
1963 @BeanReference(type = PasswordPolicyRelPersistence.class)
1964 protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1965 @BeanReference(type = PasswordTrackerPersistence.class)
1966 protected PasswordTrackerPersistence passwordTrackerPersistence;
1967 @BeanReference(type = PermissionPersistence.class)
1968 protected PermissionPersistence permissionPersistence;
1969 @BeanReference(type = PhonePersistence.class)
1970 protected PhonePersistence phonePersistence;
1971 @BeanReference(type = PluginSettingPersistence.class)
1972 protected PluginSettingPersistence pluginSettingPersistence;
1973 @BeanReference(type = PortalPreferencesPersistence.class)
1974 protected PortalPreferencesPersistence portalPreferencesPersistence;
1975 @BeanReference(type = PortletPersistence.class)
1976 protected PortletPersistence portletPersistence;
1977 @BeanReference(type = PortletItemPersistence.class)
1978 protected PortletItemPersistence portletItemPersistence;
1979 @BeanReference(type = PortletPreferencesPersistence.class)
1980 protected PortletPreferencesPersistence portletPreferencesPersistence;
1981 @BeanReference(type = RegionPersistence.class)
1982 protected RegionPersistence regionPersistence;
1983 @BeanReference(type = ReleasePersistence.class)
1984 protected ReleasePersistence releasePersistence;
1985 @BeanReference(type = RepositoryPersistence.class)
1986 protected RepositoryPersistence repositoryPersistence;
1987 @BeanReference(type = RepositoryEntryPersistence.class)
1988 protected RepositoryEntryPersistence repositoryEntryPersistence;
1989 @BeanReference(type = ResourcePersistence.class)
1990 protected ResourcePersistence resourcePersistence;
1991 @BeanReference(type = ResourceActionPersistence.class)
1992 protected ResourceActionPersistence resourceActionPersistence;
1993 @BeanReference(type = ResourceBlockPersistence.class)
1994 protected ResourceBlockPersistence resourceBlockPersistence;
1995 @BeanReference(type = ResourceBlockPermissionPersistence.class)
1996 protected ResourceBlockPermissionPersistence resourceBlockPermissionPersistence;
1997 @BeanReference(type = ResourceCodePersistence.class)
1998 protected ResourceCodePersistence resourceCodePersistence;
1999 @BeanReference(type = ResourcePermissionPersistence.class)
2000 protected ResourcePermissionPersistence resourcePermissionPersistence;
2001 @BeanReference(type = ResourceTypePermissionPersistence.class)
2002 protected ResourceTypePermissionPersistence resourceTypePermissionPersistence;
2003 @BeanReference(type = RolePersistence.class)
2004 protected RolePersistence rolePersistence;
2005 @BeanReference(type = ServiceComponentPersistence.class)
2006 protected ServiceComponentPersistence serviceComponentPersistence;
2007 @BeanReference(type = ShardPersistence.class)
2008 protected ShardPersistence shardPersistence;
2009 @BeanReference(type = SubscriptionPersistence.class)
2010 protected SubscriptionPersistence subscriptionPersistence;
2011 @BeanReference(type = TeamPersistence.class)
2012 protected TeamPersistence teamPersistence;
2013 @BeanReference(type = TicketPersistence.class)
2014 protected TicketPersistence ticketPersistence;
2015 @BeanReference(type = UserPersistence.class)
2016 protected UserPersistence userPersistence;
2017 @BeanReference(type = UserGroupPersistence.class)
2018 protected UserGroupPersistence userGroupPersistence;
2019 @BeanReference(type = UserGroupGroupRolePersistence.class)
2020 protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
2021 @BeanReference(type = UserGroupRolePersistence.class)
2022 protected UserGroupRolePersistence userGroupRolePersistence;
2023 @BeanReference(type = UserIdMapperPersistence.class)
2024 protected UserIdMapperPersistence userIdMapperPersistence;
2025 @BeanReference(type = UserNotificationEventPersistence.class)
2026 protected UserNotificationEventPersistence userNotificationEventPersistence;
2027 @BeanReference(type = UserTrackerPersistence.class)
2028 protected UserTrackerPersistence userTrackerPersistence;
2029 @BeanReference(type = UserTrackerPathPersistence.class)
2030 protected UserTrackerPathPersistence userTrackerPathPersistence;
2031 @BeanReference(type = VirtualHostPersistence.class)
2032 protected VirtualHostPersistence virtualHostPersistence;
2033 @BeanReference(type = WebDAVPropsPersistence.class)
2034 protected WebDAVPropsPersistence webDAVPropsPersistence;
2035 @BeanReference(type = WebsitePersistence.class)
2036 protected WebsitePersistence websitePersistence;
2037 @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
2038 protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
2039 @BeanReference(type = WorkflowInstanceLinkPersistence.class)
2040 protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
2041 private static final String _SQL_SELECT_RESOURCE = "SELECT resource FROM Resource resource";
2042 private static final String _SQL_SELECT_RESOURCE_WHERE = "SELECT resource FROM Resource resource WHERE ";
2043 private static final String _SQL_COUNT_RESOURCE = "SELECT COUNT(resource) FROM Resource resource";
2044 private static final String _SQL_COUNT_RESOURCE_WHERE = "SELECT COUNT(resource) FROM Resource resource WHERE ";
2045 private static final String _FINDER_COLUMN_CODEID_CODEID_2 = "resource.codeId = ?";
2046 private static final String _FINDER_COLUMN_PRIMKEY_PRIMKEY_1 = "resource.primKey IS NULL";
2047 private static final String _FINDER_COLUMN_PRIMKEY_PRIMKEY_2 = "resource.primKey = ?";
2048 private static final String _FINDER_COLUMN_PRIMKEY_PRIMKEY_3 = "(resource.primKey IS NULL OR resource.primKey = ?)";
2049 private static final String _FINDER_COLUMN_C_P_CODEID_2 = "resource.codeId = ? AND ";
2050 private static final String _FINDER_COLUMN_C_P_PRIMKEY_1 = "resource.primKey IS NULL";
2051 private static final String _FINDER_COLUMN_C_P_PRIMKEY_2 = "resource.primKey = ?";
2052 private static final String _FINDER_COLUMN_C_P_PRIMKEY_3 = "(resource.primKey IS NULL OR resource.primKey = ?)";
2053 private static final String _ORDER_BY_ENTITY_ALIAS = "resource.";
2054 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Resource exists with the primary key ";
2055 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Resource exists with the key {";
2056 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2057 private static Log _log = LogFactoryUtil.getLog(ResourcePersistenceImpl.class);
2058 private static Resource _nullResource = new ResourceImpl() {
2059 @Override
2060 public Object clone() {
2061 return this;
2062 }
2063
2064 @Override
2065 public CacheModel<Resource> toCacheModel() {
2066 return _nullResourceCacheModel;
2067 }
2068 };
2069
2070 private static CacheModel<Resource> _nullResourceCacheModel = new CacheModel<Resource>() {
2071 public Resource toEntityModel() {
2072 return _nullResource;
2073 }
2074 };
2075 }