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 public List<ResourceBlock> findByC_N(long companyId, String name)
116 throws SystemException {
117 return findByC_N(companyId, name, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
118 null);
119 }
120
121
135 public List<ResourceBlock> findByC_N(long companyId, String name,
136 int start, int end) throws SystemException {
137 return findByC_N(companyId, name, start, end, null);
138 }
139
140
155 public List<ResourceBlock> findByC_N(long companyId, String name,
156 int start, int end, OrderByComparator orderByComparator)
157 throws SystemException {
158 boolean pagination = true;
159 FinderPath finderPath = null;
160 Object[] finderArgs = null;
161
162 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
163 (orderByComparator == null)) {
164 pagination = false;
165 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N;
166 finderArgs = new Object[] { companyId, name };
167 }
168 else {
169 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_N;
170 finderArgs = new Object[] {
171 companyId, name,
172
173 start, end, orderByComparator
174 };
175 }
176
177 List<ResourceBlock> list = (List<ResourceBlock>)FinderCacheUtil.getResult(finderPath,
178 finderArgs, this);
179
180 if ((list != null) && !list.isEmpty()) {
181 for (ResourceBlock resourceBlock : list) {
182 if ((companyId != resourceBlock.getCompanyId()) ||
183 !Validator.equals(name, resourceBlock.getName())) {
184 list = null;
185
186 break;
187 }
188 }
189 }
190
191 if (list == null) {
192 StringBundler query = null;
193
194 if (orderByComparator != null) {
195 query = new StringBundler(4 +
196 (orderByComparator.getOrderByFields().length * 3));
197 }
198 else {
199 query = new StringBundler(4);
200 }
201
202 query.append(_SQL_SELECT_RESOURCEBLOCK_WHERE);
203
204 query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
205
206 boolean bindName = false;
207
208 if (name == null) {
209 query.append(_FINDER_COLUMN_C_N_NAME_1);
210 }
211 else if (name.equals(StringPool.BLANK)) {
212 query.append(_FINDER_COLUMN_C_N_NAME_3);
213 }
214 else {
215 bindName = true;
216
217 query.append(_FINDER_COLUMN_C_N_NAME_2);
218 }
219
220 if (orderByComparator != null) {
221 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
222 orderByComparator);
223 }
224 else
225 if (pagination) {
226 query.append(ResourceBlockModelImpl.ORDER_BY_JPQL);
227 }
228
229 String sql = query.toString();
230
231 Session session = null;
232
233 try {
234 session = openSession();
235
236 Query q = session.createQuery(sql);
237
238 QueryPos qPos = QueryPos.getInstance(q);
239
240 qPos.add(companyId);
241
242 if (bindName) {
243 qPos.add(name);
244 }
245
246 if (!pagination) {
247 list = (List<ResourceBlock>)QueryUtil.list(q, getDialect(),
248 start, end, false);
249
250 Collections.sort(list);
251
252 list = new UnmodifiableList<ResourceBlock>(list);
253 }
254 else {
255 list = (List<ResourceBlock>)QueryUtil.list(q, getDialect(),
256 start, end);
257 }
258
259 cacheResult(list);
260
261 FinderCacheUtil.putResult(finderPath, finderArgs, list);
262 }
263 catch (Exception e) {
264 FinderCacheUtil.removeResult(finderPath, finderArgs);
265
266 throw processException(e);
267 }
268 finally {
269 closeSession(session);
270 }
271 }
272
273 return list;
274 }
275
276
286 public ResourceBlock findByC_N_First(long companyId, String name,
287 OrderByComparator orderByComparator)
288 throws NoSuchResourceBlockException, SystemException {
289 ResourceBlock resourceBlock = fetchByC_N_First(companyId, name,
290 orderByComparator);
291
292 if (resourceBlock != null) {
293 return resourceBlock;
294 }
295
296 StringBundler msg = new StringBundler(6);
297
298 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
299
300 msg.append("companyId=");
301 msg.append(companyId);
302
303 msg.append(", name=");
304 msg.append(name);
305
306 msg.append(StringPool.CLOSE_CURLY_BRACE);
307
308 throw new NoSuchResourceBlockException(msg.toString());
309 }
310
311
320 public ResourceBlock fetchByC_N_First(long companyId, String name,
321 OrderByComparator orderByComparator) throws SystemException {
322 List<ResourceBlock> list = findByC_N(companyId, name, 0, 1,
323 orderByComparator);
324
325 if (!list.isEmpty()) {
326 return list.get(0);
327 }
328
329 return null;
330 }
331
332
342 public ResourceBlock findByC_N_Last(long companyId, String name,
343 OrderByComparator orderByComparator)
344 throws NoSuchResourceBlockException, SystemException {
345 ResourceBlock resourceBlock = fetchByC_N_Last(companyId, name,
346 orderByComparator);
347
348 if (resourceBlock != null) {
349 return resourceBlock;
350 }
351
352 StringBundler msg = new StringBundler(6);
353
354 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
355
356 msg.append("companyId=");
357 msg.append(companyId);
358
359 msg.append(", name=");
360 msg.append(name);
361
362 msg.append(StringPool.CLOSE_CURLY_BRACE);
363
364 throw new NoSuchResourceBlockException(msg.toString());
365 }
366
367
376 public ResourceBlock fetchByC_N_Last(long companyId, String name,
377 OrderByComparator orderByComparator) throws SystemException {
378 int count = countByC_N(companyId, name);
379
380 List<ResourceBlock> list = findByC_N(companyId, name, count - 1, count,
381 orderByComparator);
382
383 if (!list.isEmpty()) {
384 return list.get(0);
385 }
386
387 return null;
388 }
389
390
401 public ResourceBlock[] findByC_N_PrevAndNext(long resourceBlockId,
402 long companyId, String name, OrderByComparator orderByComparator)
403 throws NoSuchResourceBlockException, SystemException {
404 ResourceBlock resourceBlock = findByPrimaryKey(resourceBlockId);
405
406 Session session = null;
407
408 try {
409 session = openSession();
410
411 ResourceBlock[] array = new ResourceBlockImpl[3];
412
413 array[0] = getByC_N_PrevAndNext(session, resourceBlock, companyId,
414 name, orderByComparator, true);
415
416 array[1] = resourceBlock;
417
418 array[2] = getByC_N_PrevAndNext(session, resourceBlock, companyId,
419 name, orderByComparator, false);
420
421 return array;
422 }
423 catch (Exception e) {
424 throw processException(e);
425 }
426 finally {
427 closeSession(session);
428 }
429 }
430
431 protected ResourceBlock getByC_N_PrevAndNext(Session session,
432 ResourceBlock resourceBlock, long companyId, String name,
433 OrderByComparator orderByComparator, boolean previous) {
434 StringBundler query = null;
435
436 if (orderByComparator != null) {
437 query = new StringBundler(6 +
438 (orderByComparator.getOrderByFields().length * 6));
439 }
440 else {
441 query = new StringBundler(3);
442 }
443
444 query.append(_SQL_SELECT_RESOURCEBLOCK_WHERE);
445
446 query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
447
448 boolean bindName = false;
449
450 if (name == null) {
451 query.append(_FINDER_COLUMN_C_N_NAME_1);
452 }
453 else if (name.equals(StringPool.BLANK)) {
454 query.append(_FINDER_COLUMN_C_N_NAME_3);
455 }
456 else {
457 bindName = true;
458
459 query.append(_FINDER_COLUMN_C_N_NAME_2);
460 }
461
462 if (orderByComparator != null) {
463 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
464
465 if (orderByConditionFields.length > 0) {
466 query.append(WHERE_AND);
467 }
468
469 for (int i = 0; i < orderByConditionFields.length; i++) {
470 query.append(_ORDER_BY_ENTITY_ALIAS);
471 query.append(orderByConditionFields[i]);
472
473 if ((i + 1) < orderByConditionFields.length) {
474 if (orderByComparator.isAscending() ^ previous) {
475 query.append(WHERE_GREATER_THAN_HAS_NEXT);
476 }
477 else {
478 query.append(WHERE_LESSER_THAN_HAS_NEXT);
479 }
480 }
481 else {
482 if (orderByComparator.isAscending() ^ previous) {
483 query.append(WHERE_GREATER_THAN);
484 }
485 else {
486 query.append(WHERE_LESSER_THAN);
487 }
488 }
489 }
490
491 query.append(ORDER_BY_CLAUSE);
492
493 String[] orderByFields = orderByComparator.getOrderByFields();
494
495 for (int i = 0; i < orderByFields.length; i++) {
496 query.append(_ORDER_BY_ENTITY_ALIAS);
497 query.append(orderByFields[i]);
498
499 if ((i + 1) < orderByFields.length) {
500 if (orderByComparator.isAscending() ^ previous) {
501 query.append(ORDER_BY_ASC_HAS_NEXT);
502 }
503 else {
504 query.append(ORDER_BY_DESC_HAS_NEXT);
505 }
506 }
507 else {
508 if (orderByComparator.isAscending() ^ previous) {
509 query.append(ORDER_BY_ASC);
510 }
511 else {
512 query.append(ORDER_BY_DESC);
513 }
514 }
515 }
516 }
517 else {
518 query.append(ResourceBlockModelImpl.ORDER_BY_JPQL);
519 }
520
521 String sql = query.toString();
522
523 Query q = session.createQuery(sql);
524
525 q.setFirstResult(0);
526 q.setMaxResults(2);
527
528 QueryPos qPos = QueryPos.getInstance(q);
529
530 qPos.add(companyId);
531
532 if (bindName) {
533 qPos.add(name);
534 }
535
536 if (orderByComparator != null) {
537 Object[] values = orderByComparator.getOrderByConditionValues(resourceBlock);
538
539 for (Object value : values) {
540 qPos.add(value);
541 }
542 }
543
544 List<ResourceBlock> list = q.list();
545
546 if (list.size() == 2) {
547 return list.get(1);
548 }
549 else {
550 return null;
551 }
552 }
553
554
561 public void removeByC_N(long companyId, String name)
562 throws SystemException {
563 for (ResourceBlock resourceBlock : findByC_N(companyId, name,
564 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
565 remove(resourceBlock);
566 }
567 }
568
569
577 public int countByC_N(long companyId, String name)
578 throws SystemException {
579 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_N;
580
581 Object[] finderArgs = new Object[] { companyId, name };
582
583 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
584 this);
585
586 if (count == null) {
587 StringBundler query = new StringBundler(3);
588
589 query.append(_SQL_COUNT_RESOURCEBLOCK_WHERE);
590
591 query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
592
593 boolean bindName = false;
594
595 if (name == null) {
596 query.append(_FINDER_COLUMN_C_N_NAME_1);
597 }
598 else if (name.equals(StringPool.BLANK)) {
599 query.append(_FINDER_COLUMN_C_N_NAME_3);
600 }
601 else {
602 bindName = true;
603
604 query.append(_FINDER_COLUMN_C_N_NAME_2);
605 }
606
607 String sql = query.toString();
608
609 Session session = null;
610
611 try {
612 session = openSession();
613
614 Query q = session.createQuery(sql);
615
616 QueryPos qPos = QueryPos.getInstance(q);
617
618 qPos.add(companyId);
619
620 if (bindName) {
621 qPos.add(name);
622 }
623
624 count = (Long)q.uniqueResult();
625
626 FinderCacheUtil.putResult(finderPath, finderArgs, count);
627 }
628 catch (Exception e) {
629 FinderCacheUtil.removeResult(finderPath, finderArgs);
630
631 throw processException(e);
632 }
633 finally {
634 closeSession(session);
635 }
636 }
637
638 return count.intValue();
639 }
640
641 private static final String _FINDER_COLUMN_C_N_COMPANYID_2 = "resourceBlock.companyId = ? AND ";
642 private static final String _FINDER_COLUMN_C_N_NAME_1 = "resourceBlock.name IS NULL";
643 private static final String _FINDER_COLUMN_C_N_NAME_2 = "resourceBlock.name = ?";
644 private static final String _FINDER_COLUMN_C_N_NAME_3 = "(resourceBlock.name IS NULL OR resourceBlock.name = '')";
645 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_G_N = new FinderPath(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
646 ResourceBlockModelImpl.FINDER_CACHE_ENABLED,
647 ResourceBlockImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
648 "findByC_G_N",
649 new String[] {
650 Long.class.getName(), Long.class.getName(),
651 String.class.getName(),
652
653 Integer.class.getName(), Integer.class.getName(),
654 OrderByComparator.class.getName()
655 });
656 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_G_N = new FinderPath(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
657 ResourceBlockModelImpl.FINDER_CACHE_ENABLED,
658 ResourceBlockImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
659 "findByC_G_N",
660 new String[] {
661 Long.class.getName(), Long.class.getName(),
662 String.class.getName()
663 },
664 ResourceBlockModelImpl.COMPANYID_COLUMN_BITMASK |
665 ResourceBlockModelImpl.GROUPID_COLUMN_BITMASK |
666 ResourceBlockModelImpl.NAME_COLUMN_BITMASK);
667 public static final FinderPath FINDER_PATH_COUNT_BY_C_G_N = new FinderPath(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
668 ResourceBlockModelImpl.FINDER_CACHE_ENABLED, Long.class,
669 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_G_N",
670 new String[] {
671 Long.class.getName(), Long.class.getName(),
672 String.class.getName()
673 });
674
675
684 public List<ResourceBlock> findByC_G_N(long companyId, long groupId,
685 String name) throws SystemException {
686 return findByC_G_N(companyId, groupId, name, QueryUtil.ALL_POS,
687 QueryUtil.ALL_POS, null);
688 }
689
690
705 public List<ResourceBlock> findByC_G_N(long companyId, long groupId,
706 String name, int start, int end) throws SystemException {
707 return findByC_G_N(companyId, groupId, name, start, end, null);
708 }
709
710
726 public List<ResourceBlock> findByC_G_N(long companyId, long groupId,
727 String name, int start, int end, OrderByComparator orderByComparator)
728 throws SystemException {
729 boolean pagination = true;
730 FinderPath finderPath = null;
731 Object[] finderArgs = null;
732
733 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
734 (orderByComparator == null)) {
735 pagination = false;
736 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_G_N;
737 finderArgs = new Object[] { companyId, groupId, name };
738 }
739 else {
740 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_G_N;
741 finderArgs = new Object[] {
742 companyId, groupId, name,
743
744 start, end, orderByComparator
745 };
746 }
747
748 List<ResourceBlock> list = (List<ResourceBlock>)FinderCacheUtil.getResult(finderPath,
749 finderArgs, this);
750
751 if ((list != null) && !list.isEmpty()) {
752 for (ResourceBlock resourceBlock : list) {
753 if ((companyId != resourceBlock.getCompanyId()) ||
754 (groupId != resourceBlock.getGroupId()) ||
755 !Validator.equals(name, resourceBlock.getName())) {
756 list = null;
757
758 break;
759 }
760 }
761 }
762
763 if (list == null) {
764 StringBundler query = null;
765
766 if (orderByComparator != null) {
767 query = new StringBundler(5 +
768 (orderByComparator.getOrderByFields().length * 3));
769 }
770 else {
771 query = new StringBundler(5);
772 }
773
774 query.append(_SQL_SELECT_RESOURCEBLOCK_WHERE);
775
776 query.append(_FINDER_COLUMN_C_G_N_COMPANYID_2);
777
778 query.append(_FINDER_COLUMN_C_G_N_GROUPID_2);
779
780 boolean bindName = false;
781
782 if (name == null) {
783 query.append(_FINDER_COLUMN_C_G_N_NAME_1);
784 }
785 else if (name.equals(StringPool.BLANK)) {
786 query.append(_FINDER_COLUMN_C_G_N_NAME_3);
787 }
788 else {
789 bindName = true;
790
791 query.append(_FINDER_COLUMN_C_G_N_NAME_2);
792 }
793
794 if (orderByComparator != null) {
795 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
796 orderByComparator);
797 }
798 else
799 if (pagination) {
800 query.append(ResourceBlockModelImpl.ORDER_BY_JPQL);
801 }
802
803 String sql = query.toString();
804
805 Session session = null;
806
807 try {
808 session = openSession();
809
810 Query q = session.createQuery(sql);
811
812 QueryPos qPos = QueryPos.getInstance(q);
813
814 qPos.add(companyId);
815
816 qPos.add(groupId);
817
818 if (bindName) {
819 qPos.add(name);
820 }
821
822 if (!pagination) {
823 list = (List<ResourceBlock>)QueryUtil.list(q, getDialect(),
824 start, end, false);
825
826 Collections.sort(list);
827
828 list = new UnmodifiableList<ResourceBlock>(list);
829 }
830 else {
831 list = (List<ResourceBlock>)QueryUtil.list(q, getDialect(),
832 start, end);
833 }
834
835 cacheResult(list);
836
837 FinderCacheUtil.putResult(finderPath, finderArgs, list);
838 }
839 catch (Exception e) {
840 FinderCacheUtil.removeResult(finderPath, finderArgs);
841
842 throw processException(e);
843 }
844 finally {
845 closeSession(session);
846 }
847 }
848
849 return list;
850 }
851
852
863 public ResourceBlock findByC_G_N_First(long companyId, long groupId,
864 String name, OrderByComparator orderByComparator)
865 throws NoSuchResourceBlockException, SystemException {
866 ResourceBlock resourceBlock = fetchByC_G_N_First(companyId, groupId,
867 name, orderByComparator);
868
869 if (resourceBlock != null) {
870 return resourceBlock;
871 }
872
873 StringBundler msg = new StringBundler(8);
874
875 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
876
877 msg.append("companyId=");
878 msg.append(companyId);
879
880 msg.append(", groupId=");
881 msg.append(groupId);
882
883 msg.append(", name=");
884 msg.append(name);
885
886 msg.append(StringPool.CLOSE_CURLY_BRACE);
887
888 throw new NoSuchResourceBlockException(msg.toString());
889 }
890
891
901 public ResourceBlock fetchByC_G_N_First(long companyId, long groupId,
902 String name, OrderByComparator orderByComparator)
903 throws SystemException {
904 List<ResourceBlock> list = findByC_G_N(companyId, groupId, name, 0, 1,
905 orderByComparator);
906
907 if (!list.isEmpty()) {
908 return list.get(0);
909 }
910
911 return null;
912 }
913
914
925 public ResourceBlock findByC_G_N_Last(long companyId, long groupId,
926 String name, OrderByComparator orderByComparator)
927 throws NoSuchResourceBlockException, SystemException {
928 ResourceBlock resourceBlock = fetchByC_G_N_Last(companyId, groupId,
929 name, orderByComparator);
930
931 if (resourceBlock != null) {
932 return resourceBlock;
933 }
934
935 StringBundler msg = new StringBundler(8);
936
937 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
938
939 msg.append("companyId=");
940 msg.append(companyId);
941
942 msg.append(", groupId=");
943 msg.append(groupId);
944
945 msg.append(", name=");
946 msg.append(name);
947
948 msg.append(StringPool.CLOSE_CURLY_BRACE);
949
950 throw new NoSuchResourceBlockException(msg.toString());
951 }
952
953
963 public ResourceBlock fetchByC_G_N_Last(long companyId, long groupId,
964 String name, OrderByComparator orderByComparator)
965 throws SystemException {
966 int count = countByC_G_N(companyId, groupId, name);
967
968 List<ResourceBlock> list = findByC_G_N(companyId, groupId, name,
969 count - 1, count, orderByComparator);
970
971 if (!list.isEmpty()) {
972 return list.get(0);
973 }
974
975 return null;
976 }
977
978
990 public ResourceBlock[] findByC_G_N_PrevAndNext(long resourceBlockId,
991 long companyId, long groupId, String name,
992 OrderByComparator orderByComparator)
993 throws NoSuchResourceBlockException, SystemException {
994 ResourceBlock resourceBlock = findByPrimaryKey(resourceBlockId);
995
996 Session session = null;
997
998 try {
999 session = openSession();
1000
1001 ResourceBlock[] array = new ResourceBlockImpl[3];
1002
1003 array[0] = getByC_G_N_PrevAndNext(session, resourceBlock,
1004 companyId, groupId, name, orderByComparator, true);
1005
1006 array[1] = resourceBlock;
1007
1008 array[2] = getByC_G_N_PrevAndNext(session, resourceBlock,
1009 companyId, groupId, name, orderByComparator, false);
1010
1011 return array;
1012 }
1013 catch (Exception e) {
1014 throw processException(e);
1015 }
1016 finally {
1017 closeSession(session);
1018 }
1019 }
1020
1021 protected ResourceBlock getByC_G_N_PrevAndNext(Session session,
1022 ResourceBlock resourceBlock, long companyId, long groupId, String name,
1023 OrderByComparator orderByComparator, boolean previous) {
1024 StringBundler query = null;
1025
1026 if (orderByComparator != null) {
1027 query = new StringBundler(6 +
1028 (orderByComparator.getOrderByFields().length * 6));
1029 }
1030 else {
1031 query = new StringBundler(3);
1032 }
1033
1034 query.append(_SQL_SELECT_RESOURCEBLOCK_WHERE);
1035
1036 query.append(_FINDER_COLUMN_C_G_N_COMPANYID_2);
1037
1038 query.append(_FINDER_COLUMN_C_G_N_GROUPID_2);
1039
1040 boolean bindName = false;
1041
1042 if (name == null) {
1043 query.append(_FINDER_COLUMN_C_G_N_NAME_1);
1044 }
1045 else if (name.equals(StringPool.BLANK)) {
1046 query.append(_FINDER_COLUMN_C_G_N_NAME_3);
1047 }
1048 else {
1049 bindName = true;
1050
1051 query.append(_FINDER_COLUMN_C_G_N_NAME_2);
1052 }
1053
1054 if (orderByComparator != null) {
1055 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1056
1057 if (orderByConditionFields.length > 0) {
1058 query.append(WHERE_AND);
1059 }
1060
1061 for (int i = 0; i < orderByConditionFields.length; i++) {
1062 query.append(_ORDER_BY_ENTITY_ALIAS);
1063 query.append(orderByConditionFields[i]);
1064
1065 if ((i + 1) < orderByConditionFields.length) {
1066 if (orderByComparator.isAscending() ^ previous) {
1067 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1068 }
1069 else {
1070 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1071 }
1072 }
1073 else {
1074 if (orderByComparator.isAscending() ^ previous) {
1075 query.append(WHERE_GREATER_THAN);
1076 }
1077 else {
1078 query.append(WHERE_LESSER_THAN);
1079 }
1080 }
1081 }
1082
1083 query.append(ORDER_BY_CLAUSE);
1084
1085 String[] orderByFields = orderByComparator.getOrderByFields();
1086
1087 for (int i = 0; i < orderByFields.length; i++) {
1088 query.append(_ORDER_BY_ENTITY_ALIAS);
1089 query.append(orderByFields[i]);
1090
1091 if ((i + 1) < orderByFields.length) {
1092 if (orderByComparator.isAscending() ^ previous) {
1093 query.append(ORDER_BY_ASC_HAS_NEXT);
1094 }
1095 else {
1096 query.append(ORDER_BY_DESC_HAS_NEXT);
1097 }
1098 }
1099 else {
1100 if (orderByComparator.isAscending() ^ previous) {
1101 query.append(ORDER_BY_ASC);
1102 }
1103 else {
1104 query.append(ORDER_BY_DESC);
1105 }
1106 }
1107 }
1108 }
1109 else {
1110 query.append(ResourceBlockModelImpl.ORDER_BY_JPQL);
1111 }
1112
1113 String sql = query.toString();
1114
1115 Query q = session.createQuery(sql);
1116
1117 q.setFirstResult(0);
1118 q.setMaxResults(2);
1119
1120 QueryPos qPos = QueryPos.getInstance(q);
1121
1122 qPos.add(companyId);
1123
1124 qPos.add(groupId);
1125
1126 if (bindName) {
1127 qPos.add(name);
1128 }
1129
1130 if (orderByComparator != null) {
1131 Object[] values = orderByComparator.getOrderByConditionValues(resourceBlock);
1132
1133 for (Object value : values) {
1134 qPos.add(value);
1135 }
1136 }
1137
1138 List<ResourceBlock> list = q.list();
1139
1140 if (list.size() == 2) {
1141 return list.get(1);
1142 }
1143 else {
1144 return null;
1145 }
1146 }
1147
1148
1156 public void removeByC_G_N(long companyId, long groupId, String name)
1157 throws SystemException {
1158 for (ResourceBlock resourceBlock : findByC_G_N(companyId, groupId,
1159 name, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1160 remove(resourceBlock);
1161 }
1162 }
1163
1164
1173 public int countByC_G_N(long companyId, long groupId, String name)
1174 throws SystemException {
1175 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_G_N;
1176
1177 Object[] finderArgs = new Object[] { companyId, groupId, name };
1178
1179 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1180 this);
1181
1182 if (count == null) {
1183 StringBundler query = new StringBundler(4);
1184
1185 query.append(_SQL_COUNT_RESOURCEBLOCK_WHERE);
1186
1187 query.append(_FINDER_COLUMN_C_G_N_COMPANYID_2);
1188
1189 query.append(_FINDER_COLUMN_C_G_N_GROUPID_2);
1190
1191 boolean bindName = false;
1192
1193 if (name == null) {
1194 query.append(_FINDER_COLUMN_C_G_N_NAME_1);
1195 }
1196 else if (name.equals(StringPool.BLANK)) {
1197 query.append(_FINDER_COLUMN_C_G_N_NAME_3);
1198 }
1199 else {
1200 bindName = true;
1201
1202 query.append(_FINDER_COLUMN_C_G_N_NAME_2);
1203 }
1204
1205 String sql = query.toString();
1206
1207 Session session = null;
1208
1209 try {
1210 session = openSession();
1211
1212 Query q = session.createQuery(sql);
1213
1214 QueryPos qPos = QueryPos.getInstance(q);
1215
1216 qPos.add(companyId);
1217
1218 qPos.add(groupId);
1219
1220 if (bindName) {
1221 qPos.add(name);
1222 }
1223
1224 count = (Long)q.uniqueResult();
1225
1226 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1227 }
1228 catch (Exception e) {
1229 FinderCacheUtil.removeResult(finderPath, finderArgs);
1230
1231 throw processException(e);
1232 }
1233 finally {
1234 closeSession(session);
1235 }
1236 }
1237
1238 return count.intValue();
1239 }
1240
1241 private static final String _FINDER_COLUMN_C_G_N_COMPANYID_2 = "resourceBlock.companyId = ? AND ";
1242 private static final String _FINDER_COLUMN_C_G_N_GROUPID_2 = "resourceBlock.groupId = ? AND ";
1243 private static final String _FINDER_COLUMN_C_G_N_NAME_1 = "resourceBlock.name IS NULL";
1244 private static final String _FINDER_COLUMN_C_G_N_NAME_2 = "resourceBlock.name = ?";
1245 private static final String _FINDER_COLUMN_C_G_N_NAME_3 = "(resourceBlock.name IS NULL OR resourceBlock.name = '')";
1246 public static final FinderPath FINDER_PATH_FETCH_BY_C_G_N_P = new FinderPath(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
1247 ResourceBlockModelImpl.FINDER_CACHE_ENABLED,
1248 ResourceBlockImpl.class, FINDER_CLASS_NAME_ENTITY,
1249 "fetchByC_G_N_P",
1250 new String[] {
1251 Long.class.getName(), Long.class.getName(),
1252 String.class.getName(), String.class.getName()
1253 },
1254 ResourceBlockModelImpl.COMPANYID_COLUMN_BITMASK |
1255 ResourceBlockModelImpl.GROUPID_COLUMN_BITMASK |
1256 ResourceBlockModelImpl.NAME_COLUMN_BITMASK |
1257 ResourceBlockModelImpl.PERMISSIONSHASH_COLUMN_BITMASK);
1258 public static final FinderPath FINDER_PATH_COUNT_BY_C_G_N_P = new FinderPath(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
1259 ResourceBlockModelImpl.FINDER_CACHE_ENABLED, Long.class,
1260 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_G_N_P",
1261 new String[] {
1262 Long.class.getName(), Long.class.getName(),
1263 String.class.getName(), String.class.getName()
1264 });
1265
1266
1277 public ResourceBlock findByC_G_N_P(long companyId, long groupId,
1278 String name, String permissionsHash)
1279 throws NoSuchResourceBlockException, SystemException {
1280 ResourceBlock resourceBlock = fetchByC_G_N_P(companyId, groupId, name,
1281 permissionsHash);
1282
1283 if (resourceBlock == null) {
1284 StringBundler msg = new StringBundler(10);
1285
1286 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1287
1288 msg.append("companyId=");
1289 msg.append(companyId);
1290
1291 msg.append(", groupId=");
1292 msg.append(groupId);
1293
1294 msg.append(", name=");
1295 msg.append(name);
1296
1297 msg.append(", permissionsHash=");
1298 msg.append(permissionsHash);
1299
1300 msg.append(StringPool.CLOSE_CURLY_BRACE);
1301
1302 if (_log.isWarnEnabled()) {
1303 _log.warn(msg.toString());
1304 }
1305
1306 throw new NoSuchResourceBlockException(msg.toString());
1307 }
1308
1309 return resourceBlock;
1310 }
1311
1312
1322 public ResourceBlock fetchByC_G_N_P(long companyId, long groupId,
1323 String name, String permissionsHash) throws SystemException {
1324 return fetchByC_G_N_P(companyId, groupId, name, permissionsHash, true);
1325 }
1326
1327
1338 public ResourceBlock fetchByC_G_N_P(long companyId, long groupId,
1339 String name, String permissionsHash, boolean retrieveFromCache)
1340 throws SystemException {
1341 Object[] finderArgs = new Object[] {
1342 companyId, groupId, name, permissionsHash
1343 };
1344
1345 Object result = null;
1346
1347 if (retrieveFromCache) {
1348 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_G_N_P,
1349 finderArgs, this);
1350 }
1351
1352 if (result instanceof ResourceBlock) {
1353 ResourceBlock resourceBlock = (ResourceBlock)result;
1354
1355 if ((companyId != resourceBlock.getCompanyId()) ||
1356 (groupId != resourceBlock.getGroupId()) ||
1357 !Validator.equals(name, resourceBlock.getName()) ||
1358 !Validator.equals(permissionsHash,
1359 resourceBlock.getPermissionsHash())) {
1360 result = null;
1361 }
1362 }
1363
1364 if (result == null) {
1365 StringBundler query = new StringBundler(6);
1366
1367 query.append(_SQL_SELECT_RESOURCEBLOCK_WHERE);
1368
1369 query.append(_FINDER_COLUMN_C_G_N_P_COMPANYID_2);
1370
1371 query.append(_FINDER_COLUMN_C_G_N_P_GROUPID_2);
1372
1373 boolean bindName = false;
1374
1375 if (name == null) {
1376 query.append(_FINDER_COLUMN_C_G_N_P_NAME_1);
1377 }
1378 else if (name.equals(StringPool.BLANK)) {
1379 query.append(_FINDER_COLUMN_C_G_N_P_NAME_3);
1380 }
1381 else {
1382 bindName = true;
1383
1384 query.append(_FINDER_COLUMN_C_G_N_P_NAME_2);
1385 }
1386
1387 boolean bindPermissionsHash = false;
1388
1389 if (permissionsHash == null) {
1390 query.append(_FINDER_COLUMN_C_G_N_P_PERMISSIONSHASH_1);
1391 }
1392 else if (permissionsHash.equals(StringPool.BLANK)) {
1393 query.append(_FINDER_COLUMN_C_G_N_P_PERMISSIONSHASH_3);
1394 }
1395 else {
1396 bindPermissionsHash = true;
1397
1398 query.append(_FINDER_COLUMN_C_G_N_P_PERMISSIONSHASH_2);
1399 }
1400
1401 String sql = query.toString();
1402
1403 Session session = null;
1404
1405 try {
1406 session = openSession();
1407
1408 Query q = session.createQuery(sql);
1409
1410 QueryPos qPos = QueryPos.getInstance(q);
1411
1412 qPos.add(companyId);
1413
1414 qPos.add(groupId);
1415
1416 if (bindName) {
1417 qPos.add(name);
1418 }
1419
1420 if (bindPermissionsHash) {
1421 qPos.add(permissionsHash);
1422 }
1423
1424 List<ResourceBlock> list = q.list();
1425
1426 if (list.isEmpty()) {
1427 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_G_N_P,
1428 finderArgs, list);
1429 }
1430 else {
1431 ResourceBlock resourceBlock = list.get(0);
1432
1433 result = resourceBlock;
1434
1435 cacheResult(resourceBlock);
1436
1437 if ((resourceBlock.getCompanyId() != companyId) ||
1438 (resourceBlock.getGroupId() != groupId) ||
1439 (resourceBlock.getName() == null) ||
1440 !resourceBlock.getName().equals(name) ||
1441 (resourceBlock.getPermissionsHash() == null) ||
1442 !resourceBlock.getPermissionsHash()
1443 .equals(permissionsHash)) {
1444 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_G_N_P,
1445 finderArgs, resourceBlock);
1446 }
1447 }
1448 }
1449 catch (Exception e) {
1450 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_G_N_P,
1451 finderArgs);
1452
1453 throw processException(e);
1454 }
1455 finally {
1456 closeSession(session);
1457 }
1458 }
1459
1460 if (result instanceof List<?>) {
1461 return null;
1462 }
1463 else {
1464 return (ResourceBlock)result;
1465 }
1466 }
1467
1468
1478 public ResourceBlock removeByC_G_N_P(long companyId, long groupId,
1479 String name, String permissionsHash)
1480 throws NoSuchResourceBlockException, SystemException {
1481 ResourceBlock resourceBlock = findByC_G_N_P(companyId, groupId, name,
1482 permissionsHash);
1483
1484 return remove(resourceBlock);
1485 }
1486
1487
1497 public int countByC_G_N_P(long companyId, long groupId, String name,
1498 String permissionsHash) throws SystemException {
1499 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_G_N_P;
1500
1501 Object[] finderArgs = new Object[] {
1502 companyId, groupId, name, permissionsHash
1503 };
1504
1505 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1506 this);
1507
1508 if (count == null) {
1509 StringBundler query = new StringBundler(5);
1510
1511 query.append(_SQL_COUNT_RESOURCEBLOCK_WHERE);
1512
1513 query.append(_FINDER_COLUMN_C_G_N_P_COMPANYID_2);
1514
1515 query.append(_FINDER_COLUMN_C_G_N_P_GROUPID_2);
1516
1517 boolean bindName = false;
1518
1519 if (name == null) {
1520 query.append(_FINDER_COLUMN_C_G_N_P_NAME_1);
1521 }
1522 else if (name.equals(StringPool.BLANK)) {
1523 query.append(_FINDER_COLUMN_C_G_N_P_NAME_3);
1524 }
1525 else {
1526 bindName = true;
1527
1528 query.append(_FINDER_COLUMN_C_G_N_P_NAME_2);
1529 }
1530
1531 boolean bindPermissionsHash = false;
1532
1533 if (permissionsHash == null) {
1534 query.append(_FINDER_COLUMN_C_G_N_P_PERMISSIONSHASH_1);
1535 }
1536 else if (permissionsHash.equals(StringPool.BLANK)) {
1537 query.append(_FINDER_COLUMN_C_G_N_P_PERMISSIONSHASH_3);
1538 }
1539 else {
1540 bindPermissionsHash = true;
1541
1542 query.append(_FINDER_COLUMN_C_G_N_P_PERMISSIONSHASH_2);
1543 }
1544
1545 String sql = query.toString();
1546
1547 Session session = null;
1548
1549 try {
1550 session = openSession();
1551
1552 Query q = session.createQuery(sql);
1553
1554 QueryPos qPos = QueryPos.getInstance(q);
1555
1556 qPos.add(companyId);
1557
1558 qPos.add(groupId);
1559
1560 if (bindName) {
1561 qPos.add(name);
1562 }
1563
1564 if (bindPermissionsHash) {
1565 qPos.add(permissionsHash);
1566 }
1567
1568 count = (Long)q.uniqueResult();
1569
1570 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1571 }
1572 catch (Exception e) {
1573 FinderCacheUtil.removeResult(finderPath, finderArgs);
1574
1575 throw processException(e);
1576 }
1577 finally {
1578 closeSession(session);
1579 }
1580 }
1581
1582 return count.intValue();
1583 }
1584
1585 private static final String _FINDER_COLUMN_C_G_N_P_COMPANYID_2 = "resourceBlock.companyId = ? AND ";
1586 private static final String _FINDER_COLUMN_C_G_N_P_GROUPID_2 = "resourceBlock.groupId = ? AND ";
1587 private static final String _FINDER_COLUMN_C_G_N_P_NAME_1 = "resourceBlock.name IS NULL AND ";
1588 private static final String _FINDER_COLUMN_C_G_N_P_NAME_2 = "resourceBlock.name = ? AND ";
1589 private static final String _FINDER_COLUMN_C_G_N_P_NAME_3 = "(resourceBlock.name IS NULL OR resourceBlock.name = '') AND ";
1590 private static final String _FINDER_COLUMN_C_G_N_P_PERMISSIONSHASH_1 = "resourceBlock.permissionsHash IS NULL";
1591 private static final String _FINDER_COLUMN_C_G_N_P_PERMISSIONSHASH_2 = "resourceBlock.permissionsHash = ?";
1592 private static final String _FINDER_COLUMN_C_G_N_P_PERMISSIONSHASH_3 = "(resourceBlock.permissionsHash IS NULL OR resourceBlock.permissionsHash = '')";
1593
1594
1599 public void cacheResult(ResourceBlock resourceBlock) {
1600 EntityCacheUtil.putResult(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
1601 ResourceBlockImpl.class, resourceBlock.getPrimaryKey(),
1602 resourceBlock);
1603
1604 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_G_N_P,
1605 new Object[] {
1606 resourceBlock.getCompanyId(), resourceBlock.getGroupId(),
1607 resourceBlock.getName(), resourceBlock.getPermissionsHash()
1608 }, resourceBlock);
1609
1610 resourceBlock.resetOriginalValues();
1611 }
1612
1613
1618 public void cacheResult(List<ResourceBlock> resourceBlocks) {
1619 for (ResourceBlock resourceBlock : resourceBlocks) {
1620 if (EntityCacheUtil.getResult(
1621 ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
1622 ResourceBlockImpl.class, resourceBlock.getPrimaryKey()) == null) {
1623 cacheResult(resourceBlock);
1624 }
1625 else {
1626 resourceBlock.resetOriginalValues();
1627 }
1628 }
1629 }
1630
1631
1638 @Override
1639 public void clearCache() {
1640 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
1641 CacheRegistryUtil.clear(ResourceBlockImpl.class.getName());
1642 }
1643
1644 EntityCacheUtil.clearCache(ResourceBlockImpl.class.getName());
1645
1646 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1647 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1648 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1649 }
1650
1651
1658 @Override
1659 public void clearCache(ResourceBlock resourceBlock) {
1660 EntityCacheUtil.removeResult(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
1661 ResourceBlockImpl.class, resourceBlock.getPrimaryKey());
1662
1663 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1664 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1665
1666 clearUniqueFindersCache(resourceBlock);
1667 }
1668
1669 @Override
1670 public void clearCache(List<ResourceBlock> resourceBlocks) {
1671 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1672 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1673
1674 for (ResourceBlock resourceBlock : resourceBlocks) {
1675 EntityCacheUtil.removeResult(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
1676 ResourceBlockImpl.class, resourceBlock.getPrimaryKey());
1677
1678 clearUniqueFindersCache(resourceBlock);
1679 }
1680 }
1681
1682 protected void cacheUniqueFindersCache(ResourceBlock resourceBlock) {
1683 if (resourceBlock.isNew()) {
1684 Object[] args = new Object[] {
1685 resourceBlock.getCompanyId(), resourceBlock.getGroupId(),
1686 resourceBlock.getName(), resourceBlock.getPermissionsHash()
1687 };
1688
1689 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_G_N_P, args,
1690 Long.valueOf(1));
1691 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_G_N_P, args,
1692 resourceBlock);
1693 }
1694 else {
1695 ResourceBlockModelImpl resourceBlockModelImpl = (ResourceBlockModelImpl)resourceBlock;
1696
1697 if ((resourceBlockModelImpl.getColumnBitmask() &
1698 FINDER_PATH_FETCH_BY_C_G_N_P.getColumnBitmask()) != 0) {
1699 Object[] args = new Object[] {
1700 resourceBlock.getCompanyId(), resourceBlock.getGroupId(),
1701 resourceBlock.getName(),
1702 resourceBlock.getPermissionsHash()
1703 };
1704
1705 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_G_N_P, args,
1706 Long.valueOf(1));
1707 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_G_N_P, args,
1708 resourceBlock);
1709 }
1710 }
1711 }
1712
1713 protected void clearUniqueFindersCache(ResourceBlock resourceBlock) {
1714 ResourceBlockModelImpl resourceBlockModelImpl = (ResourceBlockModelImpl)resourceBlock;
1715
1716 Object[] args = new Object[] {
1717 resourceBlock.getCompanyId(), resourceBlock.getGroupId(),
1718 resourceBlock.getName(), resourceBlock.getPermissionsHash()
1719 };
1720
1721 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_G_N_P, args);
1722 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_G_N_P, args);
1723
1724 if ((resourceBlockModelImpl.getColumnBitmask() &
1725 FINDER_PATH_FETCH_BY_C_G_N_P.getColumnBitmask()) != 0) {
1726 args = new Object[] {
1727 resourceBlockModelImpl.getOriginalCompanyId(),
1728 resourceBlockModelImpl.getOriginalGroupId(),
1729 resourceBlockModelImpl.getOriginalName(),
1730 resourceBlockModelImpl.getOriginalPermissionsHash()
1731 };
1732
1733 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_G_N_P, args);
1734 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_G_N_P, args);
1735 }
1736 }
1737
1738
1744 public ResourceBlock create(long resourceBlockId) {
1745 ResourceBlock resourceBlock = new ResourceBlockImpl();
1746
1747 resourceBlock.setNew(true);
1748 resourceBlock.setPrimaryKey(resourceBlockId);
1749
1750 return resourceBlock;
1751 }
1752
1753
1761 public ResourceBlock remove(long resourceBlockId)
1762 throws NoSuchResourceBlockException, SystemException {
1763 return remove((Serializable)resourceBlockId);
1764 }
1765
1766
1774 @Override
1775 public ResourceBlock remove(Serializable primaryKey)
1776 throws NoSuchResourceBlockException, SystemException {
1777 Session session = null;
1778
1779 try {
1780 session = openSession();
1781
1782 ResourceBlock resourceBlock = (ResourceBlock)session.get(ResourceBlockImpl.class,
1783 primaryKey);
1784
1785 if (resourceBlock == null) {
1786 if (_log.isWarnEnabled()) {
1787 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1788 }
1789
1790 throw new NoSuchResourceBlockException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1791 primaryKey);
1792 }
1793
1794 return remove(resourceBlock);
1795 }
1796 catch (NoSuchResourceBlockException nsee) {
1797 throw nsee;
1798 }
1799 catch (Exception e) {
1800 throw processException(e);
1801 }
1802 finally {
1803 closeSession(session);
1804 }
1805 }
1806
1807 @Override
1808 protected ResourceBlock removeImpl(ResourceBlock resourceBlock)
1809 throws SystemException {
1810 resourceBlock = toUnwrappedModel(resourceBlock);
1811
1812 Session session = null;
1813
1814 try {
1815 session = openSession();
1816
1817 if (!session.contains(resourceBlock)) {
1818 resourceBlock = (ResourceBlock)session.get(ResourceBlockImpl.class,
1819 resourceBlock.getPrimaryKeyObj());
1820 }
1821
1822 if (resourceBlock != null) {
1823 session.delete(resourceBlock);
1824 }
1825 }
1826 catch (Exception e) {
1827 throw processException(e);
1828 }
1829 finally {
1830 closeSession(session);
1831 }
1832
1833 if (resourceBlock != null) {
1834 clearCache(resourceBlock);
1835 }
1836
1837 return resourceBlock;
1838 }
1839
1840 @Override
1841 public ResourceBlock updateImpl(
1842 com.liferay.portal.model.ResourceBlock resourceBlock)
1843 throws SystemException {
1844 resourceBlock = toUnwrappedModel(resourceBlock);
1845
1846 boolean isNew = resourceBlock.isNew();
1847
1848 ResourceBlockModelImpl resourceBlockModelImpl = (ResourceBlockModelImpl)resourceBlock;
1849
1850 Session session = null;
1851
1852 try {
1853 session = openSession();
1854
1855 if (resourceBlock.isNew()) {
1856 session.save(resourceBlock);
1857
1858 resourceBlock.setNew(false);
1859 }
1860 else {
1861 session.merge(resourceBlock);
1862 }
1863 }
1864 catch (Exception e) {
1865 throw processException(e);
1866 }
1867 finally {
1868 closeSession(session);
1869 }
1870
1871 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1872
1873 if (isNew || !ResourceBlockModelImpl.COLUMN_BITMASK_ENABLED) {
1874 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1875 }
1876
1877 else {
1878 if ((resourceBlockModelImpl.getColumnBitmask() &
1879 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N.getColumnBitmask()) != 0) {
1880 Object[] args = new Object[] {
1881 resourceBlockModelImpl.getOriginalCompanyId(),
1882 resourceBlockModelImpl.getOriginalName()
1883 };
1884
1885 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N, args);
1886 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N,
1887 args);
1888
1889 args = new Object[] {
1890 resourceBlockModelImpl.getCompanyId(),
1891 resourceBlockModelImpl.getName()
1892 };
1893
1894 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N, args);
1895 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N,
1896 args);
1897 }
1898
1899 if ((resourceBlockModelImpl.getColumnBitmask() &
1900 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_G_N.getColumnBitmask()) != 0) {
1901 Object[] args = new Object[] {
1902 resourceBlockModelImpl.getOriginalCompanyId(),
1903 resourceBlockModelImpl.getOriginalGroupId(),
1904 resourceBlockModelImpl.getOriginalName()
1905 };
1906
1907 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_G_N, args);
1908 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_G_N,
1909 args);
1910
1911 args = new Object[] {
1912 resourceBlockModelImpl.getCompanyId(),
1913 resourceBlockModelImpl.getGroupId(),
1914 resourceBlockModelImpl.getName()
1915 };
1916
1917 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_G_N, args);
1918 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_G_N,
1919 args);
1920 }
1921 }
1922
1923 EntityCacheUtil.putResult(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
1924 ResourceBlockImpl.class, resourceBlock.getPrimaryKey(),
1925 resourceBlock);
1926
1927 clearUniqueFindersCache(resourceBlock);
1928 cacheUniqueFindersCache(resourceBlock);
1929
1930 return resourceBlock;
1931 }
1932
1933 protected ResourceBlock toUnwrappedModel(ResourceBlock resourceBlock) {
1934 if (resourceBlock instanceof ResourceBlockImpl) {
1935 return resourceBlock;
1936 }
1937
1938 ResourceBlockImpl resourceBlockImpl = new ResourceBlockImpl();
1939
1940 resourceBlockImpl.setNew(resourceBlock.isNew());
1941 resourceBlockImpl.setPrimaryKey(resourceBlock.getPrimaryKey());
1942
1943 resourceBlockImpl.setResourceBlockId(resourceBlock.getResourceBlockId());
1944 resourceBlockImpl.setCompanyId(resourceBlock.getCompanyId());
1945 resourceBlockImpl.setGroupId(resourceBlock.getGroupId());
1946 resourceBlockImpl.setName(resourceBlock.getName());
1947 resourceBlockImpl.setPermissionsHash(resourceBlock.getPermissionsHash());
1948 resourceBlockImpl.setReferenceCount(resourceBlock.getReferenceCount());
1949
1950 return resourceBlockImpl;
1951 }
1952
1953
1961 @Override
1962 public ResourceBlock findByPrimaryKey(Serializable primaryKey)
1963 throws NoSuchResourceBlockException, SystemException {
1964 ResourceBlock resourceBlock = fetchByPrimaryKey(primaryKey);
1965
1966 if (resourceBlock == null) {
1967 if (_log.isWarnEnabled()) {
1968 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1969 }
1970
1971 throw new NoSuchResourceBlockException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1972 primaryKey);
1973 }
1974
1975 return resourceBlock;
1976 }
1977
1978
1986 public ResourceBlock findByPrimaryKey(long resourceBlockId)
1987 throws NoSuchResourceBlockException, SystemException {
1988 return findByPrimaryKey((Serializable)resourceBlockId);
1989 }
1990
1991
1998 @Override
1999 public ResourceBlock fetchByPrimaryKey(Serializable primaryKey)
2000 throws SystemException {
2001 ResourceBlock resourceBlock = (ResourceBlock)EntityCacheUtil.getResult(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
2002 ResourceBlockImpl.class, primaryKey);
2003
2004 if (resourceBlock == _nullResourceBlock) {
2005 return null;
2006 }
2007
2008 if (resourceBlock == null) {
2009 Session session = null;
2010
2011 try {
2012 session = openSession();
2013
2014 resourceBlock = (ResourceBlock)session.get(ResourceBlockImpl.class,
2015 primaryKey);
2016
2017 if (resourceBlock != null) {
2018 cacheResult(resourceBlock);
2019 }
2020 else {
2021 EntityCacheUtil.putResult(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
2022 ResourceBlockImpl.class, primaryKey, _nullResourceBlock);
2023 }
2024 }
2025 catch (Exception e) {
2026 EntityCacheUtil.removeResult(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
2027 ResourceBlockImpl.class, primaryKey);
2028
2029 throw processException(e);
2030 }
2031 finally {
2032 closeSession(session);
2033 }
2034 }
2035
2036 return resourceBlock;
2037 }
2038
2039
2046 public ResourceBlock fetchByPrimaryKey(long resourceBlockId)
2047 throws SystemException {
2048 return fetchByPrimaryKey((Serializable)resourceBlockId);
2049 }
2050
2051
2057 public List<ResourceBlock> findAll() throws SystemException {
2058 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2059 }
2060
2061
2073 public List<ResourceBlock> findAll(int start, int end)
2074 throws SystemException {
2075 return findAll(start, end, null);
2076 }
2077
2078
2091 public List<ResourceBlock> findAll(int start, int end,
2092 OrderByComparator orderByComparator) throws SystemException {
2093 boolean pagination = true;
2094 FinderPath finderPath = null;
2095 Object[] finderArgs = null;
2096
2097 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2098 (orderByComparator == null)) {
2099 pagination = false;
2100 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2101 finderArgs = FINDER_ARGS_EMPTY;
2102 }
2103 else {
2104 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2105 finderArgs = new Object[] { start, end, orderByComparator };
2106 }
2107
2108 List<ResourceBlock> list = (List<ResourceBlock>)FinderCacheUtil.getResult(finderPath,
2109 finderArgs, this);
2110
2111 if (list == null) {
2112 StringBundler query = null;
2113 String sql = null;
2114
2115 if (orderByComparator != null) {
2116 query = new StringBundler(2 +
2117 (orderByComparator.getOrderByFields().length * 3));
2118
2119 query.append(_SQL_SELECT_RESOURCEBLOCK);
2120
2121 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2122 orderByComparator);
2123
2124 sql = query.toString();
2125 }
2126 else {
2127 sql = _SQL_SELECT_RESOURCEBLOCK;
2128
2129 if (pagination) {
2130 sql = sql.concat(ResourceBlockModelImpl.ORDER_BY_JPQL);
2131 }
2132 }
2133
2134 Session session = null;
2135
2136 try {
2137 session = openSession();
2138
2139 Query q = session.createQuery(sql);
2140
2141 if (!pagination) {
2142 list = (List<ResourceBlock>)QueryUtil.list(q, getDialect(),
2143 start, end, false);
2144
2145 Collections.sort(list);
2146
2147 list = new UnmodifiableList<ResourceBlock>(list);
2148 }
2149 else {
2150 list = (List<ResourceBlock>)QueryUtil.list(q, getDialect(),
2151 start, end);
2152 }
2153
2154 cacheResult(list);
2155
2156 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2157 }
2158 catch (Exception e) {
2159 FinderCacheUtil.removeResult(finderPath, finderArgs);
2160
2161 throw processException(e);
2162 }
2163 finally {
2164 closeSession(session);
2165 }
2166 }
2167
2168 return list;
2169 }
2170
2171
2176 public void removeAll() throws SystemException {
2177 for (ResourceBlock resourceBlock : findAll()) {
2178 remove(resourceBlock);
2179 }
2180 }
2181
2182
2188 public int countAll() throws SystemException {
2189 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2190 FINDER_ARGS_EMPTY, this);
2191
2192 if (count == null) {
2193 Session session = null;
2194
2195 try {
2196 session = openSession();
2197
2198 Query q = session.createQuery(_SQL_COUNT_RESOURCEBLOCK);
2199
2200 count = (Long)q.uniqueResult();
2201
2202 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2203 FINDER_ARGS_EMPTY, count);
2204 }
2205 catch (Exception e) {
2206 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
2207 FINDER_ARGS_EMPTY);
2208
2209 throw processException(e);
2210 }
2211 finally {
2212 closeSession(session);
2213 }
2214 }
2215
2216 return count.intValue();
2217 }
2218
2219
2222 public void afterPropertiesSet() {
2223 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2224 com.liferay.portal.util.PropsUtil.get(
2225 "value.object.listener.com.liferay.portal.model.ResourceBlock")));
2226
2227 if (listenerClassNames.length > 0) {
2228 try {
2229 List<ModelListener<ResourceBlock>> listenersList = new ArrayList<ModelListener<ResourceBlock>>();
2230
2231 for (String listenerClassName : listenerClassNames) {
2232 listenersList.add((ModelListener<ResourceBlock>)InstanceFactory.newInstance(
2233 listenerClassName));
2234 }
2235
2236 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2237 }
2238 catch (Exception e) {
2239 _log.error(e);
2240 }
2241 }
2242 }
2243
2244 public void destroy() {
2245 EntityCacheUtil.removeCache(ResourceBlockImpl.class.getName());
2246 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2247 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2248 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2249 }
2250
2251 private static final String _SQL_SELECT_RESOURCEBLOCK = "SELECT resourceBlock FROM ResourceBlock resourceBlock";
2252 private static final String _SQL_SELECT_RESOURCEBLOCK_WHERE = "SELECT resourceBlock FROM ResourceBlock resourceBlock WHERE ";
2253 private static final String _SQL_COUNT_RESOURCEBLOCK = "SELECT COUNT(resourceBlock) FROM ResourceBlock resourceBlock";
2254 private static final String _SQL_COUNT_RESOURCEBLOCK_WHERE = "SELECT COUNT(resourceBlock) FROM ResourceBlock resourceBlock WHERE ";
2255 private static final String _ORDER_BY_ENTITY_ALIAS = "resourceBlock.";
2256 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ResourceBlock exists with the primary key ";
2257 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ResourceBlock exists with the key {";
2258 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2259 private static Log _log = LogFactoryUtil.getLog(ResourceBlockPersistenceImpl.class);
2260 private static ResourceBlock _nullResourceBlock = new ResourceBlockImpl() {
2261 @Override
2262 public Object clone() {
2263 return this;
2264 }
2265
2266 @Override
2267 public CacheModel<ResourceBlock> toCacheModel() {
2268 return _nullResourceBlockCacheModel;
2269 }
2270 };
2271
2272 private static CacheModel<ResourceBlock> _nullResourceBlockCacheModel = new CacheModel<ResourceBlock>() {
2273 public ResourceBlock toEntityModel() {
2274 return _nullResourceBlock;
2275 }
2276 };
2277 }