001
014
015 package com.liferay.portal.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.NoSuchResourceBlockException;
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.ResourceBlock;
041 import com.liferay.portal.model.impl.ResourceBlockImpl;
042 import com.liferay.portal.model.impl.ResourceBlockModelImpl;
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 ResourceBlockPersistenceImpl extends BasePersistenceImpl<ResourceBlock>
064 implements ResourceBlockPersistence {
065
070 public static final String FINDER_CLASS_NAME_ENTITY = ResourceBlockImpl.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_C_N = new FinderPath(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
076 ResourceBlockModelImpl.FINDER_CACHE_ENABLED,
077 ResourceBlockImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
078 "findByC_N",
079 new String[] {
080 Long.class.getName(), String.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_C_N = new FinderPath(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
086 ResourceBlockModelImpl.FINDER_CACHE_ENABLED,
087 ResourceBlockImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
088 "findByC_N",
089 new String[] { Long.class.getName(), String.class.getName() },
090 ResourceBlockModelImpl.COMPANYID_COLUMN_BITMASK |
091 ResourceBlockModelImpl.NAME_COLUMN_BITMASK);
092 public static final FinderPath FINDER_PATH_COUNT_BY_C_N = new FinderPath(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
093 ResourceBlockModelImpl.FINDER_CACHE_ENABLED, Long.class,
094 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_N",
095 new String[] { Long.class.getName(), String.class.getName() });
096 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_G_N = new FinderPath(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
097 ResourceBlockModelImpl.FINDER_CACHE_ENABLED,
098 ResourceBlockImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
099 "findByC_G_N",
100 new String[] {
101 Long.class.getName(), Long.class.getName(),
102 String.class.getName(),
103
104 "java.lang.Integer", "java.lang.Integer",
105 "com.liferay.portal.kernel.util.OrderByComparator"
106 });
107 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_G_N = new FinderPath(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
108 ResourceBlockModelImpl.FINDER_CACHE_ENABLED,
109 ResourceBlockImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
110 "findByC_G_N",
111 new String[] {
112 Long.class.getName(), Long.class.getName(),
113 String.class.getName()
114 },
115 ResourceBlockModelImpl.COMPANYID_COLUMN_BITMASK |
116 ResourceBlockModelImpl.GROUPID_COLUMN_BITMASK |
117 ResourceBlockModelImpl.NAME_COLUMN_BITMASK);
118 public static final FinderPath FINDER_PATH_COUNT_BY_C_G_N = new FinderPath(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
119 ResourceBlockModelImpl.FINDER_CACHE_ENABLED, Long.class,
120 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_G_N",
121 new String[] {
122 Long.class.getName(), Long.class.getName(),
123 String.class.getName()
124 });
125 public static final FinderPath FINDER_PATH_FETCH_BY_C_G_N_P = new FinderPath(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
126 ResourceBlockModelImpl.FINDER_CACHE_ENABLED,
127 ResourceBlockImpl.class, FINDER_CLASS_NAME_ENTITY,
128 "fetchByC_G_N_P",
129 new String[] {
130 Long.class.getName(), Long.class.getName(),
131 String.class.getName(), String.class.getName()
132 },
133 ResourceBlockModelImpl.COMPANYID_COLUMN_BITMASK |
134 ResourceBlockModelImpl.GROUPID_COLUMN_BITMASK |
135 ResourceBlockModelImpl.NAME_COLUMN_BITMASK |
136 ResourceBlockModelImpl.PERMISSIONSHASH_COLUMN_BITMASK);
137 public static final FinderPath FINDER_PATH_COUNT_BY_C_G_N_P = new FinderPath(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
138 ResourceBlockModelImpl.FINDER_CACHE_ENABLED, Long.class,
139 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_G_N_P",
140 new String[] {
141 Long.class.getName(), Long.class.getName(),
142 String.class.getName(), String.class.getName()
143 });
144 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
145 ResourceBlockModelImpl.FINDER_CACHE_ENABLED,
146 ResourceBlockImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
147 "findAll", new String[0]);
148 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
149 ResourceBlockModelImpl.FINDER_CACHE_ENABLED,
150 ResourceBlockImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
151 "findAll", new String[0]);
152 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
153 ResourceBlockModelImpl.FINDER_CACHE_ENABLED, Long.class,
154 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
155
156
161 public void cacheResult(ResourceBlock resourceBlock) {
162 EntityCacheUtil.putResult(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
163 ResourceBlockImpl.class, resourceBlock.getPrimaryKey(),
164 resourceBlock);
165
166 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_G_N_P,
167 new Object[] {
168 Long.valueOf(resourceBlock.getCompanyId()),
169 Long.valueOf(resourceBlock.getGroupId()),
170
171 resourceBlock.getName(),
172
173 resourceBlock.getPermissionsHash()
174 }, resourceBlock);
175
176 resourceBlock.resetOriginalValues();
177 }
178
179
184 public void cacheResult(List<ResourceBlock> resourceBlocks) {
185 for (ResourceBlock resourceBlock : resourceBlocks) {
186 if (EntityCacheUtil.getResult(
187 ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
188 ResourceBlockImpl.class, resourceBlock.getPrimaryKey()) == null) {
189 cacheResult(resourceBlock);
190 }
191 else {
192 resourceBlock.resetOriginalValues();
193 }
194 }
195 }
196
197
204 @Override
205 public void clearCache() {
206 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
207 CacheRegistryUtil.clear(ResourceBlockImpl.class.getName());
208 }
209
210 EntityCacheUtil.clearCache(ResourceBlockImpl.class.getName());
211
212 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
213 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
214 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
215 }
216
217
224 @Override
225 public void clearCache(ResourceBlock resourceBlock) {
226 EntityCacheUtil.removeResult(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
227 ResourceBlockImpl.class, resourceBlock.getPrimaryKey());
228
229 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
230 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
231
232 clearUniqueFindersCache(resourceBlock);
233 }
234
235 @Override
236 public void clearCache(List<ResourceBlock> resourceBlocks) {
237 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
238 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
239
240 for (ResourceBlock resourceBlock : resourceBlocks) {
241 EntityCacheUtil.removeResult(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
242 ResourceBlockImpl.class, resourceBlock.getPrimaryKey());
243
244 clearUniqueFindersCache(resourceBlock);
245 }
246 }
247
248 protected void clearUniqueFindersCache(ResourceBlock resourceBlock) {
249 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_G_N_P,
250 new Object[] {
251 Long.valueOf(resourceBlock.getCompanyId()),
252 Long.valueOf(resourceBlock.getGroupId()),
253
254 resourceBlock.getName(),
255
256 resourceBlock.getPermissionsHash()
257 });
258 }
259
260
266 public ResourceBlock create(long resourceBlockId) {
267 ResourceBlock resourceBlock = new ResourceBlockImpl();
268
269 resourceBlock.setNew(true);
270 resourceBlock.setPrimaryKey(resourceBlockId);
271
272 return resourceBlock;
273 }
274
275
283 public ResourceBlock remove(long resourceBlockId)
284 throws NoSuchResourceBlockException, SystemException {
285 return remove(Long.valueOf(resourceBlockId));
286 }
287
288
296 @Override
297 public ResourceBlock remove(Serializable primaryKey)
298 throws NoSuchResourceBlockException, SystemException {
299 Session session = null;
300
301 try {
302 session = openSession();
303
304 ResourceBlock resourceBlock = (ResourceBlock)session.get(ResourceBlockImpl.class,
305 primaryKey);
306
307 if (resourceBlock == null) {
308 if (_log.isWarnEnabled()) {
309 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
310 }
311
312 throw new NoSuchResourceBlockException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
313 primaryKey);
314 }
315
316 return remove(resourceBlock);
317 }
318 catch (NoSuchResourceBlockException nsee) {
319 throw nsee;
320 }
321 catch (Exception e) {
322 throw processException(e);
323 }
324 finally {
325 closeSession(session);
326 }
327 }
328
329 @Override
330 protected ResourceBlock removeImpl(ResourceBlock resourceBlock)
331 throws SystemException {
332 resourceBlock = toUnwrappedModel(resourceBlock);
333
334 Session session = null;
335
336 try {
337 session = openSession();
338
339 if (resourceBlock.isCachedModel()) {
340 resourceBlock = (ResourceBlock)session.get(ResourceBlockImpl.class,
341 resourceBlock.getPrimaryKeyObj());
342 }
343
344 session.delete(resourceBlock);
345 }
346 catch (Exception e) {
347 throw processException(e);
348 }
349 finally {
350 closeSession(session);
351 }
352
353 clearCache(resourceBlock);
354
355 return resourceBlock;
356 }
357
358 @Override
359 public ResourceBlock updateImpl(
360 com.liferay.portal.model.ResourceBlock resourceBlock)
361 throws SystemException {
362 resourceBlock = toUnwrappedModel(resourceBlock);
363
364 boolean isNew = resourceBlock.isNew();
365
366 ResourceBlockModelImpl resourceBlockModelImpl = (ResourceBlockModelImpl)resourceBlock;
367
368 Session session = null;
369
370 try {
371 session = openSession();
372
373 if (resourceBlock.isNew()) {
374 session.save(resourceBlock);
375
376 resourceBlock.setNew(false);
377 }
378 else {
379 session.merge(resourceBlock);
380 }
381 }
382 catch (Exception e) {
383 throw processException(e);
384 }
385 finally {
386 closeSession(session);
387 }
388
389 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
390
391 if (isNew || !ResourceBlockModelImpl.COLUMN_BITMASK_ENABLED) {
392 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
393 }
394
395 else {
396 if ((resourceBlockModelImpl.getColumnBitmask() &
397 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N.getColumnBitmask()) != 0) {
398 Object[] args = new Object[] {
399 Long.valueOf(resourceBlockModelImpl.getOriginalCompanyId()),
400
401 resourceBlockModelImpl.getOriginalName()
402 };
403
404 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N, args);
405 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N,
406 args);
407
408 args = new Object[] {
409 Long.valueOf(resourceBlockModelImpl.getCompanyId()),
410
411 resourceBlockModelImpl.getName()
412 };
413
414 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N, args);
415 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N,
416 args);
417 }
418
419 if ((resourceBlockModelImpl.getColumnBitmask() &
420 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_G_N.getColumnBitmask()) != 0) {
421 Object[] args = new Object[] {
422 Long.valueOf(resourceBlockModelImpl.getOriginalCompanyId()),
423 Long.valueOf(resourceBlockModelImpl.getOriginalGroupId()),
424
425 resourceBlockModelImpl.getOriginalName()
426 };
427
428 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_G_N, args);
429 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_G_N,
430 args);
431
432 args = new Object[] {
433 Long.valueOf(resourceBlockModelImpl.getCompanyId()),
434 Long.valueOf(resourceBlockModelImpl.getGroupId()),
435
436 resourceBlockModelImpl.getName()
437 };
438
439 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_G_N, args);
440 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_G_N,
441 args);
442 }
443 }
444
445 EntityCacheUtil.putResult(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
446 ResourceBlockImpl.class, resourceBlock.getPrimaryKey(),
447 resourceBlock);
448
449 if (isNew) {
450 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_G_N_P,
451 new Object[] {
452 Long.valueOf(resourceBlock.getCompanyId()),
453 Long.valueOf(resourceBlock.getGroupId()),
454
455 resourceBlock.getName(),
456
457 resourceBlock.getPermissionsHash()
458 }, resourceBlock);
459 }
460 else {
461 if ((resourceBlockModelImpl.getColumnBitmask() &
462 FINDER_PATH_FETCH_BY_C_G_N_P.getColumnBitmask()) != 0) {
463 Object[] args = new Object[] {
464 Long.valueOf(resourceBlockModelImpl.getOriginalCompanyId()),
465 Long.valueOf(resourceBlockModelImpl.getOriginalGroupId()),
466
467 resourceBlockModelImpl.getOriginalName(),
468
469 resourceBlockModelImpl.getOriginalPermissionsHash()
470 };
471
472 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_G_N_P, args);
473
474 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_G_N_P, args);
475
476 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_G_N_P,
477 new Object[] {
478 Long.valueOf(resourceBlock.getCompanyId()),
479 Long.valueOf(resourceBlock.getGroupId()),
480
481 resourceBlock.getName(),
482
483 resourceBlock.getPermissionsHash()
484 }, resourceBlock);
485 }
486 }
487
488 return resourceBlock;
489 }
490
491 protected ResourceBlock toUnwrappedModel(ResourceBlock resourceBlock) {
492 if (resourceBlock instanceof ResourceBlockImpl) {
493 return resourceBlock;
494 }
495
496 ResourceBlockImpl resourceBlockImpl = new ResourceBlockImpl();
497
498 resourceBlockImpl.setNew(resourceBlock.isNew());
499 resourceBlockImpl.setPrimaryKey(resourceBlock.getPrimaryKey());
500
501 resourceBlockImpl.setResourceBlockId(resourceBlock.getResourceBlockId());
502 resourceBlockImpl.setCompanyId(resourceBlock.getCompanyId());
503 resourceBlockImpl.setGroupId(resourceBlock.getGroupId());
504 resourceBlockImpl.setName(resourceBlock.getName());
505 resourceBlockImpl.setPermissionsHash(resourceBlock.getPermissionsHash());
506 resourceBlockImpl.setReferenceCount(resourceBlock.getReferenceCount());
507
508 return resourceBlockImpl;
509 }
510
511
519 @Override
520 public ResourceBlock findByPrimaryKey(Serializable primaryKey)
521 throws NoSuchModelException, SystemException {
522 return findByPrimaryKey(((Long)primaryKey).longValue());
523 }
524
525
533 public ResourceBlock findByPrimaryKey(long resourceBlockId)
534 throws NoSuchResourceBlockException, SystemException {
535 ResourceBlock resourceBlock = fetchByPrimaryKey(resourceBlockId);
536
537 if (resourceBlock == null) {
538 if (_log.isWarnEnabled()) {
539 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + resourceBlockId);
540 }
541
542 throw new NoSuchResourceBlockException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
543 resourceBlockId);
544 }
545
546 return resourceBlock;
547 }
548
549
556 @Override
557 public ResourceBlock fetchByPrimaryKey(Serializable primaryKey)
558 throws SystemException {
559 return fetchByPrimaryKey(((Long)primaryKey).longValue());
560 }
561
562
569 public ResourceBlock fetchByPrimaryKey(long resourceBlockId)
570 throws SystemException {
571 ResourceBlock resourceBlock = (ResourceBlock)EntityCacheUtil.getResult(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
572 ResourceBlockImpl.class, resourceBlockId);
573
574 if (resourceBlock == _nullResourceBlock) {
575 return null;
576 }
577
578 if (resourceBlock == null) {
579 Session session = null;
580
581 boolean hasException = false;
582
583 try {
584 session = openSession();
585
586 resourceBlock = (ResourceBlock)session.get(ResourceBlockImpl.class,
587 Long.valueOf(resourceBlockId));
588 }
589 catch (Exception e) {
590 hasException = true;
591
592 throw processException(e);
593 }
594 finally {
595 if (resourceBlock != null) {
596 cacheResult(resourceBlock);
597 }
598 else if (!hasException) {
599 EntityCacheUtil.putResult(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
600 ResourceBlockImpl.class, resourceBlockId,
601 _nullResourceBlock);
602 }
603
604 closeSession(session);
605 }
606 }
607
608 return resourceBlock;
609 }
610
611
619 public List<ResourceBlock> findByC_N(long companyId, String name)
620 throws SystemException {
621 return findByC_N(companyId, name, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
622 null);
623 }
624
625
639 public List<ResourceBlock> findByC_N(long companyId, String name,
640 int start, int end) throws SystemException {
641 return findByC_N(companyId, name, start, end, null);
642 }
643
644
659 public List<ResourceBlock> findByC_N(long companyId, String name,
660 int start, int end, OrderByComparator orderByComparator)
661 throws SystemException {
662 FinderPath finderPath = null;
663 Object[] finderArgs = null;
664
665 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
666 (orderByComparator == null)) {
667 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N;
668 finderArgs = new Object[] { companyId, name };
669 }
670 else {
671 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_N;
672 finderArgs = new Object[] {
673 companyId, name,
674
675 start, end, orderByComparator
676 };
677 }
678
679 List<ResourceBlock> list = (List<ResourceBlock>)FinderCacheUtil.getResult(finderPath,
680 finderArgs, this);
681
682 if ((list != null) && !list.isEmpty()) {
683 for (ResourceBlock resourceBlock : list) {
684 if ((companyId != resourceBlock.getCompanyId()) ||
685 !Validator.equals(name, resourceBlock.getName())) {
686 list = null;
687
688 break;
689 }
690 }
691 }
692
693 if (list == null) {
694 StringBundler query = null;
695
696 if (orderByComparator != null) {
697 query = new StringBundler(4 +
698 (orderByComparator.getOrderByFields().length * 3));
699 }
700 else {
701 query = new StringBundler(3);
702 }
703
704 query.append(_SQL_SELECT_RESOURCEBLOCK_WHERE);
705
706 query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
707
708 if (name == null) {
709 query.append(_FINDER_COLUMN_C_N_NAME_1);
710 }
711 else {
712 if (name.equals(StringPool.BLANK)) {
713 query.append(_FINDER_COLUMN_C_N_NAME_3);
714 }
715 else {
716 query.append(_FINDER_COLUMN_C_N_NAME_2);
717 }
718 }
719
720 if (orderByComparator != null) {
721 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
722 orderByComparator);
723 }
724
725 String sql = query.toString();
726
727 Session session = null;
728
729 try {
730 session = openSession();
731
732 Query q = session.createQuery(sql);
733
734 QueryPos qPos = QueryPos.getInstance(q);
735
736 qPos.add(companyId);
737
738 if (name != null) {
739 qPos.add(name);
740 }
741
742 list = (List<ResourceBlock>)QueryUtil.list(q, getDialect(),
743 start, end);
744 }
745 catch (Exception e) {
746 throw processException(e);
747 }
748 finally {
749 if (list == null) {
750 FinderCacheUtil.removeResult(finderPath, finderArgs);
751 }
752 else {
753 cacheResult(list);
754
755 FinderCacheUtil.putResult(finderPath, finderArgs, list);
756 }
757
758 closeSession(session);
759 }
760 }
761
762 return list;
763 }
764
765
775 public ResourceBlock findByC_N_First(long companyId, String name,
776 OrderByComparator orderByComparator)
777 throws NoSuchResourceBlockException, SystemException {
778 ResourceBlock resourceBlock = fetchByC_N_First(companyId, name,
779 orderByComparator);
780
781 if (resourceBlock != null) {
782 return resourceBlock;
783 }
784
785 StringBundler msg = new StringBundler(6);
786
787 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
788
789 msg.append("companyId=");
790 msg.append(companyId);
791
792 msg.append(", name=");
793 msg.append(name);
794
795 msg.append(StringPool.CLOSE_CURLY_BRACE);
796
797 throw new NoSuchResourceBlockException(msg.toString());
798 }
799
800
809 public ResourceBlock fetchByC_N_First(long companyId, String name,
810 OrderByComparator orderByComparator) throws SystemException {
811 List<ResourceBlock> list = findByC_N(companyId, name, 0, 1,
812 orderByComparator);
813
814 if (!list.isEmpty()) {
815 return list.get(0);
816 }
817
818 return null;
819 }
820
821
831 public ResourceBlock findByC_N_Last(long companyId, String name,
832 OrderByComparator orderByComparator)
833 throws NoSuchResourceBlockException, SystemException {
834 ResourceBlock resourceBlock = fetchByC_N_Last(companyId, name,
835 orderByComparator);
836
837 if (resourceBlock != null) {
838 return resourceBlock;
839 }
840
841 StringBundler msg = new StringBundler(6);
842
843 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
844
845 msg.append("companyId=");
846 msg.append(companyId);
847
848 msg.append(", name=");
849 msg.append(name);
850
851 msg.append(StringPool.CLOSE_CURLY_BRACE);
852
853 throw new NoSuchResourceBlockException(msg.toString());
854 }
855
856
865 public ResourceBlock fetchByC_N_Last(long companyId, String name,
866 OrderByComparator orderByComparator) throws SystemException {
867 int count = countByC_N(companyId, name);
868
869 List<ResourceBlock> list = findByC_N(companyId, name, count - 1, count,
870 orderByComparator);
871
872 if (!list.isEmpty()) {
873 return list.get(0);
874 }
875
876 return null;
877 }
878
879
890 public ResourceBlock[] findByC_N_PrevAndNext(long resourceBlockId,
891 long companyId, String name, OrderByComparator orderByComparator)
892 throws NoSuchResourceBlockException, SystemException {
893 ResourceBlock resourceBlock = findByPrimaryKey(resourceBlockId);
894
895 Session session = null;
896
897 try {
898 session = openSession();
899
900 ResourceBlock[] array = new ResourceBlockImpl[3];
901
902 array[0] = getByC_N_PrevAndNext(session, resourceBlock, companyId,
903 name, orderByComparator, true);
904
905 array[1] = resourceBlock;
906
907 array[2] = getByC_N_PrevAndNext(session, resourceBlock, companyId,
908 name, orderByComparator, false);
909
910 return array;
911 }
912 catch (Exception e) {
913 throw processException(e);
914 }
915 finally {
916 closeSession(session);
917 }
918 }
919
920 protected ResourceBlock getByC_N_PrevAndNext(Session session,
921 ResourceBlock resourceBlock, long companyId, String name,
922 OrderByComparator orderByComparator, boolean previous) {
923 StringBundler query = null;
924
925 if (orderByComparator != null) {
926 query = new StringBundler(6 +
927 (orderByComparator.getOrderByFields().length * 6));
928 }
929 else {
930 query = new StringBundler(3);
931 }
932
933 query.append(_SQL_SELECT_RESOURCEBLOCK_WHERE);
934
935 query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
936
937 if (name == null) {
938 query.append(_FINDER_COLUMN_C_N_NAME_1);
939 }
940 else {
941 if (name.equals(StringPool.BLANK)) {
942 query.append(_FINDER_COLUMN_C_N_NAME_3);
943 }
944 else {
945 query.append(_FINDER_COLUMN_C_N_NAME_2);
946 }
947 }
948
949 if (orderByComparator != null) {
950 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
951
952 if (orderByConditionFields.length > 0) {
953 query.append(WHERE_AND);
954 }
955
956 for (int i = 0; i < orderByConditionFields.length; i++) {
957 query.append(_ORDER_BY_ENTITY_ALIAS);
958 query.append(orderByConditionFields[i]);
959
960 if ((i + 1) < orderByConditionFields.length) {
961 if (orderByComparator.isAscending() ^ previous) {
962 query.append(WHERE_GREATER_THAN_HAS_NEXT);
963 }
964 else {
965 query.append(WHERE_LESSER_THAN_HAS_NEXT);
966 }
967 }
968 else {
969 if (orderByComparator.isAscending() ^ previous) {
970 query.append(WHERE_GREATER_THAN);
971 }
972 else {
973 query.append(WHERE_LESSER_THAN);
974 }
975 }
976 }
977
978 query.append(ORDER_BY_CLAUSE);
979
980 String[] orderByFields = orderByComparator.getOrderByFields();
981
982 for (int i = 0; i < orderByFields.length; i++) {
983 query.append(_ORDER_BY_ENTITY_ALIAS);
984 query.append(orderByFields[i]);
985
986 if ((i + 1) < orderByFields.length) {
987 if (orderByComparator.isAscending() ^ previous) {
988 query.append(ORDER_BY_ASC_HAS_NEXT);
989 }
990 else {
991 query.append(ORDER_BY_DESC_HAS_NEXT);
992 }
993 }
994 else {
995 if (orderByComparator.isAscending() ^ previous) {
996 query.append(ORDER_BY_ASC);
997 }
998 else {
999 query.append(ORDER_BY_DESC);
1000 }
1001 }
1002 }
1003 }
1004
1005 String sql = query.toString();
1006
1007 Query q = session.createQuery(sql);
1008
1009 q.setFirstResult(0);
1010 q.setMaxResults(2);
1011
1012 QueryPos qPos = QueryPos.getInstance(q);
1013
1014 qPos.add(companyId);
1015
1016 if (name != null) {
1017 qPos.add(name);
1018 }
1019
1020 if (orderByComparator != null) {
1021 Object[] values = orderByComparator.getOrderByConditionValues(resourceBlock);
1022
1023 for (Object value : values) {
1024 qPos.add(value);
1025 }
1026 }
1027
1028 List<ResourceBlock> list = q.list();
1029
1030 if (list.size() == 2) {
1031 return list.get(1);
1032 }
1033 else {
1034 return null;
1035 }
1036 }
1037
1038
1047 public List<ResourceBlock> findByC_G_N(long companyId, long groupId,
1048 String name) throws SystemException {
1049 return findByC_G_N(companyId, groupId, name, QueryUtil.ALL_POS,
1050 QueryUtil.ALL_POS, null);
1051 }
1052
1053
1068 public List<ResourceBlock> findByC_G_N(long companyId, long groupId,
1069 String name, int start, int end) throws SystemException {
1070 return findByC_G_N(companyId, groupId, name, start, end, null);
1071 }
1072
1073
1089 public List<ResourceBlock> findByC_G_N(long companyId, long groupId,
1090 String name, int start, int end, OrderByComparator orderByComparator)
1091 throws SystemException {
1092 FinderPath finderPath = null;
1093 Object[] finderArgs = null;
1094
1095 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1096 (orderByComparator == null)) {
1097 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_G_N;
1098 finderArgs = new Object[] { companyId, groupId, name };
1099 }
1100 else {
1101 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_G_N;
1102 finderArgs = new Object[] {
1103 companyId, groupId, name,
1104
1105 start, end, orderByComparator
1106 };
1107 }
1108
1109 List<ResourceBlock> list = (List<ResourceBlock>)FinderCacheUtil.getResult(finderPath,
1110 finderArgs, this);
1111
1112 if ((list != null) && !list.isEmpty()) {
1113 for (ResourceBlock resourceBlock : list) {
1114 if ((companyId != resourceBlock.getCompanyId()) ||
1115 (groupId != resourceBlock.getGroupId()) ||
1116 !Validator.equals(name, resourceBlock.getName())) {
1117 list = null;
1118
1119 break;
1120 }
1121 }
1122 }
1123
1124 if (list == null) {
1125 StringBundler query = null;
1126
1127 if (orderByComparator != null) {
1128 query = new StringBundler(5 +
1129 (orderByComparator.getOrderByFields().length * 3));
1130 }
1131 else {
1132 query = new StringBundler(4);
1133 }
1134
1135 query.append(_SQL_SELECT_RESOURCEBLOCK_WHERE);
1136
1137 query.append(_FINDER_COLUMN_C_G_N_COMPANYID_2);
1138
1139 query.append(_FINDER_COLUMN_C_G_N_GROUPID_2);
1140
1141 if (name == null) {
1142 query.append(_FINDER_COLUMN_C_G_N_NAME_1);
1143 }
1144 else {
1145 if (name.equals(StringPool.BLANK)) {
1146 query.append(_FINDER_COLUMN_C_G_N_NAME_3);
1147 }
1148 else {
1149 query.append(_FINDER_COLUMN_C_G_N_NAME_2);
1150 }
1151 }
1152
1153 if (orderByComparator != null) {
1154 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1155 orderByComparator);
1156 }
1157
1158 String sql = query.toString();
1159
1160 Session session = null;
1161
1162 try {
1163 session = openSession();
1164
1165 Query q = session.createQuery(sql);
1166
1167 QueryPos qPos = QueryPos.getInstance(q);
1168
1169 qPos.add(companyId);
1170
1171 qPos.add(groupId);
1172
1173 if (name != null) {
1174 qPos.add(name);
1175 }
1176
1177 list = (List<ResourceBlock>)QueryUtil.list(q, getDialect(),
1178 start, end);
1179 }
1180 catch (Exception e) {
1181 throw processException(e);
1182 }
1183 finally {
1184 if (list == null) {
1185 FinderCacheUtil.removeResult(finderPath, finderArgs);
1186 }
1187 else {
1188 cacheResult(list);
1189
1190 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1191 }
1192
1193 closeSession(session);
1194 }
1195 }
1196
1197 return list;
1198 }
1199
1200
1211 public ResourceBlock findByC_G_N_First(long companyId, long groupId,
1212 String name, OrderByComparator orderByComparator)
1213 throws NoSuchResourceBlockException, SystemException {
1214 ResourceBlock resourceBlock = fetchByC_G_N_First(companyId, groupId,
1215 name, orderByComparator);
1216
1217 if (resourceBlock != null) {
1218 return resourceBlock;
1219 }
1220
1221 StringBundler msg = new StringBundler(8);
1222
1223 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1224
1225 msg.append("companyId=");
1226 msg.append(companyId);
1227
1228 msg.append(", groupId=");
1229 msg.append(groupId);
1230
1231 msg.append(", name=");
1232 msg.append(name);
1233
1234 msg.append(StringPool.CLOSE_CURLY_BRACE);
1235
1236 throw new NoSuchResourceBlockException(msg.toString());
1237 }
1238
1239
1249 public ResourceBlock fetchByC_G_N_First(long companyId, long groupId,
1250 String name, OrderByComparator orderByComparator)
1251 throws SystemException {
1252 List<ResourceBlock> list = findByC_G_N(companyId, groupId, name, 0, 1,
1253 orderByComparator);
1254
1255 if (!list.isEmpty()) {
1256 return list.get(0);
1257 }
1258
1259 return null;
1260 }
1261
1262
1273 public ResourceBlock findByC_G_N_Last(long companyId, long groupId,
1274 String name, OrderByComparator orderByComparator)
1275 throws NoSuchResourceBlockException, SystemException {
1276 ResourceBlock resourceBlock = fetchByC_G_N_Last(companyId, groupId,
1277 name, orderByComparator);
1278
1279 if (resourceBlock != null) {
1280 return resourceBlock;
1281 }
1282
1283 StringBundler msg = new StringBundler(8);
1284
1285 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1286
1287 msg.append("companyId=");
1288 msg.append(companyId);
1289
1290 msg.append(", groupId=");
1291 msg.append(groupId);
1292
1293 msg.append(", name=");
1294 msg.append(name);
1295
1296 msg.append(StringPool.CLOSE_CURLY_BRACE);
1297
1298 throw new NoSuchResourceBlockException(msg.toString());
1299 }
1300
1301
1311 public ResourceBlock fetchByC_G_N_Last(long companyId, long groupId,
1312 String name, OrderByComparator orderByComparator)
1313 throws SystemException {
1314 int count = countByC_G_N(companyId, groupId, name);
1315
1316 List<ResourceBlock> list = findByC_G_N(companyId, groupId, name,
1317 count - 1, count, orderByComparator);
1318
1319 if (!list.isEmpty()) {
1320 return list.get(0);
1321 }
1322
1323 return null;
1324 }
1325
1326
1338 public ResourceBlock[] findByC_G_N_PrevAndNext(long resourceBlockId,
1339 long companyId, long groupId, String name,
1340 OrderByComparator orderByComparator)
1341 throws NoSuchResourceBlockException, SystemException {
1342 ResourceBlock resourceBlock = findByPrimaryKey(resourceBlockId);
1343
1344 Session session = null;
1345
1346 try {
1347 session = openSession();
1348
1349 ResourceBlock[] array = new ResourceBlockImpl[3];
1350
1351 array[0] = getByC_G_N_PrevAndNext(session, resourceBlock,
1352 companyId, groupId, name, orderByComparator, true);
1353
1354 array[1] = resourceBlock;
1355
1356 array[2] = getByC_G_N_PrevAndNext(session, resourceBlock,
1357 companyId, groupId, name, orderByComparator, false);
1358
1359 return array;
1360 }
1361 catch (Exception e) {
1362 throw processException(e);
1363 }
1364 finally {
1365 closeSession(session);
1366 }
1367 }
1368
1369 protected ResourceBlock getByC_G_N_PrevAndNext(Session session,
1370 ResourceBlock resourceBlock, long companyId, long groupId, String name,
1371 OrderByComparator orderByComparator, boolean previous) {
1372 StringBundler query = null;
1373
1374 if (orderByComparator != null) {
1375 query = new StringBundler(6 +
1376 (orderByComparator.getOrderByFields().length * 6));
1377 }
1378 else {
1379 query = new StringBundler(3);
1380 }
1381
1382 query.append(_SQL_SELECT_RESOURCEBLOCK_WHERE);
1383
1384 query.append(_FINDER_COLUMN_C_G_N_COMPANYID_2);
1385
1386 query.append(_FINDER_COLUMN_C_G_N_GROUPID_2);
1387
1388 if (name == null) {
1389 query.append(_FINDER_COLUMN_C_G_N_NAME_1);
1390 }
1391 else {
1392 if (name.equals(StringPool.BLANK)) {
1393 query.append(_FINDER_COLUMN_C_G_N_NAME_3);
1394 }
1395 else {
1396 query.append(_FINDER_COLUMN_C_G_N_NAME_2);
1397 }
1398 }
1399
1400 if (orderByComparator != null) {
1401 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1402
1403 if (orderByConditionFields.length > 0) {
1404 query.append(WHERE_AND);
1405 }
1406
1407 for (int i = 0; i < orderByConditionFields.length; i++) {
1408 query.append(_ORDER_BY_ENTITY_ALIAS);
1409 query.append(orderByConditionFields[i]);
1410
1411 if ((i + 1) < orderByConditionFields.length) {
1412 if (orderByComparator.isAscending() ^ previous) {
1413 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1414 }
1415 else {
1416 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1417 }
1418 }
1419 else {
1420 if (orderByComparator.isAscending() ^ previous) {
1421 query.append(WHERE_GREATER_THAN);
1422 }
1423 else {
1424 query.append(WHERE_LESSER_THAN);
1425 }
1426 }
1427 }
1428
1429 query.append(ORDER_BY_CLAUSE);
1430
1431 String[] orderByFields = orderByComparator.getOrderByFields();
1432
1433 for (int i = 0; i < orderByFields.length; i++) {
1434 query.append(_ORDER_BY_ENTITY_ALIAS);
1435 query.append(orderByFields[i]);
1436
1437 if ((i + 1) < orderByFields.length) {
1438 if (orderByComparator.isAscending() ^ previous) {
1439 query.append(ORDER_BY_ASC_HAS_NEXT);
1440 }
1441 else {
1442 query.append(ORDER_BY_DESC_HAS_NEXT);
1443 }
1444 }
1445 else {
1446 if (orderByComparator.isAscending() ^ previous) {
1447 query.append(ORDER_BY_ASC);
1448 }
1449 else {
1450 query.append(ORDER_BY_DESC);
1451 }
1452 }
1453 }
1454 }
1455
1456 String sql = query.toString();
1457
1458 Query q = session.createQuery(sql);
1459
1460 q.setFirstResult(0);
1461 q.setMaxResults(2);
1462
1463 QueryPos qPos = QueryPos.getInstance(q);
1464
1465 qPos.add(companyId);
1466
1467 qPos.add(groupId);
1468
1469 if (name != null) {
1470 qPos.add(name);
1471 }
1472
1473 if (orderByComparator != null) {
1474 Object[] values = orderByComparator.getOrderByConditionValues(resourceBlock);
1475
1476 for (Object value : values) {
1477 qPos.add(value);
1478 }
1479 }
1480
1481 List<ResourceBlock> list = q.list();
1482
1483 if (list.size() == 2) {
1484 return list.get(1);
1485 }
1486 else {
1487 return null;
1488 }
1489 }
1490
1491
1502 public ResourceBlock findByC_G_N_P(long companyId, long groupId,
1503 String name, String permissionsHash)
1504 throws NoSuchResourceBlockException, SystemException {
1505 ResourceBlock resourceBlock = fetchByC_G_N_P(companyId, groupId, name,
1506 permissionsHash);
1507
1508 if (resourceBlock == null) {
1509 StringBundler msg = new StringBundler(10);
1510
1511 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1512
1513 msg.append("companyId=");
1514 msg.append(companyId);
1515
1516 msg.append(", groupId=");
1517 msg.append(groupId);
1518
1519 msg.append(", name=");
1520 msg.append(name);
1521
1522 msg.append(", permissionsHash=");
1523 msg.append(permissionsHash);
1524
1525 msg.append(StringPool.CLOSE_CURLY_BRACE);
1526
1527 if (_log.isWarnEnabled()) {
1528 _log.warn(msg.toString());
1529 }
1530
1531 throw new NoSuchResourceBlockException(msg.toString());
1532 }
1533
1534 return resourceBlock;
1535 }
1536
1537
1547 public ResourceBlock fetchByC_G_N_P(long companyId, long groupId,
1548 String name, String permissionsHash) throws SystemException {
1549 return fetchByC_G_N_P(companyId, groupId, name, permissionsHash, true);
1550 }
1551
1552
1563 public ResourceBlock fetchByC_G_N_P(long companyId, long groupId,
1564 String name, String permissionsHash, boolean retrieveFromCache)
1565 throws SystemException {
1566 Object[] finderArgs = new Object[] {
1567 companyId, groupId, name, permissionsHash
1568 };
1569
1570 Object result = null;
1571
1572 if (retrieveFromCache) {
1573 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_G_N_P,
1574 finderArgs, this);
1575 }
1576
1577 if (result instanceof ResourceBlock) {
1578 ResourceBlock resourceBlock = (ResourceBlock)result;
1579
1580 if ((companyId != resourceBlock.getCompanyId()) ||
1581 (groupId != resourceBlock.getGroupId()) ||
1582 !Validator.equals(name, resourceBlock.getName()) ||
1583 !Validator.equals(permissionsHash,
1584 resourceBlock.getPermissionsHash())) {
1585 result = null;
1586 }
1587 }
1588
1589 if (result == null) {
1590 StringBundler query = new StringBundler(5);
1591
1592 query.append(_SQL_SELECT_RESOURCEBLOCK_WHERE);
1593
1594 query.append(_FINDER_COLUMN_C_G_N_P_COMPANYID_2);
1595
1596 query.append(_FINDER_COLUMN_C_G_N_P_GROUPID_2);
1597
1598 if (name == null) {
1599 query.append(_FINDER_COLUMN_C_G_N_P_NAME_1);
1600 }
1601 else {
1602 if (name.equals(StringPool.BLANK)) {
1603 query.append(_FINDER_COLUMN_C_G_N_P_NAME_3);
1604 }
1605 else {
1606 query.append(_FINDER_COLUMN_C_G_N_P_NAME_2);
1607 }
1608 }
1609
1610 if (permissionsHash == null) {
1611 query.append(_FINDER_COLUMN_C_G_N_P_PERMISSIONSHASH_1);
1612 }
1613 else {
1614 if (permissionsHash.equals(StringPool.BLANK)) {
1615 query.append(_FINDER_COLUMN_C_G_N_P_PERMISSIONSHASH_3);
1616 }
1617 else {
1618 query.append(_FINDER_COLUMN_C_G_N_P_PERMISSIONSHASH_2);
1619 }
1620 }
1621
1622 String sql = query.toString();
1623
1624 Session session = null;
1625
1626 try {
1627 session = openSession();
1628
1629 Query q = session.createQuery(sql);
1630
1631 QueryPos qPos = QueryPos.getInstance(q);
1632
1633 qPos.add(companyId);
1634
1635 qPos.add(groupId);
1636
1637 if (name != null) {
1638 qPos.add(name);
1639 }
1640
1641 if (permissionsHash != null) {
1642 qPos.add(permissionsHash);
1643 }
1644
1645 List<ResourceBlock> list = q.list();
1646
1647 result = list;
1648
1649 ResourceBlock resourceBlock = null;
1650
1651 if (list.isEmpty()) {
1652 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_G_N_P,
1653 finderArgs, list);
1654 }
1655 else {
1656 resourceBlock = list.get(0);
1657
1658 cacheResult(resourceBlock);
1659
1660 if ((resourceBlock.getCompanyId() != companyId) ||
1661 (resourceBlock.getGroupId() != groupId) ||
1662 (resourceBlock.getName() == null) ||
1663 !resourceBlock.getName().equals(name) ||
1664 (resourceBlock.getPermissionsHash() == null) ||
1665 !resourceBlock.getPermissionsHash()
1666 .equals(permissionsHash)) {
1667 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_G_N_P,
1668 finderArgs, resourceBlock);
1669 }
1670 }
1671
1672 return resourceBlock;
1673 }
1674 catch (Exception e) {
1675 throw processException(e);
1676 }
1677 finally {
1678 if (result == null) {
1679 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_G_N_P,
1680 finderArgs);
1681 }
1682
1683 closeSession(session);
1684 }
1685 }
1686 else {
1687 if (result instanceof List<?>) {
1688 return null;
1689 }
1690 else {
1691 return (ResourceBlock)result;
1692 }
1693 }
1694 }
1695
1696
1702 public List<ResourceBlock> findAll() throws SystemException {
1703 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1704 }
1705
1706
1718 public List<ResourceBlock> findAll(int start, int end)
1719 throws SystemException {
1720 return findAll(start, end, null);
1721 }
1722
1723
1736 public List<ResourceBlock> findAll(int start, int end,
1737 OrderByComparator orderByComparator) throws SystemException {
1738 FinderPath finderPath = null;
1739 Object[] finderArgs = new Object[] { start, end, orderByComparator };
1740
1741 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1742 (orderByComparator == null)) {
1743 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1744 finderArgs = FINDER_ARGS_EMPTY;
1745 }
1746 else {
1747 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1748 finderArgs = new Object[] { start, end, orderByComparator };
1749 }
1750
1751 List<ResourceBlock> list = (List<ResourceBlock>)FinderCacheUtil.getResult(finderPath,
1752 finderArgs, this);
1753
1754 if (list == null) {
1755 StringBundler query = null;
1756 String sql = null;
1757
1758 if (orderByComparator != null) {
1759 query = new StringBundler(2 +
1760 (orderByComparator.getOrderByFields().length * 3));
1761
1762 query.append(_SQL_SELECT_RESOURCEBLOCK);
1763
1764 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1765 orderByComparator);
1766
1767 sql = query.toString();
1768 }
1769 else {
1770 sql = _SQL_SELECT_RESOURCEBLOCK;
1771 }
1772
1773 Session session = null;
1774
1775 try {
1776 session = openSession();
1777
1778 Query q = session.createQuery(sql);
1779
1780 if (orderByComparator == null) {
1781 list = (List<ResourceBlock>)QueryUtil.list(q, getDialect(),
1782 start, end, false);
1783
1784 Collections.sort(list);
1785 }
1786 else {
1787 list = (List<ResourceBlock>)QueryUtil.list(q, getDialect(),
1788 start, end);
1789 }
1790 }
1791 catch (Exception e) {
1792 throw processException(e);
1793 }
1794 finally {
1795 if (list == null) {
1796 FinderCacheUtil.removeResult(finderPath, finderArgs);
1797 }
1798 else {
1799 cacheResult(list);
1800
1801 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1802 }
1803
1804 closeSession(session);
1805 }
1806 }
1807
1808 return list;
1809 }
1810
1811
1818 public void removeByC_N(long companyId, String name)
1819 throws SystemException {
1820 for (ResourceBlock resourceBlock : findByC_N(companyId, name)) {
1821 remove(resourceBlock);
1822 }
1823 }
1824
1825
1833 public void removeByC_G_N(long companyId, long groupId, String name)
1834 throws SystemException {
1835 for (ResourceBlock resourceBlock : findByC_G_N(companyId, groupId, name)) {
1836 remove(resourceBlock);
1837 }
1838 }
1839
1840
1850 public ResourceBlock removeByC_G_N_P(long companyId, long groupId,
1851 String name, String permissionsHash)
1852 throws NoSuchResourceBlockException, SystemException {
1853 ResourceBlock resourceBlock = findByC_G_N_P(companyId, groupId, name,
1854 permissionsHash);
1855
1856 return remove(resourceBlock);
1857 }
1858
1859
1864 public void removeAll() throws SystemException {
1865 for (ResourceBlock resourceBlock : findAll()) {
1866 remove(resourceBlock);
1867 }
1868 }
1869
1870
1878 public int countByC_N(long companyId, String name)
1879 throws SystemException {
1880 Object[] finderArgs = new Object[] { companyId, name };
1881
1882 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_N,
1883 finderArgs, this);
1884
1885 if (count == null) {
1886 StringBundler query = new StringBundler(3);
1887
1888 query.append(_SQL_COUNT_RESOURCEBLOCK_WHERE);
1889
1890 query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
1891
1892 if (name == null) {
1893 query.append(_FINDER_COLUMN_C_N_NAME_1);
1894 }
1895 else {
1896 if (name.equals(StringPool.BLANK)) {
1897 query.append(_FINDER_COLUMN_C_N_NAME_3);
1898 }
1899 else {
1900 query.append(_FINDER_COLUMN_C_N_NAME_2);
1901 }
1902 }
1903
1904 String sql = query.toString();
1905
1906 Session session = null;
1907
1908 try {
1909 session = openSession();
1910
1911 Query q = session.createQuery(sql);
1912
1913 QueryPos qPos = QueryPos.getInstance(q);
1914
1915 qPos.add(companyId);
1916
1917 if (name != null) {
1918 qPos.add(name);
1919 }
1920
1921 count = (Long)q.uniqueResult();
1922 }
1923 catch (Exception e) {
1924 throw processException(e);
1925 }
1926 finally {
1927 if (count == null) {
1928 count = Long.valueOf(0);
1929 }
1930
1931 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N, finderArgs,
1932 count);
1933
1934 closeSession(session);
1935 }
1936 }
1937
1938 return count.intValue();
1939 }
1940
1941
1950 public int countByC_G_N(long companyId, long groupId, String name)
1951 throws SystemException {
1952 Object[] finderArgs = new Object[] { companyId, groupId, name };
1953
1954 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_G_N,
1955 finderArgs, this);
1956
1957 if (count == null) {
1958 StringBundler query = new StringBundler(4);
1959
1960 query.append(_SQL_COUNT_RESOURCEBLOCK_WHERE);
1961
1962 query.append(_FINDER_COLUMN_C_G_N_COMPANYID_2);
1963
1964 query.append(_FINDER_COLUMN_C_G_N_GROUPID_2);
1965
1966 if (name == null) {
1967 query.append(_FINDER_COLUMN_C_G_N_NAME_1);
1968 }
1969 else {
1970 if (name.equals(StringPool.BLANK)) {
1971 query.append(_FINDER_COLUMN_C_G_N_NAME_3);
1972 }
1973 else {
1974 query.append(_FINDER_COLUMN_C_G_N_NAME_2);
1975 }
1976 }
1977
1978 String sql = query.toString();
1979
1980 Session session = null;
1981
1982 try {
1983 session = openSession();
1984
1985 Query q = session.createQuery(sql);
1986
1987 QueryPos qPos = QueryPos.getInstance(q);
1988
1989 qPos.add(companyId);
1990
1991 qPos.add(groupId);
1992
1993 if (name != null) {
1994 qPos.add(name);
1995 }
1996
1997 count = (Long)q.uniqueResult();
1998 }
1999 catch (Exception e) {
2000 throw processException(e);
2001 }
2002 finally {
2003 if (count == null) {
2004 count = Long.valueOf(0);
2005 }
2006
2007 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_G_N,
2008 finderArgs, count);
2009
2010 closeSession(session);
2011 }
2012 }
2013
2014 return count.intValue();
2015 }
2016
2017
2027 public int countByC_G_N_P(long companyId, long groupId, String name,
2028 String permissionsHash) throws SystemException {
2029 Object[] finderArgs = new Object[] {
2030 companyId, groupId, name, permissionsHash
2031 };
2032
2033 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_G_N_P,
2034 finderArgs, this);
2035
2036 if (count == null) {
2037 StringBundler query = new StringBundler(5);
2038
2039 query.append(_SQL_COUNT_RESOURCEBLOCK_WHERE);
2040
2041 query.append(_FINDER_COLUMN_C_G_N_P_COMPANYID_2);
2042
2043 query.append(_FINDER_COLUMN_C_G_N_P_GROUPID_2);
2044
2045 if (name == null) {
2046 query.append(_FINDER_COLUMN_C_G_N_P_NAME_1);
2047 }
2048 else {
2049 if (name.equals(StringPool.BLANK)) {
2050 query.append(_FINDER_COLUMN_C_G_N_P_NAME_3);
2051 }
2052 else {
2053 query.append(_FINDER_COLUMN_C_G_N_P_NAME_2);
2054 }
2055 }
2056
2057 if (permissionsHash == null) {
2058 query.append(_FINDER_COLUMN_C_G_N_P_PERMISSIONSHASH_1);
2059 }
2060 else {
2061 if (permissionsHash.equals(StringPool.BLANK)) {
2062 query.append(_FINDER_COLUMN_C_G_N_P_PERMISSIONSHASH_3);
2063 }
2064 else {
2065 query.append(_FINDER_COLUMN_C_G_N_P_PERMISSIONSHASH_2);
2066 }
2067 }
2068
2069 String sql = query.toString();
2070
2071 Session session = null;
2072
2073 try {
2074 session = openSession();
2075
2076 Query q = session.createQuery(sql);
2077
2078 QueryPos qPos = QueryPos.getInstance(q);
2079
2080 qPos.add(companyId);
2081
2082 qPos.add(groupId);
2083
2084 if (name != null) {
2085 qPos.add(name);
2086 }
2087
2088 if (permissionsHash != null) {
2089 qPos.add(permissionsHash);
2090 }
2091
2092 count = (Long)q.uniqueResult();
2093 }
2094 catch (Exception e) {
2095 throw processException(e);
2096 }
2097 finally {
2098 if (count == null) {
2099 count = Long.valueOf(0);
2100 }
2101
2102 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_G_N_P,
2103 finderArgs, count);
2104
2105 closeSession(session);
2106 }
2107 }
2108
2109 return count.intValue();
2110 }
2111
2112
2118 public int countAll() throws SystemException {
2119 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2120 FINDER_ARGS_EMPTY, this);
2121
2122 if (count == null) {
2123 Session session = null;
2124
2125 try {
2126 session = openSession();
2127
2128 Query q = session.createQuery(_SQL_COUNT_RESOURCEBLOCK);
2129
2130 count = (Long)q.uniqueResult();
2131 }
2132 catch (Exception e) {
2133 throw processException(e);
2134 }
2135 finally {
2136 if (count == null) {
2137 count = Long.valueOf(0);
2138 }
2139
2140 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2141 FINDER_ARGS_EMPTY, count);
2142
2143 closeSession(session);
2144 }
2145 }
2146
2147 return count.intValue();
2148 }
2149
2150
2153 public void afterPropertiesSet() {
2154 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2155 com.liferay.portal.util.PropsUtil.get(
2156 "value.object.listener.com.liferay.portal.model.ResourceBlock")));
2157
2158 if (listenerClassNames.length > 0) {
2159 try {
2160 List<ModelListener<ResourceBlock>> listenersList = new ArrayList<ModelListener<ResourceBlock>>();
2161
2162 for (String listenerClassName : listenerClassNames) {
2163 listenersList.add((ModelListener<ResourceBlock>)InstanceFactory.newInstance(
2164 listenerClassName));
2165 }
2166
2167 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2168 }
2169 catch (Exception e) {
2170 _log.error(e);
2171 }
2172 }
2173 }
2174
2175 public void destroy() {
2176 EntityCacheUtil.removeCache(ResourceBlockImpl.class.getName());
2177 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2178 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2179 }
2180
2181 @BeanReference(type = AccountPersistence.class)
2182 protected AccountPersistence accountPersistence;
2183 @BeanReference(type = AddressPersistence.class)
2184 protected AddressPersistence addressPersistence;
2185 @BeanReference(type = BrowserTrackerPersistence.class)
2186 protected BrowserTrackerPersistence browserTrackerPersistence;
2187 @BeanReference(type = ClassNamePersistence.class)
2188 protected ClassNamePersistence classNamePersistence;
2189 @BeanReference(type = ClusterGroupPersistence.class)
2190 protected ClusterGroupPersistence clusterGroupPersistence;
2191 @BeanReference(type = CompanyPersistence.class)
2192 protected CompanyPersistence companyPersistence;
2193 @BeanReference(type = ContactPersistence.class)
2194 protected ContactPersistence contactPersistence;
2195 @BeanReference(type = CountryPersistence.class)
2196 protected CountryPersistence countryPersistence;
2197 @BeanReference(type = EmailAddressPersistence.class)
2198 protected EmailAddressPersistence emailAddressPersistence;
2199 @BeanReference(type = GroupPersistence.class)
2200 protected GroupPersistence groupPersistence;
2201 @BeanReference(type = ImagePersistence.class)
2202 protected ImagePersistence imagePersistence;
2203 @BeanReference(type = LayoutPersistence.class)
2204 protected LayoutPersistence layoutPersistence;
2205 @BeanReference(type = LayoutBranchPersistence.class)
2206 protected LayoutBranchPersistence layoutBranchPersistence;
2207 @BeanReference(type = LayoutPrototypePersistence.class)
2208 protected LayoutPrototypePersistence layoutPrototypePersistence;
2209 @BeanReference(type = LayoutRevisionPersistence.class)
2210 protected LayoutRevisionPersistence layoutRevisionPersistence;
2211 @BeanReference(type = LayoutSetPersistence.class)
2212 protected LayoutSetPersistence layoutSetPersistence;
2213 @BeanReference(type = LayoutSetBranchPersistence.class)
2214 protected LayoutSetBranchPersistence layoutSetBranchPersistence;
2215 @BeanReference(type = LayoutSetPrototypePersistence.class)
2216 protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
2217 @BeanReference(type = ListTypePersistence.class)
2218 protected ListTypePersistence listTypePersistence;
2219 @BeanReference(type = LockPersistence.class)
2220 protected LockPersistence lockPersistence;
2221 @BeanReference(type = MembershipRequestPersistence.class)
2222 protected MembershipRequestPersistence membershipRequestPersistence;
2223 @BeanReference(type = OrganizationPersistence.class)
2224 protected OrganizationPersistence organizationPersistence;
2225 @BeanReference(type = OrgGroupRolePersistence.class)
2226 protected OrgGroupRolePersistence orgGroupRolePersistence;
2227 @BeanReference(type = OrgLaborPersistence.class)
2228 protected OrgLaborPersistence orgLaborPersistence;
2229 @BeanReference(type = PasswordPolicyPersistence.class)
2230 protected PasswordPolicyPersistence passwordPolicyPersistence;
2231 @BeanReference(type = PasswordPolicyRelPersistence.class)
2232 protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
2233 @BeanReference(type = PasswordTrackerPersistence.class)
2234 protected PasswordTrackerPersistence passwordTrackerPersistence;
2235 @BeanReference(type = PhonePersistence.class)
2236 protected PhonePersistence phonePersistence;
2237 @BeanReference(type = PluginSettingPersistence.class)
2238 protected PluginSettingPersistence pluginSettingPersistence;
2239 @BeanReference(type = PortalPreferencesPersistence.class)
2240 protected PortalPreferencesPersistence portalPreferencesPersistence;
2241 @BeanReference(type = PortletPersistence.class)
2242 protected PortletPersistence portletPersistence;
2243 @BeanReference(type = PortletItemPersistence.class)
2244 protected PortletItemPersistence portletItemPersistence;
2245 @BeanReference(type = PortletPreferencesPersistence.class)
2246 protected PortletPreferencesPersistence portletPreferencesPersistence;
2247 @BeanReference(type = RegionPersistence.class)
2248 protected RegionPersistence regionPersistence;
2249 @BeanReference(type = ReleasePersistence.class)
2250 protected ReleasePersistence releasePersistence;
2251 @BeanReference(type = RepositoryPersistence.class)
2252 protected RepositoryPersistence repositoryPersistence;
2253 @BeanReference(type = RepositoryEntryPersistence.class)
2254 protected RepositoryEntryPersistence repositoryEntryPersistence;
2255 @BeanReference(type = ResourceActionPersistence.class)
2256 protected ResourceActionPersistence resourceActionPersistence;
2257 @BeanReference(type = ResourceBlockPersistence.class)
2258 protected ResourceBlockPersistence resourceBlockPersistence;
2259 @BeanReference(type = ResourceBlockPermissionPersistence.class)
2260 protected ResourceBlockPermissionPersistence resourceBlockPermissionPersistence;
2261 @BeanReference(type = ResourcePermissionPersistence.class)
2262 protected ResourcePermissionPersistence resourcePermissionPersistence;
2263 @BeanReference(type = ResourceTypePermissionPersistence.class)
2264 protected ResourceTypePermissionPersistence resourceTypePermissionPersistence;
2265 @BeanReference(type = RolePersistence.class)
2266 protected RolePersistence rolePersistence;
2267 @BeanReference(type = ServiceComponentPersistence.class)
2268 protected ServiceComponentPersistence serviceComponentPersistence;
2269 @BeanReference(type = ShardPersistence.class)
2270 protected ShardPersistence shardPersistence;
2271 @BeanReference(type = SubscriptionPersistence.class)
2272 protected SubscriptionPersistence subscriptionPersistence;
2273 @BeanReference(type = TeamPersistence.class)
2274 protected TeamPersistence teamPersistence;
2275 @BeanReference(type = TicketPersistence.class)
2276 protected TicketPersistence ticketPersistence;
2277 @BeanReference(type = UserPersistence.class)
2278 protected UserPersistence userPersistence;
2279 @BeanReference(type = UserGroupPersistence.class)
2280 protected UserGroupPersistence userGroupPersistence;
2281 @BeanReference(type = UserGroupGroupRolePersistence.class)
2282 protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
2283 @BeanReference(type = UserGroupRolePersistence.class)
2284 protected UserGroupRolePersistence userGroupRolePersistence;
2285 @BeanReference(type = UserIdMapperPersistence.class)
2286 protected UserIdMapperPersistence userIdMapperPersistence;
2287 @BeanReference(type = UserNotificationEventPersistence.class)
2288 protected UserNotificationEventPersistence userNotificationEventPersistence;
2289 @BeanReference(type = UserTrackerPersistence.class)
2290 protected UserTrackerPersistence userTrackerPersistence;
2291 @BeanReference(type = UserTrackerPathPersistence.class)
2292 protected UserTrackerPathPersistence userTrackerPathPersistence;
2293 @BeanReference(type = VirtualHostPersistence.class)
2294 protected VirtualHostPersistence virtualHostPersistence;
2295 @BeanReference(type = WebDAVPropsPersistence.class)
2296 protected WebDAVPropsPersistence webDAVPropsPersistence;
2297 @BeanReference(type = WebsitePersistence.class)
2298 protected WebsitePersistence websitePersistence;
2299 @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
2300 protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
2301 @BeanReference(type = WorkflowInstanceLinkPersistence.class)
2302 protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
2303 private static final String _SQL_SELECT_RESOURCEBLOCK = "SELECT resourceBlock FROM ResourceBlock resourceBlock";
2304 private static final String _SQL_SELECT_RESOURCEBLOCK_WHERE = "SELECT resourceBlock FROM ResourceBlock resourceBlock WHERE ";
2305 private static final String _SQL_COUNT_RESOURCEBLOCK = "SELECT COUNT(resourceBlock) FROM ResourceBlock resourceBlock";
2306 private static final String _SQL_COUNT_RESOURCEBLOCK_WHERE = "SELECT COUNT(resourceBlock) FROM ResourceBlock resourceBlock WHERE ";
2307 private static final String _FINDER_COLUMN_C_N_COMPANYID_2 = "resourceBlock.companyId = ? AND ";
2308 private static final String _FINDER_COLUMN_C_N_NAME_1 = "resourceBlock.name IS NULL";
2309 private static final String _FINDER_COLUMN_C_N_NAME_2 = "resourceBlock.name = ?";
2310 private static final String _FINDER_COLUMN_C_N_NAME_3 = "(resourceBlock.name IS NULL OR resourceBlock.name = ?)";
2311 private static final String _FINDER_COLUMN_C_G_N_COMPANYID_2 = "resourceBlock.companyId = ? AND ";
2312 private static final String _FINDER_COLUMN_C_G_N_GROUPID_2 = "resourceBlock.groupId = ? AND ";
2313 private static final String _FINDER_COLUMN_C_G_N_NAME_1 = "resourceBlock.name IS NULL";
2314 private static final String _FINDER_COLUMN_C_G_N_NAME_2 = "resourceBlock.name = ?";
2315 private static final String _FINDER_COLUMN_C_G_N_NAME_3 = "(resourceBlock.name IS NULL OR resourceBlock.name = ?)";
2316 private static final String _FINDER_COLUMN_C_G_N_P_COMPANYID_2 = "resourceBlock.companyId = ? AND ";
2317 private static final String _FINDER_COLUMN_C_G_N_P_GROUPID_2 = "resourceBlock.groupId = ? AND ";
2318 private static final String _FINDER_COLUMN_C_G_N_P_NAME_1 = "resourceBlock.name IS NULL AND ";
2319 private static final String _FINDER_COLUMN_C_G_N_P_NAME_2 = "resourceBlock.name = ? AND ";
2320 private static final String _FINDER_COLUMN_C_G_N_P_NAME_3 = "(resourceBlock.name IS NULL OR resourceBlock.name = ?) AND ";
2321 private static final String _FINDER_COLUMN_C_G_N_P_PERMISSIONSHASH_1 = "resourceBlock.permissionsHash IS NULL";
2322 private static final String _FINDER_COLUMN_C_G_N_P_PERMISSIONSHASH_2 = "resourceBlock.permissionsHash = ?";
2323 private static final String _FINDER_COLUMN_C_G_N_P_PERMISSIONSHASH_3 = "(resourceBlock.permissionsHash IS NULL OR resourceBlock.permissionsHash = ?)";
2324 private static final String _ORDER_BY_ENTITY_ALIAS = "resourceBlock.";
2325 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ResourceBlock exists with the primary key ";
2326 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ResourceBlock exists with the key {";
2327 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2328 private static Log _log = LogFactoryUtil.getLog(ResourceBlockPersistenceImpl.class);
2329 private static ResourceBlock _nullResourceBlock = new ResourceBlockImpl() {
2330 @Override
2331 public Object clone() {
2332 return this;
2333 }
2334
2335 @Override
2336 public CacheModel<ResourceBlock> toCacheModel() {
2337 return _nullResourceBlockCacheModel;
2338 }
2339 };
2340
2341 private static CacheModel<ResourceBlock> _nullResourceBlockCacheModel = new CacheModel<ResourceBlock>() {
2342 public ResourceBlock toEntityModel() {
2343 return _nullResourceBlock;
2344 }
2345 };
2346 }