001
014
015 package com.liferay.portal.service.persistence.impl;
016
017 import aQute.bnd.annotation.ProviderType;
018
019 import com.liferay.portal.exception.NoSuchResourceBlockException;
020 import com.liferay.portal.kernel.bean.BeanReference;
021 import com.liferay.portal.kernel.dao.orm.EntityCache;
022 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
023 import com.liferay.portal.kernel.dao.orm.FinderCache;
024 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
025 import com.liferay.portal.kernel.dao.orm.FinderPath;
026 import com.liferay.portal.kernel.dao.orm.Query;
027 import com.liferay.portal.kernel.dao.orm.QueryPos;
028 import com.liferay.portal.kernel.dao.orm.QueryUtil;
029 import com.liferay.portal.kernel.dao.orm.Session;
030 import com.liferay.portal.kernel.log.Log;
031 import com.liferay.portal.kernel.log.LogFactoryUtil;
032 import com.liferay.portal.kernel.util.OrderByComparator;
033 import com.liferay.portal.kernel.util.StringBundler;
034 import com.liferay.portal.kernel.util.StringPool;
035 import com.liferay.portal.kernel.util.Validator;
036 import com.liferay.portal.model.CacheModel;
037 import com.liferay.portal.model.MVCCModel;
038 import com.liferay.portal.model.ResourceBlock;
039 import com.liferay.portal.model.impl.ResourceBlockImpl;
040 import com.liferay.portal.model.impl.ResourceBlockModelImpl;
041 import com.liferay.portal.service.persistence.CompanyProvider;
042 import com.liferay.portal.service.persistence.CompanyProviderWrapper;
043 import com.liferay.portal.service.persistence.ResourceBlockPersistence;
044
045 import java.io.Serializable;
046
047 import java.util.Collections;
048 import java.util.HashMap;
049 import java.util.HashSet;
050 import java.util.Iterator;
051 import java.util.List;
052 import java.util.Map;
053 import java.util.Set;
054
055
067 @ProviderType
068 public class ResourceBlockPersistenceImpl extends BasePersistenceImpl<ResourceBlock>
069 implements ResourceBlockPersistence {
070
075 public static final String FINDER_CLASS_NAME_ENTITY = ResourceBlockImpl.class.getName();
076 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
077 ".List1";
078 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
079 ".List2";
080 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
081 ResourceBlockModelImpl.FINDER_CACHE_ENABLED,
082 ResourceBlockImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
083 "findAll", new String[0]);
084 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
085 ResourceBlockModelImpl.FINDER_CACHE_ENABLED,
086 ResourceBlockImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
087 "findAll", new String[0]);
088 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
089 ResourceBlockModelImpl.FINDER_CACHE_ENABLED, Long.class,
090 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
091 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_N = new FinderPath(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
092 ResourceBlockModelImpl.FINDER_CACHE_ENABLED,
093 ResourceBlockImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
094 "findByC_N",
095 new String[] {
096 Long.class.getName(), String.class.getName(),
097
098 Integer.class.getName(), Integer.class.getName(),
099 OrderByComparator.class.getName()
100 });
101 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N = new FinderPath(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
102 ResourceBlockModelImpl.FINDER_CACHE_ENABLED,
103 ResourceBlockImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
104 "findByC_N",
105 new String[] { Long.class.getName(), String.class.getName() },
106 ResourceBlockModelImpl.COMPANYID_COLUMN_BITMASK |
107 ResourceBlockModelImpl.NAME_COLUMN_BITMASK);
108 public static final FinderPath FINDER_PATH_COUNT_BY_C_N = new FinderPath(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
109 ResourceBlockModelImpl.FINDER_CACHE_ENABLED, Long.class,
110 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_N",
111 new String[] { Long.class.getName(), String.class.getName() });
112
113
120 @Override
121 public List<ResourceBlock> findByC_N(long companyId, String name) {
122 return findByC_N(companyId, name, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
123 null);
124 }
125
126
139 @Override
140 public List<ResourceBlock> findByC_N(long companyId, String name,
141 int start, int end) {
142 return findByC_N(companyId, name, start, end, null);
143 }
144
145
159 @Override
160 public List<ResourceBlock> findByC_N(long companyId, String name,
161 int start, int end, OrderByComparator<ResourceBlock> orderByComparator) {
162 return findByC_N(companyId, name, start, end, orderByComparator, true);
163 }
164
165
180 @Override
181 public List<ResourceBlock> findByC_N(long companyId, String name,
182 int start, int end, OrderByComparator<ResourceBlock> orderByComparator,
183 boolean retrieveFromCache) {
184 boolean pagination = true;
185 FinderPath finderPath = null;
186 Object[] finderArgs = null;
187
188 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
189 (orderByComparator == null)) {
190 pagination = false;
191 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N;
192 finderArgs = new Object[] { companyId, name };
193 }
194 else {
195 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_N;
196 finderArgs = new Object[] {
197 companyId, name,
198
199 start, end, orderByComparator
200 };
201 }
202
203 List<ResourceBlock> list = null;
204
205 if (retrieveFromCache) {
206 list = (List<ResourceBlock>)finderCache.getResult(finderPath,
207 finderArgs, this);
208
209 if ((list != null) && !list.isEmpty()) {
210 for (ResourceBlock resourceBlock : list) {
211 if ((companyId != resourceBlock.getCompanyId()) ||
212 !Validator.equals(name, resourceBlock.getName())) {
213 list = null;
214
215 break;
216 }
217 }
218 }
219 }
220
221 if (list == null) {
222 StringBundler query = null;
223
224 if (orderByComparator != null) {
225 query = new StringBundler(4 +
226 (orderByComparator.getOrderByFields().length * 2));
227 }
228 else {
229 query = new StringBundler(4);
230 }
231
232 query.append(_SQL_SELECT_RESOURCEBLOCK_WHERE);
233
234 query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
235
236 boolean bindName = false;
237
238 if (name == null) {
239 query.append(_FINDER_COLUMN_C_N_NAME_1);
240 }
241 else if (name.equals(StringPool.BLANK)) {
242 query.append(_FINDER_COLUMN_C_N_NAME_3);
243 }
244 else {
245 bindName = true;
246
247 query.append(_FINDER_COLUMN_C_N_NAME_2);
248 }
249
250 if (orderByComparator != null) {
251 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
252 orderByComparator);
253 }
254 else
255 if (pagination) {
256 query.append(ResourceBlockModelImpl.ORDER_BY_JPQL);
257 }
258
259 String sql = query.toString();
260
261 Session session = null;
262
263 try {
264 session = openSession();
265
266 Query q = session.createQuery(sql);
267
268 QueryPos qPos = QueryPos.getInstance(q);
269
270 qPos.add(companyId);
271
272 if (bindName) {
273 qPos.add(name);
274 }
275
276 if (!pagination) {
277 list = (List<ResourceBlock>)QueryUtil.list(q, getDialect(),
278 start, end, false);
279
280 Collections.sort(list);
281
282 list = Collections.unmodifiableList(list);
283 }
284 else {
285 list = (List<ResourceBlock>)QueryUtil.list(q, getDialect(),
286 start, end);
287 }
288
289 cacheResult(list);
290
291 finderCache.putResult(finderPath, finderArgs, list);
292 }
293 catch (Exception e) {
294 finderCache.removeResult(finderPath, finderArgs);
295
296 throw processException(e);
297 }
298 finally {
299 closeSession(session);
300 }
301 }
302
303 return list;
304 }
305
306
315 @Override
316 public ResourceBlock findByC_N_First(long companyId, String name,
317 OrderByComparator<ResourceBlock> orderByComparator)
318 throws NoSuchResourceBlockException {
319 ResourceBlock resourceBlock = fetchByC_N_First(companyId, name,
320 orderByComparator);
321
322 if (resourceBlock != null) {
323 return resourceBlock;
324 }
325
326 StringBundler msg = new StringBundler(6);
327
328 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
329
330 msg.append("companyId=");
331 msg.append(companyId);
332
333 msg.append(", name=");
334 msg.append(name);
335
336 msg.append(StringPool.CLOSE_CURLY_BRACE);
337
338 throw new NoSuchResourceBlockException(msg.toString());
339 }
340
341
349 @Override
350 public ResourceBlock fetchByC_N_First(long companyId, String name,
351 OrderByComparator<ResourceBlock> orderByComparator) {
352 List<ResourceBlock> list = findByC_N(companyId, name, 0, 1,
353 orderByComparator);
354
355 if (!list.isEmpty()) {
356 return list.get(0);
357 }
358
359 return null;
360 }
361
362
371 @Override
372 public ResourceBlock findByC_N_Last(long companyId, String name,
373 OrderByComparator<ResourceBlock> orderByComparator)
374 throws NoSuchResourceBlockException {
375 ResourceBlock resourceBlock = fetchByC_N_Last(companyId, name,
376 orderByComparator);
377
378 if (resourceBlock != null) {
379 return resourceBlock;
380 }
381
382 StringBundler msg = new StringBundler(6);
383
384 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
385
386 msg.append("companyId=");
387 msg.append(companyId);
388
389 msg.append(", name=");
390 msg.append(name);
391
392 msg.append(StringPool.CLOSE_CURLY_BRACE);
393
394 throw new NoSuchResourceBlockException(msg.toString());
395 }
396
397
405 @Override
406 public ResourceBlock fetchByC_N_Last(long companyId, String name,
407 OrderByComparator<ResourceBlock> orderByComparator) {
408 int count = countByC_N(companyId, name);
409
410 if (count == 0) {
411 return null;
412 }
413
414 List<ResourceBlock> list = findByC_N(companyId, name, count - 1, count,
415 orderByComparator);
416
417 if (!list.isEmpty()) {
418 return list.get(0);
419 }
420
421 return null;
422 }
423
424
434 @Override
435 public ResourceBlock[] findByC_N_PrevAndNext(long resourceBlockId,
436 long companyId, String name,
437 OrderByComparator<ResourceBlock> orderByComparator)
438 throws NoSuchResourceBlockException {
439 ResourceBlock resourceBlock = findByPrimaryKey(resourceBlockId);
440
441 Session session = null;
442
443 try {
444 session = openSession();
445
446 ResourceBlock[] array = new ResourceBlockImpl[3];
447
448 array[0] = getByC_N_PrevAndNext(session, resourceBlock, companyId,
449 name, orderByComparator, true);
450
451 array[1] = resourceBlock;
452
453 array[2] = getByC_N_PrevAndNext(session, resourceBlock, companyId,
454 name, orderByComparator, false);
455
456 return array;
457 }
458 catch (Exception e) {
459 throw processException(e);
460 }
461 finally {
462 closeSession(session);
463 }
464 }
465
466 protected ResourceBlock getByC_N_PrevAndNext(Session session,
467 ResourceBlock resourceBlock, long companyId, String name,
468 OrderByComparator<ResourceBlock> orderByComparator, boolean previous) {
469 StringBundler query = null;
470
471 if (orderByComparator != null) {
472 query = new StringBundler(5 +
473 (orderByComparator.getOrderByConditionFields().length * 3) +
474 (orderByComparator.getOrderByFields().length * 3));
475 }
476 else {
477 query = new StringBundler(4);
478 }
479
480 query.append(_SQL_SELECT_RESOURCEBLOCK_WHERE);
481
482 query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
483
484 boolean bindName = false;
485
486 if (name == null) {
487 query.append(_FINDER_COLUMN_C_N_NAME_1);
488 }
489 else if (name.equals(StringPool.BLANK)) {
490 query.append(_FINDER_COLUMN_C_N_NAME_3);
491 }
492 else {
493 bindName = true;
494
495 query.append(_FINDER_COLUMN_C_N_NAME_2);
496 }
497
498 if (orderByComparator != null) {
499 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
500
501 if (orderByConditionFields.length > 0) {
502 query.append(WHERE_AND);
503 }
504
505 for (int i = 0; i < orderByConditionFields.length; i++) {
506 query.append(_ORDER_BY_ENTITY_ALIAS);
507 query.append(orderByConditionFields[i]);
508
509 if ((i + 1) < orderByConditionFields.length) {
510 if (orderByComparator.isAscending() ^ previous) {
511 query.append(WHERE_GREATER_THAN_HAS_NEXT);
512 }
513 else {
514 query.append(WHERE_LESSER_THAN_HAS_NEXT);
515 }
516 }
517 else {
518 if (orderByComparator.isAscending() ^ previous) {
519 query.append(WHERE_GREATER_THAN);
520 }
521 else {
522 query.append(WHERE_LESSER_THAN);
523 }
524 }
525 }
526
527 query.append(ORDER_BY_CLAUSE);
528
529 String[] orderByFields = orderByComparator.getOrderByFields();
530
531 for (int i = 0; i < orderByFields.length; i++) {
532 query.append(_ORDER_BY_ENTITY_ALIAS);
533 query.append(orderByFields[i]);
534
535 if ((i + 1) < orderByFields.length) {
536 if (orderByComparator.isAscending() ^ previous) {
537 query.append(ORDER_BY_ASC_HAS_NEXT);
538 }
539 else {
540 query.append(ORDER_BY_DESC_HAS_NEXT);
541 }
542 }
543 else {
544 if (orderByComparator.isAscending() ^ previous) {
545 query.append(ORDER_BY_ASC);
546 }
547 else {
548 query.append(ORDER_BY_DESC);
549 }
550 }
551 }
552 }
553 else {
554 query.append(ResourceBlockModelImpl.ORDER_BY_JPQL);
555 }
556
557 String sql = query.toString();
558
559 Query q = session.createQuery(sql);
560
561 q.setFirstResult(0);
562 q.setMaxResults(2);
563
564 QueryPos qPos = QueryPos.getInstance(q);
565
566 qPos.add(companyId);
567
568 if (bindName) {
569 qPos.add(name);
570 }
571
572 if (orderByComparator != null) {
573 Object[] values = orderByComparator.getOrderByConditionValues(resourceBlock);
574
575 for (Object value : values) {
576 qPos.add(value);
577 }
578 }
579
580 List<ResourceBlock> list = q.list();
581
582 if (list.size() == 2) {
583 return list.get(1);
584 }
585 else {
586 return null;
587 }
588 }
589
590
596 @Override
597 public void removeByC_N(long companyId, String name) {
598 for (ResourceBlock resourceBlock : findByC_N(companyId, name,
599 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
600 remove(resourceBlock);
601 }
602 }
603
604
611 @Override
612 public int countByC_N(long companyId, String name) {
613 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_N;
614
615 Object[] finderArgs = new Object[] { companyId, name };
616
617 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
618
619 if (count == null) {
620 StringBundler query = new StringBundler(3);
621
622 query.append(_SQL_COUNT_RESOURCEBLOCK_WHERE);
623
624 query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
625
626 boolean bindName = false;
627
628 if (name == null) {
629 query.append(_FINDER_COLUMN_C_N_NAME_1);
630 }
631 else if (name.equals(StringPool.BLANK)) {
632 query.append(_FINDER_COLUMN_C_N_NAME_3);
633 }
634 else {
635 bindName = true;
636
637 query.append(_FINDER_COLUMN_C_N_NAME_2);
638 }
639
640 String sql = query.toString();
641
642 Session session = null;
643
644 try {
645 session = openSession();
646
647 Query q = session.createQuery(sql);
648
649 QueryPos qPos = QueryPos.getInstance(q);
650
651 qPos.add(companyId);
652
653 if (bindName) {
654 qPos.add(name);
655 }
656
657 count = (Long)q.uniqueResult();
658
659 finderCache.putResult(finderPath, finderArgs, count);
660 }
661 catch (Exception e) {
662 finderCache.removeResult(finderPath, finderArgs);
663
664 throw processException(e);
665 }
666 finally {
667 closeSession(session);
668 }
669 }
670
671 return count.intValue();
672 }
673
674 private static final String _FINDER_COLUMN_C_N_COMPANYID_2 = "resourceBlock.companyId = ? AND ";
675 private static final String _FINDER_COLUMN_C_N_NAME_1 = "resourceBlock.name IS NULL";
676 private static final String _FINDER_COLUMN_C_N_NAME_2 = "resourceBlock.name = ?";
677 private static final String _FINDER_COLUMN_C_N_NAME_3 = "(resourceBlock.name IS NULL OR resourceBlock.name = '')";
678 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_G_N = new FinderPath(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
679 ResourceBlockModelImpl.FINDER_CACHE_ENABLED,
680 ResourceBlockImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
681 "findByC_G_N",
682 new String[] {
683 Long.class.getName(), Long.class.getName(),
684 String.class.getName(),
685
686 Integer.class.getName(), Integer.class.getName(),
687 OrderByComparator.class.getName()
688 });
689 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_G_N = new FinderPath(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
690 ResourceBlockModelImpl.FINDER_CACHE_ENABLED,
691 ResourceBlockImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
692 "findByC_G_N",
693 new String[] {
694 Long.class.getName(), Long.class.getName(),
695 String.class.getName()
696 },
697 ResourceBlockModelImpl.COMPANYID_COLUMN_BITMASK |
698 ResourceBlockModelImpl.GROUPID_COLUMN_BITMASK |
699 ResourceBlockModelImpl.NAME_COLUMN_BITMASK);
700 public static final FinderPath FINDER_PATH_COUNT_BY_C_G_N = new FinderPath(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
701 ResourceBlockModelImpl.FINDER_CACHE_ENABLED, Long.class,
702 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_G_N",
703 new String[] {
704 Long.class.getName(), Long.class.getName(),
705 String.class.getName()
706 });
707
708
716 @Override
717 public List<ResourceBlock> findByC_G_N(long companyId, long groupId,
718 String name) {
719 return findByC_G_N(companyId, groupId, name, QueryUtil.ALL_POS,
720 QueryUtil.ALL_POS, null);
721 }
722
723
737 @Override
738 public List<ResourceBlock> findByC_G_N(long companyId, long groupId,
739 String name, int start, int end) {
740 return findByC_G_N(companyId, groupId, name, start, end, null);
741 }
742
743
758 @Override
759 public List<ResourceBlock> findByC_G_N(long companyId, long groupId,
760 String name, int start, int end,
761 OrderByComparator<ResourceBlock> orderByComparator) {
762 return findByC_G_N(companyId, groupId, name, start, end,
763 orderByComparator, true);
764 }
765
766
782 @Override
783 public List<ResourceBlock> findByC_G_N(long companyId, long groupId,
784 String name, int start, int end,
785 OrderByComparator<ResourceBlock> orderByComparator,
786 boolean retrieveFromCache) {
787 boolean pagination = true;
788 FinderPath finderPath = null;
789 Object[] finderArgs = null;
790
791 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
792 (orderByComparator == null)) {
793 pagination = false;
794 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_G_N;
795 finderArgs = new Object[] { companyId, groupId, name };
796 }
797 else {
798 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_G_N;
799 finderArgs = new Object[] {
800 companyId, groupId, name,
801
802 start, end, orderByComparator
803 };
804 }
805
806 List<ResourceBlock> list = null;
807
808 if (retrieveFromCache) {
809 list = (List<ResourceBlock>)finderCache.getResult(finderPath,
810 finderArgs, this);
811
812 if ((list != null) && !list.isEmpty()) {
813 for (ResourceBlock resourceBlock : list) {
814 if ((companyId != resourceBlock.getCompanyId()) ||
815 (groupId != resourceBlock.getGroupId()) ||
816 !Validator.equals(name, resourceBlock.getName())) {
817 list = null;
818
819 break;
820 }
821 }
822 }
823 }
824
825 if (list == null) {
826 StringBundler query = null;
827
828 if (orderByComparator != null) {
829 query = new StringBundler(5 +
830 (orderByComparator.getOrderByFields().length * 2));
831 }
832 else {
833 query = new StringBundler(5);
834 }
835
836 query.append(_SQL_SELECT_RESOURCEBLOCK_WHERE);
837
838 query.append(_FINDER_COLUMN_C_G_N_COMPANYID_2);
839
840 query.append(_FINDER_COLUMN_C_G_N_GROUPID_2);
841
842 boolean bindName = false;
843
844 if (name == null) {
845 query.append(_FINDER_COLUMN_C_G_N_NAME_1);
846 }
847 else if (name.equals(StringPool.BLANK)) {
848 query.append(_FINDER_COLUMN_C_G_N_NAME_3);
849 }
850 else {
851 bindName = true;
852
853 query.append(_FINDER_COLUMN_C_G_N_NAME_2);
854 }
855
856 if (orderByComparator != null) {
857 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
858 orderByComparator);
859 }
860 else
861 if (pagination) {
862 query.append(ResourceBlockModelImpl.ORDER_BY_JPQL);
863 }
864
865 String sql = query.toString();
866
867 Session session = null;
868
869 try {
870 session = openSession();
871
872 Query q = session.createQuery(sql);
873
874 QueryPos qPos = QueryPos.getInstance(q);
875
876 qPos.add(companyId);
877
878 qPos.add(groupId);
879
880 if (bindName) {
881 qPos.add(name);
882 }
883
884 if (!pagination) {
885 list = (List<ResourceBlock>)QueryUtil.list(q, getDialect(),
886 start, end, false);
887
888 Collections.sort(list);
889
890 list = Collections.unmodifiableList(list);
891 }
892 else {
893 list = (List<ResourceBlock>)QueryUtil.list(q, getDialect(),
894 start, end);
895 }
896
897 cacheResult(list);
898
899 finderCache.putResult(finderPath, finderArgs, list);
900 }
901 catch (Exception e) {
902 finderCache.removeResult(finderPath, finderArgs);
903
904 throw processException(e);
905 }
906 finally {
907 closeSession(session);
908 }
909 }
910
911 return list;
912 }
913
914
924 @Override
925 public ResourceBlock findByC_G_N_First(long companyId, long groupId,
926 String name, OrderByComparator<ResourceBlock> orderByComparator)
927 throws NoSuchResourceBlockException {
928 ResourceBlock resourceBlock = fetchByC_G_N_First(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
962 @Override
963 public ResourceBlock fetchByC_G_N_First(long companyId, long groupId,
964 String name, OrderByComparator<ResourceBlock> orderByComparator) {
965 List<ResourceBlock> list = findByC_G_N(companyId, groupId, name, 0, 1,
966 orderByComparator);
967
968 if (!list.isEmpty()) {
969 return list.get(0);
970 }
971
972 return null;
973 }
974
975
985 @Override
986 public ResourceBlock findByC_G_N_Last(long companyId, long groupId,
987 String name, OrderByComparator<ResourceBlock> orderByComparator)
988 throws NoSuchResourceBlockException {
989 ResourceBlock resourceBlock = fetchByC_G_N_Last(companyId, groupId,
990 name, orderByComparator);
991
992 if (resourceBlock != null) {
993 return resourceBlock;
994 }
995
996 StringBundler msg = new StringBundler(8);
997
998 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
999
1000 msg.append("companyId=");
1001 msg.append(companyId);
1002
1003 msg.append(", groupId=");
1004 msg.append(groupId);
1005
1006 msg.append(", name=");
1007 msg.append(name);
1008
1009 msg.append(StringPool.CLOSE_CURLY_BRACE);
1010
1011 throw new NoSuchResourceBlockException(msg.toString());
1012 }
1013
1014
1023 @Override
1024 public ResourceBlock fetchByC_G_N_Last(long companyId, long groupId,
1025 String name, OrderByComparator<ResourceBlock> orderByComparator) {
1026 int count = countByC_G_N(companyId, groupId, name);
1027
1028 if (count == 0) {
1029 return null;
1030 }
1031
1032 List<ResourceBlock> list = findByC_G_N(companyId, groupId, name,
1033 count - 1, count, orderByComparator);
1034
1035 if (!list.isEmpty()) {
1036 return list.get(0);
1037 }
1038
1039 return null;
1040 }
1041
1042
1053 @Override
1054 public ResourceBlock[] findByC_G_N_PrevAndNext(long resourceBlockId,
1055 long companyId, long groupId, String name,
1056 OrderByComparator<ResourceBlock> orderByComparator)
1057 throws NoSuchResourceBlockException {
1058 ResourceBlock resourceBlock = findByPrimaryKey(resourceBlockId);
1059
1060 Session session = null;
1061
1062 try {
1063 session = openSession();
1064
1065 ResourceBlock[] array = new ResourceBlockImpl[3];
1066
1067 array[0] = getByC_G_N_PrevAndNext(session, resourceBlock,
1068 companyId, groupId, name, orderByComparator, true);
1069
1070 array[1] = resourceBlock;
1071
1072 array[2] = getByC_G_N_PrevAndNext(session, resourceBlock,
1073 companyId, groupId, name, orderByComparator, false);
1074
1075 return array;
1076 }
1077 catch (Exception e) {
1078 throw processException(e);
1079 }
1080 finally {
1081 closeSession(session);
1082 }
1083 }
1084
1085 protected ResourceBlock getByC_G_N_PrevAndNext(Session session,
1086 ResourceBlock resourceBlock, long companyId, long groupId, String name,
1087 OrderByComparator<ResourceBlock> orderByComparator, boolean previous) {
1088 StringBundler query = null;
1089
1090 if (orderByComparator != null) {
1091 query = new StringBundler(6 +
1092 (orderByComparator.getOrderByConditionFields().length * 3) +
1093 (orderByComparator.getOrderByFields().length * 3));
1094 }
1095 else {
1096 query = new StringBundler(5);
1097 }
1098
1099 query.append(_SQL_SELECT_RESOURCEBLOCK_WHERE);
1100
1101 query.append(_FINDER_COLUMN_C_G_N_COMPANYID_2);
1102
1103 query.append(_FINDER_COLUMN_C_G_N_GROUPID_2);
1104
1105 boolean bindName = false;
1106
1107 if (name == null) {
1108 query.append(_FINDER_COLUMN_C_G_N_NAME_1);
1109 }
1110 else if (name.equals(StringPool.BLANK)) {
1111 query.append(_FINDER_COLUMN_C_G_N_NAME_3);
1112 }
1113 else {
1114 bindName = true;
1115
1116 query.append(_FINDER_COLUMN_C_G_N_NAME_2);
1117 }
1118
1119 if (orderByComparator != null) {
1120 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1121
1122 if (orderByConditionFields.length > 0) {
1123 query.append(WHERE_AND);
1124 }
1125
1126 for (int i = 0; i < orderByConditionFields.length; i++) {
1127 query.append(_ORDER_BY_ENTITY_ALIAS);
1128 query.append(orderByConditionFields[i]);
1129
1130 if ((i + 1) < orderByConditionFields.length) {
1131 if (orderByComparator.isAscending() ^ previous) {
1132 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1133 }
1134 else {
1135 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1136 }
1137 }
1138 else {
1139 if (orderByComparator.isAscending() ^ previous) {
1140 query.append(WHERE_GREATER_THAN);
1141 }
1142 else {
1143 query.append(WHERE_LESSER_THAN);
1144 }
1145 }
1146 }
1147
1148 query.append(ORDER_BY_CLAUSE);
1149
1150 String[] orderByFields = orderByComparator.getOrderByFields();
1151
1152 for (int i = 0; i < orderByFields.length; i++) {
1153 query.append(_ORDER_BY_ENTITY_ALIAS);
1154 query.append(orderByFields[i]);
1155
1156 if ((i + 1) < orderByFields.length) {
1157 if (orderByComparator.isAscending() ^ previous) {
1158 query.append(ORDER_BY_ASC_HAS_NEXT);
1159 }
1160 else {
1161 query.append(ORDER_BY_DESC_HAS_NEXT);
1162 }
1163 }
1164 else {
1165 if (orderByComparator.isAscending() ^ previous) {
1166 query.append(ORDER_BY_ASC);
1167 }
1168 else {
1169 query.append(ORDER_BY_DESC);
1170 }
1171 }
1172 }
1173 }
1174 else {
1175 query.append(ResourceBlockModelImpl.ORDER_BY_JPQL);
1176 }
1177
1178 String sql = query.toString();
1179
1180 Query q = session.createQuery(sql);
1181
1182 q.setFirstResult(0);
1183 q.setMaxResults(2);
1184
1185 QueryPos qPos = QueryPos.getInstance(q);
1186
1187 qPos.add(companyId);
1188
1189 qPos.add(groupId);
1190
1191 if (bindName) {
1192 qPos.add(name);
1193 }
1194
1195 if (orderByComparator != null) {
1196 Object[] values = orderByComparator.getOrderByConditionValues(resourceBlock);
1197
1198 for (Object value : values) {
1199 qPos.add(value);
1200 }
1201 }
1202
1203 List<ResourceBlock> list = q.list();
1204
1205 if (list.size() == 2) {
1206 return list.get(1);
1207 }
1208 else {
1209 return null;
1210 }
1211 }
1212
1213
1220 @Override
1221 public void removeByC_G_N(long companyId, long groupId, String name) {
1222 for (ResourceBlock resourceBlock : findByC_G_N(companyId, groupId,
1223 name, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1224 remove(resourceBlock);
1225 }
1226 }
1227
1228
1236 @Override
1237 public int countByC_G_N(long companyId, long groupId, String name) {
1238 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_G_N;
1239
1240 Object[] finderArgs = new Object[] { companyId, groupId, name };
1241
1242 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1243
1244 if (count == null) {
1245 StringBundler query = new StringBundler(4);
1246
1247 query.append(_SQL_COUNT_RESOURCEBLOCK_WHERE);
1248
1249 query.append(_FINDER_COLUMN_C_G_N_COMPANYID_2);
1250
1251 query.append(_FINDER_COLUMN_C_G_N_GROUPID_2);
1252
1253 boolean bindName = false;
1254
1255 if (name == null) {
1256 query.append(_FINDER_COLUMN_C_G_N_NAME_1);
1257 }
1258 else if (name.equals(StringPool.BLANK)) {
1259 query.append(_FINDER_COLUMN_C_G_N_NAME_3);
1260 }
1261 else {
1262 bindName = true;
1263
1264 query.append(_FINDER_COLUMN_C_G_N_NAME_2);
1265 }
1266
1267 String sql = query.toString();
1268
1269 Session session = null;
1270
1271 try {
1272 session = openSession();
1273
1274 Query q = session.createQuery(sql);
1275
1276 QueryPos qPos = QueryPos.getInstance(q);
1277
1278 qPos.add(companyId);
1279
1280 qPos.add(groupId);
1281
1282 if (bindName) {
1283 qPos.add(name);
1284 }
1285
1286 count = (Long)q.uniqueResult();
1287
1288 finderCache.putResult(finderPath, finderArgs, count);
1289 }
1290 catch (Exception e) {
1291 finderCache.removeResult(finderPath, finderArgs);
1292
1293 throw processException(e);
1294 }
1295 finally {
1296 closeSession(session);
1297 }
1298 }
1299
1300 return count.intValue();
1301 }
1302
1303 private static final String _FINDER_COLUMN_C_G_N_COMPANYID_2 = "resourceBlock.companyId = ? AND ";
1304 private static final String _FINDER_COLUMN_C_G_N_GROUPID_2 = "resourceBlock.groupId = ? AND ";
1305 private static final String _FINDER_COLUMN_C_G_N_NAME_1 = "resourceBlock.name IS NULL";
1306 private static final String _FINDER_COLUMN_C_G_N_NAME_2 = "resourceBlock.name = ?";
1307 private static final String _FINDER_COLUMN_C_G_N_NAME_3 = "(resourceBlock.name IS NULL OR resourceBlock.name = '')";
1308 public static final FinderPath FINDER_PATH_FETCH_BY_C_G_N_P = new FinderPath(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
1309 ResourceBlockModelImpl.FINDER_CACHE_ENABLED,
1310 ResourceBlockImpl.class, FINDER_CLASS_NAME_ENTITY,
1311 "fetchByC_G_N_P",
1312 new String[] {
1313 Long.class.getName(), Long.class.getName(),
1314 String.class.getName(), String.class.getName()
1315 },
1316 ResourceBlockModelImpl.COMPANYID_COLUMN_BITMASK |
1317 ResourceBlockModelImpl.GROUPID_COLUMN_BITMASK |
1318 ResourceBlockModelImpl.NAME_COLUMN_BITMASK |
1319 ResourceBlockModelImpl.PERMISSIONSHASH_COLUMN_BITMASK);
1320 public static final FinderPath FINDER_PATH_COUNT_BY_C_G_N_P = new FinderPath(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
1321 ResourceBlockModelImpl.FINDER_CACHE_ENABLED, Long.class,
1322 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_G_N_P",
1323 new String[] {
1324 Long.class.getName(), Long.class.getName(),
1325 String.class.getName(), String.class.getName()
1326 });
1327
1328
1338 @Override
1339 public ResourceBlock findByC_G_N_P(long companyId, long groupId,
1340 String name, String permissionsHash)
1341 throws NoSuchResourceBlockException {
1342 ResourceBlock resourceBlock = fetchByC_G_N_P(companyId, groupId, name,
1343 permissionsHash);
1344
1345 if (resourceBlock == null) {
1346 StringBundler msg = new StringBundler(10);
1347
1348 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1349
1350 msg.append("companyId=");
1351 msg.append(companyId);
1352
1353 msg.append(", groupId=");
1354 msg.append(groupId);
1355
1356 msg.append(", name=");
1357 msg.append(name);
1358
1359 msg.append(", permissionsHash=");
1360 msg.append(permissionsHash);
1361
1362 msg.append(StringPool.CLOSE_CURLY_BRACE);
1363
1364 if (_log.isWarnEnabled()) {
1365 _log.warn(msg.toString());
1366 }
1367
1368 throw new NoSuchResourceBlockException(msg.toString());
1369 }
1370
1371 return resourceBlock;
1372 }
1373
1374
1383 @Override
1384 public ResourceBlock fetchByC_G_N_P(long companyId, long groupId,
1385 String name, String permissionsHash) {
1386 return fetchByC_G_N_P(companyId, groupId, name, permissionsHash, true);
1387 }
1388
1389
1399 @Override
1400 public ResourceBlock fetchByC_G_N_P(long companyId, long groupId,
1401 String name, String permissionsHash, boolean retrieveFromCache) {
1402 Object[] finderArgs = new Object[] {
1403 companyId, groupId, name, permissionsHash
1404 };
1405
1406 Object result = null;
1407
1408 if (retrieveFromCache) {
1409 result = finderCache.getResult(FINDER_PATH_FETCH_BY_C_G_N_P,
1410 finderArgs, this);
1411 }
1412
1413 if (result instanceof ResourceBlock) {
1414 ResourceBlock resourceBlock = (ResourceBlock)result;
1415
1416 if ((companyId != resourceBlock.getCompanyId()) ||
1417 (groupId != resourceBlock.getGroupId()) ||
1418 !Validator.equals(name, resourceBlock.getName()) ||
1419 !Validator.equals(permissionsHash,
1420 resourceBlock.getPermissionsHash())) {
1421 result = null;
1422 }
1423 }
1424
1425 if (result == null) {
1426 StringBundler query = new StringBundler(6);
1427
1428 query.append(_SQL_SELECT_RESOURCEBLOCK_WHERE);
1429
1430 query.append(_FINDER_COLUMN_C_G_N_P_COMPANYID_2);
1431
1432 query.append(_FINDER_COLUMN_C_G_N_P_GROUPID_2);
1433
1434 boolean bindName = false;
1435
1436 if (name == null) {
1437 query.append(_FINDER_COLUMN_C_G_N_P_NAME_1);
1438 }
1439 else if (name.equals(StringPool.BLANK)) {
1440 query.append(_FINDER_COLUMN_C_G_N_P_NAME_3);
1441 }
1442 else {
1443 bindName = true;
1444
1445 query.append(_FINDER_COLUMN_C_G_N_P_NAME_2);
1446 }
1447
1448 boolean bindPermissionsHash = false;
1449
1450 if (permissionsHash == null) {
1451 query.append(_FINDER_COLUMN_C_G_N_P_PERMISSIONSHASH_1);
1452 }
1453 else if (permissionsHash.equals(StringPool.BLANK)) {
1454 query.append(_FINDER_COLUMN_C_G_N_P_PERMISSIONSHASH_3);
1455 }
1456 else {
1457 bindPermissionsHash = true;
1458
1459 query.append(_FINDER_COLUMN_C_G_N_P_PERMISSIONSHASH_2);
1460 }
1461
1462 String sql = query.toString();
1463
1464 Session session = null;
1465
1466 try {
1467 session = openSession();
1468
1469 Query q = session.createQuery(sql);
1470
1471 QueryPos qPos = QueryPos.getInstance(q);
1472
1473 qPos.add(companyId);
1474
1475 qPos.add(groupId);
1476
1477 if (bindName) {
1478 qPos.add(name);
1479 }
1480
1481 if (bindPermissionsHash) {
1482 qPos.add(permissionsHash);
1483 }
1484
1485 List<ResourceBlock> list = q.list();
1486
1487 if (list.isEmpty()) {
1488 finderCache.putResult(FINDER_PATH_FETCH_BY_C_G_N_P,
1489 finderArgs, list);
1490 }
1491 else {
1492 ResourceBlock resourceBlock = list.get(0);
1493
1494 result = resourceBlock;
1495
1496 cacheResult(resourceBlock);
1497
1498 if ((resourceBlock.getCompanyId() != companyId) ||
1499 (resourceBlock.getGroupId() != groupId) ||
1500 (resourceBlock.getName() == null) ||
1501 !resourceBlock.getName().equals(name) ||
1502 (resourceBlock.getPermissionsHash() == null) ||
1503 !resourceBlock.getPermissionsHash()
1504 .equals(permissionsHash)) {
1505 finderCache.putResult(FINDER_PATH_FETCH_BY_C_G_N_P,
1506 finderArgs, resourceBlock);
1507 }
1508 }
1509 }
1510 catch (Exception e) {
1511 finderCache.removeResult(FINDER_PATH_FETCH_BY_C_G_N_P,
1512 finderArgs);
1513
1514 throw processException(e);
1515 }
1516 finally {
1517 closeSession(session);
1518 }
1519 }
1520
1521 if (result instanceof List<?>) {
1522 return null;
1523 }
1524 else {
1525 return (ResourceBlock)result;
1526 }
1527 }
1528
1529
1538 @Override
1539 public ResourceBlock removeByC_G_N_P(long companyId, long groupId,
1540 String name, String permissionsHash)
1541 throws NoSuchResourceBlockException {
1542 ResourceBlock resourceBlock = findByC_G_N_P(companyId, groupId, name,
1543 permissionsHash);
1544
1545 return remove(resourceBlock);
1546 }
1547
1548
1557 @Override
1558 public int countByC_G_N_P(long companyId, long groupId, String name,
1559 String permissionsHash) {
1560 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_G_N_P;
1561
1562 Object[] finderArgs = new Object[] {
1563 companyId, groupId, name, permissionsHash
1564 };
1565
1566 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1567
1568 if (count == null) {
1569 StringBundler query = new StringBundler(5);
1570
1571 query.append(_SQL_COUNT_RESOURCEBLOCK_WHERE);
1572
1573 query.append(_FINDER_COLUMN_C_G_N_P_COMPANYID_2);
1574
1575 query.append(_FINDER_COLUMN_C_G_N_P_GROUPID_2);
1576
1577 boolean bindName = false;
1578
1579 if (name == null) {
1580 query.append(_FINDER_COLUMN_C_G_N_P_NAME_1);
1581 }
1582 else if (name.equals(StringPool.BLANK)) {
1583 query.append(_FINDER_COLUMN_C_G_N_P_NAME_3);
1584 }
1585 else {
1586 bindName = true;
1587
1588 query.append(_FINDER_COLUMN_C_G_N_P_NAME_2);
1589 }
1590
1591 boolean bindPermissionsHash = false;
1592
1593 if (permissionsHash == null) {
1594 query.append(_FINDER_COLUMN_C_G_N_P_PERMISSIONSHASH_1);
1595 }
1596 else if (permissionsHash.equals(StringPool.BLANK)) {
1597 query.append(_FINDER_COLUMN_C_G_N_P_PERMISSIONSHASH_3);
1598 }
1599 else {
1600 bindPermissionsHash = true;
1601
1602 query.append(_FINDER_COLUMN_C_G_N_P_PERMISSIONSHASH_2);
1603 }
1604
1605 String sql = query.toString();
1606
1607 Session session = null;
1608
1609 try {
1610 session = openSession();
1611
1612 Query q = session.createQuery(sql);
1613
1614 QueryPos qPos = QueryPos.getInstance(q);
1615
1616 qPos.add(companyId);
1617
1618 qPos.add(groupId);
1619
1620 if (bindName) {
1621 qPos.add(name);
1622 }
1623
1624 if (bindPermissionsHash) {
1625 qPos.add(permissionsHash);
1626 }
1627
1628 count = (Long)q.uniqueResult();
1629
1630 finderCache.putResult(finderPath, finderArgs, count);
1631 }
1632 catch (Exception e) {
1633 finderCache.removeResult(finderPath, finderArgs);
1634
1635 throw processException(e);
1636 }
1637 finally {
1638 closeSession(session);
1639 }
1640 }
1641
1642 return count.intValue();
1643 }
1644
1645 private static final String _FINDER_COLUMN_C_G_N_P_COMPANYID_2 = "resourceBlock.companyId = ? AND ";
1646 private static final String _FINDER_COLUMN_C_G_N_P_GROUPID_2 = "resourceBlock.groupId = ? AND ";
1647 private static final String _FINDER_COLUMN_C_G_N_P_NAME_1 = "resourceBlock.name IS NULL AND ";
1648 private static final String _FINDER_COLUMN_C_G_N_P_NAME_2 = "resourceBlock.name = ? AND ";
1649 private static final String _FINDER_COLUMN_C_G_N_P_NAME_3 = "(resourceBlock.name IS NULL OR resourceBlock.name = '') AND ";
1650 private static final String _FINDER_COLUMN_C_G_N_P_PERMISSIONSHASH_1 = "resourceBlock.permissionsHash IS NULL";
1651 private static final String _FINDER_COLUMN_C_G_N_P_PERMISSIONSHASH_2 = "resourceBlock.permissionsHash = ?";
1652 private static final String _FINDER_COLUMN_C_G_N_P_PERMISSIONSHASH_3 = "(resourceBlock.permissionsHash IS NULL OR resourceBlock.permissionsHash = '')";
1653
1654 public ResourceBlockPersistenceImpl() {
1655 setModelClass(ResourceBlock.class);
1656 }
1657
1658
1663 @Override
1664 public void cacheResult(ResourceBlock resourceBlock) {
1665 entityCache.putResult(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
1666 ResourceBlockImpl.class, resourceBlock.getPrimaryKey(),
1667 resourceBlock);
1668
1669 finderCache.putResult(FINDER_PATH_FETCH_BY_C_G_N_P,
1670 new Object[] {
1671 resourceBlock.getCompanyId(), resourceBlock.getGroupId(),
1672 resourceBlock.getName(), resourceBlock.getPermissionsHash()
1673 }, resourceBlock);
1674
1675 resourceBlock.resetOriginalValues();
1676 }
1677
1678
1683 @Override
1684 public void cacheResult(List<ResourceBlock> resourceBlocks) {
1685 for (ResourceBlock resourceBlock : resourceBlocks) {
1686 if (entityCache.getResult(
1687 ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
1688 ResourceBlockImpl.class, resourceBlock.getPrimaryKey()) == null) {
1689 cacheResult(resourceBlock);
1690 }
1691 else {
1692 resourceBlock.resetOriginalValues();
1693 }
1694 }
1695 }
1696
1697
1704 @Override
1705 public void clearCache() {
1706 entityCache.clearCache(ResourceBlockImpl.class);
1707
1708 finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
1709 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1710 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1711 }
1712
1713
1720 @Override
1721 public void clearCache(ResourceBlock resourceBlock) {
1722 entityCache.removeResult(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
1723 ResourceBlockImpl.class, resourceBlock.getPrimaryKey());
1724
1725 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1726 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1727
1728 clearUniqueFindersCache((ResourceBlockModelImpl)resourceBlock);
1729 }
1730
1731 @Override
1732 public void clearCache(List<ResourceBlock> resourceBlocks) {
1733 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1734 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1735
1736 for (ResourceBlock resourceBlock : resourceBlocks) {
1737 entityCache.removeResult(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
1738 ResourceBlockImpl.class, resourceBlock.getPrimaryKey());
1739
1740 clearUniqueFindersCache((ResourceBlockModelImpl)resourceBlock);
1741 }
1742 }
1743
1744 protected void cacheUniqueFindersCache(
1745 ResourceBlockModelImpl resourceBlockModelImpl, boolean isNew) {
1746 if (isNew) {
1747 Object[] args = new Object[] {
1748 resourceBlockModelImpl.getCompanyId(),
1749 resourceBlockModelImpl.getGroupId(),
1750 resourceBlockModelImpl.getName(),
1751 resourceBlockModelImpl.getPermissionsHash()
1752 };
1753
1754 finderCache.putResult(FINDER_PATH_COUNT_BY_C_G_N_P, args,
1755 Long.valueOf(1));
1756 finderCache.putResult(FINDER_PATH_FETCH_BY_C_G_N_P, args,
1757 resourceBlockModelImpl);
1758 }
1759 else {
1760 if ((resourceBlockModelImpl.getColumnBitmask() &
1761 FINDER_PATH_FETCH_BY_C_G_N_P.getColumnBitmask()) != 0) {
1762 Object[] args = new Object[] {
1763 resourceBlockModelImpl.getCompanyId(),
1764 resourceBlockModelImpl.getGroupId(),
1765 resourceBlockModelImpl.getName(),
1766 resourceBlockModelImpl.getPermissionsHash()
1767 };
1768
1769 finderCache.putResult(FINDER_PATH_COUNT_BY_C_G_N_P, args,
1770 Long.valueOf(1));
1771 finderCache.putResult(FINDER_PATH_FETCH_BY_C_G_N_P, args,
1772 resourceBlockModelImpl);
1773 }
1774 }
1775 }
1776
1777 protected void clearUniqueFindersCache(
1778 ResourceBlockModelImpl resourceBlockModelImpl) {
1779 Object[] args = new Object[] {
1780 resourceBlockModelImpl.getCompanyId(),
1781 resourceBlockModelImpl.getGroupId(),
1782 resourceBlockModelImpl.getName(),
1783 resourceBlockModelImpl.getPermissionsHash()
1784 };
1785
1786 finderCache.removeResult(FINDER_PATH_COUNT_BY_C_G_N_P, args);
1787 finderCache.removeResult(FINDER_PATH_FETCH_BY_C_G_N_P, args);
1788
1789 if ((resourceBlockModelImpl.getColumnBitmask() &
1790 FINDER_PATH_FETCH_BY_C_G_N_P.getColumnBitmask()) != 0) {
1791 args = new Object[] {
1792 resourceBlockModelImpl.getOriginalCompanyId(),
1793 resourceBlockModelImpl.getOriginalGroupId(),
1794 resourceBlockModelImpl.getOriginalName(),
1795 resourceBlockModelImpl.getOriginalPermissionsHash()
1796 };
1797
1798 finderCache.removeResult(FINDER_PATH_COUNT_BY_C_G_N_P, args);
1799 finderCache.removeResult(FINDER_PATH_FETCH_BY_C_G_N_P, args);
1800 }
1801 }
1802
1803
1809 @Override
1810 public ResourceBlock create(long resourceBlockId) {
1811 ResourceBlock resourceBlock = new ResourceBlockImpl();
1812
1813 resourceBlock.setNew(true);
1814 resourceBlock.setPrimaryKey(resourceBlockId);
1815
1816 resourceBlock.setCompanyId(companyProvider.getCompanyId());
1817
1818 return resourceBlock;
1819 }
1820
1821
1828 @Override
1829 public ResourceBlock remove(long resourceBlockId)
1830 throws NoSuchResourceBlockException {
1831 return remove((Serializable)resourceBlockId);
1832 }
1833
1834
1841 @Override
1842 public ResourceBlock remove(Serializable primaryKey)
1843 throws NoSuchResourceBlockException {
1844 Session session = null;
1845
1846 try {
1847 session = openSession();
1848
1849 ResourceBlock resourceBlock = (ResourceBlock)session.get(ResourceBlockImpl.class,
1850 primaryKey);
1851
1852 if (resourceBlock == null) {
1853 if (_log.isWarnEnabled()) {
1854 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1855 }
1856
1857 throw new NoSuchResourceBlockException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1858 primaryKey);
1859 }
1860
1861 return remove(resourceBlock);
1862 }
1863 catch (NoSuchResourceBlockException nsee) {
1864 throw nsee;
1865 }
1866 catch (Exception e) {
1867 throw processException(e);
1868 }
1869 finally {
1870 closeSession(session);
1871 }
1872 }
1873
1874 @Override
1875 protected ResourceBlock removeImpl(ResourceBlock resourceBlock) {
1876 resourceBlock = toUnwrappedModel(resourceBlock);
1877
1878 Session session = null;
1879
1880 try {
1881 session = openSession();
1882
1883 if (!session.contains(resourceBlock)) {
1884 resourceBlock = (ResourceBlock)session.get(ResourceBlockImpl.class,
1885 resourceBlock.getPrimaryKeyObj());
1886 }
1887
1888 if (resourceBlock != null) {
1889 session.delete(resourceBlock);
1890 }
1891 }
1892 catch (Exception e) {
1893 throw processException(e);
1894 }
1895 finally {
1896 closeSession(session);
1897 }
1898
1899 if (resourceBlock != null) {
1900 clearCache(resourceBlock);
1901 }
1902
1903 return resourceBlock;
1904 }
1905
1906 @Override
1907 public ResourceBlock updateImpl(ResourceBlock resourceBlock) {
1908 resourceBlock = toUnwrappedModel(resourceBlock);
1909
1910 boolean isNew = resourceBlock.isNew();
1911
1912 ResourceBlockModelImpl resourceBlockModelImpl = (ResourceBlockModelImpl)resourceBlock;
1913
1914 Session session = null;
1915
1916 try {
1917 session = openSession();
1918
1919 if (resourceBlock.isNew()) {
1920 session.save(resourceBlock);
1921
1922 resourceBlock.setNew(false);
1923 }
1924 else {
1925 resourceBlock = (ResourceBlock)session.merge(resourceBlock);
1926 }
1927 }
1928 catch (Exception e) {
1929 throw processException(e);
1930 }
1931 finally {
1932 closeSession(session);
1933 }
1934
1935 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1936
1937 if (isNew || !ResourceBlockModelImpl.COLUMN_BITMASK_ENABLED) {
1938 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1939 }
1940
1941 else {
1942 if ((resourceBlockModelImpl.getColumnBitmask() &
1943 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N.getColumnBitmask()) != 0) {
1944 Object[] args = new Object[] {
1945 resourceBlockModelImpl.getOriginalCompanyId(),
1946 resourceBlockModelImpl.getOriginalName()
1947 };
1948
1949 finderCache.removeResult(FINDER_PATH_COUNT_BY_C_N, args);
1950 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N,
1951 args);
1952
1953 args = new Object[] {
1954 resourceBlockModelImpl.getCompanyId(),
1955 resourceBlockModelImpl.getName()
1956 };
1957
1958 finderCache.removeResult(FINDER_PATH_COUNT_BY_C_N, args);
1959 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N,
1960 args);
1961 }
1962
1963 if ((resourceBlockModelImpl.getColumnBitmask() &
1964 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_G_N.getColumnBitmask()) != 0) {
1965 Object[] args = new Object[] {
1966 resourceBlockModelImpl.getOriginalCompanyId(),
1967 resourceBlockModelImpl.getOriginalGroupId(),
1968 resourceBlockModelImpl.getOriginalName()
1969 };
1970
1971 finderCache.removeResult(FINDER_PATH_COUNT_BY_C_G_N, args);
1972 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_G_N,
1973 args);
1974
1975 args = new Object[] {
1976 resourceBlockModelImpl.getCompanyId(),
1977 resourceBlockModelImpl.getGroupId(),
1978 resourceBlockModelImpl.getName()
1979 };
1980
1981 finderCache.removeResult(FINDER_PATH_COUNT_BY_C_G_N, args);
1982 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_G_N,
1983 args);
1984 }
1985 }
1986
1987 entityCache.putResult(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
1988 ResourceBlockImpl.class, resourceBlock.getPrimaryKey(),
1989 resourceBlock, false);
1990
1991 clearUniqueFindersCache(resourceBlockModelImpl);
1992 cacheUniqueFindersCache(resourceBlockModelImpl, isNew);
1993
1994 resourceBlock.resetOriginalValues();
1995
1996 return resourceBlock;
1997 }
1998
1999 protected ResourceBlock toUnwrappedModel(ResourceBlock resourceBlock) {
2000 if (resourceBlock instanceof ResourceBlockImpl) {
2001 return resourceBlock;
2002 }
2003
2004 ResourceBlockImpl resourceBlockImpl = new ResourceBlockImpl();
2005
2006 resourceBlockImpl.setNew(resourceBlock.isNew());
2007 resourceBlockImpl.setPrimaryKey(resourceBlock.getPrimaryKey());
2008
2009 resourceBlockImpl.setMvccVersion(resourceBlock.getMvccVersion());
2010 resourceBlockImpl.setResourceBlockId(resourceBlock.getResourceBlockId());
2011 resourceBlockImpl.setCompanyId(resourceBlock.getCompanyId());
2012 resourceBlockImpl.setGroupId(resourceBlock.getGroupId());
2013 resourceBlockImpl.setName(resourceBlock.getName());
2014 resourceBlockImpl.setPermissionsHash(resourceBlock.getPermissionsHash());
2015 resourceBlockImpl.setReferenceCount(resourceBlock.getReferenceCount());
2016
2017 return resourceBlockImpl;
2018 }
2019
2020
2027 @Override
2028 public ResourceBlock findByPrimaryKey(Serializable primaryKey)
2029 throws NoSuchResourceBlockException {
2030 ResourceBlock resourceBlock = fetchByPrimaryKey(primaryKey);
2031
2032 if (resourceBlock == null) {
2033 if (_log.isWarnEnabled()) {
2034 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2035 }
2036
2037 throw new NoSuchResourceBlockException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2038 primaryKey);
2039 }
2040
2041 return resourceBlock;
2042 }
2043
2044
2051 @Override
2052 public ResourceBlock findByPrimaryKey(long resourceBlockId)
2053 throws NoSuchResourceBlockException {
2054 return findByPrimaryKey((Serializable)resourceBlockId);
2055 }
2056
2057
2063 @Override
2064 public ResourceBlock fetchByPrimaryKey(Serializable primaryKey) {
2065 ResourceBlock resourceBlock = (ResourceBlock)entityCache.getResult(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
2066 ResourceBlockImpl.class, primaryKey);
2067
2068 if (resourceBlock == _nullResourceBlock) {
2069 return null;
2070 }
2071
2072 if (resourceBlock == null) {
2073 Session session = null;
2074
2075 try {
2076 session = openSession();
2077
2078 resourceBlock = (ResourceBlock)session.get(ResourceBlockImpl.class,
2079 primaryKey);
2080
2081 if (resourceBlock != null) {
2082 cacheResult(resourceBlock);
2083 }
2084 else {
2085 entityCache.putResult(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
2086 ResourceBlockImpl.class, primaryKey, _nullResourceBlock);
2087 }
2088 }
2089 catch (Exception e) {
2090 entityCache.removeResult(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
2091 ResourceBlockImpl.class, primaryKey);
2092
2093 throw processException(e);
2094 }
2095 finally {
2096 closeSession(session);
2097 }
2098 }
2099
2100 return resourceBlock;
2101 }
2102
2103
2109 @Override
2110 public ResourceBlock fetchByPrimaryKey(long resourceBlockId) {
2111 return fetchByPrimaryKey((Serializable)resourceBlockId);
2112 }
2113
2114 @Override
2115 public Map<Serializable, ResourceBlock> fetchByPrimaryKeys(
2116 Set<Serializable> primaryKeys) {
2117 if (primaryKeys.isEmpty()) {
2118 return Collections.emptyMap();
2119 }
2120
2121 Map<Serializable, ResourceBlock> map = new HashMap<Serializable, ResourceBlock>();
2122
2123 if (primaryKeys.size() == 1) {
2124 Iterator<Serializable> iterator = primaryKeys.iterator();
2125
2126 Serializable primaryKey = iterator.next();
2127
2128 ResourceBlock resourceBlock = fetchByPrimaryKey(primaryKey);
2129
2130 if (resourceBlock != null) {
2131 map.put(primaryKey, resourceBlock);
2132 }
2133
2134 return map;
2135 }
2136
2137 Set<Serializable> uncachedPrimaryKeys = null;
2138
2139 for (Serializable primaryKey : primaryKeys) {
2140 ResourceBlock resourceBlock = (ResourceBlock)entityCache.getResult(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
2141 ResourceBlockImpl.class, primaryKey);
2142
2143 if (resourceBlock == null) {
2144 if (uncachedPrimaryKeys == null) {
2145 uncachedPrimaryKeys = new HashSet<Serializable>();
2146 }
2147
2148 uncachedPrimaryKeys.add(primaryKey);
2149 }
2150 else {
2151 map.put(primaryKey, resourceBlock);
2152 }
2153 }
2154
2155 if (uncachedPrimaryKeys == null) {
2156 return map;
2157 }
2158
2159 StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
2160 1);
2161
2162 query.append(_SQL_SELECT_RESOURCEBLOCK_WHERE_PKS_IN);
2163
2164 for (Serializable primaryKey : uncachedPrimaryKeys) {
2165 query.append(String.valueOf(primaryKey));
2166
2167 query.append(StringPool.COMMA);
2168 }
2169
2170 query.setIndex(query.index() - 1);
2171
2172 query.append(StringPool.CLOSE_PARENTHESIS);
2173
2174 String sql = query.toString();
2175
2176 Session session = null;
2177
2178 try {
2179 session = openSession();
2180
2181 Query q = session.createQuery(sql);
2182
2183 for (ResourceBlock resourceBlock : (List<ResourceBlock>)q.list()) {
2184 map.put(resourceBlock.getPrimaryKeyObj(), resourceBlock);
2185
2186 cacheResult(resourceBlock);
2187
2188 uncachedPrimaryKeys.remove(resourceBlock.getPrimaryKeyObj());
2189 }
2190
2191 for (Serializable primaryKey : uncachedPrimaryKeys) {
2192 entityCache.putResult(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
2193 ResourceBlockImpl.class, primaryKey, _nullResourceBlock);
2194 }
2195 }
2196 catch (Exception e) {
2197 throw processException(e);
2198 }
2199 finally {
2200 closeSession(session);
2201 }
2202
2203 return map;
2204 }
2205
2206
2211 @Override
2212 public List<ResourceBlock> findAll() {
2213 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2214 }
2215
2216
2227 @Override
2228 public List<ResourceBlock> findAll(int start, int end) {
2229 return findAll(start, end, null);
2230 }
2231
2232
2244 @Override
2245 public List<ResourceBlock> findAll(int start, int end,
2246 OrderByComparator<ResourceBlock> orderByComparator) {
2247 return findAll(start, end, orderByComparator, true);
2248 }
2249
2250
2263 @Override
2264 public List<ResourceBlock> findAll(int start, int end,
2265 OrderByComparator<ResourceBlock> orderByComparator,
2266 boolean retrieveFromCache) {
2267 boolean pagination = true;
2268 FinderPath finderPath = null;
2269 Object[] finderArgs = null;
2270
2271 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2272 (orderByComparator == null)) {
2273 pagination = false;
2274 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2275 finderArgs = FINDER_ARGS_EMPTY;
2276 }
2277 else {
2278 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2279 finderArgs = new Object[] { start, end, orderByComparator };
2280 }
2281
2282 List<ResourceBlock> list = null;
2283
2284 if (retrieveFromCache) {
2285 list = (List<ResourceBlock>)finderCache.getResult(finderPath,
2286 finderArgs, this);
2287 }
2288
2289 if (list == null) {
2290 StringBundler query = null;
2291 String sql = null;
2292
2293 if (orderByComparator != null) {
2294 query = new StringBundler(2 +
2295 (orderByComparator.getOrderByFields().length * 2));
2296
2297 query.append(_SQL_SELECT_RESOURCEBLOCK);
2298
2299 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2300 orderByComparator);
2301
2302 sql = query.toString();
2303 }
2304 else {
2305 sql = _SQL_SELECT_RESOURCEBLOCK;
2306
2307 if (pagination) {
2308 sql = sql.concat(ResourceBlockModelImpl.ORDER_BY_JPQL);
2309 }
2310 }
2311
2312 Session session = null;
2313
2314 try {
2315 session = openSession();
2316
2317 Query q = session.createQuery(sql);
2318
2319 if (!pagination) {
2320 list = (List<ResourceBlock>)QueryUtil.list(q, getDialect(),
2321 start, end, false);
2322
2323 Collections.sort(list);
2324
2325 list = Collections.unmodifiableList(list);
2326 }
2327 else {
2328 list = (List<ResourceBlock>)QueryUtil.list(q, getDialect(),
2329 start, end);
2330 }
2331
2332 cacheResult(list);
2333
2334 finderCache.putResult(finderPath, finderArgs, list);
2335 }
2336 catch (Exception e) {
2337 finderCache.removeResult(finderPath, finderArgs);
2338
2339 throw processException(e);
2340 }
2341 finally {
2342 closeSession(session);
2343 }
2344 }
2345
2346 return list;
2347 }
2348
2349
2353 @Override
2354 public void removeAll() {
2355 for (ResourceBlock resourceBlock : findAll()) {
2356 remove(resourceBlock);
2357 }
2358 }
2359
2360
2365 @Override
2366 public int countAll() {
2367 Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
2368 FINDER_ARGS_EMPTY, this);
2369
2370 if (count == null) {
2371 Session session = null;
2372
2373 try {
2374 session = openSession();
2375
2376 Query q = session.createQuery(_SQL_COUNT_RESOURCEBLOCK);
2377
2378 count = (Long)q.uniqueResult();
2379
2380 finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
2381 count);
2382 }
2383 catch (Exception e) {
2384 finderCache.removeResult(FINDER_PATH_COUNT_ALL,
2385 FINDER_ARGS_EMPTY);
2386
2387 throw processException(e);
2388 }
2389 finally {
2390 closeSession(session);
2391 }
2392 }
2393
2394 return count.intValue();
2395 }
2396
2397 @Override
2398 protected Map<String, Integer> getTableColumnsMap() {
2399 return ResourceBlockModelImpl.TABLE_COLUMNS_MAP;
2400 }
2401
2402
2405 public void afterPropertiesSet() {
2406 }
2407
2408 public void destroy() {
2409 entityCache.removeCache(ResourceBlockImpl.class.getName());
2410 finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
2411 finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2412 finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2413 }
2414
2415 @BeanReference(type = CompanyProviderWrapper.class)
2416 protected CompanyProvider companyProvider;
2417 protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
2418 protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
2419 private static final String _SQL_SELECT_RESOURCEBLOCK = "SELECT resourceBlock FROM ResourceBlock resourceBlock";
2420 private static final String _SQL_SELECT_RESOURCEBLOCK_WHERE_PKS_IN = "SELECT resourceBlock FROM ResourceBlock resourceBlock WHERE resourceBlockId IN (";
2421 private static final String _SQL_SELECT_RESOURCEBLOCK_WHERE = "SELECT resourceBlock FROM ResourceBlock resourceBlock WHERE ";
2422 private static final String _SQL_COUNT_RESOURCEBLOCK = "SELECT COUNT(resourceBlock) FROM ResourceBlock resourceBlock";
2423 private static final String _SQL_COUNT_RESOURCEBLOCK_WHERE = "SELECT COUNT(resourceBlock) FROM ResourceBlock resourceBlock WHERE ";
2424 private static final String _ORDER_BY_ENTITY_ALIAS = "resourceBlock.";
2425 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ResourceBlock exists with the primary key ";
2426 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ResourceBlock exists with the key {";
2427 private static final Log _log = LogFactoryUtil.getLog(ResourceBlockPersistenceImpl.class);
2428 private static final ResourceBlock _nullResourceBlock = new ResourceBlockImpl() {
2429 @Override
2430 public Object clone() {
2431 return this;
2432 }
2433
2434 @Override
2435 public CacheModel<ResourceBlock> toCacheModel() {
2436 return _nullResourceBlockCacheModel;
2437 }
2438 };
2439
2440 private static final CacheModel<ResourceBlock> _nullResourceBlockCacheModel = new NullCacheModel();
2441
2442 private static class NullCacheModel implements CacheModel<ResourceBlock>,
2443 MVCCModel {
2444 @Override
2445 public long getMvccVersion() {
2446 return -1;
2447 }
2448
2449 @Override
2450 public void setMvccVersion(long mvccVersion) {
2451 }
2452
2453 @Override
2454 public ResourceBlock toEntityModel() {
2455 return _nullResourceBlock;
2456 }
2457 }
2458 }