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 cacheUniqueFindersCache(ResourceCode resourceCode) {
229 if (resourceCode.isNew()) {
230 Object[] args = new Object[] {
231 Long.valueOf(resourceCode.getCompanyId()),
232
233 resourceCode.getName(),
234 Integer.valueOf(resourceCode.getScope())
235 };
236
237 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N_S, args,
238 Long.valueOf(1));
239 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N_S, args,
240 resourceCode);
241 }
242 else {
243 ResourceCodeModelImpl resourceCodeModelImpl = (ResourceCodeModelImpl)resourceCode;
244
245 if ((resourceCodeModelImpl.getColumnBitmask() &
246 FINDER_PATH_FETCH_BY_C_N_S.getColumnBitmask()) != 0) {
247 Object[] args = new Object[] {
248 Long.valueOf(resourceCode.getCompanyId()),
249
250 resourceCode.getName(),
251 Integer.valueOf(resourceCode.getScope())
252 };
253
254 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N_S, args,
255 Long.valueOf(1));
256 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N_S, args,
257 resourceCode);
258 }
259 }
260 }
261
262 protected void clearUniqueFindersCache(ResourceCode resourceCode) {
263 ResourceCodeModelImpl resourceCodeModelImpl = (ResourceCodeModelImpl)resourceCode;
264
265 Object[] args = new Object[] {
266 Long.valueOf(resourceCode.getCompanyId()),
267
268 resourceCode.getName(), Integer.valueOf(resourceCode.getScope())
269 };
270
271 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N_S, args);
272 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N_S, args);
273
274 if ((resourceCodeModelImpl.getColumnBitmask() &
275 FINDER_PATH_FETCH_BY_C_N_S.getColumnBitmask()) != 0) {
276 args = new Object[] {
277 Long.valueOf(resourceCodeModelImpl.getOriginalCompanyId()),
278
279 resourceCodeModelImpl.getOriginalName(),
280 Integer.valueOf(resourceCodeModelImpl.getOriginalScope())
281 };
282
283 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N_S, args);
284 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N_S, args);
285 }
286 }
287
288
294 public ResourceCode create(long codeId) {
295 ResourceCode resourceCode = new ResourceCodeImpl();
296
297 resourceCode.setNew(true);
298 resourceCode.setPrimaryKey(codeId);
299
300 return resourceCode;
301 }
302
303
311 public ResourceCode remove(long codeId)
312 throws NoSuchResourceCodeException, SystemException {
313 return remove(Long.valueOf(codeId));
314 }
315
316
324 @Override
325 public ResourceCode remove(Serializable primaryKey)
326 throws NoSuchResourceCodeException, SystemException {
327 Session session = null;
328
329 try {
330 session = openSession();
331
332 ResourceCode resourceCode = (ResourceCode)session.get(ResourceCodeImpl.class,
333 primaryKey);
334
335 if (resourceCode == null) {
336 if (_log.isWarnEnabled()) {
337 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
338 }
339
340 throw new NoSuchResourceCodeException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
341 primaryKey);
342 }
343
344 return remove(resourceCode);
345 }
346 catch (NoSuchResourceCodeException nsee) {
347 throw nsee;
348 }
349 catch (Exception e) {
350 throw processException(e);
351 }
352 finally {
353 closeSession(session);
354 }
355 }
356
357 @Override
358 protected ResourceCode removeImpl(ResourceCode resourceCode)
359 throws SystemException {
360 resourceCode = toUnwrappedModel(resourceCode);
361
362 Session session = null;
363
364 try {
365 session = openSession();
366
367 BatchSessionUtil.delete(session, resourceCode);
368 }
369 catch (Exception e) {
370 throw processException(e);
371 }
372 finally {
373 closeSession(session);
374 }
375
376 clearCache(resourceCode);
377
378 return resourceCode;
379 }
380
381 @Override
382 public ResourceCode updateImpl(
383 com.liferay.portal.model.ResourceCode resourceCode, boolean merge)
384 throws SystemException {
385 resourceCode = toUnwrappedModel(resourceCode);
386
387 boolean isNew = resourceCode.isNew();
388
389 ResourceCodeModelImpl resourceCodeModelImpl = (ResourceCodeModelImpl)resourceCode;
390
391 Session session = null;
392
393 try {
394 session = openSession();
395
396 BatchSessionUtil.update(session, resourceCode, merge);
397
398 resourceCode.setNew(false);
399 }
400 catch (Exception e) {
401 throw processException(e);
402 }
403 finally {
404 closeSession(session);
405 }
406
407 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
408
409 if (isNew || !ResourceCodeModelImpl.COLUMN_BITMASK_ENABLED) {
410 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
411 }
412
413 else {
414 if ((resourceCodeModelImpl.getColumnBitmask() &
415 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
416 Object[] args = new Object[] {
417 Long.valueOf(resourceCodeModelImpl.getOriginalCompanyId())
418 };
419
420 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
421 args);
422 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
423 args);
424
425 args = new Object[] {
426 Long.valueOf(resourceCodeModelImpl.getCompanyId())
427 };
428
429 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
430 args);
431 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
432 args);
433 }
434
435 if ((resourceCodeModelImpl.getColumnBitmask() &
436 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME.getColumnBitmask()) != 0) {
437 Object[] args = new Object[] {
438 resourceCodeModelImpl.getOriginalName()
439 };
440
441 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_NAME, args);
442 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME,
443 args);
444
445 args = new Object[] { resourceCodeModelImpl.getName() };
446
447 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_NAME, args);
448 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME,
449 args);
450 }
451 }
452
453 EntityCacheUtil.putResult(ResourceCodeModelImpl.ENTITY_CACHE_ENABLED,
454 ResourceCodeImpl.class, resourceCode.getPrimaryKey(), resourceCode);
455
456 clearUniqueFindersCache(resourceCode);
457 cacheUniqueFindersCache(resourceCode);
458
459 return resourceCode;
460 }
461
462 protected ResourceCode toUnwrappedModel(ResourceCode resourceCode) {
463 if (resourceCode instanceof ResourceCodeImpl) {
464 return resourceCode;
465 }
466
467 ResourceCodeImpl resourceCodeImpl = new ResourceCodeImpl();
468
469 resourceCodeImpl.setNew(resourceCode.isNew());
470 resourceCodeImpl.setPrimaryKey(resourceCode.getPrimaryKey());
471
472 resourceCodeImpl.setCodeId(resourceCode.getCodeId());
473 resourceCodeImpl.setCompanyId(resourceCode.getCompanyId());
474 resourceCodeImpl.setName(resourceCode.getName());
475 resourceCodeImpl.setScope(resourceCode.getScope());
476
477 return resourceCodeImpl;
478 }
479
480
488 @Override
489 public ResourceCode findByPrimaryKey(Serializable primaryKey)
490 throws NoSuchModelException, SystemException {
491 return findByPrimaryKey(((Long)primaryKey).longValue());
492 }
493
494
502 public ResourceCode findByPrimaryKey(long codeId)
503 throws NoSuchResourceCodeException, SystemException {
504 ResourceCode resourceCode = fetchByPrimaryKey(codeId);
505
506 if (resourceCode == null) {
507 if (_log.isWarnEnabled()) {
508 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + codeId);
509 }
510
511 throw new NoSuchResourceCodeException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
512 codeId);
513 }
514
515 return resourceCode;
516 }
517
518
525 @Override
526 public ResourceCode fetchByPrimaryKey(Serializable primaryKey)
527 throws SystemException {
528 return fetchByPrimaryKey(((Long)primaryKey).longValue());
529 }
530
531
538 public ResourceCode fetchByPrimaryKey(long codeId)
539 throws SystemException {
540 ResourceCode resourceCode = (ResourceCode)EntityCacheUtil.getResult(ResourceCodeModelImpl.ENTITY_CACHE_ENABLED,
541 ResourceCodeImpl.class, codeId);
542
543 if (resourceCode == _nullResourceCode) {
544 return null;
545 }
546
547 if (resourceCode == null) {
548 Session session = null;
549
550 boolean hasException = false;
551
552 try {
553 session = openSession();
554
555 resourceCode = (ResourceCode)session.get(ResourceCodeImpl.class,
556 Long.valueOf(codeId));
557 }
558 catch (Exception e) {
559 hasException = true;
560
561 throw processException(e);
562 }
563 finally {
564 if (resourceCode != null) {
565 cacheResult(resourceCode);
566 }
567 else if (!hasException) {
568 EntityCacheUtil.putResult(ResourceCodeModelImpl.ENTITY_CACHE_ENABLED,
569 ResourceCodeImpl.class, codeId, _nullResourceCode);
570 }
571
572 closeSession(session);
573 }
574 }
575
576 return resourceCode;
577 }
578
579
586 public List<ResourceCode> findByCompanyId(long companyId)
587 throws SystemException {
588 return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
589 null);
590 }
591
592
605 public List<ResourceCode> findByCompanyId(long companyId, int start, int end)
606 throws SystemException {
607 return findByCompanyId(companyId, start, end, null);
608 }
609
610
624 public List<ResourceCode> findByCompanyId(long companyId, int start,
625 int end, OrderByComparator orderByComparator) throws SystemException {
626 FinderPath finderPath = null;
627 Object[] finderArgs = null;
628
629 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
630 (orderByComparator == null)) {
631 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
632 finderArgs = new Object[] { companyId };
633 }
634 else {
635 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
636 finderArgs = new Object[] { companyId, start, end, orderByComparator };
637 }
638
639 List<ResourceCode> list = (List<ResourceCode>)FinderCacheUtil.getResult(finderPath,
640 finderArgs, this);
641
642 if ((list != null) && !list.isEmpty()) {
643 for (ResourceCode resourceCode : list) {
644 if ((companyId != resourceCode.getCompanyId())) {
645 list = null;
646
647 break;
648 }
649 }
650 }
651
652 if (list == null) {
653 StringBundler query = null;
654
655 if (orderByComparator != null) {
656 query = new StringBundler(3 +
657 (orderByComparator.getOrderByFields().length * 3));
658 }
659 else {
660 query = new StringBundler(2);
661 }
662
663 query.append(_SQL_SELECT_RESOURCECODE_WHERE);
664
665 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
666
667 if (orderByComparator != null) {
668 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
669 orderByComparator);
670 }
671
672 String sql = query.toString();
673
674 Session session = null;
675
676 try {
677 session = openSession();
678
679 Query q = session.createQuery(sql);
680
681 QueryPos qPos = QueryPos.getInstance(q);
682
683 qPos.add(companyId);
684
685 list = (List<ResourceCode>)QueryUtil.list(q, getDialect(),
686 start, end);
687 }
688 catch (Exception e) {
689 throw processException(e);
690 }
691 finally {
692 if (list == null) {
693 FinderCacheUtil.removeResult(finderPath, finderArgs);
694 }
695 else {
696 cacheResult(list);
697
698 FinderCacheUtil.putResult(finderPath, finderArgs, list);
699 }
700
701 closeSession(session);
702 }
703 }
704
705 return list;
706 }
707
708
717 public ResourceCode findByCompanyId_First(long companyId,
718 OrderByComparator orderByComparator)
719 throws NoSuchResourceCodeException, SystemException {
720 ResourceCode resourceCode = fetchByCompanyId_First(companyId,
721 orderByComparator);
722
723 if (resourceCode != null) {
724 return resourceCode;
725 }
726
727 StringBundler msg = new StringBundler(4);
728
729 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
730
731 msg.append("companyId=");
732 msg.append(companyId);
733
734 msg.append(StringPool.CLOSE_CURLY_BRACE);
735
736 throw new NoSuchResourceCodeException(msg.toString());
737 }
738
739
747 public ResourceCode fetchByCompanyId_First(long companyId,
748 OrderByComparator orderByComparator) throws SystemException {
749 List<ResourceCode> list = findByCompanyId(companyId, 0, 1,
750 orderByComparator);
751
752 if (!list.isEmpty()) {
753 return list.get(0);
754 }
755
756 return null;
757 }
758
759
768 public ResourceCode findByCompanyId_Last(long companyId,
769 OrderByComparator orderByComparator)
770 throws NoSuchResourceCodeException, SystemException {
771 ResourceCode resourceCode = fetchByCompanyId_Last(companyId,
772 orderByComparator);
773
774 if (resourceCode != null) {
775 return resourceCode;
776 }
777
778 StringBundler msg = new StringBundler(4);
779
780 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
781
782 msg.append("companyId=");
783 msg.append(companyId);
784
785 msg.append(StringPool.CLOSE_CURLY_BRACE);
786
787 throw new NoSuchResourceCodeException(msg.toString());
788 }
789
790
798 public ResourceCode fetchByCompanyId_Last(long companyId,
799 OrderByComparator orderByComparator) throws SystemException {
800 int count = countByCompanyId(companyId);
801
802 List<ResourceCode> list = findByCompanyId(companyId, count - 1, count,
803 orderByComparator);
804
805 if (!list.isEmpty()) {
806 return list.get(0);
807 }
808
809 return null;
810 }
811
812
822 public ResourceCode[] findByCompanyId_PrevAndNext(long codeId,
823 long companyId, OrderByComparator orderByComparator)
824 throws NoSuchResourceCodeException, SystemException {
825 ResourceCode resourceCode = findByPrimaryKey(codeId);
826
827 Session session = null;
828
829 try {
830 session = openSession();
831
832 ResourceCode[] array = new ResourceCodeImpl[3];
833
834 array[0] = getByCompanyId_PrevAndNext(session, resourceCode,
835 companyId, orderByComparator, true);
836
837 array[1] = resourceCode;
838
839 array[2] = getByCompanyId_PrevAndNext(session, resourceCode,
840 companyId, orderByComparator, false);
841
842 return array;
843 }
844 catch (Exception e) {
845 throw processException(e);
846 }
847 finally {
848 closeSession(session);
849 }
850 }
851
852 protected ResourceCode getByCompanyId_PrevAndNext(Session session,
853 ResourceCode resourceCode, long companyId,
854 OrderByComparator orderByComparator, boolean previous) {
855 StringBundler query = null;
856
857 if (orderByComparator != null) {
858 query = new StringBundler(6 +
859 (orderByComparator.getOrderByFields().length * 6));
860 }
861 else {
862 query = new StringBundler(3);
863 }
864
865 query.append(_SQL_SELECT_RESOURCECODE_WHERE);
866
867 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
868
869 if (orderByComparator != null) {
870 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
871
872 if (orderByConditionFields.length > 0) {
873 query.append(WHERE_AND);
874 }
875
876 for (int i = 0; i < orderByConditionFields.length; i++) {
877 query.append(_ORDER_BY_ENTITY_ALIAS);
878 query.append(orderByConditionFields[i]);
879
880 if ((i + 1) < orderByConditionFields.length) {
881 if (orderByComparator.isAscending() ^ previous) {
882 query.append(WHERE_GREATER_THAN_HAS_NEXT);
883 }
884 else {
885 query.append(WHERE_LESSER_THAN_HAS_NEXT);
886 }
887 }
888 else {
889 if (orderByComparator.isAscending() ^ previous) {
890 query.append(WHERE_GREATER_THAN);
891 }
892 else {
893 query.append(WHERE_LESSER_THAN);
894 }
895 }
896 }
897
898 query.append(ORDER_BY_CLAUSE);
899
900 String[] orderByFields = orderByComparator.getOrderByFields();
901
902 for (int i = 0; i < orderByFields.length; i++) {
903 query.append(_ORDER_BY_ENTITY_ALIAS);
904 query.append(orderByFields[i]);
905
906 if ((i + 1) < orderByFields.length) {
907 if (orderByComparator.isAscending() ^ previous) {
908 query.append(ORDER_BY_ASC_HAS_NEXT);
909 }
910 else {
911 query.append(ORDER_BY_DESC_HAS_NEXT);
912 }
913 }
914 else {
915 if (orderByComparator.isAscending() ^ previous) {
916 query.append(ORDER_BY_ASC);
917 }
918 else {
919 query.append(ORDER_BY_DESC);
920 }
921 }
922 }
923 }
924
925 String sql = query.toString();
926
927 Query q = session.createQuery(sql);
928
929 q.setFirstResult(0);
930 q.setMaxResults(2);
931
932 QueryPos qPos = QueryPos.getInstance(q);
933
934 qPos.add(companyId);
935
936 if (orderByComparator != null) {
937 Object[] values = orderByComparator.getOrderByConditionValues(resourceCode);
938
939 for (Object value : values) {
940 qPos.add(value);
941 }
942 }
943
944 List<ResourceCode> list = q.list();
945
946 if (list.size() == 2) {
947 return list.get(1);
948 }
949 else {
950 return null;
951 }
952 }
953
954
961 public List<ResourceCode> findByName(String name) throws SystemException {
962 return findByName(name, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
963 }
964
965
978 public List<ResourceCode> findByName(String name, int start, int end)
979 throws SystemException {
980 return findByName(name, start, end, null);
981 }
982
983
997 public List<ResourceCode> findByName(String name, int start, int end,
998 OrderByComparator orderByComparator) throws SystemException {
999 FinderPath finderPath = null;
1000 Object[] finderArgs = null;
1001
1002 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1003 (orderByComparator == null)) {
1004 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME;
1005 finderArgs = new Object[] { name };
1006 }
1007 else {
1008 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_NAME;
1009 finderArgs = new Object[] { name, start, end, orderByComparator };
1010 }
1011
1012 List<ResourceCode> list = (List<ResourceCode>)FinderCacheUtil.getResult(finderPath,
1013 finderArgs, this);
1014
1015 if ((list != null) && !list.isEmpty()) {
1016 for (ResourceCode resourceCode : list) {
1017 if (!Validator.equals(name, resourceCode.getName())) {
1018 list = null;
1019
1020 break;
1021 }
1022 }
1023 }
1024
1025 if (list == null) {
1026 StringBundler query = null;
1027
1028 if (orderByComparator != null) {
1029 query = new StringBundler(3 +
1030 (orderByComparator.getOrderByFields().length * 3));
1031 }
1032 else {
1033 query = new StringBundler(2);
1034 }
1035
1036 query.append(_SQL_SELECT_RESOURCECODE_WHERE);
1037
1038 if (name == null) {
1039 query.append(_FINDER_COLUMN_NAME_NAME_1);
1040 }
1041 else {
1042 if (name.equals(StringPool.BLANK)) {
1043 query.append(_FINDER_COLUMN_NAME_NAME_3);
1044 }
1045 else {
1046 query.append(_FINDER_COLUMN_NAME_NAME_2);
1047 }
1048 }
1049
1050 if (orderByComparator != null) {
1051 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1052 orderByComparator);
1053 }
1054
1055 String sql = query.toString();
1056
1057 Session session = null;
1058
1059 try {
1060 session = openSession();
1061
1062 Query q = session.createQuery(sql);
1063
1064 QueryPos qPos = QueryPos.getInstance(q);
1065
1066 if (name != null) {
1067 qPos.add(name);
1068 }
1069
1070 list = (List<ResourceCode>)QueryUtil.list(q, getDialect(),
1071 start, end);
1072 }
1073 catch (Exception e) {
1074 throw processException(e);
1075 }
1076 finally {
1077 if (list == null) {
1078 FinderCacheUtil.removeResult(finderPath, finderArgs);
1079 }
1080 else {
1081 cacheResult(list);
1082
1083 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1084 }
1085
1086 closeSession(session);
1087 }
1088 }
1089
1090 return list;
1091 }
1092
1093
1102 public ResourceCode findByName_First(String name,
1103 OrderByComparator orderByComparator)
1104 throws NoSuchResourceCodeException, SystemException {
1105 ResourceCode resourceCode = fetchByName_First(name, orderByComparator);
1106
1107 if (resourceCode != null) {
1108 return resourceCode;
1109 }
1110
1111 StringBundler msg = new StringBundler(4);
1112
1113 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1114
1115 msg.append("name=");
1116 msg.append(name);
1117
1118 msg.append(StringPool.CLOSE_CURLY_BRACE);
1119
1120 throw new NoSuchResourceCodeException(msg.toString());
1121 }
1122
1123
1131 public ResourceCode fetchByName_First(String name,
1132 OrderByComparator orderByComparator) throws SystemException {
1133 List<ResourceCode> list = findByName(name, 0, 1, orderByComparator);
1134
1135 if (!list.isEmpty()) {
1136 return list.get(0);
1137 }
1138
1139 return null;
1140 }
1141
1142
1151 public ResourceCode findByName_Last(String name,
1152 OrderByComparator orderByComparator)
1153 throws NoSuchResourceCodeException, SystemException {
1154 ResourceCode resourceCode = fetchByName_Last(name, orderByComparator);
1155
1156 if (resourceCode != null) {
1157 return resourceCode;
1158 }
1159
1160 StringBundler msg = new StringBundler(4);
1161
1162 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1163
1164 msg.append("name=");
1165 msg.append(name);
1166
1167 msg.append(StringPool.CLOSE_CURLY_BRACE);
1168
1169 throw new NoSuchResourceCodeException(msg.toString());
1170 }
1171
1172
1180 public ResourceCode fetchByName_Last(String name,
1181 OrderByComparator orderByComparator) throws SystemException {
1182 int count = countByName(name);
1183
1184 List<ResourceCode> list = findByName(name, count - 1, count,
1185 orderByComparator);
1186
1187 if (!list.isEmpty()) {
1188 return list.get(0);
1189 }
1190
1191 return null;
1192 }
1193
1194
1204 public ResourceCode[] findByName_PrevAndNext(long codeId, String name,
1205 OrderByComparator orderByComparator)
1206 throws NoSuchResourceCodeException, SystemException {
1207 ResourceCode resourceCode = findByPrimaryKey(codeId);
1208
1209 Session session = null;
1210
1211 try {
1212 session = openSession();
1213
1214 ResourceCode[] array = new ResourceCodeImpl[3];
1215
1216 array[0] = getByName_PrevAndNext(session, resourceCode, name,
1217 orderByComparator, true);
1218
1219 array[1] = resourceCode;
1220
1221 array[2] = getByName_PrevAndNext(session, resourceCode, name,
1222 orderByComparator, false);
1223
1224 return array;
1225 }
1226 catch (Exception e) {
1227 throw processException(e);
1228 }
1229 finally {
1230 closeSession(session);
1231 }
1232 }
1233
1234 protected ResourceCode getByName_PrevAndNext(Session session,
1235 ResourceCode resourceCode, String name,
1236 OrderByComparator orderByComparator, boolean previous) {
1237 StringBundler query = null;
1238
1239 if (orderByComparator != null) {
1240 query = new StringBundler(6 +
1241 (orderByComparator.getOrderByFields().length * 6));
1242 }
1243 else {
1244 query = new StringBundler(3);
1245 }
1246
1247 query.append(_SQL_SELECT_RESOURCECODE_WHERE);
1248
1249 if (name == null) {
1250 query.append(_FINDER_COLUMN_NAME_NAME_1);
1251 }
1252 else {
1253 if (name.equals(StringPool.BLANK)) {
1254 query.append(_FINDER_COLUMN_NAME_NAME_3);
1255 }
1256 else {
1257 query.append(_FINDER_COLUMN_NAME_NAME_2);
1258 }
1259 }
1260
1261 if (orderByComparator != null) {
1262 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1263
1264 if (orderByConditionFields.length > 0) {
1265 query.append(WHERE_AND);
1266 }
1267
1268 for (int i = 0; i < orderByConditionFields.length; i++) {
1269 query.append(_ORDER_BY_ENTITY_ALIAS);
1270 query.append(orderByConditionFields[i]);
1271
1272 if ((i + 1) < orderByConditionFields.length) {
1273 if (orderByComparator.isAscending() ^ previous) {
1274 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1275 }
1276 else {
1277 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1278 }
1279 }
1280 else {
1281 if (orderByComparator.isAscending() ^ previous) {
1282 query.append(WHERE_GREATER_THAN);
1283 }
1284 else {
1285 query.append(WHERE_LESSER_THAN);
1286 }
1287 }
1288 }
1289
1290 query.append(ORDER_BY_CLAUSE);
1291
1292 String[] orderByFields = orderByComparator.getOrderByFields();
1293
1294 for (int i = 0; i < orderByFields.length; i++) {
1295 query.append(_ORDER_BY_ENTITY_ALIAS);
1296 query.append(orderByFields[i]);
1297
1298 if ((i + 1) < orderByFields.length) {
1299 if (orderByComparator.isAscending() ^ previous) {
1300 query.append(ORDER_BY_ASC_HAS_NEXT);
1301 }
1302 else {
1303 query.append(ORDER_BY_DESC_HAS_NEXT);
1304 }
1305 }
1306 else {
1307 if (orderByComparator.isAscending() ^ previous) {
1308 query.append(ORDER_BY_ASC);
1309 }
1310 else {
1311 query.append(ORDER_BY_DESC);
1312 }
1313 }
1314 }
1315 }
1316
1317 String sql = query.toString();
1318
1319 Query q = session.createQuery(sql);
1320
1321 q.setFirstResult(0);
1322 q.setMaxResults(2);
1323
1324 QueryPos qPos = QueryPos.getInstance(q);
1325
1326 if (name != null) {
1327 qPos.add(name);
1328 }
1329
1330 if (orderByComparator != null) {
1331 Object[] values = orderByComparator.getOrderByConditionValues(resourceCode);
1332
1333 for (Object value : values) {
1334 qPos.add(value);
1335 }
1336 }
1337
1338 List<ResourceCode> list = q.list();
1339
1340 if (list.size() == 2) {
1341 return list.get(1);
1342 }
1343 else {
1344 return null;
1345 }
1346 }
1347
1348
1358 public ResourceCode findByC_N_S(long companyId, String name, int scope)
1359 throws NoSuchResourceCodeException, SystemException {
1360 ResourceCode resourceCode = fetchByC_N_S(companyId, name, scope);
1361
1362 if (resourceCode == null) {
1363 StringBundler msg = new StringBundler(8);
1364
1365 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1366
1367 msg.append("companyId=");
1368 msg.append(companyId);
1369
1370 msg.append(", name=");
1371 msg.append(name);
1372
1373 msg.append(", scope=");
1374 msg.append(scope);
1375
1376 msg.append(StringPool.CLOSE_CURLY_BRACE);
1377
1378 if (_log.isWarnEnabled()) {
1379 _log.warn(msg.toString());
1380 }
1381
1382 throw new NoSuchResourceCodeException(msg.toString());
1383 }
1384
1385 return resourceCode;
1386 }
1387
1388
1397 public ResourceCode fetchByC_N_S(long companyId, String name, int scope)
1398 throws SystemException {
1399 return fetchByC_N_S(companyId, name, scope, true);
1400 }
1401
1402
1412 public ResourceCode fetchByC_N_S(long companyId, String name, int scope,
1413 boolean retrieveFromCache) throws SystemException {
1414 Object[] finderArgs = new Object[] { companyId, name, scope };
1415
1416 Object result = null;
1417
1418 if (retrieveFromCache) {
1419 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_N_S,
1420 finderArgs, this);
1421 }
1422
1423 if (result instanceof ResourceCode) {
1424 ResourceCode resourceCode = (ResourceCode)result;
1425
1426 if ((companyId != resourceCode.getCompanyId()) ||
1427 !Validator.equals(name, resourceCode.getName()) ||
1428 (scope != resourceCode.getScope())) {
1429 result = null;
1430 }
1431 }
1432
1433 if (result == null) {
1434 StringBundler query = new StringBundler(4);
1435
1436 query.append(_SQL_SELECT_RESOURCECODE_WHERE);
1437
1438 query.append(_FINDER_COLUMN_C_N_S_COMPANYID_2);
1439
1440 if (name == null) {
1441 query.append(_FINDER_COLUMN_C_N_S_NAME_1);
1442 }
1443 else {
1444 if (name.equals(StringPool.BLANK)) {
1445 query.append(_FINDER_COLUMN_C_N_S_NAME_3);
1446 }
1447 else {
1448 query.append(_FINDER_COLUMN_C_N_S_NAME_2);
1449 }
1450 }
1451
1452 query.append(_FINDER_COLUMN_C_N_S_SCOPE_2);
1453
1454 String sql = query.toString();
1455
1456 Session session = null;
1457
1458 try {
1459 session = openSession();
1460
1461 Query q = session.createQuery(sql);
1462
1463 QueryPos qPos = QueryPos.getInstance(q);
1464
1465 qPos.add(companyId);
1466
1467 if (name != null) {
1468 qPos.add(name);
1469 }
1470
1471 qPos.add(scope);
1472
1473 List<ResourceCode> list = q.list();
1474
1475 result = list;
1476
1477 ResourceCode resourceCode = null;
1478
1479 if (list.isEmpty()) {
1480 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N_S,
1481 finderArgs, list);
1482 }
1483 else {
1484 resourceCode = list.get(0);
1485
1486 cacheResult(resourceCode);
1487
1488 if ((resourceCode.getCompanyId() != companyId) ||
1489 (resourceCode.getName() == null) ||
1490 !resourceCode.getName().equals(name) ||
1491 (resourceCode.getScope() != scope)) {
1492 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N_S,
1493 finderArgs, resourceCode);
1494 }
1495 }
1496
1497 return resourceCode;
1498 }
1499 catch (Exception e) {
1500 throw processException(e);
1501 }
1502 finally {
1503 if (result == null) {
1504 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N_S,
1505 finderArgs);
1506 }
1507
1508 closeSession(session);
1509 }
1510 }
1511 else {
1512 if (result instanceof List<?>) {
1513 return null;
1514 }
1515 else {
1516 return (ResourceCode)result;
1517 }
1518 }
1519 }
1520
1521
1527 public List<ResourceCode> findAll() throws SystemException {
1528 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1529 }
1530
1531
1543 public List<ResourceCode> findAll(int start, int end)
1544 throws SystemException {
1545 return findAll(start, end, null);
1546 }
1547
1548
1561 public List<ResourceCode> findAll(int start, int end,
1562 OrderByComparator orderByComparator) throws SystemException {
1563 FinderPath finderPath = null;
1564 Object[] finderArgs = new Object[] { start, end, orderByComparator };
1565
1566 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1567 (orderByComparator == null)) {
1568 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1569 finderArgs = FINDER_ARGS_EMPTY;
1570 }
1571 else {
1572 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1573 finderArgs = new Object[] { start, end, orderByComparator };
1574 }
1575
1576 List<ResourceCode> list = (List<ResourceCode>)FinderCacheUtil.getResult(finderPath,
1577 finderArgs, this);
1578
1579 if (list == null) {
1580 StringBundler query = null;
1581 String sql = null;
1582
1583 if (orderByComparator != null) {
1584 query = new StringBundler(2 +
1585 (orderByComparator.getOrderByFields().length * 3));
1586
1587 query.append(_SQL_SELECT_RESOURCECODE);
1588
1589 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1590 orderByComparator);
1591
1592 sql = query.toString();
1593 }
1594 else {
1595 sql = _SQL_SELECT_RESOURCECODE;
1596 }
1597
1598 Session session = null;
1599
1600 try {
1601 session = openSession();
1602
1603 Query q = session.createQuery(sql);
1604
1605 if (orderByComparator == null) {
1606 list = (List<ResourceCode>)QueryUtil.list(q, getDialect(),
1607 start, end, false);
1608
1609 Collections.sort(list);
1610 }
1611 else {
1612 list = (List<ResourceCode>)QueryUtil.list(q, getDialect(),
1613 start, end);
1614 }
1615 }
1616 catch (Exception e) {
1617 throw processException(e);
1618 }
1619 finally {
1620 if (list == null) {
1621 FinderCacheUtil.removeResult(finderPath, finderArgs);
1622 }
1623 else {
1624 cacheResult(list);
1625
1626 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1627 }
1628
1629 closeSession(session);
1630 }
1631 }
1632
1633 return list;
1634 }
1635
1636
1642 public void removeByCompanyId(long companyId) throws SystemException {
1643 for (ResourceCode resourceCode : findByCompanyId(companyId)) {
1644 remove(resourceCode);
1645 }
1646 }
1647
1648
1654 public void removeByName(String name) throws SystemException {
1655 for (ResourceCode resourceCode : findByName(name)) {
1656 remove(resourceCode);
1657 }
1658 }
1659
1660
1669 public ResourceCode removeByC_N_S(long companyId, String name, int scope)
1670 throws NoSuchResourceCodeException, SystemException {
1671 ResourceCode resourceCode = findByC_N_S(companyId, name, scope);
1672
1673 return remove(resourceCode);
1674 }
1675
1676
1681 public void removeAll() throws SystemException {
1682 for (ResourceCode resourceCode : findAll()) {
1683 remove(resourceCode);
1684 }
1685 }
1686
1687
1694 public int countByCompanyId(long companyId) throws SystemException {
1695 Object[] finderArgs = new Object[] { companyId };
1696
1697 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
1698 finderArgs, this);
1699
1700 if (count == null) {
1701 StringBundler query = new StringBundler(2);
1702
1703 query.append(_SQL_COUNT_RESOURCECODE_WHERE);
1704
1705 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1706
1707 String sql = query.toString();
1708
1709 Session session = null;
1710
1711 try {
1712 session = openSession();
1713
1714 Query q = session.createQuery(sql);
1715
1716 QueryPos qPos = QueryPos.getInstance(q);
1717
1718 qPos.add(companyId);
1719
1720 count = (Long)q.uniqueResult();
1721 }
1722 catch (Exception e) {
1723 throw processException(e);
1724 }
1725 finally {
1726 if (count == null) {
1727 count = Long.valueOf(0);
1728 }
1729
1730 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
1731 finderArgs, count);
1732
1733 closeSession(session);
1734 }
1735 }
1736
1737 return count.intValue();
1738 }
1739
1740
1747 public int countByName(String name) throws SystemException {
1748 Object[] finderArgs = new Object[] { name };
1749
1750 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_NAME,
1751 finderArgs, this);
1752
1753 if (count == null) {
1754 StringBundler query = new StringBundler(2);
1755
1756 query.append(_SQL_COUNT_RESOURCECODE_WHERE);
1757
1758 if (name == null) {
1759 query.append(_FINDER_COLUMN_NAME_NAME_1);
1760 }
1761 else {
1762 if (name.equals(StringPool.BLANK)) {
1763 query.append(_FINDER_COLUMN_NAME_NAME_3);
1764 }
1765 else {
1766 query.append(_FINDER_COLUMN_NAME_NAME_2);
1767 }
1768 }
1769
1770 String sql = query.toString();
1771
1772 Session session = null;
1773
1774 try {
1775 session = openSession();
1776
1777 Query q = session.createQuery(sql);
1778
1779 QueryPos qPos = QueryPos.getInstance(q);
1780
1781 if (name != null) {
1782 qPos.add(name);
1783 }
1784
1785 count = (Long)q.uniqueResult();
1786 }
1787 catch (Exception e) {
1788 throw processException(e);
1789 }
1790 finally {
1791 if (count == null) {
1792 count = Long.valueOf(0);
1793 }
1794
1795 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_NAME,
1796 finderArgs, count);
1797
1798 closeSession(session);
1799 }
1800 }
1801
1802 return count.intValue();
1803 }
1804
1805
1814 public int countByC_N_S(long companyId, String name, int scope)
1815 throws SystemException {
1816 Object[] finderArgs = new Object[] { companyId, name, scope };
1817
1818 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_N_S,
1819 finderArgs, this);
1820
1821 if (count == null) {
1822 StringBundler query = new StringBundler(4);
1823
1824 query.append(_SQL_COUNT_RESOURCECODE_WHERE);
1825
1826 query.append(_FINDER_COLUMN_C_N_S_COMPANYID_2);
1827
1828 if (name == null) {
1829 query.append(_FINDER_COLUMN_C_N_S_NAME_1);
1830 }
1831 else {
1832 if (name.equals(StringPool.BLANK)) {
1833 query.append(_FINDER_COLUMN_C_N_S_NAME_3);
1834 }
1835 else {
1836 query.append(_FINDER_COLUMN_C_N_S_NAME_2);
1837 }
1838 }
1839
1840 query.append(_FINDER_COLUMN_C_N_S_SCOPE_2);
1841
1842 String sql = query.toString();
1843
1844 Session session = null;
1845
1846 try {
1847 session = openSession();
1848
1849 Query q = session.createQuery(sql);
1850
1851 QueryPos qPos = QueryPos.getInstance(q);
1852
1853 qPos.add(companyId);
1854
1855 if (name != null) {
1856 qPos.add(name);
1857 }
1858
1859 qPos.add(scope);
1860
1861 count = (Long)q.uniqueResult();
1862 }
1863 catch (Exception e) {
1864 throw processException(e);
1865 }
1866 finally {
1867 if (count == null) {
1868 count = Long.valueOf(0);
1869 }
1870
1871 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N_S,
1872 finderArgs, count);
1873
1874 closeSession(session);
1875 }
1876 }
1877
1878 return count.intValue();
1879 }
1880
1881
1887 public int countAll() throws SystemException {
1888 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1889 FINDER_ARGS_EMPTY, this);
1890
1891 if (count == null) {
1892 Session session = null;
1893
1894 try {
1895 session = openSession();
1896
1897 Query q = session.createQuery(_SQL_COUNT_RESOURCECODE);
1898
1899 count = (Long)q.uniqueResult();
1900 }
1901 catch (Exception e) {
1902 throw processException(e);
1903 }
1904 finally {
1905 if (count == null) {
1906 count = Long.valueOf(0);
1907 }
1908
1909 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1910 FINDER_ARGS_EMPTY, count);
1911
1912 closeSession(session);
1913 }
1914 }
1915
1916 return count.intValue();
1917 }
1918
1919
1922 public void afterPropertiesSet() {
1923 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1924 com.liferay.portal.util.PropsUtil.get(
1925 "value.object.listener.com.liferay.portal.model.ResourceCode")));
1926
1927 if (listenerClassNames.length > 0) {
1928 try {
1929 List<ModelListener<ResourceCode>> listenersList = new ArrayList<ModelListener<ResourceCode>>();
1930
1931 for (String listenerClassName : listenerClassNames) {
1932 Class<?> clazz = getClass();
1933
1934 listenersList.add((ModelListener<ResourceCode>)InstanceFactory.newInstance(
1935 clazz.getClassLoader(), listenerClassName));
1936 }
1937
1938 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1939 }
1940 catch (Exception e) {
1941 _log.error(e);
1942 }
1943 }
1944 }
1945
1946 public void destroy() {
1947 EntityCacheUtil.removeCache(ResourceCodeImpl.class.getName());
1948 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1949 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1950 }
1951
1952 @BeanReference(type = AccountPersistence.class)
1953 protected AccountPersistence accountPersistence;
1954 @BeanReference(type = AddressPersistence.class)
1955 protected AddressPersistence addressPersistence;
1956 @BeanReference(type = BrowserTrackerPersistence.class)
1957 protected BrowserTrackerPersistence browserTrackerPersistence;
1958 @BeanReference(type = ClassNamePersistence.class)
1959 protected ClassNamePersistence classNamePersistence;
1960 @BeanReference(type = ClusterGroupPersistence.class)
1961 protected ClusterGroupPersistence clusterGroupPersistence;
1962 @BeanReference(type = CompanyPersistence.class)
1963 protected CompanyPersistence companyPersistence;
1964 @BeanReference(type = ContactPersistence.class)
1965 protected ContactPersistence contactPersistence;
1966 @BeanReference(type = CountryPersistence.class)
1967 protected CountryPersistence countryPersistence;
1968 @BeanReference(type = EmailAddressPersistence.class)
1969 protected EmailAddressPersistence emailAddressPersistence;
1970 @BeanReference(type = GroupPersistence.class)
1971 protected GroupPersistence groupPersistence;
1972 @BeanReference(type = ImagePersistence.class)
1973 protected ImagePersistence imagePersistence;
1974 @BeanReference(type = LayoutPersistence.class)
1975 protected LayoutPersistence layoutPersistence;
1976 @BeanReference(type = LayoutBranchPersistence.class)
1977 protected LayoutBranchPersistence layoutBranchPersistence;
1978 @BeanReference(type = LayoutPrototypePersistence.class)
1979 protected LayoutPrototypePersistence layoutPrototypePersistence;
1980 @BeanReference(type = LayoutRevisionPersistence.class)
1981 protected LayoutRevisionPersistence layoutRevisionPersistence;
1982 @BeanReference(type = LayoutSetPersistence.class)
1983 protected LayoutSetPersistence layoutSetPersistence;
1984 @BeanReference(type = LayoutSetBranchPersistence.class)
1985 protected LayoutSetBranchPersistence layoutSetBranchPersistence;
1986 @BeanReference(type = LayoutSetPrototypePersistence.class)
1987 protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
1988 @BeanReference(type = ListTypePersistence.class)
1989 protected ListTypePersistence listTypePersistence;
1990 @BeanReference(type = LockPersistence.class)
1991 protected LockPersistence lockPersistence;
1992 @BeanReference(type = MembershipRequestPersistence.class)
1993 protected MembershipRequestPersistence membershipRequestPersistence;
1994 @BeanReference(type = OrganizationPersistence.class)
1995 protected OrganizationPersistence organizationPersistence;
1996 @BeanReference(type = OrgGroupPermissionPersistence.class)
1997 protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1998 @BeanReference(type = OrgGroupRolePersistence.class)
1999 protected OrgGroupRolePersistence orgGroupRolePersistence;
2000 @BeanReference(type = OrgLaborPersistence.class)
2001 protected OrgLaborPersistence orgLaborPersistence;
2002 @BeanReference(type = PasswordPolicyPersistence.class)
2003 protected PasswordPolicyPersistence passwordPolicyPersistence;
2004 @BeanReference(type = PasswordPolicyRelPersistence.class)
2005 protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
2006 @BeanReference(type = PasswordTrackerPersistence.class)
2007 protected PasswordTrackerPersistence passwordTrackerPersistence;
2008 @BeanReference(type = PermissionPersistence.class)
2009 protected PermissionPersistence permissionPersistence;
2010 @BeanReference(type = PhonePersistence.class)
2011 protected PhonePersistence phonePersistence;
2012 @BeanReference(type = PluginSettingPersistence.class)
2013 protected PluginSettingPersistence pluginSettingPersistence;
2014 @BeanReference(type = PortalPreferencesPersistence.class)
2015 protected PortalPreferencesPersistence portalPreferencesPersistence;
2016 @BeanReference(type = PortletPersistence.class)
2017 protected PortletPersistence portletPersistence;
2018 @BeanReference(type = PortletItemPersistence.class)
2019 protected PortletItemPersistence portletItemPersistence;
2020 @BeanReference(type = PortletPreferencesPersistence.class)
2021 protected PortletPreferencesPersistence portletPreferencesPersistence;
2022 @BeanReference(type = RegionPersistence.class)
2023 protected RegionPersistence regionPersistence;
2024 @BeanReference(type = ReleasePersistence.class)
2025 protected ReleasePersistence releasePersistence;
2026 @BeanReference(type = RepositoryPersistence.class)
2027 protected RepositoryPersistence repositoryPersistence;
2028 @BeanReference(type = RepositoryEntryPersistence.class)
2029 protected RepositoryEntryPersistence repositoryEntryPersistence;
2030 @BeanReference(type = ResourcePersistence.class)
2031 protected ResourcePersistence resourcePersistence;
2032 @BeanReference(type = ResourceActionPersistence.class)
2033 protected ResourceActionPersistence resourceActionPersistence;
2034 @BeanReference(type = ResourceBlockPersistence.class)
2035 protected ResourceBlockPersistence resourceBlockPersistence;
2036 @BeanReference(type = ResourceBlockPermissionPersistence.class)
2037 protected ResourceBlockPermissionPersistence resourceBlockPermissionPersistence;
2038 @BeanReference(type = ResourceCodePersistence.class)
2039 protected ResourceCodePersistence resourceCodePersistence;
2040 @BeanReference(type = ResourcePermissionPersistence.class)
2041 protected ResourcePermissionPersistence resourcePermissionPersistence;
2042 @BeanReference(type = ResourceTypePermissionPersistence.class)
2043 protected ResourceTypePermissionPersistence resourceTypePermissionPersistence;
2044 @BeanReference(type = RolePersistence.class)
2045 protected RolePersistence rolePersistence;
2046 @BeanReference(type = ServiceComponentPersistence.class)
2047 protected ServiceComponentPersistence serviceComponentPersistence;
2048 @BeanReference(type = ShardPersistence.class)
2049 protected ShardPersistence shardPersistence;
2050 @BeanReference(type = SubscriptionPersistence.class)
2051 protected SubscriptionPersistence subscriptionPersistence;
2052 @BeanReference(type = TeamPersistence.class)
2053 protected TeamPersistence teamPersistence;
2054 @BeanReference(type = TicketPersistence.class)
2055 protected TicketPersistence ticketPersistence;
2056 @BeanReference(type = UserPersistence.class)
2057 protected UserPersistence userPersistence;
2058 @BeanReference(type = UserGroupPersistence.class)
2059 protected UserGroupPersistence userGroupPersistence;
2060 @BeanReference(type = UserGroupGroupRolePersistence.class)
2061 protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
2062 @BeanReference(type = UserGroupRolePersistence.class)
2063 protected UserGroupRolePersistence userGroupRolePersistence;
2064 @BeanReference(type = UserIdMapperPersistence.class)
2065 protected UserIdMapperPersistence userIdMapperPersistence;
2066 @BeanReference(type = UserNotificationEventPersistence.class)
2067 protected UserNotificationEventPersistence userNotificationEventPersistence;
2068 @BeanReference(type = UserTrackerPersistence.class)
2069 protected UserTrackerPersistence userTrackerPersistence;
2070 @BeanReference(type = UserTrackerPathPersistence.class)
2071 protected UserTrackerPathPersistence userTrackerPathPersistence;
2072 @BeanReference(type = VirtualHostPersistence.class)
2073 protected VirtualHostPersistence virtualHostPersistence;
2074 @BeanReference(type = WebDAVPropsPersistence.class)
2075 protected WebDAVPropsPersistence webDAVPropsPersistence;
2076 @BeanReference(type = WebsitePersistence.class)
2077 protected WebsitePersistence websitePersistence;
2078 @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
2079 protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
2080 @BeanReference(type = WorkflowInstanceLinkPersistence.class)
2081 protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
2082 private static final String _SQL_SELECT_RESOURCECODE = "SELECT resourceCode FROM ResourceCode resourceCode";
2083 private static final String _SQL_SELECT_RESOURCECODE_WHERE = "SELECT resourceCode FROM ResourceCode resourceCode WHERE ";
2084 private static final String _SQL_COUNT_RESOURCECODE = "SELECT COUNT(resourceCode) FROM ResourceCode resourceCode";
2085 private static final String _SQL_COUNT_RESOURCECODE_WHERE = "SELECT COUNT(resourceCode) FROM ResourceCode resourceCode WHERE ";
2086 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "resourceCode.companyId = ?";
2087 private static final String _FINDER_COLUMN_NAME_NAME_1 = "resourceCode.name IS NULL";
2088 private static final String _FINDER_COLUMN_NAME_NAME_2 = "resourceCode.name = ?";
2089 private static final String _FINDER_COLUMN_NAME_NAME_3 = "(resourceCode.name IS NULL OR resourceCode.name = ?)";
2090 private static final String _FINDER_COLUMN_C_N_S_COMPANYID_2 = "resourceCode.companyId = ? AND ";
2091 private static final String _FINDER_COLUMN_C_N_S_NAME_1 = "resourceCode.name IS NULL AND ";
2092 private static final String _FINDER_COLUMN_C_N_S_NAME_2 = "resourceCode.name = ? AND ";
2093 private static final String _FINDER_COLUMN_C_N_S_NAME_3 = "(resourceCode.name IS NULL OR resourceCode.name = ?) AND ";
2094 private static final String _FINDER_COLUMN_C_N_S_SCOPE_2 = "resourceCode.scope = ?";
2095 private static final String _ORDER_BY_ENTITY_ALIAS = "resourceCode.";
2096 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ResourceCode exists with the primary key ";
2097 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ResourceCode exists with the key {";
2098 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2099 private static Log _log = LogFactoryUtil.getLog(ResourceCodePersistenceImpl.class);
2100 private static ResourceCode _nullResourceCode = new ResourceCodeImpl() {
2101 @Override
2102 public Object clone() {
2103 return this;
2104 }
2105
2106 @Override
2107 public CacheModel<ResourceCode> toCacheModel() {
2108 return _nullResourceCodeCacheModel;
2109 }
2110 };
2111
2112 private static CacheModel<ResourceCode> _nullResourceCodeCacheModel = new CacheModel<ResourceCode>() {
2113 public ResourceCode toEntityModel() {
2114 return _nullResourceCode;
2115 }
2116 };
2117 }