001
014
015 package com.liferay.portal.service.persistence;
016
017 import com.liferay.portal.NoSuchResourceBlockException;
018 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
019 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
020 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderPath;
022 import com.liferay.portal.kernel.dao.orm.Query;
023 import com.liferay.portal.kernel.dao.orm.QueryPos;
024 import com.liferay.portal.kernel.dao.orm.QueryUtil;
025 import com.liferay.portal.kernel.dao.orm.Session;
026 import com.liferay.portal.kernel.exception.SystemException;
027 import com.liferay.portal.kernel.log.Log;
028 import com.liferay.portal.kernel.log.LogFactoryUtil;
029 import com.liferay.portal.kernel.util.GetterUtil;
030 import com.liferay.portal.kernel.util.InstanceFactory;
031 import com.liferay.portal.kernel.util.OrderByComparator;
032 import com.liferay.portal.kernel.util.StringBundler;
033 import com.liferay.portal.kernel.util.StringPool;
034 import com.liferay.portal.kernel.util.StringUtil;
035 import com.liferay.portal.kernel.util.UnmodifiableList;
036 import com.liferay.portal.kernel.util.Validator;
037 import com.liferay.portal.model.CacheModel;
038 import com.liferay.portal.model.ModelListener;
039 import com.liferay.portal.model.ResourceBlock;
040 import com.liferay.portal.model.impl.ResourceBlockImpl;
041 import com.liferay.portal.model.impl.ResourceBlockModelImpl;
042 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
043
044 import java.io.Serializable;
045
046 import java.util.ArrayList;
047 import java.util.Collections;
048 import java.util.List;
049
050
062 public class ResourceBlockPersistenceImpl extends BasePersistenceImpl<ResourceBlock>
063 implements ResourceBlockPersistence {
064
069 public static final String FINDER_CLASS_NAME_ENTITY = ResourceBlockImpl.class.getName();
070 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
071 ".List1";
072 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
073 ".List2";
074 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
075 ResourceBlockModelImpl.FINDER_CACHE_ENABLED,
076 ResourceBlockImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
077 "findAll", new String[0]);
078 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
079 ResourceBlockModelImpl.FINDER_CACHE_ENABLED,
080 ResourceBlockImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
081 "findAll", new String[0]);
082 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
083 ResourceBlockModelImpl.FINDER_CACHE_ENABLED, Long.class,
084 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
085 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_N = new FinderPath(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
086 ResourceBlockModelImpl.FINDER_CACHE_ENABLED,
087 ResourceBlockImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
088 "findByC_N",
089 new String[] {
090 Long.class.getName(), String.class.getName(),
091
092 Integer.class.getName(), Integer.class.getName(),
093 OrderByComparator.class.getName()
094 });
095 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N = new FinderPath(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
096 ResourceBlockModelImpl.FINDER_CACHE_ENABLED,
097 ResourceBlockImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
098 "findByC_N",
099 new String[] { Long.class.getName(), String.class.getName() },
100 ResourceBlockModelImpl.COMPANYID_COLUMN_BITMASK |
101 ResourceBlockModelImpl.NAME_COLUMN_BITMASK);
102 public static final FinderPath FINDER_PATH_COUNT_BY_C_N = new FinderPath(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
103 ResourceBlockModelImpl.FINDER_CACHE_ENABLED, Long.class,
104 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_N",
105 new String[] { Long.class.getName(), String.class.getName() });
106
107
115 @Override
116 public List<ResourceBlock> findByC_N(long companyId, String name)
117 throws SystemException {
118 return findByC_N(companyId, name, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
119 null);
120 }
121
122
136 @Override
137 public List<ResourceBlock> findByC_N(long companyId, String name,
138 int start, int end) throws SystemException {
139 return findByC_N(companyId, name, start, end, null);
140 }
141
142
157 @Override
158 public List<ResourceBlock> findByC_N(long companyId, String name,
159 int start, int end, OrderByComparator orderByComparator)
160 throws SystemException {
161 boolean pagination = true;
162 FinderPath finderPath = null;
163 Object[] finderArgs = null;
164
165 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
166 (orderByComparator == null)) {
167 pagination = false;
168 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N;
169 finderArgs = new Object[] { companyId, name };
170 }
171 else {
172 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_N;
173 finderArgs = new Object[] {
174 companyId, name,
175
176 start, end, orderByComparator
177 };
178 }
179
180 List<ResourceBlock> list = (List<ResourceBlock>)FinderCacheUtil.getResult(finderPath,
181 finderArgs, this);
182
183 if ((list != null) && !list.isEmpty()) {
184 for (ResourceBlock resourceBlock : list) {
185 if ((companyId != resourceBlock.getCompanyId()) ||
186 !Validator.equals(name, resourceBlock.getName())) {
187 list = null;
188
189 break;
190 }
191 }
192 }
193
194 if (list == null) {
195 StringBundler query = null;
196
197 if (orderByComparator != null) {
198 query = new StringBundler(4 +
199 (orderByComparator.getOrderByFields().length * 3));
200 }
201 else {
202 query = new StringBundler(4);
203 }
204
205 query.append(_SQL_SELECT_RESOURCEBLOCK_WHERE);
206
207 query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
208
209 boolean bindName = false;
210
211 if (name == null) {
212 query.append(_FINDER_COLUMN_C_N_NAME_1);
213 }
214 else if (name.equals(StringPool.BLANK)) {
215 query.append(_FINDER_COLUMN_C_N_NAME_3);
216 }
217 else {
218 bindName = true;
219
220 query.append(_FINDER_COLUMN_C_N_NAME_2);
221 }
222
223 if (orderByComparator != null) {
224 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
225 orderByComparator);
226 }
227 else
228 if (pagination) {
229 query.append(ResourceBlockModelImpl.ORDER_BY_JPQL);
230 }
231
232 String sql = query.toString();
233
234 Session session = null;
235
236 try {
237 session = openSession();
238
239 Query q = session.createQuery(sql);
240
241 QueryPos qPos = QueryPos.getInstance(q);
242
243 qPos.add(companyId);
244
245 if (bindName) {
246 qPos.add(name);
247 }
248
249 if (!pagination) {
250 list = (List<ResourceBlock>)QueryUtil.list(q, getDialect(),
251 start, end, false);
252
253 Collections.sort(list);
254
255 list = new UnmodifiableList<ResourceBlock>(list);
256 }
257 else {
258 list = (List<ResourceBlock>)QueryUtil.list(q, getDialect(),
259 start, end);
260 }
261
262 cacheResult(list);
263
264 FinderCacheUtil.putResult(finderPath, finderArgs, list);
265 }
266 catch (Exception e) {
267 FinderCacheUtil.removeResult(finderPath, finderArgs);
268
269 throw processException(e);
270 }
271 finally {
272 closeSession(session);
273 }
274 }
275
276 return list;
277 }
278
279
289 @Override
290 public ResourceBlock findByC_N_First(long companyId, String name,
291 OrderByComparator orderByComparator)
292 throws NoSuchResourceBlockException, SystemException {
293 ResourceBlock resourceBlock = fetchByC_N_First(companyId, name,
294 orderByComparator);
295
296 if (resourceBlock != null) {
297 return resourceBlock;
298 }
299
300 StringBundler msg = new StringBundler(6);
301
302 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
303
304 msg.append("companyId=");
305 msg.append(companyId);
306
307 msg.append(", name=");
308 msg.append(name);
309
310 msg.append(StringPool.CLOSE_CURLY_BRACE);
311
312 throw new NoSuchResourceBlockException(msg.toString());
313 }
314
315
324 @Override
325 public ResourceBlock fetchByC_N_First(long companyId, String name,
326 OrderByComparator orderByComparator) throws SystemException {
327 List<ResourceBlock> list = findByC_N(companyId, name, 0, 1,
328 orderByComparator);
329
330 if (!list.isEmpty()) {
331 return list.get(0);
332 }
333
334 return null;
335 }
336
337
347 @Override
348 public ResourceBlock findByC_N_Last(long companyId, String name,
349 OrderByComparator orderByComparator)
350 throws NoSuchResourceBlockException, SystemException {
351 ResourceBlock resourceBlock = fetchByC_N_Last(companyId, name,
352 orderByComparator);
353
354 if (resourceBlock != null) {
355 return resourceBlock;
356 }
357
358 StringBundler msg = new StringBundler(6);
359
360 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
361
362 msg.append("companyId=");
363 msg.append(companyId);
364
365 msg.append(", name=");
366 msg.append(name);
367
368 msg.append(StringPool.CLOSE_CURLY_BRACE);
369
370 throw new NoSuchResourceBlockException(msg.toString());
371 }
372
373
382 @Override
383 public ResourceBlock fetchByC_N_Last(long companyId, String name,
384 OrderByComparator orderByComparator) throws SystemException {
385 int count = countByC_N(companyId, name);
386
387 if (count == 0) {
388 return null;
389 }
390
391 List<ResourceBlock> list = findByC_N(companyId, name, count - 1, count,
392 orderByComparator);
393
394 if (!list.isEmpty()) {
395 return list.get(0);
396 }
397
398 return null;
399 }
400
401
412 @Override
413 public ResourceBlock[] findByC_N_PrevAndNext(long resourceBlockId,
414 long companyId, String name, OrderByComparator orderByComparator)
415 throws NoSuchResourceBlockException, SystemException {
416 ResourceBlock resourceBlock = findByPrimaryKey(resourceBlockId);
417
418 Session session = null;
419
420 try {
421 session = openSession();
422
423 ResourceBlock[] array = new ResourceBlockImpl[3];
424
425 array[0] = getByC_N_PrevAndNext(session, resourceBlock, companyId,
426 name, orderByComparator, true);
427
428 array[1] = resourceBlock;
429
430 array[2] = getByC_N_PrevAndNext(session, resourceBlock, companyId,
431 name, orderByComparator, false);
432
433 return array;
434 }
435 catch (Exception e) {
436 throw processException(e);
437 }
438 finally {
439 closeSession(session);
440 }
441 }
442
443 protected ResourceBlock getByC_N_PrevAndNext(Session session,
444 ResourceBlock resourceBlock, long companyId, String name,
445 OrderByComparator orderByComparator, boolean previous) {
446 StringBundler query = null;
447
448 if (orderByComparator != null) {
449 query = new StringBundler(6 +
450 (orderByComparator.getOrderByFields().length * 6));
451 }
452 else {
453 query = new StringBundler(3);
454 }
455
456 query.append(_SQL_SELECT_RESOURCEBLOCK_WHERE);
457
458 query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
459
460 boolean bindName = false;
461
462 if (name == null) {
463 query.append(_FINDER_COLUMN_C_N_NAME_1);
464 }
465 else if (name.equals(StringPool.BLANK)) {
466 query.append(_FINDER_COLUMN_C_N_NAME_3);
467 }
468 else {
469 bindName = true;
470
471 query.append(_FINDER_COLUMN_C_N_NAME_2);
472 }
473
474 if (orderByComparator != null) {
475 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
476
477 if (orderByConditionFields.length > 0) {
478 query.append(WHERE_AND);
479 }
480
481 for (int i = 0; i < orderByConditionFields.length; i++) {
482 query.append(_ORDER_BY_ENTITY_ALIAS);
483 query.append(orderByConditionFields[i]);
484
485 if ((i + 1) < orderByConditionFields.length) {
486 if (orderByComparator.isAscending() ^ previous) {
487 query.append(WHERE_GREATER_THAN_HAS_NEXT);
488 }
489 else {
490 query.append(WHERE_LESSER_THAN_HAS_NEXT);
491 }
492 }
493 else {
494 if (orderByComparator.isAscending() ^ previous) {
495 query.append(WHERE_GREATER_THAN);
496 }
497 else {
498 query.append(WHERE_LESSER_THAN);
499 }
500 }
501 }
502
503 query.append(ORDER_BY_CLAUSE);
504
505 String[] orderByFields = orderByComparator.getOrderByFields();
506
507 for (int i = 0; i < orderByFields.length; i++) {
508 query.append(_ORDER_BY_ENTITY_ALIAS);
509 query.append(orderByFields[i]);
510
511 if ((i + 1) < orderByFields.length) {
512 if (orderByComparator.isAscending() ^ previous) {
513 query.append(ORDER_BY_ASC_HAS_NEXT);
514 }
515 else {
516 query.append(ORDER_BY_DESC_HAS_NEXT);
517 }
518 }
519 else {
520 if (orderByComparator.isAscending() ^ previous) {
521 query.append(ORDER_BY_ASC);
522 }
523 else {
524 query.append(ORDER_BY_DESC);
525 }
526 }
527 }
528 }
529 else {
530 query.append(ResourceBlockModelImpl.ORDER_BY_JPQL);
531 }
532
533 String sql = query.toString();
534
535 Query q = session.createQuery(sql);
536
537 q.setFirstResult(0);
538 q.setMaxResults(2);
539
540 QueryPos qPos = QueryPos.getInstance(q);
541
542 qPos.add(companyId);
543
544 if (bindName) {
545 qPos.add(name);
546 }
547
548 if (orderByComparator != null) {
549 Object[] values = orderByComparator.getOrderByConditionValues(resourceBlock);
550
551 for (Object value : values) {
552 qPos.add(value);
553 }
554 }
555
556 List<ResourceBlock> list = q.list();
557
558 if (list.size() == 2) {
559 return list.get(1);
560 }
561 else {
562 return null;
563 }
564 }
565
566
573 @Override
574 public void removeByC_N(long companyId, String name)
575 throws SystemException {
576 for (ResourceBlock resourceBlock : findByC_N(companyId, name,
577 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
578 remove(resourceBlock);
579 }
580 }
581
582
590 @Override
591 public int countByC_N(long companyId, String name)
592 throws SystemException {
593 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_N;
594
595 Object[] finderArgs = new Object[] { companyId, name };
596
597 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
598 this);
599
600 if (count == null) {
601 StringBundler query = new StringBundler(3);
602
603 query.append(_SQL_COUNT_RESOURCEBLOCK_WHERE);
604
605 query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
606
607 boolean bindName = false;
608
609 if (name == null) {
610 query.append(_FINDER_COLUMN_C_N_NAME_1);
611 }
612 else if (name.equals(StringPool.BLANK)) {
613 query.append(_FINDER_COLUMN_C_N_NAME_3);
614 }
615 else {
616 bindName = true;
617
618 query.append(_FINDER_COLUMN_C_N_NAME_2);
619 }
620
621 String sql = query.toString();
622
623 Session session = null;
624
625 try {
626 session = openSession();
627
628 Query q = session.createQuery(sql);
629
630 QueryPos qPos = QueryPos.getInstance(q);
631
632 qPos.add(companyId);
633
634 if (bindName) {
635 qPos.add(name);
636 }
637
638 count = (Long)q.uniqueResult();
639
640 FinderCacheUtil.putResult(finderPath, finderArgs, count);
641 }
642 catch (Exception e) {
643 FinderCacheUtil.removeResult(finderPath, finderArgs);
644
645 throw processException(e);
646 }
647 finally {
648 closeSession(session);
649 }
650 }
651
652 return count.intValue();
653 }
654
655 private static final String _FINDER_COLUMN_C_N_COMPANYID_2 = "resourceBlock.companyId = ? AND ";
656 private static final String _FINDER_COLUMN_C_N_NAME_1 = "resourceBlock.name IS NULL";
657 private static final String _FINDER_COLUMN_C_N_NAME_2 = "resourceBlock.name = ?";
658 private static final String _FINDER_COLUMN_C_N_NAME_3 = "(resourceBlock.name IS NULL OR resourceBlock.name = '')";
659 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_G_N = new FinderPath(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
660 ResourceBlockModelImpl.FINDER_CACHE_ENABLED,
661 ResourceBlockImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
662 "findByC_G_N",
663 new String[] {
664 Long.class.getName(), Long.class.getName(),
665 String.class.getName(),
666
667 Integer.class.getName(), Integer.class.getName(),
668 OrderByComparator.class.getName()
669 });
670 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_G_N = new FinderPath(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
671 ResourceBlockModelImpl.FINDER_CACHE_ENABLED,
672 ResourceBlockImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
673 "findByC_G_N",
674 new String[] {
675 Long.class.getName(), Long.class.getName(),
676 String.class.getName()
677 },
678 ResourceBlockModelImpl.COMPANYID_COLUMN_BITMASK |
679 ResourceBlockModelImpl.GROUPID_COLUMN_BITMASK |
680 ResourceBlockModelImpl.NAME_COLUMN_BITMASK);
681 public static final FinderPath FINDER_PATH_COUNT_BY_C_G_N = new FinderPath(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
682 ResourceBlockModelImpl.FINDER_CACHE_ENABLED, Long.class,
683 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_G_N",
684 new String[] {
685 Long.class.getName(), Long.class.getName(),
686 String.class.getName()
687 });
688
689
698 @Override
699 public List<ResourceBlock> findByC_G_N(long companyId, long groupId,
700 String name) throws SystemException {
701 return findByC_G_N(companyId, groupId, name, QueryUtil.ALL_POS,
702 QueryUtil.ALL_POS, null);
703 }
704
705
720 @Override
721 public List<ResourceBlock> findByC_G_N(long companyId, long groupId,
722 String name, int start, int end) throws SystemException {
723 return findByC_G_N(companyId, groupId, name, start, end, null);
724 }
725
726
742 @Override
743 public List<ResourceBlock> findByC_G_N(long companyId, long groupId,
744 String name, int start, int end, OrderByComparator orderByComparator)
745 throws SystemException {
746 boolean pagination = true;
747 FinderPath finderPath = null;
748 Object[] finderArgs = null;
749
750 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
751 (orderByComparator == null)) {
752 pagination = false;
753 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_G_N;
754 finderArgs = new Object[] { companyId, groupId, name };
755 }
756 else {
757 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_G_N;
758 finderArgs = new Object[] {
759 companyId, groupId, name,
760
761 start, end, orderByComparator
762 };
763 }
764
765 List<ResourceBlock> list = (List<ResourceBlock>)FinderCacheUtil.getResult(finderPath,
766 finderArgs, this);
767
768 if ((list != null) && !list.isEmpty()) {
769 for (ResourceBlock resourceBlock : list) {
770 if ((companyId != resourceBlock.getCompanyId()) ||
771 (groupId != resourceBlock.getGroupId()) ||
772 !Validator.equals(name, resourceBlock.getName())) {
773 list = null;
774
775 break;
776 }
777 }
778 }
779
780 if (list == null) {
781 StringBundler query = null;
782
783 if (orderByComparator != null) {
784 query = new StringBundler(5 +
785 (orderByComparator.getOrderByFields().length * 3));
786 }
787 else {
788 query = new StringBundler(5);
789 }
790
791 query.append(_SQL_SELECT_RESOURCEBLOCK_WHERE);
792
793 query.append(_FINDER_COLUMN_C_G_N_COMPANYID_2);
794
795 query.append(_FINDER_COLUMN_C_G_N_GROUPID_2);
796
797 boolean bindName = false;
798
799 if (name == null) {
800 query.append(_FINDER_COLUMN_C_G_N_NAME_1);
801 }
802 else if (name.equals(StringPool.BLANK)) {
803 query.append(_FINDER_COLUMN_C_G_N_NAME_3);
804 }
805 else {
806 bindName = true;
807
808 query.append(_FINDER_COLUMN_C_G_N_NAME_2);
809 }
810
811 if (orderByComparator != null) {
812 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
813 orderByComparator);
814 }
815 else
816 if (pagination) {
817 query.append(ResourceBlockModelImpl.ORDER_BY_JPQL);
818 }
819
820 String sql = query.toString();
821
822 Session session = null;
823
824 try {
825 session = openSession();
826
827 Query q = session.createQuery(sql);
828
829 QueryPos qPos = QueryPos.getInstance(q);
830
831 qPos.add(companyId);
832
833 qPos.add(groupId);
834
835 if (bindName) {
836 qPos.add(name);
837 }
838
839 if (!pagination) {
840 list = (List<ResourceBlock>)QueryUtil.list(q, getDialect(),
841 start, end, false);
842
843 Collections.sort(list);
844
845 list = new UnmodifiableList<ResourceBlock>(list);
846 }
847 else {
848 list = (List<ResourceBlock>)QueryUtil.list(q, getDialect(),
849 start, end);
850 }
851
852 cacheResult(list);
853
854 FinderCacheUtil.putResult(finderPath, finderArgs, list);
855 }
856 catch (Exception e) {
857 FinderCacheUtil.removeResult(finderPath, finderArgs);
858
859 throw processException(e);
860 }
861 finally {
862 closeSession(session);
863 }
864 }
865
866 return list;
867 }
868
869
880 @Override
881 public ResourceBlock findByC_G_N_First(long companyId, long groupId,
882 String name, OrderByComparator orderByComparator)
883 throws NoSuchResourceBlockException, SystemException {
884 ResourceBlock resourceBlock = fetchByC_G_N_First(companyId, groupId,
885 name, orderByComparator);
886
887 if (resourceBlock != null) {
888 return resourceBlock;
889 }
890
891 StringBundler msg = new StringBundler(8);
892
893 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
894
895 msg.append("companyId=");
896 msg.append(companyId);
897
898 msg.append(", groupId=");
899 msg.append(groupId);
900
901 msg.append(", name=");
902 msg.append(name);
903
904 msg.append(StringPool.CLOSE_CURLY_BRACE);
905
906 throw new NoSuchResourceBlockException(msg.toString());
907 }
908
909
919 @Override
920 public ResourceBlock fetchByC_G_N_First(long companyId, long groupId,
921 String name, OrderByComparator orderByComparator)
922 throws SystemException {
923 List<ResourceBlock> list = findByC_G_N(companyId, groupId, name, 0, 1,
924 orderByComparator);
925
926 if (!list.isEmpty()) {
927 return list.get(0);
928 }
929
930 return null;
931 }
932
933
944 @Override
945 public ResourceBlock findByC_G_N_Last(long companyId, long groupId,
946 String name, OrderByComparator orderByComparator)
947 throws NoSuchResourceBlockException, SystemException {
948 ResourceBlock resourceBlock = fetchByC_G_N_Last(companyId, groupId,
949 name, orderByComparator);
950
951 if (resourceBlock != null) {
952 return resourceBlock;
953 }
954
955 StringBundler msg = new StringBundler(8);
956
957 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
958
959 msg.append("companyId=");
960 msg.append(companyId);
961
962 msg.append(", groupId=");
963 msg.append(groupId);
964
965 msg.append(", name=");
966 msg.append(name);
967
968 msg.append(StringPool.CLOSE_CURLY_BRACE);
969
970 throw new NoSuchResourceBlockException(msg.toString());
971 }
972
973
983 @Override
984 public ResourceBlock fetchByC_G_N_Last(long companyId, long groupId,
985 String name, OrderByComparator orderByComparator)
986 throws SystemException {
987 int count = countByC_G_N(companyId, groupId, name);
988
989 if (count == 0) {
990 return null;
991 }
992
993 List<ResourceBlock> list = findByC_G_N(companyId, groupId, name,
994 count - 1, count, orderByComparator);
995
996 if (!list.isEmpty()) {
997 return list.get(0);
998 }
999
1000 return null;
1001 }
1002
1003
1015 @Override
1016 public ResourceBlock[] findByC_G_N_PrevAndNext(long resourceBlockId,
1017 long companyId, long groupId, String name,
1018 OrderByComparator orderByComparator)
1019 throws NoSuchResourceBlockException, SystemException {
1020 ResourceBlock resourceBlock = findByPrimaryKey(resourceBlockId);
1021
1022 Session session = null;
1023
1024 try {
1025 session = openSession();
1026
1027 ResourceBlock[] array = new ResourceBlockImpl[3];
1028
1029 array[0] = getByC_G_N_PrevAndNext(session, resourceBlock,
1030 companyId, groupId, name, orderByComparator, true);
1031
1032 array[1] = resourceBlock;
1033
1034 array[2] = getByC_G_N_PrevAndNext(session, resourceBlock,
1035 companyId, groupId, name, orderByComparator, false);
1036
1037 return array;
1038 }
1039 catch (Exception e) {
1040 throw processException(e);
1041 }
1042 finally {
1043 closeSession(session);
1044 }
1045 }
1046
1047 protected ResourceBlock getByC_G_N_PrevAndNext(Session session,
1048 ResourceBlock resourceBlock, long companyId, long groupId, String name,
1049 OrderByComparator orderByComparator, boolean previous) {
1050 StringBundler query = null;
1051
1052 if (orderByComparator != null) {
1053 query = new StringBundler(6 +
1054 (orderByComparator.getOrderByFields().length * 6));
1055 }
1056 else {
1057 query = new StringBundler(3);
1058 }
1059
1060 query.append(_SQL_SELECT_RESOURCEBLOCK_WHERE);
1061
1062 query.append(_FINDER_COLUMN_C_G_N_COMPANYID_2);
1063
1064 query.append(_FINDER_COLUMN_C_G_N_GROUPID_2);
1065
1066 boolean bindName = false;
1067
1068 if (name == null) {
1069 query.append(_FINDER_COLUMN_C_G_N_NAME_1);
1070 }
1071 else if (name.equals(StringPool.BLANK)) {
1072 query.append(_FINDER_COLUMN_C_G_N_NAME_3);
1073 }
1074 else {
1075 bindName = true;
1076
1077 query.append(_FINDER_COLUMN_C_G_N_NAME_2);
1078 }
1079
1080 if (orderByComparator != null) {
1081 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1082
1083 if (orderByConditionFields.length > 0) {
1084 query.append(WHERE_AND);
1085 }
1086
1087 for (int i = 0; i < orderByConditionFields.length; i++) {
1088 query.append(_ORDER_BY_ENTITY_ALIAS);
1089 query.append(orderByConditionFields[i]);
1090
1091 if ((i + 1) < orderByConditionFields.length) {
1092 if (orderByComparator.isAscending() ^ previous) {
1093 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1094 }
1095 else {
1096 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1097 }
1098 }
1099 else {
1100 if (orderByComparator.isAscending() ^ previous) {
1101 query.append(WHERE_GREATER_THAN);
1102 }
1103 else {
1104 query.append(WHERE_LESSER_THAN);
1105 }
1106 }
1107 }
1108
1109 query.append(ORDER_BY_CLAUSE);
1110
1111 String[] orderByFields = orderByComparator.getOrderByFields();
1112
1113 for (int i = 0; i < orderByFields.length; i++) {
1114 query.append(_ORDER_BY_ENTITY_ALIAS);
1115 query.append(orderByFields[i]);
1116
1117 if ((i + 1) < orderByFields.length) {
1118 if (orderByComparator.isAscending() ^ previous) {
1119 query.append(ORDER_BY_ASC_HAS_NEXT);
1120 }
1121 else {
1122 query.append(ORDER_BY_DESC_HAS_NEXT);
1123 }
1124 }
1125 else {
1126 if (orderByComparator.isAscending() ^ previous) {
1127 query.append(ORDER_BY_ASC);
1128 }
1129 else {
1130 query.append(ORDER_BY_DESC);
1131 }
1132 }
1133 }
1134 }
1135 else {
1136 query.append(ResourceBlockModelImpl.ORDER_BY_JPQL);
1137 }
1138
1139 String sql = query.toString();
1140
1141 Query q = session.createQuery(sql);
1142
1143 q.setFirstResult(0);
1144 q.setMaxResults(2);
1145
1146 QueryPos qPos = QueryPos.getInstance(q);
1147
1148 qPos.add(companyId);
1149
1150 qPos.add(groupId);
1151
1152 if (bindName) {
1153 qPos.add(name);
1154 }
1155
1156 if (orderByComparator != null) {
1157 Object[] values = orderByComparator.getOrderByConditionValues(resourceBlock);
1158
1159 for (Object value : values) {
1160 qPos.add(value);
1161 }
1162 }
1163
1164 List<ResourceBlock> list = q.list();
1165
1166 if (list.size() == 2) {
1167 return list.get(1);
1168 }
1169 else {
1170 return null;
1171 }
1172 }
1173
1174
1182 @Override
1183 public void removeByC_G_N(long companyId, long groupId, String name)
1184 throws SystemException {
1185 for (ResourceBlock resourceBlock : findByC_G_N(companyId, groupId,
1186 name, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1187 remove(resourceBlock);
1188 }
1189 }
1190
1191
1200 @Override
1201 public int countByC_G_N(long companyId, long groupId, String name)
1202 throws SystemException {
1203 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_G_N;
1204
1205 Object[] finderArgs = new Object[] { companyId, groupId, name };
1206
1207 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1208 this);
1209
1210 if (count == null) {
1211 StringBundler query = new StringBundler(4);
1212
1213 query.append(_SQL_COUNT_RESOURCEBLOCK_WHERE);
1214
1215 query.append(_FINDER_COLUMN_C_G_N_COMPANYID_2);
1216
1217 query.append(_FINDER_COLUMN_C_G_N_GROUPID_2);
1218
1219 boolean bindName = false;
1220
1221 if (name == null) {
1222 query.append(_FINDER_COLUMN_C_G_N_NAME_1);
1223 }
1224 else if (name.equals(StringPool.BLANK)) {
1225 query.append(_FINDER_COLUMN_C_G_N_NAME_3);
1226 }
1227 else {
1228 bindName = true;
1229
1230 query.append(_FINDER_COLUMN_C_G_N_NAME_2);
1231 }
1232
1233 String sql = query.toString();
1234
1235 Session session = null;
1236
1237 try {
1238 session = openSession();
1239
1240 Query q = session.createQuery(sql);
1241
1242 QueryPos qPos = QueryPos.getInstance(q);
1243
1244 qPos.add(companyId);
1245
1246 qPos.add(groupId);
1247
1248 if (bindName) {
1249 qPos.add(name);
1250 }
1251
1252 count = (Long)q.uniqueResult();
1253
1254 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1255 }
1256 catch (Exception e) {
1257 FinderCacheUtil.removeResult(finderPath, finderArgs);
1258
1259 throw processException(e);
1260 }
1261 finally {
1262 closeSession(session);
1263 }
1264 }
1265
1266 return count.intValue();
1267 }
1268
1269 private static final String _FINDER_COLUMN_C_G_N_COMPANYID_2 = "resourceBlock.companyId = ? AND ";
1270 private static final String _FINDER_COLUMN_C_G_N_GROUPID_2 = "resourceBlock.groupId = ? AND ";
1271 private static final String _FINDER_COLUMN_C_G_N_NAME_1 = "resourceBlock.name IS NULL";
1272 private static final String _FINDER_COLUMN_C_G_N_NAME_2 = "resourceBlock.name = ?";
1273 private static final String _FINDER_COLUMN_C_G_N_NAME_3 = "(resourceBlock.name IS NULL OR resourceBlock.name = '')";
1274 public static final FinderPath FINDER_PATH_FETCH_BY_C_G_N_P = new FinderPath(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
1275 ResourceBlockModelImpl.FINDER_CACHE_ENABLED,
1276 ResourceBlockImpl.class, FINDER_CLASS_NAME_ENTITY,
1277 "fetchByC_G_N_P",
1278 new String[] {
1279 Long.class.getName(), Long.class.getName(),
1280 String.class.getName(), String.class.getName()
1281 },
1282 ResourceBlockModelImpl.COMPANYID_COLUMN_BITMASK |
1283 ResourceBlockModelImpl.GROUPID_COLUMN_BITMASK |
1284 ResourceBlockModelImpl.NAME_COLUMN_BITMASK |
1285 ResourceBlockModelImpl.PERMISSIONSHASH_COLUMN_BITMASK);
1286 public static final FinderPath FINDER_PATH_COUNT_BY_C_G_N_P = new FinderPath(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
1287 ResourceBlockModelImpl.FINDER_CACHE_ENABLED, Long.class,
1288 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_G_N_P",
1289 new String[] {
1290 Long.class.getName(), Long.class.getName(),
1291 String.class.getName(), String.class.getName()
1292 });
1293
1294
1305 @Override
1306 public ResourceBlock findByC_G_N_P(long companyId, long groupId,
1307 String name, String permissionsHash)
1308 throws NoSuchResourceBlockException, SystemException {
1309 ResourceBlock resourceBlock = fetchByC_G_N_P(companyId, groupId, name,
1310 permissionsHash);
1311
1312 if (resourceBlock == null) {
1313 StringBundler msg = new StringBundler(10);
1314
1315 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1316
1317 msg.append("companyId=");
1318 msg.append(companyId);
1319
1320 msg.append(", groupId=");
1321 msg.append(groupId);
1322
1323 msg.append(", name=");
1324 msg.append(name);
1325
1326 msg.append(", permissionsHash=");
1327 msg.append(permissionsHash);
1328
1329 msg.append(StringPool.CLOSE_CURLY_BRACE);
1330
1331 if (_log.isWarnEnabled()) {
1332 _log.warn(msg.toString());
1333 }
1334
1335 throw new NoSuchResourceBlockException(msg.toString());
1336 }
1337
1338 return resourceBlock;
1339 }
1340
1341
1351 @Override
1352 public ResourceBlock fetchByC_G_N_P(long companyId, long groupId,
1353 String name, String permissionsHash) throws SystemException {
1354 return fetchByC_G_N_P(companyId, groupId, name, permissionsHash, true);
1355 }
1356
1357
1368 @Override
1369 public ResourceBlock fetchByC_G_N_P(long companyId, long groupId,
1370 String name, String permissionsHash, boolean retrieveFromCache)
1371 throws SystemException {
1372 Object[] finderArgs = new Object[] {
1373 companyId, groupId, name, permissionsHash
1374 };
1375
1376 Object result = null;
1377
1378 if (retrieveFromCache) {
1379 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_G_N_P,
1380 finderArgs, this);
1381 }
1382
1383 if (result instanceof ResourceBlock) {
1384 ResourceBlock resourceBlock = (ResourceBlock)result;
1385
1386 if ((companyId != resourceBlock.getCompanyId()) ||
1387 (groupId != resourceBlock.getGroupId()) ||
1388 !Validator.equals(name, resourceBlock.getName()) ||
1389 !Validator.equals(permissionsHash,
1390 resourceBlock.getPermissionsHash())) {
1391 result = null;
1392 }
1393 }
1394
1395 if (result == null) {
1396 StringBundler query = new StringBundler(6);
1397
1398 query.append(_SQL_SELECT_RESOURCEBLOCK_WHERE);
1399
1400 query.append(_FINDER_COLUMN_C_G_N_P_COMPANYID_2);
1401
1402 query.append(_FINDER_COLUMN_C_G_N_P_GROUPID_2);
1403
1404 boolean bindName = false;
1405
1406 if (name == null) {
1407 query.append(_FINDER_COLUMN_C_G_N_P_NAME_1);
1408 }
1409 else if (name.equals(StringPool.BLANK)) {
1410 query.append(_FINDER_COLUMN_C_G_N_P_NAME_3);
1411 }
1412 else {
1413 bindName = true;
1414
1415 query.append(_FINDER_COLUMN_C_G_N_P_NAME_2);
1416 }
1417
1418 boolean bindPermissionsHash = false;
1419
1420 if (permissionsHash == null) {
1421 query.append(_FINDER_COLUMN_C_G_N_P_PERMISSIONSHASH_1);
1422 }
1423 else if (permissionsHash.equals(StringPool.BLANK)) {
1424 query.append(_FINDER_COLUMN_C_G_N_P_PERMISSIONSHASH_3);
1425 }
1426 else {
1427 bindPermissionsHash = true;
1428
1429 query.append(_FINDER_COLUMN_C_G_N_P_PERMISSIONSHASH_2);
1430 }
1431
1432 String sql = query.toString();
1433
1434 Session session = null;
1435
1436 try {
1437 session = openSession();
1438
1439 Query q = session.createQuery(sql);
1440
1441 QueryPos qPos = QueryPos.getInstance(q);
1442
1443 qPos.add(companyId);
1444
1445 qPos.add(groupId);
1446
1447 if (bindName) {
1448 qPos.add(name);
1449 }
1450
1451 if (bindPermissionsHash) {
1452 qPos.add(permissionsHash);
1453 }
1454
1455 List<ResourceBlock> list = q.list();
1456
1457 if (list.isEmpty()) {
1458 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_G_N_P,
1459 finderArgs, list);
1460 }
1461 else {
1462 ResourceBlock resourceBlock = list.get(0);
1463
1464 result = resourceBlock;
1465
1466 cacheResult(resourceBlock);
1467
1468 if ((resourceBlock.getCompanyId() != companyId) ||
1469 (resourceBlock.getGroupId() != groupId) ||
1470 (resourceBlock.getName() == null) ||
1471 !resourceBlock.getName().equals(name) ||
1472 (resourceBlock.getPermissionsHash() == null) ||
1473 !resourceBlock.getPermissionsHash()
1474 .equals(permissionsHash)) {
1475 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_G_N_P,
1476 finderArgs, resourceBlock);
1477 }
1478 }
1479 }
1480 catch (Exception e) {
1481 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_G_N_P,
1482 finderArgs);
1483
1484 throw processException(e);
1485 }
1486 finally {
1487 closeSession(session);
1488 }
1489 }
1490
1491 if (result instanceof List<?>) {
1492 return null;
1493 }
1494 else {
1495 return (ResourceBlock)result;
1496 }
1497 }
1498
1499
1509 @Override
1510 public ResourceBlock removeByC_G_N_P(long companyId, long groupId,
1511 String name, String permissionsHash)
1512 throws NoSuchResourceBlockException, SystemException {
1513 ResourceBlock resourceBlock = findByC_G_N_P(companyId, groupId, name,
1514 permissionsHash);
1515
1516 return remove(resourceBlock);
1517 }
1518
1519
1529 @Override
1530 public int countByC_G_N_P(long companyId, long groupId, String name,
1531 String permissionsHash) throws SystemException {
1532 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_G_N_P;
1533
1534 Object[] finderArgs = new Object[] {
1535 companyId, groupId, name, permissionsHash
1536 };
1537
1538 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1539 this);
1540
1541 if (count == null) {
1542 StringBundler query = new StringBundler(5);
1543
1544 query.append(_SQL_COUNT_RESOURCEBLOCK_WHERE);
1545
1546 query.append(_FINDER_COLUMN_C_G_N_P_COMPANYID_2);
1547
1548 query.append(_FINDER_COLUMN_C_G_N_P_GROUPID_2);
1549
1550 boolean bindName = false;
1551
1552 if (name == null) {
1553 query.append(_FINDER_COLUMN_C_G_N_P_NAME_1);
1554 }
1555 else if (name.equals(StringPool.BLANK)) {
1556 query.append(_FINDER_COLUMN_C_G_N_P_NAME_3);
1557 }
1558 else {
1559 bindName = true;
1560
1561 query.append(_FINDER_COLUMN_C_G_N_P_NAME_2);
1562 }
1563
1564 boolean bindPermissionsHash = false;
1565
1566 if (permissionsHash == null) {
1567 query.append(_FINDER_COLUMN_C_G_N_P_PERMISSIONSHASH_1);
1568 }
1569 else if (permissionsHash.equals(StringPool.BLANK)) {
1570 query.append(_FINDER_COLUMN_C_G_N_P_PERMISSIONSHASH_3);
1571 }
1572 else {
1573 bindPermissionsHash = true;
1574
1575 query.append(_FINDER_COLUMN_C_G_N_P_PERMISSIONSHASH_2);
1576 }
1577
1578 String sql = query.toString();
1579
1580 Session session = null;
1581
1582 try {
1583 session = openSession();
1584
1585 Query q = session.createQuery(sql);
1586
1587 QueryPos qPos = QueryPos.getInstance(q);
1588
1589 qPos.add(companyId);
1590
1591 qPos.add(groupId);
1592
1593 if (bindName) {
1594 qPos.add(name);
1595 }
1596
1597 if (bindPermissionsHash) {
1598 qPos.add(permissionsHash);
1599 }
1600
1601 count = (Long)q.uniqueResult();
1602
1603 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1604 }
1605 catch (Exception e) {
1606 FinderCacheUtil.removeResult(finderPath, finderArgs);
1607
1608 throw processException(e);
1609 }
1610 finally {
1611 closeSession(session);
1612 }
1613 }
1614
1615 return count.intValue();
1616 }
1617
1618 private static final String _FINDER_COLUMN_C_G_N_P_COMPANYID_2 = "resourceBlock.companyId = ? AND ";
1619 private static final String _FINDER_COLUMN_C_G_N_P_GROUPID_2 = "resourceBlock.groupId = ? AND ";
1620 private static final String _FINDER_COLUMN_C_G_N_P_NAME_1 = "resourceBlock.name IS NULL AND ";
1621 private static final String _FINDER_COLUMN_C_G_N_P_NAME_2 = "resourceBlock.name = ? AND ";
1622 private static final String _FINDER_COLUMN_C_G_N_P_NAME_3 = "(resourceBlock.name IS NULL OR resourceBlock.name = '') AND ";
1623 private static final String _FINDER_COLUMN_C_G_N_P_PERMISSIONSHASH_1 = "resourceBlock.permissionsHash IS NULL";
1624 private static final String _FINDER_COLUMN_C_G_N_P_PERMISSIONSHASH_2 = "resourceBlock.permissionsHash = ?";
1625 private static final String _FINDER_COLUMN_C_G_N_P_PERMISSIONSHASH_3 = "(resourceBlock.permissionsHash IS NULL OR resourceBlock.permissionsHash = '')";
1626
1627
1632 @Override
1633 public void cacheResult(ResourceBlock resourceBlock) {
1634 EntityCacheUtil.putResult(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
1635 ResourceBlockImpl.class, resourceBlock.getPrimaryKey(),
1636 resourceBlock);
1637
1638 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_G_N_P,
1639 new Object[] {
1640 resourceBlock.getCompanyId(), resourceBlock.getGroupId(),
1641 resourceBlock.getName(), resourceBlock.getPermissionsHash()
1642 }, resourceBlock);
1643
1644 resourceBlock.resetOriginalValues();
1645 }
1646
1647
1652 @Override
1653 public void cacheResult(List<ResourceBlock> resourceBlocks) {
1654 for (ResourceBlock resourceBlock : resourceBlocks) {
1655 if (EntityCacheUtil.getResult(
1656 ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
1657 ResourceBlockImpl.class, resourceBlock.getPrimaryKey()) == null) {
1658 cacheResult(resourceBlock);
1659 }
1660 else {
1661 resourceBlock.resetOriginalValues();
1662 }
1663 }
1664 }
1665
1666
1673 @Override
1674 public void clearCache() {
1675 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
1676 CacheRegistryUtil.clear(ResourceBlockImpl.class.getName());
1677 }
1678
1679 EntityCacheUtil.clearCache(ResourceBlockImpl.class.getName());
1680
1681 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1682 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1683 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1684 }
1685
1686
1693 @Override
1694 public void clearCache(ResourceBlock resourceBlock) {
1695 EntityCacheUtil.removeResult(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
1696 ResourceBlockImpl.class, resourceBlock.getPrimaryKey());
1697
1698 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1699 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1700
1701 clearUniqueFindersCache(resourceBlock);
1702 }
1703
1704 @Override
1705 public void clearCache(List<ResourceBlock> resourceBlocks) {
1706 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1707 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1708
1709 for (ResourceBlock resourceBlock : resourceBlocks) {
1710 EntityCacheUtil.removeResult(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
1711 ResourceBlockImpl.class, resourceBlock.getPrimaryKey());
1712
1713 clearUniqueFindersCache(resourceBlock);
1714 }
1715 }
1716
1717 protected void cacheUniqueFindersCache(ResourceBlock resourceBlock) {
1718 if (resourceBlock.isNew()) {
1719 Object[] args = new Object[] {
1720 resourceBlock.getCompanyId(), resourceBlock.getGroupId(),
1721 resourceBlock.getName(), resourceBlock.getPermissionsHash()
1722 };
1723
1724 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_G_N_P, args,
1725 Long.valueOf(1));
1726 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_G_N_P, args,
1727 resourceBlock);
1728 }
1729 else {
1730 ResourceBlockModelImpl resourceBlockModelImpl = (ResourceBlockModelImpl)resourceBlock;
1731
1732 if ((resourceBlockModelImpl.getColumnBitmask() &
1733 FINDER_PATH_FETCH_BY_C_G_N_P.getColumnBitmask()) != 0) {
1734 Object[] args = new Object[] {
1735 resourceBlock.getCompanyId(), resourceBlock.getGroupId(),
1736 resourceBlock.getName(),
1737 resourceBlock.getPermissionsHash()
1738 };
1739
1740 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_G_N_P, args,
1741 Long.valueOf(1));
1742 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_G_N_P, args,
1743 resourceBlock);
1744 }
1745 }
1746 }
1747
1748 protected void clearUniqueFindersCache(ResourceBlock resourceBlock) {
1749 ResourceBlockModelImpl resourceBlockModelImpl = (ResourceBlockModelImpl)resourceBlock;
1750
1751 Object[] args = new Object[] {
1752 resourceBlock.getCompanyId(), resourceBlock.getGroupId(),
1753 resourceBlock.getName(), resourceBlock.getPermissionsHash()
1754 };
1755
1756 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_G_N_P, args);
1757 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_G_N_P, args);
1758
1759 if ((resourceBlockModelImpl.getColumnBitmask() &
1760 FINDER_PATH_FETCH_BY_C_G_N_P.getColumnBitmask()) != 0) {
1761 args = new Object[] {
1762 resourceBlockModelImpl.getOriginalCompanyId(),
1763 resourceBlockModelImpl.getOriginalGroupId(),
1764 resourceBlockModelImpl.getOriginalName(),
1765 resourceBlockModelImpl.getOriginalPermissionsHash()
1766 };
1767
1768 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_G_N_P, args);
1769 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_G_N_P, args);
1770 }
1771 }
1772
1773
1779 @Override
1780 public ResourceBlock create(long resourceBlockId) {
1781 ResourceBlock resourceBlock = new ResourceBlockImpl();
1782
1783 resourceBlock.setNew(true);
1784 resourceBlock.setPrimaryKey(resourceBlockId);
1785
1786 return resourceBlock;
1787 }
1788
1789
1797 @Override
1798 public ResourceBlock remove(long resourceBlockId)
1799 throws NoSuchResourceBlockException, SystemException {
1800 return remove((Serializable)resourceBlockId);
1801 }
1802
1803
1811 @Override
1812 public ResourceBlock remove(Serializable primaryKey)
1813 throws NoSuchResourceBlockException, SystemException {
1814 Session session = null;
1815
1816 try {
1817 session = openSession();
1818
1819 ResourceBlock resourceBlock = (ResourceBlock)session.get(ResourceBlockImpl.class,
1820 primaryKey);
1821
1822 if (resourceBlock == null) {
1823 if (_log.isWarnEnabled()) {
1824 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1825 }
1826
1827 throw new NoSuchResourceBlockException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1828 primaryKey);
1829 }
1830
1831 return remove(resourceBlock);
1832 }
1833 catch (NoSuchResourceBlockException nsee) {
1834 throw nsee;
1835 }
1836 catch (Exception e) {
1837 throw processException(e);
1838 }
1839 finally {
1840 closeSession(session);
1841 }
1842 }
1843
1844 @Override
1845 protected ResourceBlock removeImpl(ResourceBlock resourceBlock)
1846 throws SystemException {
1847 resourceBlock = toUnwrappedModel(resourceBlock);
1848
1849 Session session = null;
1850
1851 try {
1852 session = openSession();
1853
1854 if (!session.contains(resourceBlock)) {
1855 resourceBlock = (ResourceBlock)session.get(ResourceBlockImpl.class,
1856 resourceBlock.getPrimaryKeyObj());
1857 }
1858
1859 if (resourceBlock != null) {
1860 session.delete(resourceBlock);
1861 }
1862 }
1863 catch (Exception e) {
1864 throw processException(e);
1865 }
1866 finally {
1867 closeSession(session);
1868 }
1869
1870 if (resourceBlock != null) {
1871 clearCache(resourceBlock);
1872 }
1873
1874 return resourceBlock;
1875 }
1876
1877 @Override
1878 public ResourceBlock updateImpl(
1879 com.liferay.portal.model.ResourceBlock resourceBlock)
1880 throws SystemException {
1881 resourceBlock = toUnwrappedModel(resourceBlock);
1882
1883 boolean isNew = resourceBlock.isNew();
1884
1885 ResourceBlockModelImpl resourceBlockModelImpl = (ResourceBlockModelImpl)resourceBlock;
1886
1887 Session session = null;
1888
1889 try {
1890 session = openSession();
1891
1892 if (resourceBlock.isNew()) {
1893 session.save(resourceBlock);
1894
1895 resourceBlock.setNew(false);
1896 }
1897 else {
1898 session.merge(resourceBlock);
1899 }
1900 }
1901 catch (Exception e) {
1902 throw processException(e);
1903 }
1904 finally {
1905 closeSession(session);
1906 }
1907
1908 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1909
1910 if (isNew || !ResourceBlockModelImpl.COLUMN_BITMASK_ENABLED) {
1911 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1912 }
1913
1914 else {
1915 if ((resourceBlockModelImpl.getColumnBitmask() &
1916 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N.getColumnBitmask()) != 0) {
1917 Object[] args = new Object[] {
1918 resourceBlockModelImpl.getOriginalCompanyId(),
1919 resourceBlockModelImpl.getOriginalName()
1920 };
1921
1922 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N, args);
1923 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N,
1924 args);
1925
1926 args = new Object[] {
1927 resourceBlockModelImpl.getCompanyId(),
1928 resourceBlockModelImpl.getName()
1929 };
1930
1931 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N, args);
1932 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N,
1933 args);
1934 }
1935
1936 if ((resourceBlockModelImpl.getColumnBitmask() &
1937 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_G_N.getColumnBitmask()) != 0) {
1938 Object[] args = new Object[] {
1939 resourceBlockModelImpl.getOriginalCompanyId(),
1940 resourceBlockModelImpl.getOriginalGroupId(),
1941 resourceBlockModelImpl.getOriginalName()
1942 };
1943
1944 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_G_N, args);
1945 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_G_N,
1946 args);
1947
1948 args = new Object[] {
1949 resourceBlockModelImpl.getCompanyId(),
1950 resourceBlockModelImpl.getGroupId(),
1951 resourceBlockModelImpl.getName()
1952 };
1953
1954 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_G_N, args);
1955 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_G_N,
1956 args);
1957 }
1958 }
1959
1960 EntityCacheUtil.putResult(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
1961 ResourceBlockImpl.class, resourceBlock.getPrimaryKey(),
1962 resourceBlock);
1963
1964 clearUniqueFindersCache(resourceBlock);
1965 cacheUniqueFindersCache(resourceBlock);
1966
1967 return resourceBlock;
1968 }
1969
1970 protected ResourceBlock toUnwrappedModel(ResourceBlock resourceBlock) {
1971 if (resourceBlock instanceof ResourceBlockImpl) {
1972 return resourceBlock;
1973 }
1974
1975 ResourceBlockImpl resourceBlockImpl = new ResourceBlockImpl();
1976
1977 resourceBlockImpl.setNew(resourceBlock.isNew());
1978 resourceBlockImpl.setPrimaryKey(resourceBlock.getPrimaryKey());
1979
1980 resourceBlockImpl.setResourceBlockId(resourceBlock.getResourceBlockId());
1981 resourceBlockImpl.setCompanyId(resourceBlock.getCompanyId());
1982 resourceBlockImpl.setGroupId(resourceBlock.getGroupId());
1983 resourceBlockImpl.setName(resourceBlock.getName());
1984 resourceBlockImpl.setPermissionsHash(resourceBlock.getPermissionsHash());
1985 resourceBlockImpl.setReferenceCount(resourceBlock.getReferenceCount());
1986
1987 return resourceBlockImpl;
1988 }
1989
1990
1998 @Override
1999 public ResourceBlock findByPrimaryKey(Serializable primaryKey)
2000 throws NoSuchResourceBlockException, SystemException {
2001 ResourceBlock resourceBlock = fetchByPrimaryKey(primaryKey);
2002
2003 if (resourceBlock == null) {
2004 if (_log.isWarnEnabled()) {
2005 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2006 }
2007
2008 throw new NoSuchResourceBlockException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2009 primaryKey);
2010 }
2011
2012 return resourceBlock;
2013 }
2014
2015
2023 @Override
2024 public ResourceBlock findByPrimaryKey(long resourceBlockId)
2025 throws NoSuchResourceBlockException, SystemException {
2026 return findByPrimaryKey((Serializable)resourceBlockId);
2027 }
2028
2029
2036 @Override
2037 public ResourceBlock fetchByPrimaryKey(Serializable primaryKey)
2038 throws SystemException {
2039 ResourceBlock resourceBlock = (ResourceBlock)EntityCacheUtil.getResult(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
2040 ResourceBlockImpl.class, primaryKey);
2041
2042 if (resourceBlock == _nullResourceBlock) {
2043 return null;
2044 }
2045
2046 if (resourceBlock == null) {
2047 Session session = null;
2048
2049 try {
2050 session = openSession();
2051
2052 resourceBlock = (ResourceBlock)session.get(ResourceBlockImpl.class,
2053 primaryKey);
2054
2055 if (resourceBlock != null) {
2056 cacheResult(resourceBlock);
2057 }
2058 else {
2059 EntityCacheUtil.putResult(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
2060 ResourceBlockImpl.class, primaryKey, _nullResourceBlock);
2061 }
2062 }
2063 catch (Exception e) {
2064 EntityCacheUtil.removeResult(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
2065 ResourceBlockImpl.class, primaryKey);
2066
2067 throw processException(e);
2068 }
2069 finally {
2070 closeSession(session);
2071 }
2072 }
2073
2074 return resourceBlock;
2075 }
2076
2077
2084 @Override
2085 public ResourceBlock fetchByPrimaryKey(long resourceBlockId)
2086 throws SystemException {
2087 return fetchByPrimaryKey((Serializable)resourceBlockId);
2088 }
2089
2090
2096 @Override
2097 public List<ResourceBlock> findAll() throws SystemException {
2098 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2099 }
2100
2101
2113 @Override
2114 public List<ResourceBlock> findAll(int start, int end)
2115 throws SystemException {
2116 return findAll(start, end, null);
2117 }
2118
2119
2132 @Override
2133 public List<ResourceBlock> findAll(int start, int end,
2134 OrderByComparator orderByComparator) throws SystemException {
2135 boolean pagination = true;
2136 FinderPath finderPath = null;
2137 Object[] finderArgs = null;
2138
2139 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2140 (orderByComparator == null)) {
2141 pagination = false;
2142 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2143 finderArgs = FINDER_ARGS_EMPTY;
2144 }
2145 else {
2146 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2147 finderArgs = new Object[] { start, end, orderByComparator };
2148 }
2149
2150 List<ResourceBlock> list = (List<ResourceBlock>)FinderCacheUtil.getResult(finderPath,
2151 finderArgs, this);
2152
2153 if (list == null) {
2154 StringBundler query = null;
2155 String sql = null;
2156
2157 if (orderByComparator != null) {
2158 query = new StringBundler(2 +
2159 (orderByComparator.getOrderByFields().length * 3));
2160
2161 query.append(_SQL_SELECT_RESOURCEBLOCK);
2162
2163 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2164 orderByComparator);
2165
2166 sql = query.toString();
2167 }
2168 else {
2169 sql = _SQL_SELECT_RESOURCEBLOCK;
2170
2171 if (pagination) {
2172 sql = sql.concat(ResourceBlockModelImpl.ORDER_BY_JPQL);
2173 }
2174 }
2175
2176 Session session = null;
2177
2178 try {
2179 session = openSession();
2180
2181 Query q = session.createQuery(sql);
2182
2183 if (!pagination) {
2184 list = (List<ResourceBlock>)QueryUtil.list(q, getDialect(),
2185 start, end, false);
2186
2187 Collections.sort(list);
2188
2189 list = new UnmodifiableList<ResourceBlock>(list);
2190 }
2191 else {
2192 list = (List<ResourceBlock>)QueryUtil.list(q, getDialect(),
2193 start, end);
2194 }
2195
2196 cacheResult(list);
2197
2198 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2199 }
2200 catch (Exception e) {
2201 FinderCacheUtil.removeResult(finderPath, finderArgs);
2202
2203 throw processException(e);
2204 }
2205 finally {
2206 closeSession(session);
2207 }
2208 }
2209
2210 return list;
2211 }
2212
2213
2218 @Override
2219 public void removeAll() throws SystemException {
2220 for (ResourceBlock resourceBlock : findAll()) {
2221 remove(resourceBlock);
2222 }
2223 }
2224
2225
2231 @Override
2232 public int countAll() throws SystemException {
2233 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2234 FINDER_ARGS_EMPTY, this);
2235
2236 if (count == null) {
2237 Session session = null;
2238
2239 try {
2240 session = openSession();
2241
2242 Query q = session.createQuery(_SQL_COUNT_RESOURCEBLOCK);
2243
2244 count = (Long)q.uniqueResult();
2245
2246 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2247 FINDER_ARGS_EMPTY, count);
2248 }
2249 catch (Exception e) {
2250 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
2251 FINDER_ARGS_EMPTY);
2252
2253 throw processException(e);
2254 }
2255 finally {
2256 closeSession(session);
2257 }
2258 }
2259
2260 return count.intValue();
2261 }
2262
2263
2266 public void afterPropertiesSet() {
2267 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2268 com.liferay.portal.util.PropsUtil.get(
2269 "value.object.listener.com.liferay.portal.model.ResourceBlock")));
2270
2271 if (listenerClassNames.length > 0) {
2272 try {
2273 List<ModelListener<ResourceBlock>> listenersList = new ArrayList<ModelListener<ResourceBlock>>();
2274
2275 for (String listenerClassName : listenerClassNames) {
2276 listenersList.add((ModelListener<ResourceBlock>)InstanceFactory.newInstance(
2277 getClassLoader(), listenerClassName));
2278 }
2279
2280 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2281 }
2282 catch (Exception e) {
2283 _log.error(e);
2284 }
2285 }
2286 }
2287
2288 public void destroy() {
2289 EntityCacheUtil.removeCache(ResourceBlockImpl.class.getName());
2290 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2291 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2292 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2293 }
2294
2295 private static final String _SQL_SELECT_RESOURCEBLOCK = "SELECT resourceBlock FROM ResourceBlock resourceBlock";
2296 private static final String _SQL_SELECT_RESOURCEBLOCK_WHERE = "SELECT resourceBlock FROM ResourceBlock resourceBlock WHERE ";
2297 private static final String _SQL_COUNT_RESOURCEBLOCK = "SELECT COUNT(resourceBlock) FROM ResourceBlock resourceBlock";
2298 private static final String _SQL_COUNT_RESOURCEBLOCK_WHERE = "SELECT COUNT(resourceBlock) FROM ResourceBlock resourceBlock WHERE ";
2299 private static final String _ORDER_BY_ENTITY_ALIAS = "resourceBlock.";
2300 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ResourceBlock exists with the primary key ";
2301 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ResourceBlock exists with the key {";
2302 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2303 private static Log _log = LogFactoryUtil.getLog(ResourceBlockPersistenceImpl.class);
2304 private static ResourceBlock _nullResourceBlock = new ResourceBlockImpl() {
2305 @Override
2306 public Object clone() {
2307 return this;
2308 }
2309
2310 @Override
2311 public CacheModel<ResourceBlock> toCacheModel() {
2312 return _nullResourceBlockCacheModel;
2313 }
2314 };
2315
2316 private static CacheModel<ResourceBlock> _nullResourceBlockCacheModel = new CacheModel<ResourceBlock>() {
2317 @Override
2318 public ResourceBlock toEntityModel() {
2319 return _nullResourceBlock;
2320 }
2321 };
2322 }