001
014
015 package com.liferay.portal.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.NoSuchResourceCodeException;
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.ResourceCode;
041 import com.liferay.portal.model.impl.ResourceCodeImpl;
042 import com.liferay.portal.model.impl.ResourceCodeModelImpl;
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 ResourceCodePersistenceImpl extends BasePersistenceImpl<ResourceCode>
064 implements ResourceCodePersistence {
065
070 public static final String FINDER_CLASS_NAME_ENTITY = ResourceCodeImpl.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_COMPANYID =
076 new FinderPath(ResourceCodeModelImpl.ENTITY_CACHE_ENABLED,
077 ResourceCodeModelImpl.FINDER_CACHE_ENABLED, ResourceCodeImpl.class,
078 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
079 new String[] {
080 Long.class.getName(),
081
082 "java.lang.Integer", "java.lang.Integer",
083 "com.liferay.portal.kernel.util.OrderByComparator"
084 });
085 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
086 new FinderPath(ResourceCodeModelImpl.ENTITY_CACHE_ENABLED,
087 ResourceCodeModelImpl.FINDER_CACHE_ENABLED, ResourceCodeImpl.class,
088 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
089 new String[] { Long.class.getName() },
090 ResourceCodeModelImpl.COMPANYID_COLUMN_BITMASK);
091 public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(ResourceCodeModelImpl.ENTITY_CACHE_ENABLED,
092 ResourceCodeModelImpl.FINDER_CACHE_ENABLED, Long.class,
093 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
094 new String[] { Long.class.getName() });
095 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_NAME = new FinderPath(ResourceCodeModelImpl.ENTITY_CACHE_ENABLED,
096 ResourceCodeModelImpl.FINDER_CACHE_ENABLED, ResourceCodeImpl.class,
097 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByName",
098 new String[] {
099 String.class.getName(),
100
101 "java.lang.Integer", "java.lang.Integer",
102 "com.liferay.portal.kernel.util.OrderByComparator"
103 });
104 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME = new FinderPath(ResourceCodeModelImpl.ENTITY_CACHE_ENABLED,
105 ResourceCodeModelImpl.FINDER_CACHE_ENABLED, ResourceCodeImpl.class,
106 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByName",
107 new String[] { String.class.getName() },
108 ResourceCodeModelImpl.NAME_COLUMN_BITMASK);
109 public static final FinderPath FINDER_PATH_COUNT_BY_NAME = new FinderPath(ResourceCodeModelImpl.ENTITY_CACHE_ENABLED,
110 ResourceCodeModelImpl.FINDER_CACHE_ENABLED, Long.class,
111 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByName",
112 new String[] { String.class.getName() });
113 public static final FinderPath FINDER_PATH_FETCH_BY_C_N_S = new FinderPath(ResourceCodeModelImpl.ENTITY_CACHE_ENABLED,
114 ResourceCodeModelImpl.FINDER_CACHE_ENABLED, ResourceCodeImpl.class,
115 FINDER_CLASS_NAME_ENTITY, "fetchByC_N_S",
116 new String[] {
117 Long.class.getName(), String.class.getName(),
118 Integer.class.getName()
119 },
120 ResourceCodeModelImpl.COMPANYID_COLUMN_BITMASK |
121 ResourceCodeModelImpl.NAME_COLUMN_BITMASK |
122 ResourceCodeModelImpl.SCOPE_COLUMN_BITMASK);
123 public static final FinderPath FINDER_PATH_COUNT_BY_C_N_S = new FinderPath(ResourceCodeModelImpl.ENTITY_CACHE_ENABLED,
124 ResourceCodeModelImpl.FINDER_CACHE_ENABLED, Long.class,
125 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_N_S",
126 new String[] {
127 Long.class.getName(), String.class.getName(),
128 Integer.class.getName()
129 });
130 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(ResourceCodeModelImpl.ENTITY_CACHE_ENABLED,
131 ResourceCodeModelImpl.FINDER_CACHE_ENABLED, ResourceCodeImpl.class,
132 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
133 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ResourceCodeModelImpl.ENTITY_CACHE_ENABLED,
134 ResourceCodeModelImpl.FINDER_CACHE_ENABLED, ResourceCodeImpl.class,
135 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
136 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ResourceCodeModelImpl.ENTITY_CACHE_ENABLED,
137 ResourceCodeModelImpl.FINDER_CACHE_ENABLED, Long.class,
138 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
139
140
145 public void cacheResult(ResourceCode resourceCode) {
146 EntityCacheUtil.putResult(ResourceCodeModelImpl.ENTITY_CACHE_ENABLED,
147 ResourceCodeImpl.class, resourceCode.getPrimaryKey(), resourceCode);
148
149 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N_S,
150 new Object[] {
151 Long.valueOf(resourceCode.getCompanyId()),
152
153 resourceCode.getName(), Integer.valueOf(resourceCode.getScope())
154 }, resourceCode);
155
156 resourceCode.resetOriginalValues();
157 }
158
159
164 public void cacheResult(List<ResourceCode> resourceCodes) {
165 for (ResourceCode resourceCode : resourceCodes) {
166 if (EntityCacheUtil.getResult(
167 ResourceCodeModelImpl.ENTITY_CACHE_ENABLED,
168 ResourceCodeImpl.class, resourceCode.getPrimaryKey()) == null) {
169 cacheResult(resourceCode);
170 }
171 else {
172 resourceCode.resetOriginalValues();
173 }
174 }
175 }
176
177
184 @Override
185 public void clearCache() {
186 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
187 CacheRegistryUtil.clear(ResourceCodeImpl.class.getName());
188 }
189
190 EntityCacheUtil.clearCache(ResourceCodeImpl.class.getName());
191
192 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
193 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
194 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
195 }
196
197
204 @Override
205 public void clearCache(ResourceCode resourceCode) {
206 EntityCacheUtil.removeResult(ResourceCodeModelImpl.ENTITY_CACHE_ENABLED,
207 ResourceCodeImpl.class, resourceCode.getPrimaryKey());
208
209 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
210 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
211
212 clearUniqueFindersCache(resourceCode);
213 }
214
215 @Override
216 public void clearCache(List<ResourceCode> resourceCodes) {
217 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
218 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
219
220 for (ResourceCode resourceCode : resourceCodes) {
221 EntityCacheUtil.removeResult(ResourceCodeModelImpl.ENTITY_CACHE_ENABLED,
222 ResourceCodeImpl.class, resourceCode.getPrimaryKey());
223
224 clearUniqueFindersCache(resourceCode);
225 }
226 }
227
228 protected void clearUniqueFindersCache(ResourceCode resourceCode) {
229 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N_S,
230 new Object[] {
231 Long.valueOf(resourceCode.getCompanyId()),
232
233 resourceCode.getName(), Integer.valueOf(resourceCode.getScope())
234 });
235 }
236
237
243 public ResourceCode create(long codeId) {
244 ResourceCode resourceCode = new ResourceCodeImpl();
245
246 resourceCode.setNew(true);
247 resourceCode.setPrimaryKey(codeId);
248
249 return resourceCode;
250 }
251
252
260 public ResourceCode remove(long codeId)
261 throws NoSuchResourceCodeException, SystemException {
262 return remove(Long.valueOf(codeId));
263 }
264
265
273 @Override
274 public ResourceCode remove(Serializable primaryKey)
275 throws NoSuchResourceCodeException, SystemException {
276 Session session = null;
277
278 try {
279 session = openSession();
280
281 ResourceCode resourceCode = (ResourceCode)session.get(ResourceCodeImpl.class,
282 primaryKey);
283
284 if (resourceCode == null) {
285 if (_log.isWarnEnabled()) {
286 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
287 }
288
289 throw new NoSuchResourceCodeException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
290 primaryKey);
291 }
292
293 return remove(resourceCode);
294 }
295 catch (NoSuchResourceCodeException nsee) {
296 throw nsee;
297 }
298 catch (Exception e) {
299 throw processException(e);
300 }
301 finally {
302 closeSession(session);
303 }
304 }
305
306 @Override
307 protected ResourceCode removeImpl(ResourceCode resourceCode)
308 throws SystemException {
309 resourceCode = toUnwrappedModel(resourceCode);
310
311 Session session = null;
312
313 try {
314 session = openSession();
315
316 BatchSessionUtil.delete(session, resourceCode);
317 }
318 catch (Exception e) {
319 throw processException(e);
320 }
321 finally {
322 closeSession(session);
323 }
324
325 clearCache(resourceCode);
326
327 return resourceCode;
328 }
329
330 @Override
331 public ResourceCode updateImpl(
332 com.liferay.portal.model.ResourceCode resourceCode, boolean merge)
333 throws SystemException {
334 resourceCode = toUnwrappedModel(resourceCode);
335
336 boolean isNew = resourceCode.isNew();
337
338 ResourceCodeModelImpl resourceCodeModelImpl = (ResourceCodeModelImpl)resourceCode;
339
340 Session session = null;
341
342 try {
343 session = openSession();
344
345 BatchSessionUtil.update(session, resourceCode, merge);
346
347 resourceCode.setNew(false);
348 }
349 catch (Exception e) {
350 throw processException(e);
351 }
352 finally {
353 closeSession(session);
354 }
355
356 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
357
358 if (isNew || !ResourceCodeModelImpl.COLUMN_BITMASK_ENABLED) {
359 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
360 }
361 else {
362 if ((resourceCodeModelImpl.getColumnBitmask() &
363 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
364 Object[] args = new Object[] {
365 Long.valueOf(resourceCodeModelImpl.getOriginalCompanyId())
366 };
367
368 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
369 args);
370 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
371 args);
372
373 args = new Object[] {
374 Long.valueOf(resourceCodeModelImpl.getCompanyId())
375 };
376
377 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
378 args);
379 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
380 args);
381 }
382
383 if ((resourceCodeModelImpl.getColumnBitmask() &
384 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME.getColumnBitmask()) != 0) {
385 Object[] args = new Object[] {
386 resourceCodeModelImpl.getOriginalName()
387 };
388
389 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_NAME, args);
390 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME,
391 args);
392
393 args = new Object[] { resourceCodeModelImpl.getName() };
394
395 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_NAME, args);
396 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME,
397 args);
398 }
399 }
400
401 EntityCacheUtil.putResult(ResourceCodeModelImpl.ENTITY_CACHE_ENABLED,
402 ResourceCodeImpl.class, resourceCode.getPrimaryKey(), resourceCode);
403
404 if (isNew) {
405 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N_S,
406 new Object[] {
407 Long.valueOf(resourceCode.getCompanyId()),
408
409 resourceCode.getName(), Integer.valueOf(resourceCode.getScope())
410 }, resourceCode);
411 }
412 else {
413 if ((resourceCodeModelImpl.getColumnBitmask() &
414 FINDER_PATH_FETCH_BY_C_N_S.getColumnBitmask()) != 0) {
415 Object[] args = new Object[] {
416 Long.valueOf(resourceCodeModelImpl.getOriginalCompanyId()),
417
418 resourceCodeModelImpl.getOriginalName(),
419 Integer.valueOf(resourceCodeModelImpl.getOriginalScope())
420 };
421
422 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N_S, args);
423 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N_S, args);
424
425 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N_S,
426 new Object[] {
427 Long.valueOf(resourceCode.getCompanyId()),
428
429 resourceCode.getName(),
430 Integer.valueOf(resourceCode.getScope())
431 }, resourceCode);
432 }
433 }
434
435 return resourceCode;
436 }
437
438 protected ResourceCode toUnwrappedModel(ResourceCode resourceCode) {
439 if (resourceCode instanceof ResourceCodeImpl) {
440 return resourceCode;
441 }
442
443 ResourceCodeImpl resourceCodeImpl = new ResourceCodeImpl();
444
445 resourceCodeImpl.setNew(resourceCode.isNew());
446 resourceCodeImpl.setPrimaryKey(resourceCode.getPrimaryKey());
447
448 resourceCodeImpl.setCodeId(resourceCode.getCodeId());
449 resourceCodeImpl.setCompanyId(resourceCode.getCompanyId());
450 resourceCodeImpl.setName(resourceCode.getName());
451 resourceCodeImpl.setScope(resourceCode.getScope());
452
453 return resourceCodeImpl;
454 }
455
456
464 @Override
465 public ResourceCode findByPrimaryKey(Serializable primaryKey)
466 throws NoSuchModelException, SystemException {
467 return findByPrimaryKey(((Long)primaryKey).longValue());
468 }
469
470
478 public ResourceCode findByPrimaryKey(long codeId)
479 throws NoSuchResourceCodeException, SystemException {
480 ResourceCode resourceCode = fetchByPrimaryKey(codeId);
481
482 if (resourceCode == null) {
483 if (_log.isWarnEnabled()) {
484 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + codeId);
485 }
486
487 throw new NoSuchResourceCodeException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
488 codeId);
489 }
490
491 return resourceCode;
492 }
493
494
501 @Override
502 public ResourceCode fetchByPrimaryKey(Serializable primaryKey)
503 throws SystemException {
504 return fetchByPrimaryKey(((Long)primaryKey).longValue());
505 }
506
507
514 public ResourceCode fetchByPrimaryKey(long codeId)
515 throws SystemException {
516 ResourceCode resourceCode = (ResourceCode)EntityCacheUtil.getResult(ResourceCodeModelImpl.ENTITY_CACHE_ENABLED,
517 ResourceCodeImpl.class, codeId);
518
519 if (resourceCode == _nullResourceCode) {
520 return null;
521 }
522
523 if (resourceCode == null) {
524 Session session = null;
525
526 boolean hasException = false;
527
528 try {
529 session = openSession();
530
531 resourceCode = (ResourceCode)session.get(ResourceCodeImpl.class,
532 Long.valueOf(codeId));
533 }
534 catch (Exception e) {
535 hasException = true;
536
537 throw processException(e);
538 }
539 finally {
540 if (resourceCode != null) {
541 cacheResult(resourceCode);
542 }
543 else if (!hasException) {
544 EntityCacheUtil.putResult(ResourceCodeModelImpl.ENTITY_CACHE_ENABLED,
545 ResourceCodeImpl.class, codeId, _nullResourceCode);
546 }
547
548 closeSession(session);
549 }
550 }
551
552 return resourceCode;
553 }
554
555
562 public List<ResourceCode> findByCompanyId(long companyId)
563 throws SystemException {
564 return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
565 null);
566 }
567
568
581 public List<ResourceCode> findByCompanyId(long companyId, int start, int end)
582 throws SystemException {
583 return findByCompanyId(companyId, start, end, null);
584 }
585
586
600 public List<ResourceCode> findByCompanyId(long companyId, int start,
601 int end, OrderByComparator orderByComparator) throws SystemException {
602 FinderPath finderPath = null;
603 Object[] finderArgs = null;
604
605 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
606 (orderByComparator == null)) {
607 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
608 finderArgs = new Object[] { companyId };
609 }
610 else {
611 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
612 finderArgs = new Object[] { companyId, start, end, orderByComparator };
613 }
614
615 List<ResourceCode> list = (List<ResourceCode>)FinderCacheUtil.getResult(finderPath,
616 finderArgs, this);
617
618 if ((list != null) && !list.isEmpty()) {
619 for (ResourceCode resourceCode : list) {
620 if ((companyId != resourceCode.getCompanyId())) {
621 list = null;
622
623 break;
624 }
625 }
626 }
627
628 if (list == null) {
629 StringBundler query = null;
630
631 if (orderByComparator != null) {
632 query = new StringBundler(3 +
633 (orderByComparator.getOrderByFields().length * 3));
634 }
635 else {
636 query = new StringBundler(2);
637 }
638
639 query.append(_SQL_SELECT_RESOURCECODE_WHERE);
640
641 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
642
643 if (orderByComparator != null) {
644 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
645 orderByComparator);
646 }
647
648 String sql = query.toString();
649
650 Session session = null;
651
652 try {
653 session = openSession();
654
655 Query q = session.createQuery(sql);
656
657 QueryPos qPos = QueryPos.getInstance(q);
658
659 qPos.add(companyId);
660
661 list = (List<ResourceCode>)QueryUtil.list(q, getDialect(),
662 start, end);
663 }
664 catch (Exception e) {
665 throw processException(e);
666 }
667 finally {
668 if (list == null) {
669 FinderCacheUtil.removeResult(finderPath, finderArgs);
670 }
671 else {
672 cacheResult(list);
673
674 FinderCacheUtil.putResult(finderPath, finderArgs, list);
675 }
676
677 closeSession(session);
678 }
679 }
680
681 return list;
682 }
683
684
697 public ResourceCode findByCompanyId_First(long companyId,
698 OrderByComparator orderByComparator)
699 throws NoSuchResourceCodeException, SystemException {
700 List<ResourceCode> list = findByCompanyId(companyId, 0, 1,
701 orderByComparator);
702
703 if (list.isEmpty()) {
704 StringBundler msg = new StringBundler(4);
705
706 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
707
708 msg.append("companyId=");
709 msg.append(companyId);
710
711 msg.append(StringPool.CLOSE_CURLY_BRACE);
712
713 throw new NoSuchResourceCodeException(msg.toString());
714 }
715 else {
716 return list.get(0);
717 }
718 }
719
720
733 public ResourceCode findByCompanyId_Last(long companyId,
734 OrderByComparator orderByComparator)
735 throws NoSuchResourceCodeException, SystemException {
736 int count = countByCompanyId(companyId);
737
738 List<ResourceCode> list = findByCompanyId(companyId, count - 1, count,
739 orderByComparator);
740
741 if (list.isEmpty()) {
742 StringBundler msg = new StringBundler(4);
743
744 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
745
746 msg.append("companyId=");
747 msg.append(companyId);
748
749 msg.append(StringPool.CLOSE_CURLY_BRACE);
750
751 throw new NoSuchResourceCodeException(msg.toString());
752 }
753 else {
754 return list.get(0);
755 }
756 }
757
758
772 public ResourceCode[] findByCompanyId_PrevAndNext(long codeId,
773 long companyId, OrderByComparator orderByComparator)
774 throws NoSuchResourceCodeException, SystemException {
775 ResourceCode resourceCode = findByPrimaryKey(codeId);
776
777 Session session = null;
778
779 try {
780 session = openSession();
781
782 ResourceCode[] array = new ResourceCodeImpl[3];
783
784 array[0] = getByCompanyId_PrevAndNext(session, resourceCode,
785 companyId, orderByComparator, true);
786
787 array[1] = resourceCode;
788
789 array[2] = getByCompanyId_PrevAndNext(session, resourceCode,
790 companyId, orderByComparator, false);
791
792 return array;
793 }
794 catch (Exception e) {
795 throw processException(e);
796 }
797 finally {
798 closeSession(session);
799 }
800 }
801
802 protected ResourceCode getByCompanyId_PrevAndNext(Session session,
803 ResourceCode resourceCode, long companyId,
804 OrderByComparator orderByComparator, boolean previous) {
805 StringBundler query = null;
806
807 if (orderByComparator != null) {
808 query = new StringBundler(6 +
809 (orderByComparator.getOrderByFields().length * 6));
810 }
811 else {
812 query = new StringBundler(3);
813 }
814
815 query.append(_SQL_SELECT_RESOURCECODE_WHERE);
816
817 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
818
819 if (orderByComparator != null) {
820 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
821
822 if (orderByConditionFields.length > 0) {
823 query.append(WHERE_AND);
824 }
825
826 for (int i = 0; i < orderByConditionFields.length; i++) {
827 query.append(_ORDER_BY_ENTITY_ALIAS);
828 query.append(orderByConditionFields[i]);
829
830 if ((i + 1) < orderByConditionFields.length) {
831 if (orderByComparator.isAscending() ^ previous) {
832 query.append(WHERE_GREATER_THAN_HAS_NEXT);
833 }
834 else {
835 query.append(WHERE_LESSER_THAN_HAS_NEXT);
836 }
837 }
838 else {
839 if (orderByComparator.isAscending() ^ previous) {
840 query.append(WHERE_GREATER_THAN);
841 }
842 else {
843 query.append(WHERE_LESSER_THAN);
844 }
845 }
846 }
847
848 query.append(ORDER_BY_CLAUSE);
849
850 String[] orderByFields = orderByComparator.getOrderByFields();
851
852 for (int i = 0; i < orderByFields.length; i++) {
853 query.append(_ORDER_BY_ENTITY_ALIAS);
854 query.append(orderByFields[i]);
855
856 if ((i + 1) < orderByFields.length) {
857 if (orderByComparator.isAscending() ^ previous) {
858 query.append(ORDER_BY_ASC_HAS_NEXT);
859 }
860 else {
861 query.append(ORDER_BY_DESC_HAS_NEXT);
862 }
863 }
864 else {
865 if (orderByComparator.isAscending() ^ previous) {
866 query.append(ORDER_BY_ASC);
867 }
868 else {
869 query.append(ORDER_BY_DESC);
870 }
871 }
872 }
873 }
874
875 String sql = query.toString();
876
877 Query q = session.createQuery(sql);
878
879 q.setFirstResult(0);
880 q.setMaxResults(2);
881
882 QueryPos qPos = QueryPos.getInstance(q);
883
884 qPos.add(companyId);
885
886 if (orderByComparator != null) {
887 Object[] values = orderByComparator.getOrderByConditionValues(resourceCode);
888
889 for (Object value : values) {
890 qPos.add(value);
891 }
892 }
893
894 List<ResourceCode> list = q.list();
895
896 if (list.size() == 2) {
897 return list.get(1);
898 }
899 else {
900 return null;
901 }
902 }
903
904
911 public List<ResourceCode> findByName(String name) throws SystemException {
912 return findByName(name, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
913 }
914
915
928 public List<ResourceCode> findByName(String name, int start, int end)
929 throws SystemException {
930 return findByName(name, start, end, null);
931 }
932
933
947 public List<ResourceCode> findByName(String name, int start, int end,
948 OrderByComparator orderByComparator) throws SystemException {
949 FinderPath finderPath = null;
950 Object[] finderArgs = null;
951
952 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
953 (orderByComparator == null)) {
954 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME;
955 finderArgs = new Object[] { name };
956 }
957 else {
958 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_NAME;
959 finderArgs = new Object[] { name, start, end, orderByComparator };
960 }
961
962 List<ResourceCode> list = (List<ResourceCode>)FinderCacheUtil.getResult(finderPath,
963 finderArgs, this);
964
965 if ((list != null) && !list.isEmpty()) {
966 for (ResourceCode resourceCode : list) {
967 if (!Validator.equals(name, resourceCode.getName())) {
968 list = null;
969
970 break;
971 }
972 }
973 }
974
975 if (list == null) {
976 StringBundler query = null;
977
978 if (orderByComparator != null) {
979 query = new StringBundler(3 +
980 (orderByComparator.getOrderByFields().length * 3));
981 }
982 else {
983 query = new StringBundler(2);
984 }
985
986 query.append(_SQL_SELECT_RESOURCECODE_WHERE);
987
988 if (name == null) {
989 query.append(_FINDER_COLUMN_NAME_NAME_1);
990 }
991 else {
992 if (name.equals(StringPool.BLANK)) {
993 query.append(_FINDER_COLUMN_NAME_NAME_3);
994 }
995 else {
996 query.append(_FINDER_COLUMN_NAME_NAME_2);
997 }
998 }
999
1000 if (orderByComparator != null) {
1001 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1002 orderByComparator);
1003 }
1004
1005 String sql = query.toString();
1006
1007 Session session = null;
1008
1009 try {
1010 session = openSession();
1011
1012 Query q = session.createQuery(sql);
1013
1014 QueryPos qPos = QueryPos.getInstance(q);
1015
1016 if (name != null) {
1017 qPos.add(name);
1018 }
1019
1020 list = (List<ResourceCode>)QueryUtil.list(q, getDialect(),
1021 start, end);
1022 }
1023 catch (Exception e) {
1024 throw processException(e);
1025 }
1026 finally {
1027 if (list == null) {
1028 FinderCacheUtil.removeResult(finderPath, finderArgs);
1029 }
1030 else {
1031 cacheResult(list);
1032
1033 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1034 }
1035
1036 closeSession(session);
1037 }
1038 }
1039
1040 return list;
1041 }
1042
1043
1056 public ResourceCode findByName_First(String name,
1057 OrderByComparator orderByComparator)
1058 throws NoSuchResourceCodeException, SystemException {
1059 List<ResourceCode> list = findByName(name, 0, 1, orderByComparator);
1060
1061 if (list.isEmpty()) {
1062 StringBundler msg = new StringBundler(4);
1063
1064 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1065
1066 msg.append("name=");
1067 msg.append(name);
1068
1069 msg.append(StringPool.CLOSE_CURLY_BRACE);
1070
1071 throw new NoSuchResourceCodeException(msg.toString());
1072 }
1073 else {
1074 return list.get(0);
1075 }
1076 }
1077
1078
1091 public ResourceCode findByName_Last(String name,
1092 OrderByComparator orderByComparator)
1093 throws NoSuchResourceCodeException, SystemException {
1094 int count = countByName(name);
1095
1096 List<ResourceCode> list = findByName(name, count - 1, count,
1097 orderByComparator);
1098
1099 if (list.isEmpty()) {
1100 StringBundler msg = new StringBundler(4);
1101
1102 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1103
1104 msg.append("name=");
1105 msg.append(name);
1106
1107 msg.append(StringPool.CLOSE_CURLY_BRACE);
1108
1109 throw new NoSuchResourceCodeException(msg.toString());
1110 }
1111 else {
1112 return list.get(0);
1113 }
1114 }
1115
1116
1130 public ResourceCode[] findByName_PrevAndNext(long codeId, String name,
1131 OrderByComparator orderByComparator)
1132 throws NoSuchResourceCodeException, SystemException {
1133 ResourceCode resourceCode = findByPrimaryKey(codeId);
1134
1135 Session session = null;
1136
1137 try {
1138 session = openSession();
1139
1140 ResourceCode[] array = new ResourceCodeImpl[3];
1141
1142 array[0] = getByName_PrevAndNext(session, resourceCode, name,
1143 orderByComparator, true);
1144
1145 array[1] = resourceCode;
1146
1147 array[2] = getByName_PrevAndNext(session, resourceCode, name,
1148 orderByComparator, false);
1149
1150 return array;
1151 }
1152 catch (Exception e) {
1153 throw processException(e);
1154 }
1155 finally {
1156 closeSession(session);
1157 }
1158 }
1159
1160 protected ResourceCode getByName_PrevAndNext(Session session,
1161 ResourceCode resourceCode, String name,
1162 OrderByComparator orderByComparator, boolean previous) {
1163 StringBundler query = null;
1164
1165 if (orderByComparator != null) {
1166 query = new StringBundler(6 +
1167 (orderByComparator.getOrderByFields().length * 6));
1168 }
1169 else {
1170 query = new StringBundler(3);
1171 }
1172
1173 query.append(_SQL_SELECT_RESOURCECODE_WHERE);
1174
1175 if (name == null) {
1176 query.append(_FINDER_COLUMN_NAME_NAME_1);
1177 }
1178 else {
1179 if (name.equals(StringPool.BLANK)) {
1180 query.append(_FINDER_COLUMN_NAME_NAME_3);
1181 }
1182 else {
1183 query.append(_FINDER_COLUMN_NAME_NAME_2);
1184 }
1185 }
1186
1187 if (orderByComparator != null) {
1188 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1189
1190 if (orderByConditionFields.length > 0) {
1191 query.append(WHERE_AND);
1192 }
1193
1194 for (int i = 0; i < orderByConditionFields.length; i++) {
1195 query.append(_ORDER_BY_ENTITY_ALIAS);
1196 query.append(orderByConditionFields[i]);
1197
1198 if ((i + 1) < orderByConditionFields.length) {
1199 if (orderByComparator.isAscending() ^ previous) {
1200 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1201 }
1202 else {
1203 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1204 }
1205 }
1206 else {
1207 if (orderByComparator.isAscending() ^ previous) {
1208 query.append(WHERE_GREATER_THAN);
1209 }
1210 else {
1211 query.append(WHERE_LESSER_THAN);
1212 }
1213 }
1214 }
1215
1216 query.append(ORDER_BY_CLAUSE);
1217
1218 String[] orderByFields = orderByComparator.getOrderByFields();
1219
1220 for (int i = 0; i < orderByFields.length; i++) {
1221 query.append(_ORDER_BY_ENTITY_ALIAS);
1222 query.append(orderByFields[i]);
1223
1224 if ((i + 1) < orderByFields.length) {
1225 if (orderByComparator.isAscending() ^ previous) {
1226 query.append(ORDER_BY_ASC_HAS_NEXT);
1227 }
1228 else {
1229 query.append(ORDER_BY_DESC_HAS_NEXT);
1230 }
1231 }
1232 else {
1233 if (orderByComparator.isAscending() ^ previous) {
1234 query.append(ORDER_BY_ASC);
1235 }
1236 else {
1237 query.append(ORDER_BY_DESC);
1238 }
1239 }
1240 }
1241 }
1242
1243 String sql = query.toString();
1244
1245 Query q = session.createQuery(sql);
1246
1247 q.setFirstResult(0);
1248 q.setMaxResults(2);
1249
1250 QueryPos qPos = QueryPos.getInstance(q);
1251
1252 if (name != null) {
1253 qPos.add(name);
1254 }
1255
1256 if (orderByComparator != null) {
1257 Object[] values = orderByComparator.getOrderByConditionValues(resourceCode);
1258
1259 for (Object value : values) {
1260 qPos.add(value);
1261 }
1262 }
1263
1264 List<ResourceCode> list = q.list();
1265
1266 if (list.size() == 2) {
1267 return list.get(1);
1268 }
1269 else {
1270 return null;
1271 }
1272 }
1273
1274
1284 public ResourceCode findByC_N_S(long companyId, String name, int scope)
1285 throws NoSuchResourceCodeException, SystemException {
1286 ResourceCode resourceCode = fetchByC_N_S(companyId, name, scope);
1287
1288 if (resourceCode == null) {
1289 StringBundler msg = new StringBundler(8);
1290
1291 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1292
1293 msg.append("companyId=");
1294 msg.append(companyId);
1295
1296 msg.append(", name=");
1297 msg.append(name);
1298
1299 msg.append(", scope=");
1300 msg.append(scope);
1301
1302 msg.append(StringPool.CLOSE_CURLY_BRACE);
1303
1304 if (_log.isWarnEnabled()) {
1305 _log.warn(msg.toString());
1306 }
1307
1308 throw new NoSuchResourceCodeException(msg.toString());
1309 }
1310
1311 return resourceCode;
1312 }
1313
1314
1323 public ResourceCode fetchByC_N_S(long companyId, String name, int scope)
1324 throws SystemException {
1325 return fetchByC_N_S(companyId, name, scope, true);
1326 }
1327
1328
1338 public ResourceCode fetchByC_N_S(long companyId, String name, int scope,
1339 boolean retrieveFromCache) throws SystemException {
1340 Object[] finderArgs = new Object[] { companyId, name, scope };
1341
1342 Object result = null;
1343
1344 if (retrieveFromCache) {
1345 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_N_S,
1346 finderArgs, this);
1347 }
1348
1349 if (result instanceof ResourceCode) {
1350 ResourceCode resourceCode = (ResourceCode)result;
1351
1352 if ((companyId != resourceCode.getCompanyId()) ||
1353 !Validator.equals(name, resourceCode.getName()) ||
1354 (scope != resourceCode.getScope())) {
1355 result = null;
1356 }
1357 }
1358
1359 if (result == null) {
1360 StringBundler query = new StringBundler(4);
1361
1362 query.append(_SQL_SELECT_RESOURCECODE_WHERE);
1363
1364 query.append(_FINDER_COLUMN_C_N_S_COMPANYID_2);
1365
1366 if (name == null) {
1367 query.append(_FINDER_COLUMN_C_N_S_NAME_1);
1368 }
1369 else {
1370 if (name.equals(StringPool.BLANK)) {
1371 query.append(_FINDER_COLUMN_C_N_S_NAME_3);
1372 }
1373 else {
1374 query.append(_FINDER_COLUMN_C_N_S_NAME_2);
1375 }
1376 }
1377
1378 query.append(_FINDER_COLUMN_C_N_S_SCOPE_2);
1379
1380 String sql = query.toString();
1381
1382 Session session = null;
1383
1384 try {
1385 session = openSession();
1386
1387 Query q = session.createQuery(sql);
1388
1389 QueryPos qPos = QueryPos.getInstance(q);
1390
1391 qPos.add(companyId);
1392
1393 if (name != null) {
1394 qPos.add(name);
1395 }
1396
1397 qPos.add(scope);
1398
1399 List<ResourceCode> list = q.list();
1400
1401 result = list;
1402
1403 ResourceCode resourceCode = null;
1404
1405 if (list.isEmpty()) {
1406 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N_S,
1407 finderArgs, list);
1408 }
1409 else {
1410 resourceCode = list.get(0);
1411
1412 cacheResult(resourceCode);
1413
1414 if ((resourceCode.getCompanyId() != companyId) ||
1415 (resourceCode.getName() == null) ||
1416 !resourceCode.getName().equals(name) ||
1417 (resourceCode.getScope() != scope)) {
1418 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N_S,
1419 finderArgs, resourceCode);
1420 }
1421 }
1422
1423 return resourceCode;
1424 }
1425 catch (Exception e) {
1426 throw processException(e);
1427 }
1428 finally {
1429 if (result == null) {
1430 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N_S,
1431 finderArgs);
1432 }
1433
1434 closeSession(session);
1435 }
1436 }
1437 else {
1438 if (result instanceof List<?>) {
1439 return null;
1440 }
1441 else {
1442 return (ResourceCode)result;
1443 }
1444 }
1445 }
1446
1447
1453 public List<ResourceCode> findAll() throws SystemException {
1454 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1455 }
1456
1457
1469 public List<ResourceCode> findAll(int start, int end)
1470 throws SystemException {
1471 return findAll(start, end, null);
1472 }
1473
1474
1487 public List<ResourceCode> findAll(int start, int end,
1488 OrderByComparator orderByComparator) throws SystemException {
1489 FinderPath finderPath = null;
1490 Object[] finderArgs = new Object[] { start, end, orderByComparator };
1491
1492 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1493 (orderByComparator == null)) {
1494 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1495 finderArgs = FINDER_ARGS_EMPTY;
1496 }
1497 else {
1498 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1499 finderArgs = new Object[] { start, end, orderByComparator };
1500 }
1501
1502 List<ResourceCode> list = (List<ResourceCode>)FinderCacheUtil.getResult(finderPath,
1503 finderArgs, this);
1504
1505 if (list == null) {
1506 StringBundler query = null;
1507 String sql = null;
1508
1509 if (orderByComparator != null) {
1510 query = new StringBundler(2 +
1511 (orderByComparator.getOrderByFields().length * 3));
1512
1513 query.append(_SQL_SELECT_RESOURCECODE);
1514
1515 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1516 orderByComparator);
1517
1518 sql = query.toString();
1519 }
1520 else {
1521 sql = _SQL_SELECT_RESOURCECODE;
1522 }
1523
1524 Session session = null;
1525
1526 try {
1527 session = openSession();
1528
1529 Query q = session.createQuery(sql);
1530
1531 if (orderByComparator == null) {
1532 list = (List<ResourceCode>)QueryUtil.list(q, getDialect(),
1533 start, end, false);
1534
1535 Collections.sort(list);
1536 }
1537 else {
1538 list = (List<ResourceCode>)QueryUtil.list(q, getDialect(),
1539 start, end);
1540 }
1541 }
1542 catch (Exception e) {
1543 throw processException(e);
1544 }
1545 finally {
1546 if (list == null) {
1547 FinderCacheUtil.removeResult(finderPath, finderArgs);
1548 }
1549 else {
1550 cacheResult(list);
1551
1552 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1553 }
1554
1555 closeSession(session);
1556 }
1557 }
1558
1559 return list;
1560 }
1561
1562
1568 public void removeByCompanyId(long companyId) throws SystemException {
1569 for (ResourceCode resourceCode : findByCompanyId(companyId)) {
1570 remove(resourceCode);
1571 }
1572 }
1573
1574
1580 public void removeByName(String name) throws SystemException {
1581 for (ResourceCode resourceCode : findByName(name)) {
1582 remove(resourceCode);
1583 }
1584 }
1585
1586
1594 public void removeByC_N_S(long companyId, String name, int scope)
1595 throws NoSuchResourceCodeException, SystemException {
1596 ResourceCode resourceCode = findByC_N_S(companyId, name, scope);
1597
1598 remove(resourceCode);
1599 }
1600
1601
1606 public void removeAll() throws SystemException {
1607 for (ResourceCode resourceCode : findAll()) {
1608 remove(resourceCode);
1609 }
1610 }
1611
1612
1619 public int countByCompanyId(long companyId) throws SystemException {
1620 Object[] finderArgs = new Object[] { companyId };
1621
1622 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
1623 finderArgs, this);
1624
1625 if (count == null) {
1626 StringBundler query = new StringBundler(2);
1627
1628 query.append(_SQL_COUNT_RESOURCECODE_WHERE);
1629
1630 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1631
1632 String sql = query.toString();
1633
1634 Session session = null;
1635
1636 try {
1637 session = openSession();
1638
1639 Query q = session.createQuery(sql);
1640
1641 QueryPos qPos = QueryPos.getInstance(q);
1642
1643 qPos.add(companyId);
1644
1645 count = (Long)q.uniqueResult();
1646 }
1647 catch (Exception e) {
1648 throw processException(e);
1649 }
1650 finally {
1651 if (count == null) {
1652 count = Long.valueOf(0);
1653 }
1654
1655 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
1656 finderArgs, count);
1657
1658 closeSession(session);
1659 }
1660 }
1661
1662 return count.intValue();
1663 }
1664
1665
1672 public int countByName(String name) throws SystemException {
1673 Object[] finderArgs = new Object[] { name };
1674
1675 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_NAME,
1676 finderArgs, this);
1677
1678 if (count == null) {
1679 StringBundler query = new StringBundler(2);
1680
1681 query.append(_SQL_COUNT_RESOURCECODE_WHERE);
1682
1683 if (name == null) {
1684 query.append(_FINDER_COLUMN_NAME_NAME_1);
1685 }
1686 else {
1687 if (name.equals(StringPool.BLANK)) {
1688 query.append(_FINDER_COLUMN_NAME_NAME_3);
1689 }
1690 else {
1691 query.append(_FINDER_COLUMN_NAME_NAME_2);
1692 }
1693 }
1694
1695 String sql = query.toString();
1696
1697 Session session = null;
1698
1699 try {
1700 session = openSession();
1701
1702 Query q = session.createQuery(sql);
1703
1704 QueryPos qPos = QueryPos.getInstance(q);
1705
1706 if (name != null) {
1707 qPos.add(name);
1708 }
1709
1710 count = (Long)q.uniqueResult();
1711 }
1712 catch (Exception e) {
1713 throw processException(e);
1714 }
1715 finally {
1716 if (count == null) {
1717 count = Long.valueOf(0);
1718 }
1719
1720 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_NAME,
1721 finderArgs, count);
1722
1723 closeSession(session);
1724 }
1725 }
1726
1727 return count.intValue();
1728 }
1729
1730
1739 public int countByC_N_S(long companyId, String name, int scope)
1740 throws SystemException {
1741 Object[] finderArgs = new Object[] { companyId, name, scope };
1742
1743 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_N_S,
1744 finderArgs, this);
1745
1746 if (count == null) {
1747 StringBundler query = new StringBundler(4);
1748
1749 query.append(_SQL_COUNT_RESOURCECODE_WHERE);
1750
1751 query.append(_FINDER_COLUMN_C_N_S_COMPANYID_2);
1752
1753 if (name == null) {
1754 query.append(_FINDER_COLUMN_C_N_S_NAME_1);
1755 }
1756 else {
1757 if (name.equals(StringPool.BLANK)) {
1758 query.append(_FINDER_COLUMN_C_N_S_NAME_3);
1759 }
1760 else {
1761 query.append(_FINDER_COLUMN_C_N_S_NAME_2);
1762 }
1763 }
1764
1765 query.append(_FINDER_COLUMN_C_N_S_SCOPE_2);
1766
1767 String sql = query.toString();
1768
1769 Session session = null;
1770
1771 try {
1772 session = openSession();
1773
1774 Query q = session.createQuery(sql);
1775
1776 QueryPos qPos = QueryPos.getInstance(q);
1777
1778 qPos.add(companyId);
1779
1780 if (name != null) {
1781 qPos.add(name);
1782 }
1783
1784 qPos.add(scope);
1785
1786 count = (Long)q.uniqueResult();
1787 }
1788 catch (Exception e) {
1789 throw processException(e);
1790 }
1791 finally {
1792 if (count == null) {
1793 count = Long.valueOf(0);
1794 }
1795
1796 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N_S,
1797 finderArgs, count);
1798
1799 closeSession(session);
1800 }
1801 }
1802
1803 return count.intValue();
1804 }
1805
1806
1812 public int countAll() throws SystemException {
1813 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1814 FINDER_ARGS_EMPTY, this);
1815
1816 if (count == null) {
1817 Session session = null;
1818
1819 try {
1820 session = openSession();
1821
1822 Query q = session.createQuery(_SQL_COUNT_RESOURCECODE);
1823
1824 count = (Long)q.uniqueResult();
1825 }
1826 catch (Exception e) {
1827 throw processException(e);
1828 }
1829 finally {
1830 if (count == null) {
1831 count = Long.valueOf(0);
1832 }
1833
1834 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1835 FINDER_ARGS_EMPTY, count);
1836
1837 closeSession(session);
1838 }
1839 }
1840
1841 return count.intValue();
1842 }
1843
1844
1847 public void afterPropertiesSet() {
1848 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1849 com.liferay.portal.util.PropsUtil.get(
1850 "value.object.listener.com.liferay.portal.model.ResourceCode")));
1851
1852 if (listenerClassNames.length > 0) {
1853 try {
1854 List<ModelListener<ResourceCode>> listenersList = new ArrayList<ModelListener<ResourceCode>>();
1855
1856 for (String listenerClassName : listenerClassNames) {
1857 listenersList.add((ModelListener<ResourceCode>)InstanceFactory.newInstance(
1858 listenerClassName));
1859 }
1860
1861 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1862 }
1863 catch (Exception e) {
1864 _log.error(e);
1865 }
1866 }
1867 }
1868
1869 public void destroy() {
1870 EntityCacheUtil.removeCache(ResourceCodeImpl.class.getName());
1871 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1872 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1873 }
1874
1875 @BeanReference(type = AccountPersistence.class)
1876 protected AccountPersistence accountPersistence;
1877 @BeanReference(type = AddressPersistence.class)
1878 protected AddressPersistence addressPersistence;
1879 @BeanReference(type = BrowserTrackerPersistence.class)
1880 protected BrowserTrackerPersistence browserTrackerPersistence;
1881 @BeanReference(type = ClassNamePersistence.class)
1882 protected ClassNamePersistence classNamePersistence;
1883 @BeanReference(type = ClusterGroupPersistence.class)
1884 protected ClusterGroupPersistence clusterGroupPersistence;
1885 @BeanReference(type = CompanyPersistence.class)
1886 protected CompanyPersistence companyPersistence;
1887 @BeanReference(type = ContactPersistence.class)
1888 protected ContactPersistence contactPersistence;
1889 @BeanReference(type = CountryPersistence.class)
1890 protected CountryPersistence countryPersistence;
1891 @BeanReference(type = EmailAddressPersistence.class)
1892 protected EmailAddressPersistence emailAddressPersistence;
1893 @BeanReference(type = GroupPersistence.class)
1894 protected GroupPersistence groupPersistence;
1895 @BeanReference(type = ImagePersistence.class)
1896 protected ImagePersistence imagePersistence;
1897 @BeanReference(type = LayoutPersistence.class)
1898 protected LayoutPersistence layoutPersistence;
1899 @BeanReference(type = LayoutBranchPersistence.class)
1900 protected LayoutBranchPersistence layoutBranchPersistence;
1901 @BeanReference(type = LayoutPrototypePersistence.class)
1902 protected LayoutPrototypePersistence layoutPrototypePersistence;
1903 @BeanReference(type = LayoutRevisionPersistence.class)
1904 protected LayoutRevisionPersistence layoutRevisionPersistence;
1905 @BeanReference(type = LayoutSetPersistence.class)
1906 protected LayoutSetPersistence layoutSetPersistence;
1907 @BeanReference(type = LayoutSetBranchPersistence.class)
1908 protected LayoutSetBranchPersistence layoutSetBranchPersistence;
1909 @BeanReference(type = LayoutSetPrototypePersistence.class)
1910 protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
1911 @BeanReference(type = ListTypePersistence.class)
1912 protected ListTypePersistence listTypePersistence;
1913 @BeanReference(type = LockPersistence.class)
1914 protected LockPersistence lockPersistence;
1915 @BeanReference(type = MembershipRequestPersistence.class)
1916 protected MembershipRequestPersistence membershipRequestPersistence;
1917 @BeanReference(type = OrganizationPersistence.class)
1918 protected OrganizationPersistence organizationPersistence;
1919 @BeanReference(type = OrgGroupPermissionPersistence.class)
1920 protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1921 @BeanReference(type = OrgGroupRolePersistence.class)
1922 protected OrgGroupRolePersistence orgGroupRolePersistence;
1923 @BeanReference(type = OrgLaborPersistence.class)
1924 protected OrgLaborPersistence orgLaborPersistence;
1925 @BeanReference(type = PasswordPolicyPersistence.class)
1926 protected PasswordPolicyPersistence passwordPolicyPersistence;
1927 @BeanReference(type = PasswordPolicyRelPersistence.class)
1928 protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1929 @BeanReference(type = PasswordTrackerPersistence.class)
1930 protected PasswordTrackerPersistence passwordTrackerPersistence;
1931 @BeanReference(type = PermissionPersistence.class)
1932 protected PermissionPersistence permissionPersistence;
1933 @BeanReference(type = PhonePersistence.class)
1934 protected PhonePersistence phonePersistence;
1935 @BeanReference(type = PluginSettingPersistence.class)
1936 protected PluginSettingPersistence pluginSettingPersistence;
1937 @BeanReference(type = PortalPreferencesPersistence.class)
1938 protected PortalPreferencesPersistence portalPreferencesPersistence;
1939 @BeanReference(type = PortletPersistence.class)
1940 protected PortletPersistence portletPersistence;
1941 @BeanReference(type = PortletItemPersistence.class)
1942 protected PortletItemPersistence portletItemPersistence;
1943 @BeanReference(type = PortletPreferencesPersistence.class)
1944 protected PortletPreferencesPersistence portletPreferencesPersistence;
1945 @BeanReference(type = RegionPersistence.class)
1946 protected RegionPersistence regionPersistence;
1947 @BeanReference(type = ReleasePersistence.class)
1948 protected ReleasePersistence releasePersistence;
1949 @BeanReference(type = RepositoryPersistence.class)
1950 protected RepositoryPersistence repositoryPersistence;
1951 @BeanReference(type = RepositoryEntryPersistence.class)
1952 protected RepositoryEntryPersistence repositoryEntryPersistence;
1953 @BeanReference(type = ResourcePersistence.class)
1954 protected ResourcePersistence resourcePersistence;
1955 @BeanReference(type = ResourceActionPersistence.class)
1956 protected ResourceActionPersistence resourceActionPersistence;
1957 @BeanReference(type = ResourceBlockPersistence.class)
1958 protected ResourceBlockPersistence resourceBlockPersistence;
1959 @BeanReference(type = ResourceBlockPermissionPersistence.class)
1960 protected ResourceBlockPermissionPersistence resourceBlockPermissionPersistence;
1961 @BeanReference(type = ResourceCodePersistence.class)
1962 protected ResourceCodePersistence resourceCodePersistence;
1963 @BeanReference(type = ResourcePermissionPersistence.class)
1964 protected ResourcePermissionPersistence resourcePermissionPersistence;
1965 @BeanReference(type = ResourceTypePermissionPersistence.class)
1966 protected ResourceTypePermissionPersistence resourceTypePermissionPersistence;
1967 @BeanReference(type = RolePersistence.class)
1968 protected RolePersistence rolePersistence;
1969 @BeanReference(type = ServiceComponentPersistence.class)
1970 protected ServiceComponentPersistence serviceComponentPersistence;
1971 @BeanReference(type = ShardPersistence.class)
1972 protected ShardPersistence shardPersistence;
1973 @BeanReference(type = SubscriptionPersistence.class)
1974 protected SubscriptionPersistence subscriptionPersistence;
1975 @BeanReference(type = TeamPersistence.class)
1976 protected TeamPersistence teamPersistence;
1977 @BeanReference(type = TicketPersistence.class)
1978 protected TicketPersistence ticketPersistence;
1979 @BeanReference(type = UserPersistence.class)
1980 protected UserPersistence userPersistence;
1981 @BeanReference(type = UserGroupPersistence.class)
1982 protected UserGroupPersistence userGroupPersistence;
1983 @BeanReference(type = UserGroupGroupRolePersistence.class)
1984 protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1985 @BeanReference(type = UserGroupRolePersistence.class)
1986 protected UserGroupRolePersistence userGroupRolePersistence;
1987 @BeanReference(type = UserIdMapperPersistence.class)
1988 protected UserIdMapperPersistence userIdMapperPersistence;
1989 @BeanReference(type = UserNotificationEventPersistence.class)
1990 protected UserNotificationEventPersistence userNotificationEventPersistence;
1991 @BeanReference(type = UserTrackerPersistence.class)
1992 protected UserTrackerPersistence userTrackerPersistence;
1993 @BeanReference(type = UserTrackerPathPersistence.class)
1994 protected UserTrackerPathPersistence userTrackerPathPersistence;
1995 @BeanReference(type = VirtualHostPersistence.class)
1996 protected VirtualHostPersistence virtualHostPersistence;
1997 @BeanReference(type = WebDAVPropsPersistence.class)
1998 protected WebDAVPropsPersistence webDAVPropsPersistence;
1999 @BeanReference(type = WebsitePersistence.class)
2000 protected WebsitePersistence websitePersistence;
2001 @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
2002 protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
2003 @BeanReference(type = WorkflowInstanceLinkPersistence.class)
2004 protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
2005 private static final String _SQL_SELECT_RESOURCECODE = "SELECT resourceCode FROM ResourceCode resourceCode";
2006 private static final String _SQL_SELECT_RESOURCECODE_WHERE = "SELECT resourceCode FROM ResourceCode resourceCode WHERE ";
2007 private static final String _SQL_COUNT_RESOURCECODE = "SELECT COUNT(resourceCode) FROM ResourceCode resourceCode";
2008 private static final String _SQL_COUNT_RESOURCECODE_WHERE = "SELECT COUNT(resourceCode) FROM ResourceCode resourceCode WHERE ";
2009 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "resourceCode.companyId = ?";
2010 private static final String _FINDER_COLUMN_NAME_NAME_1 = "resourceCode.name IS NULL";
2011 private static final String _FINDER_COLUMN_NAME_NAME_2 = "resourceCode.name = ?";
2012 private static final String _FINDER_COLUMN_NAME_NAME_3 = "(resourceCode.name IS NULL OR resourceCode.name = ?)";
2013 private static final String _FINDER_COLUMN_C_N_S_COMPANYID_2 = "resourceCode.companyId = ? AND ";
2014 private static final String _FINDER_COLUMN_C_N_S_NAME_1 = "resourceCode.name IS NULL AND ";
2015 private static final String _FINDER_COLUMN_C_N_S_NAME_2 = "resourceCode.name = ? AND ";
2016 private static final String _FINDER_COLUMN_C_N_S_NAME_3 = "(resourceCode.name IS NULL OR resourceCode.name = ?) AND ";
2017 private static final String _FINDER_COLUMN_C_N_S_SCOPE_2 = "resourceCode.scope = ?";
2018 private static final String _ORDER_BY_ENTITY_ALIAS = "resourceCode.";
2019 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ResourceCode exists with the primary key ";
2020 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ResourceCode exists with the key {";
2021 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2022 private static Log _log = LogFactoryUtil.getLog(ResourceCodePersistenceImpl.class);
2023 private static ResourceCode _nullResourceCode = new ResourceCodeImpl() {
2024 @Override
2025 public Object clone() {
2026 return this;
2027 }
2028
2029 @Override
2030 public CacheModel<ResourceCode> toCacheModel() {
2031 return _nullResourceCodeCacheModel;
2032 }
2033 };
2034
2035 private static CacheModel<ResourceCode> _nullResourceCodeCacheModel = new CacheModel<ResourceCode>() {
2036 public ResourceCode toEntityModel() {
2037 return _nullResourceCode;
2038 }
2039 };
2040 }