001
014
015 package com.liferay.portal.service.persistence.impl;
016
017 import aQute.bnd.annotation.ProviderType;
018
019 import com.liferay.portal.NoSuchResourceBlockException;
020 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderPath;
023 import com.liferay.portal.kernel.dao.orm.Query;
024 import com.liferay.portal.kernel.dao.orm.QueryPos;
025 import com.liferay.portal.kernel.dao.orm.QueryUtil;
026 import com.liferay.portal.kernel.dao.orm.Session;
027 import com.liferay.portal.kernel.log.Log;
028 import com.liferay.portal.kernel.log.LogFactoryUtil;
029 import com.liferay.portal.kernel.util.OrderByComparator;
030 import com.liferay.portal.kernel.util.StringBundler;
031 import com.liferay.portal.kernel.util.StringPool;
032 import com.liferay.portal.kernel.util.Validator;
033 import com.liferay.portal.model.CacheModel;
034 import com.liferay.portal.model.MVCCModel;
035 import com.liferay.portal.model.ResourceBlock;
036 import com.liferay.portal.model.impl.ResourceBlockImpl;
037 import com.liferay.portal.model.impl.ResourceBlockModelImpl;
038 import com.liferay.portal.service.persistence.ResourceBlockPersistence;
039
040 import java.io.Serializable;
041
042 import java.util.Collections;
043 import java.util.HashMap;
044 import java.util.HashSet;
045 import java.util.Iterator;
046 import java.util.List;
047 import java.util.Map;
048 import java.util.Set;
049
050
062 @ProviderType
063 public class ResourceBlockPersistenceImpl extends BasePersistenceImpl<ResourceBlock>
064 implements ResourceBlockPersistence {
065
070 public static final String FINDER_CLASS_NAME_ENTITY = ResourceBlockImpl.class.getName();
071 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
072 ".List1";
073 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
074 ".List2";
075 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
076 ResourceBlockModelImpl.FINDER_CACHE_ENABLED,
077 ResourceBlockImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
078 "findAll", new String[0]);
079 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
080 ResourceBlockModelImpl.FINDER_CACHE_ENABLED,
081 ResourceBlockImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
082 "findAll", new String[0]);
083 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
084 ResourceBlockModelImpl.FINDER_CACHE_ENABLED, Long.class,
085 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
086 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_N = new FinderPath(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
087 ResourceBlockModelImpl.FINDER_CACHE_ENABLED,
088 ResourceBlockImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
089 "findByC_N",
090 new String[] {
091 Long.class.getName(), String.class.getName(),
092
093 Integer.class.getName(), Integer.class.getName(),
094 OrderByComparator.class.getName()
095 });
096 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N = new FinderPath(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
097 ResourceBlockModelImpl.FINDER_CACHE_ENABLED,
098 ResourceBlockImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
099 "findByC_N",
100 new String[] { Long.class.getName(), String.class.getName() },
101 ResourceBlockModelImpl.COMPANYID_COLUMN_BITMASK |
102 ResourceBlockModelImpl.NAME_COLUMN_BITMASK);
103 public static final FinderPath FINDER_PATH_COUNT_BY_C_N = new FinderPath(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
104 ResourceBlockModelImpl.FINDER_CACHE_ENABLED, Long.class,
105 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_N",
106 new String[] { Long.class.getName(), String.class.getName() });
107
108
115 @Override
116 public List<ResourceBlock> findByC_N(long companyId, String name) {
117 return findByC_N(companyId, name, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
118 null);
119 }
120
121
134 @Override
135 public List<ResourceBlock> findByC_N(long companyId, String name,
136 int start, int end) {
137 return findByC_N(companyId, name, start, end, null);
138 }
139
140
154 @Override
155 public List<ResourceBlock> findByC_N(long companyId, String name,
156 int start, int end, OrderByComparator<ResourceBlock> orderByComparator) {
157 boolean pagination = true;
158 FinderPath finderPath = null;
159 Object[] finderArgs = null;
160
161 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
162 (orderByComparator == null)) {
163 pagination = false;
164 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N;
165 finderArgs = new Object[] { companyId, name };
166 }
167 else {
168 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_N;
169 finderArgs = new Object[] {
170 companyId, name,
171
172 start, end, orderByComparator
173 };
174 }
175
176 List<ResourceBlock> list = (List<ResourceBlock>)FinderCacheUtil.getResult(finderPath,
177 finderArgs, this);
178
179 if ((list != null) && !list.isEmpty()) {
180 for (ResourceBlock resourceBlock : list) {
181 if ((companyId != resourceBlock.getCompanyId()) ||
182 !Validator.equals(name, resourceBlock.getName())) {
183 list = null;
184
185 break;
186 }
187 }
188 }
189
190 if (list == null) {
191 StringBundler query = null;
192
193 if (orderByComparator != null) {
194 query = new StringBundler(4 +
195 (orderByComparator.getOrderByFields().length * 3));
196 }
197 else {
198 query = new StringBundler(4);
199 }
200
201 query.append(_SQL_SELECT_RESOURCEBLOCK_WHERE);
202
203 query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
204
205 boolean bindName = false;
206
207 if (name == null) {
208 query.append(_FINDER_COLUMN_C_N_NAME_1);
209 }
210 else if (name.equals(StringPool.BLANK)) {
211 query.append(_FINDER_COLUMN_C_N_NAME_3);
212 }
213 else {
214 bindName = true;
215
216 query.append(_FINDER_COLUMN_C_N_NAME_2);
217 }
218
219 if (orderByComparator != null) {
220 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
221 orderByComparator);
222 }
223 else
224 if (pagination) {
225 query.append(ResourceBlockModelImpl.ORDER_BY_JPQL);
226 }
227
228 String sql = query.toString();
229
230 Session session = null;
231
232 try {
233 session = openSession();
234
235 Query q = session.createQuery(sql);
236
237 QueryPos qPos = QueryPos.getInstance(q);
238
239 qPos.add(companyId);
240
241 if (bindName) {
242 qPos.add(name);
243 }
244
245 if (!pagination) {
246 list = (List<ResourceBlock>)QueryUtil.list(q, getDialect(),
247 start, end, false);
248
249 Collections.sort(list);
250
251 list = Collections.unmodifiableList(list);
252 }
253 else {
254 list = (List<ResourceBlock>)QueryUtil.list(q, getDialect(),
255 start, end);
256 }
257
258 cacheResult(list);
259
260 FinderCacheUtil.putResult(finderPath, finderArgs, list);
261 }
262 catch (Exception e) {
263 FinderCacheUtil.removeResult(finderPath, finderArgs);
264
265 throw processException(e);
266 }
267 finally {
268 closeSession(session);
269 }
270 }
271
272 return list;
273 }
274
275
284 @Override
285 public ResourceBlock findByC_N_First(long companyId, String name,
286 OrderByComparator<ResourceBlock> orderByComparator)
287 throws NoSuchResourceBlockException {
288 ResourceBlock resourceBlock = fetchByC_N_First(companyId, name,
289 orderByComparator);
290
291 if (resourceBlock != null) {
292 return resourceBlock;
293 }
294
295 StringBundler msg = new StringBundler(6);
296
297 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
298
299 msg.append("companyId=");
300 msg.append(companyId);
301
302 msg.append(", name=");
303 msg.append(name);
304
305 msg.append(StringPool.CLOSE_CURLY_BRACE);
306
307 throw new NoSuchResourceBlockException(msg.toString());
308 }
309
310
318 @Override
319 public ResourceBlock fetchByC_N_First(long companyId, String name,
320 OrderByComparator<ResourceBlock> orderByComparator) {
321 List<ResourceBlock> list = findByC_N(companyId, name, 0, 1,
322 orderByComparator);
323
324 if (!list.isEmpty()) {
325 return list.get(0);
326 }
327
328 return null;
329 }
330
331
340 @Override
341 public ResourceBlock findByC_N_Last(long companyId, String name,
342 OrderByComparator<ResourceBlock> orderByComparator)
343 throws NoSuchResourceBlockException {
344 ResourceBlock resourceBlock = fetchByC_N_Last(companyId, name,
345 orderByComparator);
346
347 if (resourceBlock != null) {
348 return resourceBlock;
349 }
350
351 StringBundler msg = new StringBundler(6);
352
353 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
354
355 msg.append("companyId=");
356 msg.append(companyId);
357
358 msg.append(", name=");
359 msg.append(name);
360
361 msg.append(StringPool.CLOSE_CURLY_BRACE);
362
363 throw new NoSuchResourceBlockException(msg.toString());
364 }
365
366
374 @Override
375 public ResourceBlock fetchByC_N_Last(long companyId, String name,
376 OrderByComparator<ResourceBlock> orderByComparator) {
377 int count = countByC_N(companyId, name);
378
379 if (count == 0) {
380 return null;
381 }
382
383 List<ResourceBlock> list = findByC_N(companyId, name, count - 1, count,
384 orderByComparator);
385
386 if (!list.isEmpty()) {
387 return list.get(0);
388 }
389
390 return null;
391 }
392
393
403 @Override
404 public ResourceBlock[] findByC_N_PrevAndNext(long resourceBlockId,
405 long companyId, String name,
406 OrderByComparator<ResourceBlock> orderByComparator)
407 throws NoSuchResourceBlockException {
408 ResourceBlock resourceBlock = findByPrimaryKey(resourceBlockId);
409
410 Session session = null;
411
412 try {
413 session = openSession();
414
415 ResourceBlock[] array = new ResourceBlockImpl[3];
416
417 array[0] = getByC_N_PrevAndNext(session, resourceBlock, companyId,
418 name, orderByComparator, true);
419
420 array[1] = resourceBlock;
421
422 array[2] = getByC_N_PrevAndNext(session, resourceBlock, companyId,
423 name, orderByComparator, false);
424
425 return array;
426 }
427 catch (Exception e) {
428 throw processException(e);
429 }
430 finally {
431 closeSession(session);
432 }
433 }
434
435 protected ResourceBlock getByC_N_PrevAndNext(Session session,
436 ResourceBlock resourceBlock, long companyId, String name,
437 OrderByComparator<ResourceBlock> orderByComparator, boolean previous) {
438 StringBundler query = null;
439
440 if (orderByComparator != null) {
441 query = new StringBundler(6 +
442 (orderByComparator.getOrderByFields().length * 6));
443 }
444 else {
445 query = new StringBundler(3);
446 }
447
448 query.append(_SQL_SELECT_RESOURCEBLOCK_WHERE);
449
450 query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
451
452 boolean bindName = false;
453
454 if (name == null) {
455 query.append(_FINDER_COLUMN_C_N_NAME_1);
456 }
457 else if (name.equals(StringPool.BLANK)) {
458 query.append(_FINDER_COLUMN_C_N_NAME_3);
459 }
460 else {
461 bindName = true;
462
463 query.append(_FINDER_COLUMN_C_N_NAME_2);
464 }
465
466 if (orderByComparator != null) {
467 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
468
469 if (orderByConditionFields.length > 0) {
470 query.append(WHERE_AND);
471 }
472
473 for (int i = 0; i < orderByConditionFields.length; i++) {
474 query.append(_ORDER_BY_ENTITY_ALIAS);
475 query.append(orderByConditionFields[i]);
476
477 if ((i + 1) < orderByConditionFields.length) {
478 if (orderByComparator.isAscending() ^ previous) {
479 query.append(WHERE_GREATER_THAN_HAS_NEXT);
480 }
481 else {
482 query.append(WHERE_LESSER_THAN_HAS_NEXT);
483 }
484 }
485 else {
486 if (orderByComparator.isAscending() ^ previous) {
487 query.append(WHERE_GREATER_THAN);
488 }
489 else {
490 query.append(WHERE_LESSER_THAN);
491 }
492 }
493 }
494
495 query.append(ORDER_BY_CLAUSE);
496
497 String[] orderByFields = orderByComparator.getOrderByFields();
498
499 for (int i = 0; i < orderByFields.length; i++) {
500 query.append(_ORDER_BY_ENTITY_ALIAS);
501 query.append(orderByFields[i]);
502
503 if ((i + 1) < orderByFields.length) {
504 if (orderByComparator.isAscending() ^ previous) {
505 query.append(ORDER_BY_ASC_HAS_NEXT);
506 }
507 else {
508 query.append(ORDER_BY_DESC_HAS_NEXT);
509 }
510 }
511 else {
512 if (orderByComparator.isAscending() ^ previous) {
513 query.append(ORDER_BY_ASC);
514 }
515 else {
516 query.append(ORDER_BY_DESC);
517 }
518 }
519 }
520 }
521 else {
522 query.append(ResourceBlockModelImpl.ORDER_BY_JPQL);
523 }
524
525 String sql = query.toString();
526
527 Query q = session.createQuery(sql);
528
529 q.setFirstResult(0);
530 q.setMaxResults(2);
531
532 QueryPos qPos = QueryPos.getInstance(q);
533
534 qPos.add(companyId);
535
536 if (bindName) {
537 qPos.add(name);
538 }
539
540 if (orderByComparator != null) {
541 Object[] values = orderByComparator.getOrderByConditionValues(resourceBlock);
542
543 for (Object value : values) {
544 qPos.add(value);
545 }
546 }
547
548 List<ResourceBlock> list = q.list();
549
550 if (list.size() == 2) {
551 return list.get(1);
552 }
553 else {
554 return null;
555 }
556 }
557
558
564 @Override
565 public void removeByC_N(long companyId, String name) {
566 for (ResourceBlock resourceBlock : findByC_N(companyId, name,
567 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
568 remove(resourceBlock);
569 }
570 }
571
572
579 @Override
580 public int countByC_N(long companyId, String name) {
581 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_N;
582
583 Object[] finderArgs = new Object[] { companyId, name };
584
585 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
586 this);
587
588 if (count == null) {
589 StringBundler query = new StringBundler(3);
590
591 query.append(_SQL_COUNT_RESOURCEBLOCK_WHERE);
592
593 query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
594
595 boolean bindName = false;
596
597 if (name == null) {
598 query.append(_FINDER_COLUMN_C_N_NAME_1);
599 }
600 else if (name.equals(StringPool.BLANK)) {
601 query.append(_FINDER_COLUMN_C_N_NAME_3);
602 }
603 else {
604 bindName = true;
605
606 query.append(_FINDER_COLUMN_C_N_NAME_2);
607 }
608
609 String sql = query.toString();
610
611 Session session = null;
612
613 try {
614 session = openSession();
615
616 Query q = session.createQuery(sql);
617
618 QueryPos qPos = QueryPos.getInstance(q);
619
620 qPos.add(companyId);
621
622 if (bindName) {
623 qPos.add(name);
624 }
625
626 count = (Long)q.uniqueResult();
627
628 FinderCacheUtil.putResult(finderPath, finderArgs, count);
629 }
630 catch (Exception e) {
631 FinderCacheUtil.removeResult(finderPath, finderArgs);
632
633 throw processException(e);
634 }
635 finally {
636 closeSession(session);
637 }
638 }
639
640 return count.intValue();
641 }
642
643 private static final String _FINDER_COLUMN_C_N_COMPANYID_2 = "resourceBlock.companyId = ? AND ";
644 private static final String _FINDER_COLUMN_C_N_NAME_1 = "resourceBlock.name IS NULL";
645 private static final String _FINDER_COLUMN_C_N_NAME_2 = "resourceBlock.name = ?";
646 private static final String _FINDER_COLUMN_C_N_NAME_3 = "(resourceBlock.name IS NULL OR resourceBlock.name = '')";
647 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_G_N = new FinderPath(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
648 ResourceBlockModelImpl.FINDER_CACHE_ENABLED,
649 ResourceBlockImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
650 "findByC_G_N",
651 new String[] {
652 Long.class.getName(), Long.class.getName(),
653 String.class.getName(),
654
655 Integer.class.getName(), Integer.class.getName(),
656 OrderByComparator.class.getName()
657 });
658 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_G_N = new FinderPath(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
659 ResourceBlockModelImpl.FINDER_CACHE_ENABLED,
660 ResourceBlockImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
661 "findByC_G_N",
662 new String[] {
663 Long.class.getName(), Long.class.getName(),
664 String.class.getName()
665 },
666 ResourceBlockModelImpl.COMPANYID_COLUMN_BITMASK |
667 ResourceBlockModelImpl.GROUPID_COLUMN_BITMASK |
668 ResourceBlockModelImpl.NAME_COLUMN_BITMASK);
669 public static final FinderPath FINDER_PATH_COUNT_BY_C_G_N = new FinderPath(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
670 ResourceBlockModelImpl.FINDER_CACHE_ENABLED, Long.class,
671 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_G_N",
672 new String[] {
673 Long.class.getName(), Long.class.getName(),
674 String.class.getName()
675 });
676
677
685 @Override
686 public List<ResourceBlock> findByC_G_N(long companyId, long groupId,
687 String name) {
688 return findByC_G_N(companyId, groupId, name, QueryUtil.ALL_POS,
689 QueryUtil.ALL_POS, null);
690 }
691
692
706 @Override
707 public List<ResourceBlock> findByC_G_N(long companyId, long groupId,
708 String name, int start, int end) {
709 return findByC_G_N(companyId, groupId, name, start, end, null);
710 }
711
712
727 @Override
728 public List<ResourceBlock> findByC_G_N(long companyId, long groupId,
729 String name, int start, int end,
730 OrderByComparator<ResourceBlock> orderByComparator) {
731 boolean pagination = true;
732 FinderPath finderPath = null;
733 Object[] finderArgs = null;
734
735 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
736 (orderByComparator == null)) {
737 pagination = false;
738 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_G_N;
739 finderArgs = new Object[] { companyId, groupId, name };
740 }
741 else {
742 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_G_N;
743 finderArgs = new Object[] {
744 companyId, groupId, name,
745
746 start, end, orderByComparator
747 };
748 }
749
750 List<ResourceBlock> list = (List<ResourceBlock>)FinderCacheUtil.getResult(finderPath,
751 finderArgs, this);
752
753 if ((list != null) && !list.isEmpty()) {
754 for (ResourceBlock resourceBlock : list) {
755 if ((companyId != resourceBlock.getCompanyId()) ||
756 (groupId != resourceBlock.getGroupId()) ||
757 !Validator.equals(name, resourceBlock.getName())) {
758 list = null;
759
760 break;
761 }
762 }
763 }
764
765 if (list == null) {
766 StringBundler query = null;
767
768 if (orderByComparator != null) {
769 query = new StringBundler(5 +
770 (orderByComparator.getOrderByFields().length * 3));
771 }
772 else {
773 query = new StringBundler(5);
774 }
775
776 query.append(_SQL_SELECT_RESOURCEBLOCK_WHERE);
777
778 query.append(_FINDER_COLUMN_C_G_N_COMPANYID_2);
779
780 query.append(_FINDER_COLUMN_C_G_N_GROUPID_2);
781
782 boolean bindName = false;
783
784 if (name == null) {
785 query.append(_FINDER_COLUMN_C_G_N_NAME_1);
786 }
787 else if (name.equals(StringPool.BLANK)) {
788 query.append(_FINDER_COLUMN_C_G_N_NAME_3);
789 }
790 else {
791 bindName = true;
792
793 query.append(_FINDER_COLUMN_C_G_N_NAME_2);
794 }
795
796 if (orderByComparator != null) {
797 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
798 orderByComparator);
799 }
800 else
801 if (pagination) {
802 query.append(ResourceBlockModelImpl.ORDER_BY_JPQL);
803 }
804
805 String sql = query.toString();
806
807 Session session = null;
808
809 try {
810 session = openSession();
811
812 Query q = session.createQuery(sql);
813
814 QueryPos qPos = QueryPos.getInstance(q);
815
816 qPos.add(companyId);
817
818 qPos.add(groupId);
819
820 if (bindName) {
821 qPos.add(name);
822 }
823
824 if (!pagination) {
825 list = (List<ResourceBlock>)QueryUtil.list(q, getDialect(),
826 start, end, false);
827
828 Collections.sort(list);
829
830 list = Collections.unmodifiableList(list);
831 }
832 else {
833 list = (List<ResourceBlock>)QueryUtil.list(q, getDialect(),
834 start, end);
835 }
836
837 cacheResult(list);
838
839 FinderCacheUtil.putResult(finderPath, finderArgs, list);
840 }
841 catch (Exception e) {
842 FinderCacheUtil.removeResult(finderPath, finderArgs);
843
844 throw processException(e);
845 }
846 finally {
847 closeSession(session);
848 }
849 }
850
851 return list;
852 }
853
854
864 @Override
865 public ResourceBlock findByC_G_N_First(long companyId, long groupId,
866 String name, OrderByComparator<ResourceBlock> orderByComparator)
867 throws NoSuchResourceBlockException {
868 ResourceBlock resourceBlock = fetchByC_G_N_First(companyId, groupId,
869 name, orderByComparator);
870
871 if (resourceBlock != null) {
872 return resourceBlock;
873 }
874
875 StringBundler msg = new StringBundler(8);
876
877 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
878
879 msg.append("companyId=");
880 msg.append(companyId);
881
882 msg.append(", groupId=");
883 msg.append(groupId);
884
885 msg.append(", name=");
886 msg.append(name);
887
888 msg.append(StringPool.CLOSE_CURLY_BRACE);
889
890 throw new NoSuchResourceBlockException(msg.toString());
891 }
892
893
902 @Override
903 public ResourceBlock fetchByC_G_N_First(long companyId, long groupId,
904 String name, OrderByComparator<ResourceBlock> orderByComparator) {
905 List<ResourceBlock> list = findByC_G_N(companyId, groupId, name, 0, 1,
906 orderByComparator);
907
908 if (!list.isEmpty()) {
909 return list.get(0);
910 }
911
912 return null;
913 }
914
915
925 @Override
926 public ResourceBlock findByC_G_N_Last(long companyId, long groupId,
927 String name, OrderByComparator<ResourceBlock> orderByComparator)
928 throws NoSuchResourceBlockException {
929 ResourceBlock resourceBlock = fetchByC_G_N_Last(companyId, groupId,
930 name, orderByComparator);
931
932 if (resourceBlock != null) {
933 return resourceBlock;
934 }
935
936 StringBundler msg = new StringBundler(8);
937
938 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
939
940 msg.append("companyId=");
941 msg.append(companyId);
942
943 msg.append(", groupId=");
944 msg.append(groupId);
945
946 msg.append(", name=");
947 msg.append(name);
948
949 msg.append(StringPool.CLOSE_CURLY_BRACE);
950
951 throw new NoSuchResourceBlockException(msg.toString());
952 }
953
954
963 @Override
964 public ResourceBlock fetchByC_G_N_Last(long companyId, long groupId,
965 String name, OrderByComparator<ResourceBlock> orderByComparator) {
966 int count = countByC_G_N(companyId, groupId, name);
967
968 if (count == 0) {
969 return null;
970 }
971
972 List<ResourceBlock> list = findByC_G_N(companyId, groupId, name,
973 count - 1, count, orderByComparator);
974
975 if (!list.isEmpty()) {
976 return list.get(0);
977 }
978
979 return null;
980 }
981
982
993 @Override
994 public ResourceBlock[] findByC_G_N_PrevAndNext(long resourceBlockId,
995 long companyId, long groupId, String name,
996 OrderByComparator<ResourceBlock> orderByComparator)
997 throws NoSuchResourceBlockException {
998 ResourceBlock resourceBlock = findByPrimaryKey(resourceBlockId);
999
1000 Session session = null;
1001
1002 try {
1003 session = openSession();
1004
1005 ResourceBlock[] array = new ResourceBlockImpl[3];
1006
1007 array[0] = getByC_G_N_PrevAndNext(session, resourceBlock,
1008 companyId, groupId, name, orderByComparator, true);
1009
1010 array[1] = resourceBlock;
1011
1012 array[2] = getByC_G_N_PrevAndNext(session, resourceBlock,
1013 companyId, groupId, name, orderByComparator, false);
1014
1015 return array;
1016 }
1017 catch (Exception e) {
1018 throw processException(e);
1019 }
1020 finally {
1021 closeSession(session);
1022 }
1023 }
1024
1025 protected ResourceBlock getByC_G_N_PrevAndNext(Session session,
1026 ResourceBlock resourceBlock, long companyId, long groupId, String name,
1027 OrderByComparator<ResourceBlock> orderByComparator, boolean previous) {
1028 StringBundler query = null;
1029
1030 if (orderByComparator != null) {
1031 query = new StringBundler(6 +
1032 (orderByComparator.getOrderByFields().length * 6));
1033 }
1034 else {
1035 query = new StringBundler(3);
1036 }
1037
1038 query.append(_SQL_SELECT_RESOURCEBLOCK_WHERE);
1039
1040 query.append(_FINDER_COLUMN_C_G_N_COMPANYID_2);
1041
1042 query.append(_FINDER_COLUMN_C_G_N_GROUPID_2);
1043
1044 boolean bindName = false;
1045
1046 if (name == null) {
1047 query.append(_FINDER_COLUMN_C_G_N_NAME_1);
1048 }
1049 else if (name.equals(StringPool.BLANK)) {
1050 query.append(_FINDER_COLUMN_C_G_N_NAME_3);
1051 }
1052 else {
1053 bindName = true;
1054
1055 query.append(_FINDER_COLUMN_C_G_N_NAME_2);
1056 }
1057
1058 if (orderByComparator != null) {
1059 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1060
1061 if (orderByConditionFields.length > 0) {
1062 query.append(WHERE_AND);
1063 }
1064
1065 for (int i = 0; i < orderByConditionFields.length; i++) {
1066 query.append(_ORDER_BY_ENTITY_ALIAS);
1067 query.append(orderByConditionFields[i]);
1068
1069 if ((i + 1) < orderByConditionFields.length) {
1070 if (orderByComparator.isAscending() ^ previous) {
1071 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1072 }
1073 else {
1074 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1075 }
1076 }
1077 else {
1078 if (orderByComparator.isAscending() ^ previous) {
1079 query.append(WHERE_GREATER_THAN);
1080 }
1081 else {
1082 query.append(WHERE_LESSER_THAN);
1083 }
1084 }
1085 }
1086
1087 query.append(ORDER_BY_CLAUSE);
1088
1089 String[] orderByFields = orderByComparator.getOrderByFields();
1090
1091 for (int i = 0; i < orderByFields.length; i++) {
1092 query.append(_ORDER_BY_ENTITY_ALIAS);
1093 query.append(orderByFields[i]);
1094
1095 if ((i + 1) < orderByFields.length) {
1096 if (orderByComparator.isAscending() ^ previous) {
1097 query.append(ORDER_BY_ASC_HAS_NEXT);
1098 }
1099 else {
1100 query.append(ORDER_BY_DESC_HAS_NEXT);
1101 }
1102 }
1103 else {
1104 if (orderByComparator.isAscending() ^ previous) {
1105 query.append(ORDER_BY_ASC);
1106 }
1107 else {
1108 query.append(ORDER_BY_DESC);
1109 }
1110 }
1111 }
1112 }
1113 else {
1114 query.append(ResourceBlockModelImpl.ORDER_BY_JPQL);
1115 }
1116
1117 String sql = query.toString();
1118
1119 Query q = session.createQuery(sql);
1120
1121 q.setFirstResult(0);
1122 q.setMaxResults(2);
1123
1124 QueryPos qPos = QueryPos.getInstance(q);
1125
1126 qPos.add(companyId);
1127
1128 qPos.add(groupId);
1129
1130 if (bindName) {
1131 qPos.add(name);
1132 }
1133
1134 if (orderByComparator != null) {
1135 Object[] values = orderByComparator.getOrderByConditionValues(resourceBlock);
1136
1137 for (Object value : values) {
1138 qPos.add(value);
1139 }
1140 }
1141
1142 List<ResourceBlock> list = q.list();
1143
1144 if (list.size() == 2) {
1145 return list.get(1);
1146 }
1147 else {
1148 return null;
1149 }
1150 }
1151
1152
1159 @Override
1160 public void removeByC_G_N(long companyId, long groupId, String name) {
1161 for (ResourceBlock resourceBlock : findByC_G_N(companyId, groupId,
1162 name, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1163 remove(resourceBlock);
1164 }
1165 }
1166
1167
1175 @Override
1176 public int countByC_G_N(long companyId, long groupId, String name) {
1177 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_G_N;
1178
1179 Object[] finderArgs = new Object[] { companyId, groupId, name };
1180
1181 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1182 this);
1183
1184 if (count == null) {
1185 StringBundler query = new StringBundler(4);
1186
1187 query.append(_SQL_COUNT_RESOURCEBLOCK_WHERE);
1188
1189 query.append(_FINDER_COLUMN_C_G_N_COMPANYID_2);
1190
1191 query.append(_FINDER_COLUMN_C_G_N_GROUPID_2);
1192
1193 boolean bindName = false;
1194
1195 if (name == null) {
1196 query.append(_FINDER_COLUMN_C_G_N_NAME_1);
1197 }
1198 else if (name.equals(StringPool.BLANK)) {
1199 query.append(_FINDER_COLUMN_C_G_N_NAME_3);
1200 }
1201 else {
1202 bindName = true;
1203
1204 query.append(_FINDER_COLUMN_C_G_N_NAME_2);
1205 }
1206
1207 String sql = query.toString();
1208
1209 Session session = null;
1210
1211 try {
1212 session = openSession();
1213
1214 Query q = session.createQuery(sql);
1215
1216 QueryPos qPos = QueryPos.getInstance(q);
1217
1218 qPos.add(companyId);
1219
1220 qPos.add(groupId);
1221
1222 if (bindName) {
1223 qPos.add(name);
1224 }
1225
1226 count = (Long)q.uniqueResult();
1227
1228 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1229 }
1230 catch (Exception e) {
1231 FinderCacheUtil.removeResult(finderPath, finderArgs);
1232
1233 throw processException(e);
1234 }
1235 finally {
1236 closeSession(session);
1237 }
1238 }
1239
1240 return count.intValue();
1241 }
1242
1243 private static final String _FINDER_COLUMN_C_G_N_COMPANYID_2 = "resourceBlock.companyId = ? AND ";
1244 private static final String _FINDER_COLUMN_C_G_N_GROUPID_2 = "resourceBlock.groupId = ? AND ";
1245 private static final String _FINDER_COLUMN_C_G_N_NAME_1 = "resourceBlock.name IS NULL";
1246 private static final String _FINDER_COLUMN_C_G_N_NAME_2 = "resourceBlock.name = ?";
1247 private static final String _FINDER_COLUMN_C_G_N_NAME_3 = "(resourceBlock.name IS NULL OR resourceBlock.name = '')";
1248 public static final FinderPath FINDER_PATH_FETCH_BY_C_G_N_P = new FinderPath(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
1249 ResourceBlockModelImpl.FINDER_CACHE_ENABLED,
1250 ResourceBlockImpl.class, FINDER_CLASS_NAME_ENTITY,
1251 "fetchByC_G_N_P",
1252 new String[] {
1253 Long.class.getName(), Long.class.getName(),
1254 String.class.getName(), String.class.getName()
1255 },
1256 ResourceBlockModelImpl.COMPANYID_COLUMN_BITMASK |
1257 ResourceBlockModelImpl.GROUPID_COLUMN_BITMASK |
1258 ResourceBlockModelImpl.NAME_COLUMN_BITMASK |
1259 ResourceBlockModelImpl.PERMISSIONSHASH_COLUMN_BITMASK);
1260 public static final FinderPath FINDER_PATH_COUNT_BY_C_G_N_P = new FinderPath(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
1261 ResourceBlockModelImpl.FINDER_CACHE_ENABLED, Long.class,
1262 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_G_N_P",
1263 new String[] {
1264 Long.class.getName(), Long.class.getName(),
1265 String.class.getName(), String.class.getName()
1266 });
1267
1268
1278 @Override
1279 public ResourceBlock findByC_G_N_P(long companyId, long groupId,
1280 String name, String permissionsHash)
1281 throws NoSuchResourceBlockException {
1282 ResourceBlock resourceBlock = fetchByC_G_N_P(companyId, groupId, name,
1283 permissionsHash);
1284
1285 if (resourceBlock == null) {
1286 StringBundler msg = new StringBundler(10);
1287
1288 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1289
1290 msg.append("companyId=");
1291 msg.append(companyId);
1292
1293 msg.append(", groupId=");
1294 msg.append(groupId);
1295
1296 msg.append(", name=");
1297 msg.append(name);
1298
1299 msg.append(", permissionsHash=");
1300 msg.append(permissionsHash);
1301
1302 msg.append(StringPool.CLOSE_CURLY_BRACE);
1303
1304 if (_log.isWarnEnabled()) {
1305 _log.warn(msg.toString());
1306 }
1307
1308 throw new NoSuchResourceBlockException(msg.toString());
1309 }
1310
1311 return resourceBlock;
1312 }
1313
1314
1323 @Override
1324 public ResourceBlock fetchByC_G_N_P(long companyId, long groupId,
1325 String name, String permissionsHash) {
1326 return fetchByC_G_N_P(companyId, groupId, name, permissionsHash, true);
1327 }
1328
1329
1339 @Override
1340 public ResourceBlock fetchByC_G_N_P(long companyId, long groupId,
1341 String name, String permissionsHash, boolean retrieveFromCache) {
1342 Object[] finderArgs = new Object[] {
1343 companyId, groupId, name, permissionsHash
1344 };
1345
1346 Object result = null;
1347
1348 if (retrieveFromCache) {
1349 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_G_N_P,
1350 finderArgs, this);
1351 }
1352
1353 if (result instanceof ResourceBlock) {
1354 ResourceBlock resourceBlock = (ResourceBlock)result;
1355
1356 if ((companyId != resourceBlock.getCompanyId()) ||
1357 (groupId != resourceBlock.getGroupId()) ||
1358 !Validator.equals(name, resourceBlock.getName()) ||
1359 !Validator.equals(permissionsHash,
1360 resourceBlock.getPermissionsHash())) {
1361 result = null;
1362 }
1363 }
1364
1365 if (result == null) {
1366 StringBundler query = new StringBundler(6);
1367
1368 query.append(_SQL_SELECT_RESOURCEBLOCK_WHERE);
1369
1370 query.append(_FINDER_COLUMN_C_G_N_P_COMPANYID_2);
1371
1372 query.append(_FINDER_COLUMN_C_G_N_P_GROUPID_2);
1373
1374 boolean bindName = false;
1375
1376 if (name == null) {
1377 query.append(_FINDER_COLUMN_C_G_N_P_NAME_1);
1378 }
1379 else if (name.equals(StringPool.BLANK)) {
1380 query.append(_FINDER_COLUMN_C_G_N_P_NAME_3);
1381 }
1382 else {
1383 bindName = true;
1384
1385 query.append(_FINDER_COLUMN_C_G_N_P_NAME_2);
1386 }
1387
1388 boolean bindPermissionsHash = false;
1389
1390 if (permissionsHash == null) {
1391 query.append(_FINDER_COLUMN_C_G_N_P_PERMISSIONSHASH_1);
1392 }
1393 else if (permissionsHash.equals(StringPool.BLANK)) {
1394 query.append(_FINDER_COLUMN_C_G_N_P_PERMISSIONSHASH_3);
1395 }
1396 else {
1397 bindPermissionsHash = true;
1398
1399 query.append(_FINDER_COLUMN_C_G_N_P_PERMISSIONSHASH_2);
1400 }
1401
1402 String sql = query.toString();
1403
1404 Session session = null;
1405
1406 try {
1407 session = openSession();
1408
1409 Query q = session.createQuery(sql);
1410
1411 QueryPos qPos = QueryPos.getInstance(q);
1412
1413 qPos.add(companyId);
1414
1415 qPos.add(groupId);
1416
1417 if (bindName) {
1418 qPos.add(name);
1419 }
1420
1421 if (bindPermissionsHash) {
1422 qPos.add(permissionsHash);
1423 }
1424
1425 List<ResourceBlock> list = q.list();
1426
1427 if (list.isEmpty()) {
1428 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_G_N_P,
1429 finderArgs, list);
1430 }
1431 else {
1432 ResourceBlock resourceBlock = list.get(0);
1433
1434 result = resourceBlock;
1435
1436 cacheResult(resourceBlock);
1437
1438 if ((resourceBlock.getCompanyId() != companyId) ||
1439 (resourceBlock.getGroupId() != groupId) ||
1440 (resourceBlock.getName() == null) ||
1441 !resourceBlock.getName().equals(name) ||
1442 (resourceBlock.getPermissionsHash() == null) ||
1443 !resourceBlock.getPermissionsHash()
1444 .equals(permissionsHash)) {
1445 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_G_N_P,
1446 finderArgs, resourceBlock);
1447 }
1448 }
1449 }
1450 catch (Exception e) {
1451 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_G_N_P,
1452 finderArgs);
1453
1454 throw processException(e);
1455 }
1456 finally {
1457 closeSession(session);
1458 }
1459 }
1460
1461 if (result instanceof List<?>) {
1462 return null;
1463 }
1464 else {
1465 return (ResourceBlock)result;
1466 }
1467 }
1468
1469
1478 @Override
1479 public ResourceBlock removeByC_G_N_P(long companyId, long groupId,
1480 String name, String permissionsHash)
1481 throws NoSuchResourceBlockException {
1482 ResourceBlock resourceBlock = findByC_G_N_P(companyId, groupId, name,
1483 permissionsHash);
1484
1485 return remove(resourceBlock);
1486 }
1487
1488
1497 @Override
1498 public int countByC_G_N_P(long companyId, long groupId, String name,
1499 String permissionsHash) {
1500 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_G_N_P;
1501
1502 Object[] finderArgs = new Object[] {
1503 companyId, groupId, name, permissionsHash
1504 };
1505
1506 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1507 this);
1508
1509 if (count == null) {
1510 StringBundler query = new StringBundler(5);
1511
1512 query.append(_SQL_COUNT_RESOURCEBLOCK_WHERE);
1513
1514 query.append(_FINDER_COLUMN_C_G_N_P_COMPANYID_2);
1515
1516 query.append(_FINDER_COLUMN_C_G_N_P_GROUPID_2);
1517
1518 boolean bindName = false;
1519
1520 if (name == null) {
1521 query.append(_FINDER_COLUMN_C_G_N_P_NAME_1);
1522 }
1523 else if (name.equals(StringPool.BLANK)) {
1524 query.append(_FINDER_COLUMN_C_G_N_P_NAME_3);
1525 }
1526 else {
1527 bindName = true;
1528
1529 query.append(_FINDER_COLUMN_C_G_N_P_NAME_2);
1530 }
1531
1532 boolean bindPermissionsHash = false;
1533
1534 if (permissionsHash == null) {
1535 query.append(_FINDER_COLUMN_C_G_N_P_PERMISSIONSHASH_1);
1536 }
1537 else if (permissionsHash.equals(StringPool.BLANK)) {
1538 query.append(_FINDER_COLUMN_C_G_N_P_PERMISSIONSHASH_3);
1539 }
1540 else {
1541 bindPermissionsHash = true;
1542
1543 query.append(_FINDER_COLUMN_C_G_N_P_PERMISSIONSHASH_2);
1544 }
1545
1546 String sql = query.toString();
1547
1548 Session session = null;
1549
1550 try {
1551 session = openSession();
1552
1553 Query q = session.createQuery(sql);
1554
1555 QueryPos qPos = QueryPos.getInstance(q);
1556
1557 qPos.add(companyId);
1558
1559 qPos.add(groupId);
1560
1561 if (bindName) {
1562 qPos.add(name);
1563 }
1564
1565 if (bindPermissionsHash) {
1566 qPos.add(permissionsHash);
1567 }
1568
1569 count = (Long)q.uniqueResult();
1570
1571 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1572 }
1573 catch (Exception e) {
1574 FinderCacheUtil.removeResult(finderPath, finderArgs);
1575
1576 throw processException(e);
1577 }
1578 finally {
1579 closeSession(session);
1580 }
1581 }
1582
1583 return count.intValue();
1584 }
1585
1586 private static final String _FINDER_COLUMN_C_G_N_P_COMPANYID_2 = "resourceBlock.companyId = ? AND ";
1587 private static final String _FINDER_COLUMN_C_G_N_P_GROUPID_2 = "resourceBlock.groupId = ? AND ";
1588 private static final String _FINDER_COLUMN_C_G_N_P_NAME_1 = "resourceBlock.name IS NULL AND ";
1589 private static final String _FINDER_COLUMN_C_G_N_P_NAME_2 = "resourceBlock.name = ? AND ";
1590 private static final String _FINDER_COLUMN_C_G_N_P_NAME_3 = "(resourceBlock.name IS NULL OR resourceBlock.name = '') AND ";
1591 private static final String _FINDER_COLUMN_C_G_N_P_PERMISSIONSHASH_1 = "resourceBlock.permissionsHash IS NULL";
1592 private static final String _FINDER_COLUMN_C_G_N_P_PERMISSIONSHASH_2 = "resourceBlock.permissionsHash = ?";
1593 private static final String _FINDER_COLUMN_C_G_N_P_PERMISSIONSHASH_3 = "(resourceBlock.permissionsHash IS NULL OR resourceBlock.permissionsHash = '')";
1594
1595 public ResourceBlockPersistenceImpl() {
1596 setModelClass(ResourceBlock.class);
1597 }
1598
1599
1604 @Override
1605 public void cacheResult(ResourceBlock resourceBlock) {
1606 EntityCacheUtil.putResult(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
1607 ResourceBlockImpl.class, resourceBlock.getPrimaryKey(),
1608 resourceBlock);
1609
1610 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_G_N_P,
1611 new Object[] {
1612 resourceBlock.getCompanyId(), resourceBlock.getGroupId(),
1613 resourceBlock.getName(), resourceBlock.getPermissionsHash()
1614 }, resourceBlock);
1615
1616 resourceBlock.resetOriginalValues();
1617 }
1618
1619
1624 @Override
1625 public void cacheResult(List<ResourceBlock> resourceBlocks) {
1626 for (ResourceBlock resourceBlock : resourceBlocks) {
1627 if (EntityCacheUtil.getResult(
1628 ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
1629 ResourceBlockImpl.class, resourceBlock.getPrimaryKey()) == null) {
1630 cacheResult(resourceBlock);
1631 }
1632 else {
1633 resourceBlock.resetOriginalValues();
1634 }
1635 }
1636 }
1637
1638
1645 @Override
1646 public void clearCache() {
1647 EntityCacheUtil.clearCache(ResourceBlockImpl.class);
1648
1649 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1650 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1651 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1652 }
1653
1654
1661 @Override
1662 public void clearCache(ResourceBlock resourceBlock) {
1663 EntityCacheUtil.removeResult(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
1664 ResourceBlockImpl.class, resourceBlock.getPrimaryKey());
1665
1666 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1667 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1668
1669 clearUniqueFindersCache(resourceBlock);
1670 }
1671
1672 @Override
1673 public void clearCache(List<ResourceBlock> resourceBlocks) {
1674 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1675 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1676
1677 for (ResourceBlock resourceBlock : resourceBlocks) {
1678 EntityCacheUtil.removeResult(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
1679 ResourceBlockImpl.class, resourceBlock.getPrimaryKey());
1680
1681 clearUniqueFindersCache(resourceBlock);
1682 }
1683 }
1684
1685 protected void cacheUniqueFindersCache(ResourceBlock resourceBlock) {
1686 if (resourceBlock.isNew()) {
1687 Object[] args = new Object[] {
1688 resourceBlock.getCompanyId(), resourceBlock.getGroupId(),
1689 resourceBlock.getName(), resourceBlock.getPermissionsHash()
1690 };
1691
1692 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_G_N_P, args,
1693 Long.valueOf(1));
1694 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_G_N_P, args,
1695 resourceBlock);
1696 }
1697 else {
1698 ResourceBlockModelImpl resourceBlockModelImpl = (ResourceBlockModelImpl)resourceBlock;
1699
1700 if ((resourceBlockModelImpl.getColumnBitmask() &
1701 FINDER_PATH_FETCH_BY_C_G_N_P.getColumnBitmask()) != 0) {
1702 Object[] args = new Object[] {
1703 resourceBlock.getCompanyId(), resourceBlock.getGroupId(),
1704 resourceBlock.getName(),
1705 resourceBlock.getPermissionsHash()
1706 };
1707
1708 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_G_N_P, args,
1709 Long.valueOf(1));
1710 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_G_N_P, args,
1711 resourceBlock);
1712 }
1713 }
1714 }
1715
1716 protected void clearUniqueFindersCache(ResourceBlock resourceBlock) {
1717 ResourceBlockModelImpl resourceBlockModelImpl = (ResourceBlockModelImpl)resourceBlock;
1718
1719 Object[] args = new Object[] {
1720 resourceBlock.getCompanyId(), resourceBlock.getGroupId(),
1721 resourceBlock.getName(), resourceBlock.getPermissionsHash()
1722 };
1723
1724 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_G_N_P, args);
1725 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_G_N_P, args);
1726
1727 if ((resourceBlockModelImpl.getColumnBitmask() &
1728 FINDER_PATH_FETCH_BY_C_G_N_P.getColumnBitmask()) != 0) {
1729 args = new Object[] {
1730 resourceBlockModelImpl.getOriginalCompanyId(),
1731 resourceBlockModelImpl.getOriginalGroupId(),
1732 resourceBlockModelImpl.getOriginalName(),
1733 resourceBlockModelImpl.getOriginalPermissionsHash()
1734 };
1735
1736 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_G_N_P, args);
1737 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_G_N_P, args);
1738 }
1739 }
1740
1741
1747 @Override
1748 public ResourceBlock create(long resourceBlockId) {
1749 ResourceBlock resourceBlock = new ResourceBlockImpl();
1750
1751 resourceBlock.setNew(true);
1752 resourceBlock.setPrimaryKey(resourceBlockId);
1753
1754 return resourceBlock;
1755 }
1756
1757
1764 @Override
1765 public ResourceBlock remove(long resourceBlockId)
1766 throws NoSuchResourceBlockException {
1767 return remove((Serializable)resourceBlockId);
1768 }
1769
1770
1777 @Override
1778 public ResourceBlock remove(Serializable primaryKey)
1779 throws NoSuchResourceBlockException {
1780 Session session = null;
1781
1782 try {
1783 session = openSession();
1784
1785 ResourceBlock resourceBlock = (ResourceBlock)session.get(ResourceBlockImpl.class,
1786 primaryKey);
1787
1788 if (resourceBlock == null) {
1789 if (_log.isWarnEnabled()) {
1790 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1791 }
1792
1793 throw new NoSuchResourceBlockException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1794 primaryKey);
1795 }
1796
1797 return remove(resourceBlock);
1798 }
1799 catch (NoSuchResourceBlockException nsee) {
1800 throw nsee;
1801 }
1802 catch (Exception e) {
1803 throw processException(e);
1804 }
1805 finally {
1806 closeSession(session);
1807 }
1808 }
1809
1810 @Override
1811 protected ResourceBlock removeImpl(ResourceBlock resourceBlock) {
1812 resourceBlock = toUnwrappedModel(resourceBlock);
1813
1814 Session session = null;
1815
1816 try {
1817 session = openSession();
1818
1819 if (!session.contains(resourceBlock)) {
1820 resourceBlock = (ResourceBlock)session.get(ResourceBlockImpl.class,
1821 resourceBlock.getPrimaryKeyObj());
1822 }
1823
1824 if (resourceBlock != null) {
1825 session.delete(resourceBlock);
1826 }
1827 }
1828 catch (Exception e) {
1829 throw processException(e);
1830 }
1831 finally {
1832 closeSession(session);
1833 }
1834
1835 if (resourceBlock != null) {
1836 clearCache(resourceBlock);
1837 }
1838
1839 return resourceBlock;
1840 }
1841
1842 @Override
1843 public ResourceBlock updateImpl(ResourceBlock resourceBlock) {
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, false);
1926
1927 clearUniqueFindersCache(resourceBlock);
1928 cacheUniqueFindersCache(resourceBlock);
1929
1930 resourceBlock.resetOriginalValues();
1931
1932 return resourceBlock;
1933 }
1934
1935 protected ResourceBlock toUnwrappedModel(ResourceBlock resourceBlock) {
1936 if (resourceBlock instanceof ResourceBlockImpl) {
1937 return resourceBlock;
1938 }
1939
1940 ResourceBlockImpl resourceBlockImpl = new ResourceBlockImpl();
1941
1942 resourceBlockImpl.setNew(resourceBlock.isNew());
1943 resourceBlockImpl.setPrimaryKey(resourceBlock.getPrimaryKey());
1944
1945 resourceBlockImpl.setMvccVersion(resourceBlock.getMvccVersion());
1946 resourceBlockImpl.setResourceBlockId(resourceBlock.getResourceBlockId());
1947 resourceBlockImpl.setCompanyId(resourceBlock.getCompanyId());
1948 resourceBlockImpl.setGroupId(resourceBlock.getGroupId());
1949 resourceBlockImpl.setName(resourceBlock.getName());
1950 resourceBlockImpl.setPermissionsHash(resourceBlock.getPermissionsHash());
1951 resourceBlockImpl.setReferenceCount(resourceBlock.getReferenceCount());
1952
1953 return resourceBlockImpl;
1954 }
1955
1956
1963 @Override
1964 public ResourceBlock findByPrimaryKey(Serializable primaryKey)
1965 throws NoSuchResourceBlockException {
1966 ResourceBlock resourceBlock = fetchByPrimaryKey(primaryKey);
1967
1968 if (resourceBlock == null) {
1969 if (_log.isWarnEnabled()) {
1970 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1971 }
1972
1973 throw new NoSuchResourceBlockException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1974 primaryKey);
1975 }
1976
1977 return resourceBlock;
1978 }
1979
1980
1987 @Override
1988 public ResourceBlock findByPrimaryKey(long resourceBlockId)
1989 throws NoSuchResourceBlockException {
1990 return findByPrimaryKey((Serializable)resourceBlockId);
1991 }
1992
1993
1999 @Override
2000 public ResourceBlock fetchByPrimaryKey(Serializable primaryKey) {
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
2045 @Override
2046 public ResourceBlock fetchByPrimaryKey(long resourceBlockId) {
2047 return fetchByPrimaryKey((Serializable)resourceBlockId);
2048 }
2049
2050 @Override
2051 public Map<Serializable, ResourceBlock> fetchByPrimaryKeys(
2052 Set<Serializable> primaryKeys) {
2053 if (primaryKeys.isEmpty()) {
2054 return Collections.emptyMap();
2055 }
2056
2057 Map<Serializable, ResourceBlock> map = new HashMap<Serializable, ResourceBlock>();
2058
2059 if (primaryKeys.size() == 1) {
2060 Iterator<Serializable> iterator = primaryKeys.iterator();
2061
2062 Serializable primaryKey = iterator.next();
2063
2064 ResourceBlock resourceBlock = fetchByPrimaryKey(primaryKey);
2065
2066 if (resourceBlock != null) {
2067 map.put(primaryKey, resourceBlock);
2068 }
2069
2070 return map;
2071 }
2072
2073 Set<Serializable> uncachedPrimaryKeys = null;
2074
2075 for (Serializable primaryKey : primaryKeys) {
2076 ResourceBlock resourceBlock = (ResourceBlock)EntityCacheUtil.getResult(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
2077 ResourceBlockImpl.class, primaryKey);
2078
2079 if (resourceBlock == null) {
2080 if (uncachedPrimaryKeys == null) {
2081 uncachedPrimaryKeys = new HashSet<Serializable>();
2082 }
2083
2084 uncachedPrimaryKeys.add(primaryKey);
2085 }
2086 else {
2087 map.put(primaryKey, resourceBlock);
2088 }
2089 }
2090
2091 if (uncachedPrimaryKeys == null) {
2092 return map;
2093 }
2094
2095 StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
2096 1);
2097
2098 query.append(_SQL_SELECT_RESOURCEBLOCK_WHERE_PKS_IN);
2099
2100 for (Serializable primaryKey : uncachedPrimaryKeys) {
2101 query.append(String.valueOf(primaryKey));
2102
2103 query.append(StringPool.COMMA);
2104 }
2105
2106 query.setIndex(query.index() - 1);
2107
2108 query.append(StringPool.CLOSE_PARENTHESIS);
2109
2110 String sql = query.toString();
2111
2112 Session session = null;
2113
2114 try {
2115 session = openSession();
2116
2117 Query q = session.createQuery(sql);
2118
2119 for (ResourceBlock resourceBlock : (List<ResourceBlock>)q.list()) {
2120 map.put(resourceBlock.getPrimaryKeyObj(), resourceBlock);
2121
2122 cacheResult(resourceBlock);
2123
2124 uncachedPrimaryKeys.remove(resourceBlock.getPrimaryKeyObj());
2125 }
2126
2127 for (Serializable primaryKey : uncachedPrimaryKeys) {
2128 EntityCacheUtil.putResult(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
2129 ResourceBlockImpl.class, primaryKey, _nullResourceBlock);
2130 }
2131 }
2132 catch (Exception e) {
2133 throw processException(e);
2134 }
2135 finally {
2136 closeSession(session);
2137 }
2138
2139 return map;
2140 }
2141
2142
2147 @Override
2148 public List<ResourceBlock> findAll() {
2149 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2150 }
2151
2152
2163 @Override
2164 public List<ResourceBlock> findAll(int start, int end) {
2165 return findAll(start, end, null);
2166 }
2167
2168
2180 @Override
2181 public List<ResourceBlock> findAll(int start, int end,
2182 OrderByComparator<ResourceBlock> orderByComparator) {
2183 boolean pagination = true;
2184 FinderPath finderPath = null;
2185 Object[] finderArgs = null;
2186
2187 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2188 (orderByComparator == null)) {
2189 pagination = false;
2190 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2191 finderArgs = FINDER_ARGS_EMPTY;
2192 }
2193 else {
2194 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2195 finderArgs = new Object[] { start, end, orderByComparator };
2196 }
2197
2198 List<ResourceBlock> list = (List<ResourceBlock>)FinderCacheUtil.getResult(finderPath,
2199 finderArgs, this);
2200
2201 if (list == null) {
2202 StringBundler query = null;
2203 String sql = null;
2204
2205 if (orderByComparator != null) {
2206 query = new StringBundler(2 +
2207 (orderByComparator.getOrderByFields().length * 3));
2208
2209 query.append(_SQL_SELECT_RESOURCEBLOCK);
2210
2211 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2212 orderByComparator);
2213
2214 sql = query.toString();
2215 }
2216 else {
2217 sql = _SQL_SELECT_RESOURCEBLOCK;
2218
2219 if (pagination) {
2220 sql = sql.concat(ResourceBlockModelImpl.ORDER_BY_JPQL);
2221 }
2222 }
2223
2224 Session session = null;
2225
2226 try {
2227 session = openSession();
2228
2229 Query q = session.createQuery(sql);
2230
2231 if (!pagination) {
2232 list = (List<ResourceBlock>)QueryUtil.list(q, getDialect(),
2233 start, end, false);
2234
2235 Collections.sort(list);
2236
2237 list = Collections.unmodifiableList(list);
2238 }
2239 else {
2240 list = (List<ResourceBlock>)QueryUtil.list(q, getDialect(),
2241 start, end);
2242 }
2243
2244 cacheResult(list);
2245
2246 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2247 }
2248 catch (Exception e) {
2249 FinderCacheUtil.removeResult(finderPath, finderArgs);
2250
2251 throw processException(e);
2252 }
2253 finally {
2254 closeSession(session);
2255 }
2256 }
2257
2258 return list;
2259 }
2260
2261
2265 @Override
2266 public void removeAll() {
2267 for (ResourceBlock resourceBlock : findAll()) {
2268 remove(resourceBlock);
2269 }
2270 }
2271
2272
2277 @Override
2278 public int countAll() {
2279 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2280 FINDER_ARGS_EMPTY, this);
2281
2282 if (count == null) {
2283 Session session = null;
2284
2285 try {
2286 session = openSession();
2287
2288 Query q = session.createQuery(_SQL_COUNT_RESOURCEBLOCK);
2289
2290 count = (Long)q.uniqueResult();
2291
2292 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2293 FINDER_ARGS_EMPTY, count);
2294 }
2295 catch (Exception e) {
2296 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
2297 FINDER_ARGS_EMPTY);
2298
2299 throw processException(e);
2300 }
2301 finally {
2302 closeSession(session);
2303 }
2304 }
2305
2306 return count.intValue();
2307 }
2308
2309
2312 public void afterPropertiesSet() {
2313 }
2314
2315 public void destroy() {
2316 EntityCacheUtil.removeCache(ResourceBlockImpl.class.getName());
2317 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2318 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2319 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2320 }
2321
2322 private static final String _SQL_SELECT_RESOURCEBLOCK = "SELECT resourceBlock FROM ResourceBlock resourceBlock";
2323 private static final String _SQL_SELECT_RESOURCEBLOCK_WHERE_PKS_IN = "SELECT resourceBlock FROM ResourceBlock resourceBlock WHERE resourceBlockId IN (";
2324 private static final String _SQL_SELECT_RESOURCEBLOCK_WHERE = "SELECT resourceBlock FROM ResourceBlock resourceBlock WHERE ";
2325 private static final String _SQL_COUNT_RESOURCEBLOCK = "SELECT COUNT(resourceBlock) FROM ResourceBlock resourceBlock";
2326 private static final String _SQL_COUNT_RESOURCEBLOCK_WHERE = "SELECT COUNT(resourceBlock) FROM ResourceBlock resourceBlock WHERE ";
2327 private static final String _ORDER_BY_ENTITY_ALIAS = "resourceBlock.";
2328 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ResourceBlock exists with the primary key ";
2329 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ResourceBlock exists with the key {";
2330 private static final Log _log = LogFactoryUtil.getLog(ResourceBlockPersistenceImpl.class);
2331 private static final ResourceBlock _nullResourceBlock = new ResourceBlockImpl() {
2332 @Override
2333 public Object clone() {
2334 return this;
2335 }
2336
2337 @Override
2338 public CacheModel<ResourceBlock> toCacheModel() {
2339 return _nullResourceBlockCacheModel;
2340 }
2341 };
2342
2343 private static final CacheModel<ResourceBlock> _nullResourceBlockCacheModel = new NullCacheModel();
2344
2345 private static class NullCacheModel implements CacheModel<ResourceBlock>,
2346 MVCCModel {
2347 @Override
2348 public long getMvccVersion() {
2349 return -1;
2350 }
2351
2352 @Override
2353 public void setMvccVersion(long mvccVersion) {
2354 }
2355
2356 @Override
2357 public ResourceBlock toEntityModel() {
2358 return _nullResourceBlock;
2359 }
2360 }
2361 }