001
014
015 package com.liferay.portal.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.NoSuchResourceBlockException;
019 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
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.exception.SystemException;
028 import com.liferay.portal.kernel.log.Log;
029 import com.liferay.portal.kernel.log.LogFactoryUtil;
030 import com.liferay.portal.kernel.util.GetterUtil;
031 import com.liferay.portal.kernel.util.InstanceFactory;
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.StringUtil;
036 import com.liferay.portal.kernel.util.UnmodifiableList;
037 import com.liferay.portal.kernel.util.Validator;
038 import com.liferay.portal.model.CacheModel;
039 import com.liferay.portal.model.ModelListener;
040 import com.liferay.portal.model.ResourceBlock;
041 import com.liferay.portal.model.impl.ResourceBlockImpl;
042 import com.liferay.portal.model.impl.ResourceBlockModelImpl;
043 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
044
045 import java.io.Serializable;
046
047 import java.util.ArrayList;
048 import java.util.Collections;
049 import java.util.List;
050
051
063 public class ResourceBlockPersistenceImpl extends BasePersistenceImpl<ResourceBlock>
064 implements ResourceBlockPersistence {
065
070 public static final String FINDER_CLASS_NAME_ENTITY = ResourceBlockImpl.class.getName();
071 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
072 ".List1";
073 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
074 ".List2";
075 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_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
116 public List<ResourceBlock> findByC_N(long companyId, String name)
117 throws SystemException {
118 return findByC_N(companyId, name, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
119 null);
120 }
121
122
136 public List<ResourceBlock> findByC_N(long companyId, String name,
137 int start, int end) throws SystemException {
138 return findByC_N(companyId, name, start, end, null);
139 }
140
141
156 public List<ResourceBlock> findByC_N(long companyId, String name,
157 int start, int end, OrderByComparator orderByComparator)
158 throws SystemException {
159 boolean pagination = true;
160 FinderPath finderPath = null;
161 Object[] finderArgs = null;
162
163 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
164 (orderByComparator == null)) {
165 pagination = false;
166 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N;
167 finderArgs = new Object[] { companyId, name };
168 }
169 else {
170 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_N;
171 finderArgs = new Object[] {
172 companyId, name,
173
174 start, end, orderByComparator
175 };
176 }
177
178 List<ResourceBlock> list = (List<ResourceBlock>)FinderCacheUtil.getResult(finderPath,
179 finderArgs, this);
180
181 if ((list != null) && !list.isEmpty()) {
182 for (ResourceBlock resourceBlock : list) {
183 if ((companyId != resourceBlock.getCompanyId()) ||
184 !Validator.equals(name, resourceBlock.getName())) {
185 list = null;
186
187 break;
188 }
189 }
190 }
191
192 if (list == null) {
193 StringBundler query = null;
194
195 if (orderByComparator != null) {
196 query = new StringBundler(4 +
197 (orderByComparator.getOrderByFields().length * 3));
198 }
199 else {
200 query = new StringBundler(4);
201 }
202
203 query.append(_SQL_SELECT_RESOURCEBLOCK_WHERE);
204
205 query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
206
207 if (name == null) {
208 query.append(_FINDER_COLUMN_C_N_NAME_1);
209 }
210 else {
211 if (name.equals(StringPool.BLANK)) {
212 query.append(_FINDER_COLUMN_C_N_NAME_3);
213 }
214 else {
215 query.append(_FINDER_COLUMN_C_N_NAME_2);
216 }
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 (name != null) {
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 = new UnmodifiableList<ResourceBlock>(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
285 public ResourceBlock findByC_N_First(long companyId, String name,
286 OrderByComparator orderByComparator)
287 throws NoSuchResourceBlockException, SystemException {
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
319 public ResourceBlock fetchByC_N_First(long companyId, String name,
320 OrderByComparator orderByComparator) throws SystemException {
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
341 public ResourceBlock findByC_N_Last(long companyId, String name,
342 OrderByComparator orderByComparator)
343 throws NoSuchResourceBlockException, SystemException {
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
375 public ResourceBlock fetchByC_N_Last(long companyId, String name,
376 OrderByComparator orderByComparator) throws SystemException {
377 int count = countByC_N(companyId, name);
378
379 List<ResourceBlock> list = findByC_N(companyId, name, count - 1, count,
380 orderByComparator);
381
382 if (!list.isEmpty()) {
383 return list.get(0);
384 }
385
386 return null;
387 }
388
389
400 public ResourceBlock[] findByC_N_PrevAndNext(long resourceBlockId,
401 long companyId, String name, OrderByComparator orderByComparator)
402 throws NoSuchResourceBlockException, SystemException {
403 ResourceBlock resourceBlock = findByPrimaryKey(resourceBlockId);
404
405 Session session = null;
406
407 try {
408 session = openSession();
409
410 ResourceBlock[] array = new ResourceBlockImpl[3];
411
412 array[0] = getByC_N_PrevAndNext(session, resourceBlock, companyId,
413 name, orderByComparator, true);
414
415 array[1] = resourceBlock;
416
417 array[2] = getByC_N_PrevAndNext(session, resourceBlock, companyId,
418 name, orderByComparator, false);
419
420 return array;
421 }
422 catch (Exception e) {
423 throw processException(e);
424 }
425 finally {
426 closeSession(session);
427 }
428 }
429
430 protected ResourceBlock getByC_N_PrevAndNext(Session session,
431 ResourceBlock resourceBlock, long companyId, String name,
432 OrderByComparator orderByComparator, boolean previous) {
433 StringBundler query = null;
434
435 if (orderByComparator != null) {
436 query = new StringBundler(6 +
437 (orderByComparator.getOrderByFields().length * 6));
438 }
439 else {
440 query = new StringBundler(3);
441 }
442
443 query.append(_SQL_SELECT_RESOURCEBLOCK_WHERE);
444
445 query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
446
447 if (name == null) {
448 query.append(_FINDER_COLUMN_C_N_NAME_1);
449 }
450 else {
451 if (name.equals(StringPool.BLANK)) {
452 query.append(_FINDER_COLUMN_C_N_NAME_3);
453 }
454 else {
455 query.append(_FINDER_COLUMN_C_N_NAME_2);
456 }
457 }
458
459 if (orderByComparator != null) {
460 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
461
462 if (orderByConditionFields.length > 0) {
463 query.append(WHERE_AND);
464 }
465
466 for (int i = 0; i < orderByConditionFields.length; i++) {
467 query.append(_ORDER_BY_ENTITY_ALIAS);
468 query.append(orderByConditionFields[i]);
469
470 if ((i + 1) < orderByConditionFields.length) {
471 if (orderByComparator.isAscending() ^ previous) {
472 query.append(WHERE_GREATER_THAN_HAS_NEXT);
473 }
474 else {
475 query.append(WHERE_LESSER_THAN_HAS_NEXT);
476 }
477 }
478 else {
479 if (orderByComparator.isAscending() ^ previous) {
480 query.append(WHERE_GREATER_THAN);
481 }
482 else {
483 query.append(WHERE_LESSER_THAN);
484 }
485 }
486 }
487
488 query.append(ORDER_BY_CLAUSE);
489
490 String[] orderByFields = orderByComparator.getOrderByFields();
491
492 for (int i = 0; i < orderByFields.length; i++) {
493 query.append(_ORDER_BY_ENTITY_ALIAS);
494 query.append(orderByFields[i]);
495
496 if ((i + 1) < orderByFields.length) {
497 if (orderByComparator.isAscending() ^ previous) {
498 query.append(ORDER_BY_ASC_HAS_NEXT);
499 }
500 else {
501 query.append(ORDER_BY_DESC_HAS_NEXT);
502 }
503 }
504 else {
505 if (orderByComparator.isAscending() ^ previous) {
506 query.append(ORDER_BY_ASC);
507 }
508 else {
509 query.append(ORDER_BY_DESC);
510 }
511 }
512 }
513 }
514 else {
515 query.append(ResourceBlockModelImpl.ORDER_BY_JPQL);
516 }
517
518 String sql = query.toString();
519
520 Query q = session.createQuery(sql);
521
522 q.setFirstResult(0);
523 q.setMaxResults(2);
524
525 QueryPos qPos = QueryPos.getInstance(q);
526
527 qPos.add(companyId);
528
529 if (name != null) {
530 qPos.add(name);
531 }
532
533 if (orderByComparator != null) {
534 Object[] values = orderByComparator.getOrderByConditionValues(resourceBlock);
535
536 for (Object value : values) {
537 qPos.add(value);
538 }
539 }
540
541 List<ResourceBlock> list = q.list();
542
543 if (list.size() == 2) {
544 return list.get(1);
545 }
546 else {
547 return null;
548 }
549 }
550
551
558 public void removeByC_N(long companyId, String name)
559 throws SystemException {
560 for (ResourceBlock resourceBlock : findByC_N(companyId, name,
561 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
562 remove(resourceBlock);
563 }
564 }
565
566
574 public int countByC_N(long companyId, String name)
575 throws SystemException {
576 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_N;
577
578 Object[] finderArgs = new Object[] { companyId, name };
579
580 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
581 this);
582
583 if (count == null) {
584 StringBundler query = new StringBundler(3);
585
586 query.append(_SQL_COUNT_RESOURCEBLOCK_WHERE);
587
588 query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
589
590 if (name == null) {
591 query.append(_FINDER_COLUMN_C_N_NAME_1);
592 }
593 else {
594 if (name.equals(StringPool.BLANK)) {
595 query.append(_FINDER_COLUMN_C_N_NAME_3);
596 }
597 else {
598 query.append(_FINDER_COLUMN_C_N_NAME_2);
599 }
600 }
601
602 String sql = query.toString();
603
604 Session session = null;
605
606 try {
607 session = openSession();
608
609 Query q = session.createQuery(sql);
610
611 QueryPos qPos = QueryPos.getInstance(q);
612
613 qPos.add(companyId);
614
615 if (name != null) {
616 qPos.add(name);
617 }
618
619 count = (Long)q.uniqueResult();
620
621 FinderCacheUtil.putResult(finderPath, finderArgs, count);
622 }
623 catch (Exception e) {
624 FinderCacheUtil.removeResult(finderPath, finderArgs);
625
626 throw processException(e);
627 }
628 finally {
629 closeSession(session);
630 }
631 }
632
633 return count.intValue();
634 }
635
636 private static final String _FINDER_COLUMN_C_N_COMPANYID_2 = "resourceBlock.companyId = ? AND ";
637 private static final String _FINDER_COLUMN_C_N_NAME_1 = "resourceBlock.name IS NULL";
638 private static final String _FINDER_COLUMN_C_N_NAME_2 = "resourceBlock.name = ?";
639 private static final String _FINDER_COLUMN_C_N_NAME_3 = "(resourceBlock.name IS NULL OR resourceBlock.name = ?)";
640 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_G_N = new FinderPath(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
641 ResourceBlockModelImpl.FINDER_CACHE_ENABLED,
642 ResourceBlockImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
643 "findByC_G_N",
644 new String[] {
645 Long.class.getName(), Long.class.getName(),
646 String.class.getName(),
647
648 Integer.class.getName(), Integer.class.getName(),
649 OrderByComparator.class.getName()
650 });
651 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_G_N = new FinderPath(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
652 ResourceBlockModelImpl.FINDER_CACHE_ENABLED,
653 ResourceBlockImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
654 "findByC_G_N",
655 new String[] {
656 Long.class.getName(), Long.class.getName(),
657 String.class.getName()
658 },
659 ResourceBlockModelImpl.COMPANYID_COLUMN_BITMASK |
660 ResourceBlockModelImpl.GROUPID_COLUMN_BITMASK |
661 ResourceBlockModelImpl.NAME_COLUMN_BITMASK);
662 public static final FinderPath FINDER_PATH_COUNT_BY_C_G_N = new FinderPath(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
663 ResourceBlockModelImpl.FINDER_CACHE_ENABLED, Long.class,
664 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_G_N",
665 new String[] {
666 Long.class.getName(), Long.class.getName(),
667 String.class.getName()
668 });
669
670
679 public List<ResourceBlock> findByC_G_N(long companyId, long groupId,
680 String name) throws SystemException {
681 return findByC_G_N(companyId, groupId, name, QueryUtil.ALL_POS,
682 QueryUtil.ALL_POS, null);
683 }
684
685
700 public List<ResourceBlock> findByC_G_N(long companyId, long groupId,
701 String name, int start, int end) throws SystemException {
702 return findByC_G_N(companyId, groupId, name, start, end, null);
703 }
704
705
721 public List<ResourceBlock> findByC_G_N(long companyId, long groupId,
722 String name, int start, int end, OrderByComparator orderByComparator)
723 throws SystemException {
724 boolean pagination = true;
725 FinderPath finderPath = null;
726 Object[] finderArgs = null;
727
728 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
729 (orderByComparator == null)) {
730 pagination = false;
731 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_G_N;
732 finderArgs = new Object[] { companyId, groupId, name };
733 }
734 else {
735 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_G_N;
736 finderArgs = new Object[] {
737 companyId, groupId, name,
738
739 start, end, orderByComparator
740 };
741 }
742
743 List<ResourceBlock> list = (List<ResourceBlock>)FinderCacheUtil.getResult(finderPath,
744 finderArgs, this);
745
746 if ((list != null) && !list.isEmpty()) {
747 for (ResourceBlock resourceBlock : list) {
748 if ((companyId != resourceBlock.getCompanyId()) ||
749 (groupId != resourceBlock.getGroupId()) ||
750 !Validator.equals(name, resourceBlock.getName())) {
751 list = null;
752
753 break;
754 }
755 }
756 }
757
758 if (list == null) {
759 StringBundler query = null;
760
761 if (orderByComparator != null) {
762 query = new StringBundler(5 +
763 (orderByComparator.getOrderByFields().length * 3));
764 }
765 else {
766 query = new StringBundler(5);
767 }
768
769 query.append(_SQL_SELECT_RESOURCEBLOCK_WHERE);
770
771 query.append(_FINDER_COLUMN_C_G_N_COMPANYID_2);
772
773 query.append(_FINDER_COLUMN_C_G_N_GROUPID_2);
774
775 if (name == null) {
776 query.append(_FINDER_COLUMN_C_G_N_NAME_1);
777 }
778 else {
779 if (name.equals(StringPool.BLANK)) {
780 query.append(_FINDER_COLUMN_C_G_N_NAME_3);
781 }
782 else {
783 query.append(_FINDER_COLUMN_C_G_N_NAME_2);
784 }
785 }
786
787 if (orderByComparator != null) {
788 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
789 orderByComparator);
790 }
791 else
792 if (pagination) {
793 query.append(ResourceBlockModelImpl.ORDER_BY_JPQL);
794 }
795
796 String sql = query.toString();
797
798 Session session = null;
799
800 try {
801 session = openSession();
802
803 Query q = session.createQuery(sql);
804
805 QueryPos qPos = QueryPos.getInstance(q);
806
807 qPos.add(companyId);
808
809 qPos.add(groupId);
810
811 if (name != null) {
812 qPos.add(name);
813 }
814
815 if (!pagination) {
816 list = (List<ResourceBlock>)QueryUtil.list(q, getDialect(),
817 start, end, false);
818
819 Collections.sort(list);
820
821 list = new UnmodifiableList<ResourceBlock>(list);
822 }
823 else {
824 list = (List<ResourceBlock>)QueryUtil.list(q, getDialect(),
825 start, end);
826 }
827
828 cacheResult(list);
829
830 FinderCacheUtil.putResult(finderPath, finderArgs, list);
831 }
832 catch (Exception e) {
833 FinderCacheUtil.removeResult(finderPath, finderArgs);
834
835 throw processException(e);
836 }
837 finally {
838 closeSession(session);
839 }
840 }
841
842 return list;
843 }
844
845
856 public ResourceBlock findByC_G_N_First(long companyId, long groupId,
857 String name, OrderByComparator orderByComparator)
858 throws NoSuchResourceBlockException, SystemException {
859 ResourceBlock resourceBlock = fetchByC_G_N_First(companyId, groupId,
860 name, orderByComparator);
861
862 if (resourceBlock != null) {
863 return resourceBlock;
864 }
865
866 StringBundler msg = new StringBundler(8);
867
868 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
869
870 msg.append("companyId=");
871 msg.append(companyId);
872
873 msg.append(", groupId=");
874 msg.append(groupId);
875
876 msg.append(", name=");
877 msg.append(name);
878
879 msg.append(StringPool.CLOSE_CURLY_BRACE);
880
881 throw new NoSuchResourceBlockException(msg.toString());
882 }
883
884
894 public ResourceBlock fetchByC_G_N_First(long companyId, long groupId,
895 String name, OrderByComparator orderByComparator)
896 throws SystemException {
897 List<ResourceBlock> list = findByC_G_N(companyId, groupId, name, 0, 1,
898 orderByComparator);
899
900 if (!list.isEmpty()) {
901 return list.get(0);
902 }
903
904 return null;
905 }
906
907
918 public ResourceBlock findByC_G_N_Last(long companyId, long groupId,
919 String name, OrderByComparator orderByComparator)
920 throws NoSuchResourceBlockException, SystemException {
921 ResourceBlock resourceBlock = fetchByC_G_N_Last(companyId, groupId,
922 name, orderByComparator);
923
924 if (resourceBlock != null) {
925 return resourceBlock;
926 }
927
928 StringBundler msg = new StringBundler(8);
929
930 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
931
932 msg.append("companyId=");
933 msg.append(companyId);
934
935 msg.append(", groupId=");
936 msg.append(groupId);
937
938 msg.append(", name=");
939 msg.append(name);
940
941 msg.append(StringPool.CLOSE_CURLY_BRACE);
942
943 throw new NoSuchResourceBlockException(msg.toString());
944 }
945
946
956 public ResourceBlock fetchByC_G_N_Last(long companyId, long groupId,
957 String name, OrderByComparator orderByComparator)
958 throws SystemException {
959 int count = countByC_G_N(companyId, groupId, name);
960
961 List<ResourceBlock> list = findByC_G_N(companyId, groupId, name,
962 count - 1, count, orderByComparator);
963
964 if (!list.isEmpty()) {
965 return list.get(0);
966 }
967
968 return null;
969 }
970
971
983 public ResourceBlock[] findByC_G_N_PrevAndNext(long resourceBlockId,
984 long companyId, long groupId, String name,
985 OrderByComparator orderByComparator)
986 throws NoSuchResourceBlockException, SystemException {
987 ResourceBlock resourceBlock = findByPrimaryKey(resourceBlockId);
988
989 Session session = null;
990
991 try {
992 session = openSession();
993
994 ResourceBlock[] array = new ResourceBlockImpl[3];
995
996 array[0] = getByC_G_N_PrevAndNext(session, resourceBlock,
997 companyId, groupId, name, orderByComparator, true);
998
999 array[1] = resourceBlock;
1000
1001 array[2] = getByC_G_N_PrevAndNext(session, resourceBlock,
1002 companyId, groupId, name, orderByComparator, false);
1003
1004 return array;
1005 }
1006 catch (Exception e) {
1007 throw processException(e);
1008 }
1009 finally {
1010 closeSession(session);
1011 }
1012 }
1013
1014 protected ResourceBlock getByC_G_N_PrevAndNext(Session session,
1015 ResourceBlock resourceBlock, long companyId, long groupId, String name,
1016 OrderByComparator orderByComparator, boolean previous) {
1017 StringBundler query = null;
1018
1019 if (orderByComparator != null) {
1020 query = new StringBundler(6 +
1021 (orderByComparator.getOrderByFields().length * 6));
1022 }
1023 else {
1024 query = new StringBundler(3);
1025 }
1026
1027 query.append(_SQL_SELECT_RESOURCEBLOCK_WHERE);
1028
1029 query.append(_FINDER_COLUMN_C_G_N_COMPANYID_2);
1030
1031 query.append(_FINDER_COLUMN_C_G_N_GROUPID_2);
1032
1033 if (name == null) {
1034 query.append(_FINDER_COLUMN_C_G_N_NAME_1);
1035 }
1036 else {
1037 if (name.equals(StringPool.BLANK)) {
1038 query.append(_FINDER_COLUMN_C_G_N_NAME_3);
1039 }
1040 else {
1041 query.append(_FINDER_COLUMN_C_G_N_NAME_2);
1042 }
1043 }
1044
1045 if (orderByComparator != null) {
1046 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1047
1048 if (orderByConditionFields.length > 0) {
1049 query.append(WHERE_AND);
1050 }
1051
1052 for (int i = 0; i < orderByConditionFields.length; i++) {
1053 query.append(_ORDER_BY_ENTITY_ALIAS);
1054 query.append(orderByConditionFields[i]);
1055
1056 if ((i + 1) < orderByConditionFields.length) {
1057 if (orderByComparator.isAscending() ^ previous) {
1058 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1059 }
1060 else {
1061 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1062 }
1063 }
1064 else {
1065 if (orderByComparator.isAscending() ^ previous) {
1066 query.append(WHERE_GREATER_THAN);
1067 }
1068 else {
1069 query.append(WHERE_LESSER_THAN);
1070 }
1071 }
1072 }
1073
1074 query.append(ORDER_BY_CLAUSE);
1075
1076 String[] orderByFields = orderByComparator.getOrderByFields();
1077
1078 for (int i = 0; i < orderByFields.length; i++) {
1079 query.append(_ORDER_BY_ENTITY_ALIAS);
1080 query.append(orderByFields[i]);
1081
1082 if ((i + 1) < orderByFields.length) {
1083 if (orderByComparator.isAscending() ^ previous) {
1084 query.append(ORDER_BY_ASC_HAS_NEXT);
1085 }
1086 else {
1087 query.append(ORDER_BY_DESC_HAS_NEXT);
1088 }
1089 }
1090 else {
1091 if (orderByComparator.isAscending() ^ previous) {
1092 query.append(ORDER_BY_ASC);
1093 }
1094 else {
1095 query.append(ORDER_BY_DESC);
1096 }
1097 }
1098 }
1099 }
1100 else {
1101 query.append(ResourceBlockModelImpl.ORDER_BY_JPQL);
1102 }
1103
1104 String sql = query.toString();
1105
1106 Query q = session.createQuery(sql);
1107
1108 q.setFirstResult(0);
1109 q.setMaxResults(2);
1110
1111 QueryPos qPos = QueryPos.getInstance(q);
1112
1113 qPos.add(companyId);
1114
1115 qPos.add(groupId);
1116
1117 if (name != null) {
1118 qPos.add(name);
1119 }
1120
1121 if (orderByComparator != null) {
1122 Object[] values = orderByComparator.getOrderByConditionValues(resourceBlock);
1123
1124 for (Object value : values) {
1125 qPos.add(value);
1126 }
1127 }
1128
1129 List<ResourceBlock> list = q.list();
1130
1131 if (list.size() == 2) {
1132 return list.get(1);
1133 }
1134 else {
1135 return null;
1136 }
1137 }
1138
1139
1147 public void removeByC_G_N(long companyId, long groupId, String name)
1148 throws SystemException {
1149 for (ResourceBlock resourceBlock : findByC_G_N(companyId, groupId,
1150 name, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1151 remove(resourceBlock);
1152 }
1153 }
1154
1155
1164 public int countByC_G_N(long companyId, long groupId, String name)
1165 throws SystemException {
1166 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_G_N;
1167
1168 Object[] finderArgs = new Object[] { companyId, groupId, name };
1169
1170 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1171 this);
1172
1173 if (count == null) {
1174 StringBundler query = new StringBundler(4);
1175
1176 query.append(_SQL_COUNT_RESOURCEBLOCK_WHERE);
1177
1178 query.append(_FINDER_COLUMN_C_G_N_COMPANYID_2);
1179
1180 query.append(_FINDER_COLUMN_C_G_N_GROUPID_2);
1181
1182 if (name == null) {
1183 query.append(_FINDER_COLUMN_C_G_N_NAME_1);
1184 }
1185 else {
1186 if (name.equals(StringPool.BLANK)) {
1187 query.append(_FINDER_COLUMN_C_G_N_NAME_3);
1188 }
1189 else {
1190 query.append(_FINDER_COLUMN_C_G_N_NAME_2);
1191 }
1192 }
1193
1194 String sql = query.toString();
1195
1196 Session session = null;
1197
1198 try {
1199 session = openSession();
1200
1201 Query q = session.createQuery(sql);
1202
1203 QueryPos qPos = QueryPos.getInstance(q);
1204
1205 qPos.add(companyId);
1206
1207 qPos.add(groupId);
1208
1209 if (name != null) {
1210 qPos.add(name);
1211 }
1212
1213 count = (Long)q.uniqueResult();
1214
1215 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1216 }
1217 catch (Exception e) {
1218 FinderCacheUtil.removeResult(finderPath, finderArgs);
1219
1220 throw processException(e);
1221 }
1222 finally {
1223 closeSession(session);
1224 }
1225 }
1226
1227 return count.intValue();
1228 }
1229
1230 private static final String _FINDER_COLUMN_C_G_N_COMPANYID_2 = "resourceBlock.companyId = ? AND ";
1231 private static final String _FINDER_COLUMN_C_G_N_GROUPID_2 = "resourceBlock.groupId = ? AND ";
1232 private static final String _FINDER_COLUMN_C_G_N_NAME_1 = "resourceBlock.name IS NULL";
1233 private static final String _FINDER_COLUMN_C_G_N_NAME_2 = "resourceBlock.name = ?";
1234 private static final String _FINDER_COLUMN_C_G_N_NAME_3 = "(resourceBlock.name IS NULL OR resourceBlock.name = ?)";
1235 public static final FinderPath FINDER_PATH_FETCH_BY_C_G_N_P = new FinderPath(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
1236 ResourceBlockModelImpl.FINDER_CACHE_ENABLED,
1237 ResourceBlockImpl.class, FINDER_CLASS_NAME_ENTITY,
1238 "fetchByC_G_N_P",
1239 new String[] {
1240 Long.class.getName(), Long.class.getName(),
1241 String.class.getName(), String.class.getName()
1242 },
1243 ResourceBlockModelImpl.COMPANYID_COLUMN_BITMASK |
1244 ResourceBlockModelImpl.GROUPID_COLUMN_BITMASK |
1245 ResourceBlockModelImpl.NAME_COLUMN_BITMASK |
1246 ResourceBlockModelImpl.PERMISSIONSHASH_COLUMN_BITMASK);
1247 public static final FinderPath FINDER_PATH_COUNT_BY_C_G_N_P = new FinderPath(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
1248 ResourceBlockModelImpl.FINDER_CACHE_ENABLED, Long.class,
1249 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_G_N_P",
1250 new String[] {
1251 Long.class.getName(), Long.class.getName(),
1252 String.class.getName(), String.class.getName()
1253 });
1254
1255
1266 public ResourceBlock findByC_G_N_P(long companyId, long groupId,
1267 String name, String permissionsHash)
1268 throws NoSuchResourceBlockException, SystemException {
1269 ResourceBlock resourceBlock = fetchByC_G_N_P(companyId, groupId, name,
1270 permissionsHash);
1271
1272 if (resourceBlock == null) {
1273 StringBundler msg = new StringBundler(10);
1274
1275 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1276
1277 msg.append("companyId=");
1278 msg.append(companyId);
1279
1280 msg.append(", groupId=");
1281 msg.append(groupId);
1282
1283 msg.append(", name=");
1284 msg.append(name);
1285
1286 msg.append(", permissionsHash=");
1287 msg.append(permissionsHash);
1288
1289 msg.append(StringPool.CLOSE_CURLY_BRACE);
1290
1291 if (_log.isWarnEnabled()) {
1292 _log.warn(msg.toString());
1293 }
1294
1295 throw new NoSuchResourceBlockException(msg.toString());
1296 }
1297
1298 return resourceBlock;
1299 }
1300
1301
1311 public ResourceBlock fetchByC_G_N_P(long companyId, long groupId,
1312 String name, String permissionsHash) throws SystemException {
1313 return fetchByC_G_N_P(companyId, groupId, name, permissionsHash, true);
1314 }
1315
1316
1327 public ResourceBlock fetchByC_G_N_P(long companyId, long groupId,
1328 String name, String permissionsHash, boolean retrieveFromCache)
1329 throws SystemException {
1330 Object[] finderArgs = new Object[] {
1331 companyId, groupId, name, permissionsHash
1332 };
1333
1334 Object result = null;
1335
1336 if (retrieveFromCache) {
1337 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_G_N_P,
1338 finderArgs, this);
1339 }
1340
1341 if (result instanceof ResourceBlock) {
1342 ResourceBlock resourceBlock = (ResourceBlock)result;
1343
1344 if ((companyId != resourceBlock.getCompanyId()) ||
1345 (groupId != resourceBlock.getGroupId()) ||
1346 !Validator.equals(name, resourceBlock.getName()) ||
1347 !Validator.equals(permissionsHash,
1348 resourceBlock.getPermissionsHash())) {
1349 result = null;
1350 }
1351 }
1352
1353 if (result == null) {
1354 StringBundler query = new StringBundler(6);
1355
1356 query.append(_SQL_SELECT_RESOURCEBLOCK_WHERE);
1357
1358 query.append(_FINDER_COLUMN_C_G_N_P_COMPANYID_2);
1359
1360 query.append(_FINDER_COLUMN_C_G_N_P_GROUPID_2);
1361
1362 if (name == null) {
1363 query.append(_FINDER_COLUMN_C_G_N_P_NAME_1);
1364 }
1365 else {
1366 if (name.equals(StringPool.BLANK)) {
1367 query.append(_FINDER_COLUMN_C_G_N_P_NAME_3);
1368 }
1369 else {
1370 query.append(_FINDER_COLUMN_C_G_N_P_NAME_2);
1371 }
1372 }
1373
1374 if (permissionsHash == null) {
1375 query.append(_FINDER_COLUMN_C_G_N_P_PERMISSIONSHASH_1);
1376 }
1377 else {
1378 if (permissionsHash.equals(StringPool.BLANK)) {
1379 query.append(_FINDER_COLUMN_C_G_N_P_PERMISSIONSHASH_3);
1380 }
1381 else {
1382 query.append(_FINDER_COLUMN_C_G_N_P_PERMISSIONSHASH_2);
1383 }
1384 }
1385
1386 String sql = query.toString();
1387
1388 Session session = null;
1389
1390 try {
1391 session = openSession();
1392
1393 Query q = session.createQuery(sql);
1394
1395 QueryPos qPos = QueryPos.getInstance(q);
1396
1397 qPos.add(companyId);
1398
1399 qPos.add(groupId);
1400
1401 if (name != null) {
1402 qPos.add(name);
1403 }
1404
1405 if (permissionsHash != null) {
1406 qPos.add(permissionsHash);
1407 }
1408
1409 List<ResourceBlock> list = q.list();
1410
1411 if (list.isEmpty()) {
1412 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_G_N_P,
1413 finderArgs, list);
1414 }
1415 else {
1416 ResourceBlock resourceBlock = list.get(0);
1417
1418 result = resourceBlock;
1419
1420 cacheResult(resourceBlock);
1421
1422 if ((resourceBlock.getCompanyId() != companyId) ||
1423 (resourceBlock.getGroupId() != groupId) ||
1424 (resourceBlock.getName() == null) ||
1425 !resourceBlock.getName().equals(name) ||
1426 (resourceBlock.getPermissionsHash() == null) ||
1427 !resourceBlock.getPermissionsHash()
1428 .equals(permissionsHash)) {
1429 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_G_N_P,
1430 finderArgs, resourceBlock);
1431 }
1432 }
1433 }
1434 catch (Exception e) {
1435 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_G_N_P,
1436 finderArgs);
1437
1438 throw processException(e);
1439 }
1440 finally {
1441 closeSession(session);
1442 }
1443 }
1444
1445 if (result instanceof List<?>) {
1446 return null;
1447 }
1448 else {
1449 return (ResourceBlock)result;
1450 }
1451 }
1452
1453
1463 public ResourceBlock removeByC_G_N_P(long companyId, long groupId,
1464 String name, String permissionsHash)
1465 throws NoSuchResourceBlockException, SystemException {
1466 ResourceBlock resourceBlock = findByC_G_N_P(companyId, groupId, name,
1467 permissionsHash);
1468
1469 return remove(resourceBlock);
1470 }
1471
1472
1482 public int countByC_G_N_P(long companyId, long groupId, String name,
1483 String permissionsHash) throws SystemException {
1484 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_G_N_P;
1485
1486 Object[] finderArgs = new Object[] {
1487 companyId, groupId, name, permissionsHash
1488 };
1489
1490 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1491 this);
1492
1493 if (count == null) {
1494 StringBundler query = new StringBundler(5);
1495
1496 query.append(_SQL_COUNT_RESOURCEBLOCK_WHERE);
1497
1498 query.append(_FINDER_COLUMN_C_G_N_P_COMPANYID_2);
1499
1500 query.append(_FINDER_COLUMN_C_G_N_P_GROUPID_2);
1501
1502 if (name == null) {
1503 query.append(_FINDER_COLUMN_C_G_N_P_NAME_1);
1504 }
1505 else {
1506 if (name.equals(StringPool.BLANK)) {
1507 query.append(_FINDER_COLUMN_C_G_N_P_NAME_3);
1508 }
1509 else {
1510 query.append(_FINDER_COLUMN_C_G_N_P_NAME_2);
1511 }
1512 }
1513
1514 if (permissionsHash == null) {
1515 query.append(_FINDER_COLUMN_C_G_N_P_PERMISSIONSHASH_1);
1516 }
1517 else {
1518 if (permissionsHash.equals(StringPool.BLANK)) {
1519 query.append(_FINDER_COLUMN_C_G_N_P_PERMISSIONSHASH_3);
1520 }
1521 else {
1522 query.append(_FINDER_COLUMN_C_G_N_P_PERMISSIONSHASH_2);
1523 }
1524 }
1525
1526 String sql = query.toString();
1527
1528 Session session = null;
1529
1530 try {
1531 session = openSession();
1532
1533 Query q = session.createQuery(sql);
1534
1535 QueryPos qPos = QueryPos.getInstance(q);
1536
1537 qPos.add(companyId);
1538
1539 qPos.add(groupId);
1540
1541 if (name != null) {
1542 qPos.add(name);
1543 }
1544
1545 if (permissionsHash != null) {
1546 qPos.add(permissionsHash);
1547 }
1548
1549 count = (Long)q.uniqueResult();
1550
1551 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1552 }
1553 catch (Exception e) {
1554 FinderCacheUtil.removeResult(finderPath, finderArgs);
1555
1556 throw processException(e);
1557 }
1558 finally {
1559 closeSession(session);
1560 }
1561 }
1562
1563 return count.intValue();
1564 }
1565
1566 private static final String _FINDER_COLUMN_C_G_N_P_COMPANYID_2 = "resourceBlock.companyId = ? AND ";
1567 private static final String _FINDER_COLUMN_C_G_N_P_GROUPID_2 = "resourceBlock.groupId = ? AND ";
1568 private static final String _FINDER_COLUMN_C_G_N_P_NAME_1 = "resourceBlock.name IS NULL AND ";
1569 private static final String _FINDER_COLUMN_C_G_N_P_NAME_2 = "resourceBlock.name = ? AND ";
1570 private static final String _FINDER_COLUMN_C_G_N_P_NAME_3 = "(resourceBlock.name IS NULL OR resourceBlock.name = ?) AND ";
1571 private static final String _FINDER_COLUMN_C_G_N_P_PERMISSIONSHASH_1 = "resourceBlock.permissionsHash IS NULL";
1572 private static final String _FINDER_COLUMN_C_G_N_P_PERMISSIONSHASH_2 = "resourceBlock.permissionsHash = ?";
1573 private static final String _FINDER_COLUMN_C_G_N_P_PERMISSIONSHASH_3 = "(resourceBlock.permissionsHash IS NULL OR resourceBlock.permissionsHash = ?)";
1574
1575
1580 public void cacheResult(ResourceBlock resourceBlock) {
1581 EntityCacheUtil.putResult(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
1582 ResourceBlockImpl.class, resourceBlock.getPrimaryKey(),
1583 resourceBlock);
1584
1585 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_G_N_P,
1586 new Object[] {
1587 Long.valueOf(resourceBlock.getCompanyId()),
1588 Long.valueOf(resourceBlock.getGroupId()),
1589
1590 resourceBlock.getName(),
1591
1592 resourceBlock.getPermissionsHash()
1593 }, resourceBlock);
1594
1595 resourceBlock.resetOriginalValues();
1596 }
1597
1598
1603 public void cacheResult(List<ResourceBlock> resourceBlocks) {
1604 for (ResourceBlock resourceBlock : resourceBlocks) {
1605 if (EntityCacheUtil.getResult(
1606 ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
1607 ResourceBlockImpl.class, resourceBlock.getPrimaryKey()) == null) {
1608 cacheResult(resourceBlock);
1609 }
1610 else {
1611 resourceBlock.resetOriginalValues();
1612 }
1613 }
1614 }
1615
1616
1623 @Override
1624 public void clearCache() {
1625 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
1626 CacheRegistryUtil.clear(ResourceBlockImpl.class.getName());
1627 }
1628
1629 EntityCacheUtil.clearCache(ResourceBlockImpl.class.getName());
1630
1631 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1632 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1633 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1634 }
1635
1636
1643 @Override
1644 public void clearCache(ResourceBlock resourceBlock) {
1645 EntityCacheUtil.removeResult(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
1646 ResourceBlockImpl.class, resourceBlock.getPrimaryKey());
1647
1648 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1649 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1650
1651 clearUniqueFindersCache(resourceBlock);
1652 }
1653
1654 @Override
1655 public void clearCache(List<ResourceBlock> resourceBlocks) {
1656 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1657 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1658
1659 for (ResourceBlock resourceBlock : resourceBlocks) {
1660 EntityCacheUtil.removeResult(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
1661 ResourceBlockImpl.class, resourceBlock.getPrimaryKey());
1662
1663 clearUniqueFindersCache(resourceBlock);
1664 }
1665 }
1666
1667 protected void cacheUniqueFindersCache(ResourceBlock resourceBlock) {
1668 if (resourceBlock.isNew()) {
1669 Object[] args = new Object[] {
1670 Long.valueOf(resourceBlock.getCompanyId()),
1671 Long.valueOf(resourceBlock.getGroupId()),
1672
1673 resourceBlock.getName(),
1674
1675 resourceBlock.getPermissionsHash()
1676 };
1677
1678 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_G_N_P, args,
1679 Long.valueOf(1));
1680 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_G_N_P, args,
1681 resourceBlock);
1682 }
1683 else {
1684 ResourceBlockModelImpl resourceBlockModelImpl = (ResourceBlockModelImpl)resourceBlock;
1685
1686 if ((resourceBlockModelImpl.getColumnBitmask() &
1687 FINDER_PATH_FETCH_BY_C_G_N_P.getColumnBitmask()) != 0) {
1688 Object[] args = new Object[] {
1689 Long.valueOf(resourceBlock.getCompanyId()),
1690 Long.valueOf(resourceBlock.getGroupId()),
1691
1692 resourceBlock.getName(),
1693
1694 resourceBlock.getPermissionsHash()
1695 };
1696
1697 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_G_N_P, args,
1698 Long.valueOf(1));
1699 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_G_N_P, args,
1700 resourceBlock);
1701 }
1702 }
1703 }
1704
1705 protected void clearUniqueFindersCache(ResourceBlock resourceBlock) {
1706 ResourceBlockModelImpl resourceBlockModelImpl = (ResourceBlockModelImpl)resourceBlock;
1707
1708 Object[] args = new Object[] {
1709 Long.valueOf(resourceBlock.getCompanyId()),
1710 Long.valueOf(resourceBlock.getGroupId()),
1711
1712 resourceBlock.getName(),
1713
1714 resourceBlock.getPermissionsHash()
1715 };
1716
1717 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_G_N_P, args);
1718 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_G_N_P, args);
1719
1720 if ((resourceBlockModelImpl.getColumnBitmask() &
1721 FINDER_PATH_FETCH_BY_C_G_N_P.getColumnBitmask()) != 0) {
1722 args = new Object[] {
1723 Long.valueOf(resourceBlockModelImpl.getOriginalCompanyId()),
1724 Long.valueOf(resourceBlockModelImpl.getOriginalGroupId()),
1725
1726 resourceBlockModelImpl.getOriginalName(),
1727
1728 resourceBlockModelImpl.getOriginalPermissionsHash()
1729 };
1730
1731 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_G_N_P, args);
1732 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_G_N_P, args);
1733 }
1734 }
1735
1736
1742 public ResourceBlock create(long resourceBlockId) {
1743 ResourceBlock resourceBlock = new ResourceBlockImpl();
1744
1745 resourceBlock.setNew(true);
1746 resourceBlock.setPrimaryKey(resourceBlockId);
1747
1748 return resourceBlock;
1749 }
1750
1751
1759 public ResourceBlock remove(long resourceBlockId)
1760 throws NoSuchResourceBlockException, SystemException {
1761 return remove(Long.valueOf(resourceBlockId));
1762 }
1763
1764
1772 @Override
1773 public ResourceBlock remove(Serializable primaryKey)
1774 throws NoSuchResourceBlockException, SystemException {
1775 Session session = null;
1776
1777 try {
1778 session = openSession();
1779
1780 ResourceBlock resourceBlock = (ResourceBlock)session.get(ResourceBlockImpl.class,
1781 primaryKey);
1782
1783 if (resourceBlock == null) {
1784 if (_log.isWarnEnabled()) {
1785 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1786 }
1787
1788 throw new NoSuchResourceBlockException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1789 primaryKey);
1790 }
1791
1792 return remove(resourceBlock);
1793 }
1794 catch (NoSuchResourceBlockException nsee) {
1795 throw nsee;
1796 }
1797 catch (Exception e) {
1798 throw processException(e);
1799 }
1800 finally {
1801 closeSession(session);
1802 }
1803 }
1804
1805 @Override
1806 protected ResourceBlock removeImpl(ResourceBlock resourceBlock)
1807 throws SystemException {
1808 resourceBlock = toUnwrappedModel(resourceBlock);
1809
1810 Session session = null;
1811
1812 try {
1813 session = openSession();
1814
1815 if (!session.contains(resourceBlock)) {
1816 resourceBlock = (ResourceBlock)session.get(ResourceBlockImpl.class,
1817 resourceBlock.getPrimaryKeyObj());
1818 }
1819
1820 if (resourceBlock != null) {
1821 session.delete(resourceBlock);
1822 }
1823 }
1824 catch (Exception e) {
1825 throw processException(e);
1826 }
1827 finally {
1828 closeSession(session);
1829 }
1830
1831 if (resourceBlock != null) {
1832 clearCache(resourceBlock);
1833 }
1834
1835 return resourceBlock;
1836 }
1837
1838 @Override
1839 public ResourceBlock updateImpl(
1840 com.liferay.portal.model.ResourceBlock resourceBlock)
1841 throws SystemException {
1842 resourceBlock = toUnwrappedModel(resourceBlock);
1843
1844 boolean isNew = resourceBlock.isNew();
1845
1846 ResourceBlockModelImpl resourceBlockModelImpl = (ResourceBlockModelImpl)resourceBlock;
1847
1848 Session session = null;
1849
1850 try {
1851 session = openSession();
1852
1853 if (resourceBlock.isNew()) {
1854 session.save(resourceBlock);
1855
1856 resourceBlock.setNew(false);
1857 }
1858 else {
1859 session.merge(resourceBlock);
1860 }
1861 }
1862 catch (Exception e) {
1863 throw processException(e);
1864 }
1865 finally {
1866 closeSession(session);
1867 }
1868
1869 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1870
1871 if (isNew || !ResourceBlockModelImpl.COLUMN_BITMASK_ENABLED) {
1872 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1873 }
1874
1875 else {
1876 if ((resourceBlockModelImpl.getColumnBitmask() &
1877 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N.getColumnBitmask()) != 0) {
1878 Object[] args = new Object[] {
1879 Long.valueOf(resourceBlockModelImpl.getOriginalCompanyId()),
1880
1881 resourceBlockModelImpl.getOriginalName()
1882 };
1883
1884 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N, args);
1885 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N,
1886 args);
1887
1888 args = new Object[] {
1889 Long.valueOf(resourceBlockModelImpl.getCompanyId()),
1890
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 Long.valueOf(resourceBlockModelImpl.getOriginalCompanyId()),
1903 Long.valueOf(resourceBlockModelImpl.getOriginalGroupId()),
1904
1905 resourceBlockModelImpl.getOriginalName()
1906 };
1907
1908 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_G_N, args);
1909 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_G_N,
1910 args);
1911
1912 args = new Object[] {
1913 Long.valueOf(resourceBlockModelImpl.getCompanyId()),
1914 Long.valueOf(resourceBlockModelImpl.getGroupId()),
1915
1916 resourceBlockModelImpl.getName()
1917 };
1918
1919 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_G_N, args);
1920 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_G_N,
1921 args);
1922 }
1923 }
1924
1925 EntityCacheUtil.putResult(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
1926 ResourceBlockImpl.class, resourceBlock.getPrimaryKey(),
1927 resourceBlock);
1928
1929 clearUniqueFindersCache(resourceBlock);
1930 cacheUniqueFindersCache(resourceBlock);
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.setResourceBlockId(resourceBlock.getResourceBlockId());
1946 resourceBlockImpl.setCompanyId(resourceBlock.getCompanyId());
1947 resourceBlockImpl.setGroupId(resourceBlock.getGroupId());
1948 resourceBlockImpl.setName(resourceBlock.getName());
1949 resourceBlockImpl.setPermissionsHash(resourceBlock.getPermissionsHash());
1950 resourceBlockImpl.setReferenceCount(resourceBlock.getReferenceCount());
1951
1952 return resourceBlockImpl;
1953 }
1954
1955
1963 @Override
1964 public ResourceBlock findByPrimaryKey(Serializable primaryKey)
1965 throws NoSuchModelException, SystemException {
1966 return findByPrimaryKey(((Long)primaryKey).longValue());
1967 }
1968
1969
1977 public ResourceBlock findByPrimaryKey(long resourceBlockId)
1978 throws NoSuchResourceBlockException, SystemException {
1979 ResourceBlock resourceBlock = fetchByPrimaryKey(resourceBlockId);
1980
1981 if (resourceBlock == null) {
1982 if (_log.isWarnEnabled()) {
1983 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + resourceBlockId);
1984 }
1985
1986 throw new NoSuchResourceBlockException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1987 resourceBlockId);
1988 }
1989
1990 return resourceBlock;
1991 }
1992
1993
2000 @Override
2001 public ResourceBlock fetchByPrimaryKey(Serializable primaryKey)
2002 throws SystemException {
2003 return fetchByPrimaryKey(((Long)primaryKey).longValue());
2004 }
2005
2006
2013 public ResourceBlock fetchByPrimaryKey(long resourceBlockId)
2014 throws SystemException {
2015 ResourceBlock resourceBlock = (ResourceBlock)EntityCacheUtil.getResult(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
2016 ResourceBlockImpl.class, resourceBlockId);
2017
2018 if (resourceBlock == _nullResourceBlock) {
2019 return null;
2020 }
2021
2022 if (resourceBlock == null) {
2023 Session session = null;
2024
2025 try {
2026 session = openSession();
2027
2028 resourceBlock = (ResourceBlock)session.get(ResourceBlockImpl.class,
2029 Long.valueOf(resourceBlockId));
2030
2031 if (resourceBlock != null) {
2032 cacheResult(resourceBlock);
2033 }
2034 else {
2035 EntityCacheUtil.putResult(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
2036 ResourceBlockImpl.class, resourceBlockId,
2037 _nullResourceBlock);
2038 }
2039 }
2040 catch (Exception e) {
2041 EntityCacheUtil.removeResult(ResourceBlockModelImpl.ENTITY_CACHE_ENABLED,
2042 ResourceBlockImpl.class, resourceBlockId);
2043
2044 throw processException(e);
2045 }
2046 finally {
2047 closeSession(session);
2048 }
2049 }
2050
2051 return resourceBlock;
2052 }
2053
2054
2060 public List<ResourceBlock> findAll() throws SystemException {
2061 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2062 }
2063
2064
2076 public List<ResourceBlock> findAll(int start, int end)
2077 throws SystemException {
2078 return findAll(start, end, null);
2079 }
2080
2081
2094 public List<ResourceBlock> findAll(int start, int end,
2095 OrderByComparator orderByComparator) throws SystemException {
2096 boolean pagination = true;
2097 FinderPath finderPath = null;
2098 Object[] finderArgs = null;
2099
2100 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2101 (orderByComparator == null)) {
2102 pagination = false;
2103 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2104 finderArgs = FINDER_ARGS_EMPTY;
2105 }
2106 else {
2107 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2108 finderArgs = new Object[] { start, end, orderByComparator };
2109 }
2110
2111 List<ResourceBlock> list = (List<ResourceBlock>)FinderCacheUtil.getResult(finderPath,
2112 finderArgs, this);
2113
2114 if (list == null) {
2115 StringBundler query = null;
2116 String sql = null;
2117
2118 if (orderByComparator != null) {
2119 query = new StringBundler(2 +
2120 (orderByComparator.getOrderByFields().length * 3));
2121
2122 query.append(_SQL_SELECT_RESOURCEBLOCK);
2123
2124 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2125 orderByComparator);
2126
2127 sql = query.toString();
2128 }
2129 else {
2130 sql = _SQL_SELECT_RESOURCEBLOCK;
2131
2132 if (pagination) {
2133 sql = sql.concat(ResourceBlockModelImpl.ORDER_BY_JPQL);
2134 }
2135 }
2136
2137 Session session = null;
2138
2139 try {
2140 session = openSession();
2141
2142 Query q = session.createQuery(sql);
2143
2144 if (!pagination) {
2145 list = (List<ResourceBlock>)QueryUtil.list(q, getDialect(),
2146 start, end, false);
2147
2148 Collections.sort(list);
2149
2150 list = new UnmodifiableList<ResourceBlock>(list);
2151 }
2152 else {
2153 list = (List<ResourceBlock>)QueryUtil.list(q, getDialect(),
2154 start, end);
2155 }
2156
2157 cacheResult(list);
2158
2159 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2160 }
2161 catch (Exception e) {
2162 FinderCacheUtil.removeResult(finderPath, finderArgs);
2163
2164 throw processException(e);
2165 }
2166 finally {
2167 closeSession(session);
2168 }
2169 }
2170
2171 return list;
2172 }
2173
2174
2179 public void removeAll() throws SystemException {
2180 for (ResourceBlock resourceBlock : findAll()) {
2181 remove(resourceBlock);
2182 }
2183 }
2184
2185
2191 public int countAll() throws SystemException {
2192 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2193 FINDER_ARGS_EMPTY, this);
2194
2195 if (count == null) {
2196 Session session = null;
2197
2198 try {
2199 session = openSession();
2200
2201 Query q = session.createQuery(_SQL_COUNT_RESOURCEBLOCK);
2202
2203 count = (Long)q.uniqueResult();
2204
2205 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2206 FINDER_ARGS_EMPTY, count);
2207 }
2208 catch (Exception e) {
2209 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
2210 FINDER_ARGS_EMPTY);
2211
2212 throw processException(e);
2213 }
2214 finally {
2215 closeSession(session);
2216 }
2217 }
2218
2219 return count.intValue();
2220 }
2221
2222
2225 public void afterPropertiesSet() {
2226 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2227 com.liferay.portal.util.PropsUtil.get(
2228 "value.object.listener.com.liferay.portal.model.ResourceBlock")));
2229
2230 if (listenerClassNames.length > 0) {
2231 try {
2232 List<ModelListener<ResourceBlock>> listenersList = new ArrayList<ModelListener<ResourceBlock>>();
2233
2234 for (String listenerClassName : listenerClassNames) {
2235 listenersList.add((ModelListener<ResourceBlock>)InstanceFactory.newInstance(
2236 listenerClassName));
2237 }
2238
2239 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2240 }
2241 catch (Exception e) {
2242 _log.error(e);
2243 }
2244 }
2245 }
2246
2247 public void destroy() {
2248 EntityCacheUtil.removeCache(ResourceBlockImpl.class.getName());
2249 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2250 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2251 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2252 }
2253
2254 private static final String _SQL_SELECT_RESOURCEBLOCK = "SELECT resourceBlock FROM ResourceBlock resourceBlock";
2255 private static final String _SQL_SELECT_RESOURCEBLOCK_WHERE = "SELECT resourceBlock FROM ResourceBlock resourceBlock WHERE ";
2256 private static final String _SQL_COUNT_RESOURCEBLOCK = "SELECT COUNT(resourceBlock) FROM ResourceBlock resourceBlock";
2257 private static final String _SQL_COUNT_RESOURCEBLOCK_WHERE = "SELECT COUNT(resourceBlock) FROM ResourceBlock resourceBlock WHERE ";
2258 private static final String _ORDER_BY_ENTITY_ALIAS = "resourceBlock.";
2259 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ResourceBlock exists with the primary key ";
2260 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ResourceBlock exists with the key {";
2261 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2262 private static Log _log = LogFactoryUtil.getLog(ResourceBlockPersistenceImpl.class);
2263 private static ResourceBlock _nullResourceBlock = new ResourceBlockImpl() {
2264 @Override
2265 public Object clone() {
2266 return this;
2267 }
2268
2269 @Override
2270 public CacheModel<ResourceBlock> toCacheModel() {
2271 return _nullResourceBlockCacheModel;
2272 }
2273 };
2274
2275 private static CacheModel<ResourceBlock> _nullResourceBlockCacheModel = new CacheModel<ResourceBlock>() {
2276 public ResourceBlock toEntityModel() {
2277 return _nullResourceBlock;
2278 }
2279 };
2280 }