1
22
23 package com.liferay.portlet.messageboards.service.persistence;
24
25 import com.liferay.portal.SystemException;
26 import com.liferay.portal.kernel.annotation.BeanReference;
27 import com.liferay.portal.kernel.dao.orm.DynamicQuery;
28 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
29 import com.liferay.portal.kernel.dao.orm.Query;
30 import com.liferay.portal.kernel.dao.orm.QueryPos;
31 import com.liferay.portal.kernel.dao.orm.QueryUtil;
32 import com.liferay.portal.kernel.dao.orm.Session;
33 import com.liferay.portal.kernel.log.Log;
34 import com.liferay.portal.kernel.log.LogFactoryUtil;
35 import com.liferay.portal.kernel.util.GetterUtil;
36 import com.liferay.portal.kernel.util.OrderByComparator;
37 import com.liferay.portal.kernel.util.StringPool;
38 import com.liferay.portal.kernel.util.StringUtil;
39 import com.liferay.portal.kernel.util.Validator;
40 import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
41 import com.liferay.portal.model.ModelListener;
42 import com.liferay.portal.service.persistence.BatchSessionUtil;
43 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
44
45 import com.liferay.portlet.messageboards.NoSuchCategoryException;
46 import com.liferay.portlet.messageboards.model.MBCategory;
47 import com.liferay.portlet.messageboards.model.impl.MBCategoryImpl;
48 import com.liferay.portlet.messageboards.model.impl.MBCategoryModelImpl;
49
50 import java.util.ArrayList;
51 import java.util.Collections;
52 import java.util.Iterator;
53 import java.util.List;
54
55
61 public class MBCategoryPersistenceImpl extends BasePersistenceImpl
62 implements MBCategoryPersistence {
63 public MBCategory create(long categoryId) {
64 MBCategory mbCategory = new MBCategoryImpl();
65
66 mbCategory.setNew(true);
67 mbCategory.setPrimaryKey(categoryId);
68
69 String uuid = PortalUUIDUtil.generate();
70
71 mbCategory.setUuid(uuid);
72
73 return mbCategory;
74 }
75
76 public MBCategory remove(long categoryId)
77 throws NoSuchCategoryException, SystemException {
78 Session session = null;
79
80 try {
81 session = openSession();
82
83 MBCategory mbCategory = (MBCategory)session.get(MBCategoryImpl.class,
84 new Long(categoryId));
85
86 if (mbCategory == null) {
87 if (_log.isWarnEnabled()) {
88 _log.warn("No MBCategory exists with the primary key " +
89 categoryId);
90 }
91
92 throw new NoSuchCategoryException(
93 "No MBCategory exists with the primary key " + categoryId);
94 }
95
96 return remove(mbCategory);
97 }
98 catch (NoSuchCategoryException nsee) {
99 throw nsee;
100 }
101 catch (Exception e) {
102 throw processException(e);
103 }
104 finally {
105 closeSession(session);
106 }
107 }
108
109 public MBCategory remove(MBCategory mbCategory) throws SystemException {
110 for (ModelListener listener : listeners) {
111 listener.onBeforeRemove(mbCategory);
112 }
113
114 mbCategory = removeImpl(mbCategory);
115
116 for (ModelListener listener : listeners) {
117 listener.onAfterRemove(mbCategory);
118 }
119
120 return mbCategory;
121 }
122
123 protected MBCategory removeImpl(MBCategory mbCategory)
124 throws SystemException {
125 Session session = null;
126
127 try {
128 session = openSession();
129
130 if (BatchSessionUtil.isEnabled()) {
131 Object staleObject = session.get(MBCategoryImpl.class,
132 mbCategory.getPrimaryKeyObj());
133
134 if (staleObject != null) {
135 session.evict(staleObject);
136 }
137 }
138
139 session.delete(mbCategory);
140
141 session.flush();
142
143 return mbCategory;
144 }
145 catch (Exception e) {
146 throw processException(e);
147 }
148 finally {
149 closeSession(session);
150
151 FinderCacheUtil.clearCache(MBCategory.class.getName());
152 }
153 }
154
155
158 public MBCategory update(MBCategory mbCategory) throws SystemException {
159 if (_log.isWarnEnabled()) {
160 _log.warn(
161 "Using the deprecated update(MBCategory mbCategory) method. Use update(MBCategory mbCategory, boolean merge) instead.");
162 }
163
164 return update(mbCategory, false);
165 }
166
167
180 public MBCategory update(MBCategory mbCategory, boolean merge)
181 throws SystemException {
182 boolean isNew = mbCategory.isNew();
183
184 for (ModelListener listener : listeners) {
185 if (isNew) {
186 listener.onBeforeCreate(mbCategory);
187 }
188 else {
189 listener.onBeforeUpdate(mbCategory);
190 }
191 }
192
193 mbCategory = updateImpl(mbCategory, merge);
194
195 for (ModelListener listener : listeners) {
196 if (isNew) {
197 listener.onAfterCreate(mbCategory);
198 }
199 else {
200 listener.onAfterUpdate(mbCategory);
201 }
202 }
203
204 return mbCategory;
205 }
206
207 public MBCategory updateImpl(
208 com.liferay.portlet.messageboards.model.MBCategory mbCategory,
209 boolean merge) throws SystemException {
210 if (Validator.isNull(mbCategory.getUuid())) {
211 String uuid = PortalUUIDUtil.generate();
212
213 mbCategory.setUuid(uuid);
214 }
215
216 Session session = null;
217
218 try {
219 session = openSession();
220
221 BatchSessionUtil.update(session, mbCategory, merge);
222
223 mbCategory.setNew(false);
224
225 return mbCategory;
226 }
227 catch (Exception e) {
228 throw processException(e);
229 }
230 finally {
231 closeSession(session);
232
233 FinderCacheUtil.clearCache(MBCategory.class.getName());
234 }
235 }
236
237 public MBCategory findByPrimaryKey(long categoryId)
238 throws NoSuchCategoryException, SystemException {
239 MBCategory mbCategory = fetchByPrimaryKey(categoryId);
240
241 if (mbCategory == null) {
242 if (_log.isWarnEnabled()) {
243 _log.warn("No MBCategory exists with the primary key " +
244 categoryId);
245 }
246
247 throw new NoSuchCategoryException(
248 "No MBCategory exists with the primary key " + categoryId);
249 }
250
251 return mbCategory;
252 }
253
254 public MBCategory fetchByPrimaryKey(long categoryId)
255 throws SystemException {
256 Session session = null;
257
258 try {
259 session = openSession();
260
261 return (MBCategory)session.get(MBCategoryImpl.class,
262 new Long(categoryId));
263 }
264 catch (Exception e) {
265 throw processException(e);
266 }
267 finally {
268 closeSession(session);
269 }
270 }
271
272 public List<MBCategory> findByUuid(String uuid) throws SystemException {
273 boolean finderClassNameCacheEnabled = MBCategoryModelImpl.CACHE_ENABLED;
274 String finderClassName = MBCategory.class.getName();
275 String finderMethodName = "findByUuid";
276 String[] finderParams = new String[] { String.class.getName() };
277 Object[] finderArgs = new Object[] { uuid };
278
279 Object result = null;
280
281 if (finderClassNameCacheEnabled) {
282 result = FinderCacheUtil.getResult(finderClassName,
283 finderMethodName, finderParams, finderArgs, this);
284 }
285
286 if (result == null) {
287 Session session = null;
288
289 try {
290 session = openSession();
291
292 StringBuilder query = new StringBuilder();
293
294 query.append(
295 "FROM com.liferay.portlet.messageboards.model.MBCategory WHERE ");
296
297 if (uuid == null) {
298 query.append("uuid_ IS NULL");
299 }
300 else {
301 query.append("uuid_ = ?");
302 }
303
304 query.append(" ");
305
306 query.append("ORDER BY ");
307
308 query.append("parentCategoryId ASC, ");
309 query.append("name ASC");
310
311 Query q = session.createQuery(query.toString());
312
313 QueryPos qPos = QueryPos.getInstance(q);
314
315 if (uuid != null) {
316 qPos.add(uuid);
317 }
318
319 List<MBCategory> list = q.list();
320
321 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
322 finderClassName, finderMethodName, finderParams,
323 finderArgs, list);
324
325 return list;
326 }
327 catch (Exception e) {
328 throw processException(e);
329 }
330 finally {
331 closeSession(session);
332 }
333 }
334 else {
335 return (List<MBCategory>)result;
336 }
337 }
338
339 public List<MBCategory> findByUuid(String uuid, int start, int end)
340 throws SystemException {
341 return findByUuid(uuid, start, end, null);
342 }
343
344 public List<MBCategory> findByUuid(String uuid, int start, int end,
345 OrderByComparator obc) throws SystemException {
346 boolean finderClassNameCacheEnabled = MBCategoryModelImpl.CACHE_ENABLED;
347 String finderClassName = MBCategory.class.getName();
348 String finderMethodName = "findByUuid";
349 String[] finderParams = new String[] {
350 String.class.getName(),
351
352 "java.lang.Integer", "java.lang.Integer",
353 "com.liferay.portal.kernel.util.OrderByComparator"
354 };
355 Object[] finderArgs = new Object[] {
356 uuid,
357
358 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
359 };
360
361 Object result = null;
362
363 if (finderClassNameCacheEnabled) {
364 result = FinderCacheUtil.getResult(finderClassName,
365 finderMethodName, finderParams, finderArgs, this);
366 }
367
368 if (result == null) {
369 Session session = null;
370
371 try {
372 session = openSession();
373
374 StringBuilder query = new StringBuilder();
375
376 query.append(
377 "FROM com.liferay.portlet.messageboards.model.MBCategory WHERE ");
378
379 if (uuid == null) {
380 query.append("uuid_ IS NULL");
381 }
382 else {
383 query.append("uuid_ = ?");
384 }
385
386 query.append(" ");
387
388 if (obc != null) {
389 query.append("ORDER BY ");
390 query.append(obc.getOrderBy());
391 }
392
393 else {
394 query.append("ORDER BY ");
395
396 query.append("parentCategoryId ASC, ");
397 query.append("name ASC");
398 }
399
400 Query q = session.createQuery(query.toString());
401
402 QueryPos qPos = QueryPos.getInstance(q);
403
404 if (uuid != null) {
405 qPos.add(uuid);
406 }
407
408 List<MBCategory> list = (List<MBCategory>)QueryUtil.list(q,
409 getDialect(), start, end);
410
411 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
412 finderClassName, finderMethodName, finderParams,
413 finderArgs, list);
414
415 return list;
416 }
417 catch (Exception e) {
418 throw processException(e);
419 }
420 finally {
421 closeSession(session);
422 }
423 }
424 else {
425 return (List<MBCategory>)result;
426 }
427 }
428
429 public MBCategory findByUuid_First(String uuid, OrderByComparator obc)
430 throws NoSuchCategoryException, SystemException {
431 List<MBCategory> list = findByUuid(uuid, 0, 1, obc);
432
433 if (list.size() == 0) {
434 StringBuilder msg = new StringBuilder();
435
436 msg.append("No MBCategory exists with the key {");
437
438 msg.append("uuid=" + uuid);
439
440 msg.append(StringPool.CLOSE_CURLY_BRACE);
441
442 throw new NoSuchCategoryException(msg.toString());
443 }
444 else {
445 return list.get(0);
446 }
447 }
448
449 public MBCategory findByUuid_Last(String uuid, OrderByComparator obc)
450 throws NoSuchCategoryException, SystemException {
451 int count = countByUuid(uuid);
452
453 List<MBCategory> list = findByUuid(uuid, count - 1, count, obc);
454
455 if (list.size() == 0) {
456 StringBuilder msg = new StringBuilder();
457
458 msg.append("No MBCategory exists with the key {");
459
460 msg.append("uuid=" + uuid);
461
462 msg.append(StringPool.CLOSE_CURLY_BRACE);
463
464 throw new NoSuchCategoryException(msg.toString());
465 }
466 else {
467 return list.get(0);
468 }
469 }
470
471 public MBCategory[] findByUuid_PrevAndNext(long categoryId, String uuid,
472 OrderByComparator obc) throws NoSuchCategoryException, SystemException {
473 MBCategory mbCategory = findByPrimaryKey(categoryId);
474
475 int count = countByUuid(uuid);
476
477 Session session = null;
478
479 try {
480 session = openSession();
481
482 StringBuilder query = new StringBuilder();
483
484 query.append(
485 "FROM com.liferay.portlet.messageboards.model.MBCategory WHERE ");
486
487 if (uuid == null) {
488 query.append("uuid_ IS NULL");
489 }
490 else {
491 query.append("uuid_ = ?");
492 }
493
494 query.append(" ");
495
496 if (obc != null) {
497 query.append("ORDER BY ");
498 query.append(obc.getOrderBy());
499 }
500
501 else {
502 query.append("ORDER BY ");
503
504 query.append("parentCategoryId ASC, ");
505 query.append("name ASC");
506 }
507
508 Query q = session.createQuery(query.toString());
509
510 QueryPos qPos = QueryPos.getInstance(q);
511
512 if (uuid != null) {
513 qPos.add(uuid);
514 }
515
516 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
517 mbCategory);
518
519 MBCategory[] array = new MBCategoryImpl[3];
520
521 array[0] = (MBCategory)objArray[0];
522 array[1] = (MBCategory)objArray[1];
523 array[2] = (MBCategory)objArray[2];
524
525 return array;
526 }
527 catch (Exception e) {
528 throw processException(e);
529 }
530 finally {
531 closeSession(session);
532 }
533 }
534
535 public MBCategory findByUUID_G(String uuid, long groupId)
536 throws NoSuchCategoryException, SystemException {
537 MBCategory mbCategory = fetchByUUID_G(uuid, groupId);
538
539 if (mbCategory == null) {
540 StringBuilder msg = new StringBuilder();
541
542 msg.append("No MBCategory exists with the key {");
543
544 msg.append("uuid=" + uuid);
545
546 msg.append(", ");
547 msg.append("groupId=" + groupId);
548
549 msg.append(StringPool.CLOSE_CURLY_BRACE);
550
551 if (_log.isWarnEnabled()) {
552 _log.warn(msg.toString());
553 }
554
555 throw new NoSuchCategoryException(msg.toString());
556 }
557
558 return mbCategory;
559 }
560
561 public MBCategory fetchByUUID_G(String uuid, long groupId)
562 throws SystemException {
563 boolean finderClassNameCacheEnabled = MBCategoryModelImpl.CACHE_ENABLED;
564 String finderClassName = MBCategory.class.getName();
565 String finderMethodName = "fetchByUUID_G";
566 String[] finderParams = new String[] {
567 String.class.getName(), Long.class.getName()
568 };
569 Object[] finderArgs = new Object[] { uuid, new Long(groupId) };
570
571 Object result = null;
572
573 if (finderClassNameCacheEnabled) {
574 result = FinderCacheUtil.getResult(finderClassName,
575 finderMethodName, finderParams, finderArgs, this);
576 }
577
578 if (result == null) {
579 Session session = null;
580
581 try {
582 session = openSession();
583
584 StringBuilder query = new StringBuilder();
585
586 query.append(
587 "FROM com.liferay.portlet.messageboards.model.MBCategory WHERE ");
588
589 if (uuid == null) {
590 query.append("uuid_ IS NULL");
591 }
592 else {
593 query.append("uuid_ = ?");
594 }
595
596 query.append(" AND ");
597
598 query.append("groupId = ?");
599
600 query.append(" ");
601
602 query.append("ORDER BY ");
603
604 query.append("parentCategoryId ASC, ");
605 query.append("name ASC");
606
607 Query q = session.createQuery(query.toString());
608
609 QueryPos qPos = QueryPos.getInstance(q);
610
611 if (uuid != null) {
612 qPos.add(uuid);
613 }
614
615 qPos.add(groupId);
616
617 List<MBCategory> list = q.list();
618
619 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
620 finderClassName, finderMethodName, finderParams,
621 finderArgs, list);
622
623 if (list.size() == 0) {
624 return null;
625 }
626 else {
627 return list.get(0);
628 }
629 }
630 catch (Exception e) {
631 throw processException(e);
632 }
633 finally {
634 closeSession(session);
635 }
636 }
637 else {
638 List<MBCategory> list = (List<MBCategory>)result;
639
640 if (list.size() == 0) {
641 return null;
642 }
643 else {
644 return list.get(0);
645 }
646 }
647 }
648
649 public List<MBCategory> findByGroupId(long groupId)
650 throws SystemException {
651 boolean finderClassNameCacheEnabled = MBCategoryModelImpl.CACHE_ENABLED;
652 String finderClassName = MBCategory.class.getName();
653 String finderMethodName = "findByGroupId";
654 String[] finderParams = new String[] { Long.class.getName() };
655 Object[] finderArgs = new Object[] { new Long(groupId) };
656
657 Object result = null;
658
659 if (finderClassNameCacheEnabled) {
660 result = FinderCacheUtil.getResult(finderClassName,
661 finderMethodName, finderParams, finderArgs, this);
662 }
663
664 if (result == null) {
665 Session session = null;
666
667 try {
668 session = openSession();
669
670 StringBuilder query = new StringBuilder();
671
672 query.append(
673 "FROM com.liferay.portlet.messageboards.model.MBCategory WHERE ");
674
675 query.append("groupId = ?");
676
677 query.append(" ");
678
679 query.append("ORDER BY ");
680
681 query.append("parentCategoryId ASC, ");
682 query.append("name ASC");
683
684 Query q = session.createQuery(query.toString());
685
686 QueryPos qPos = QueryPos.getInstance(q);
687
688 qPos.add(groupId);
689
690 List<MBCategory> list = q.list();
691
692 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
693 finderClassName, finderMethodName, finderParams,
694 finderArgs, list);
695
696 return list;
697 }
698 catch (Exception e) {
699 throw processException(e);
700 }
701 finally {
702 closeSession(session);
703 }
704 }
705 else {
706 return (List<MBCategory>)result;
707 }
708 }
709
710 public List<MBCategory> findByGroupId(long groupId, int start, int end)
711 throws SystemException {
712 return findByGroupId(groupId, start, end, null);
713 }
714
715 public List<MBCategory> findByGroupId(long groupId, int start, int end,
716 OrderByComparator obc) throws SystemException {
717 boolean finderClassNameCacheEnabled = MBCategoryModelImpl.CACHE_ENABLED;
718 String finderClassName = MBCategory.class.getName();
719 String finderMethodName = "findByGroupId";
720 String[] finderParams = new String[] {
721 Long.class.getName(),
722
723 "java.lang.Integer", "java.lang.Integer",
724 "com.liferay.portal.kernel.util.OrderByComparator"
725 };
726 Object[] finderArgs = new Object[] {
727 new Long(groupId),
728
729 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
730 };
731
732 Object result = null;
733
734 if (finderClassNameCacheEnabled) {
735 result = FinderCacheUtil.getResult(finderClassName,
736 finderMethodName, finderParams, finderArgs, this);
737 }
738
739 if (result == null) {
740 Session session = null;
741
742 try {
743 session = openSession();
744
745 StringBuilder query = new StringBuilder();
746
747 query.append(
748 "FROM com.liferay.portlet.messageboards.model.MBCategory WHERE ");
749
750 query.append("groupId = ?");
751
752 query.append(" ");
753
754 if (obc != null) {
755 query.append("ORDER BY ");
756 query.append(obc.getOrderBy());
757 }
758
759 else {
760 query.append("ORDER BY ");
761
762 query.append("parentCategoryId ASC, ");
763 query.append("name ASC");
764 }
765
766 Query q = session.createQuery(query.toString());
767
768 QueryPos qPos = QueryPos.getInstance(q);
769
770 qPos.add(groupId);
771
772 List<MBCategory> list = (List<MBCategory>)QueryUtil.list(q,
773 getDialect(), start, end);
774
775 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
776 finderClassName, finderMethodName, finderParams,
777 finderArgs, list);
778
779 return list;
780 }
781 catch (Exception e) {
782 throw processException(e);
783 }
784 finally {
785 closeSession(session);
786 }
787 }
788 else {
789 return (List<MBCategory>)result;
790 }
791 }
792
793 public MBCategory findByGroupId_First(long groupId, OrderByComparator obc)
794 throws NoSuchCategoryException, SystemException {
795 List<MBCategory> list = findByGroupId(groupId, 0, 1, obc);
796
797 if (list.size() == 0) {
798 StringBuilder msg = new StringBuilder();
799
800 msg.append("No MBCategory exists with the key {");
801
802 msg.append("groupId=" + groupId);
803
804 msg.append(StringPool.CLOSE_CURLY_BRACE);
805
806 throw new NoSuchCategoryException(msg.toString());
807 }
808 else {
809 return list.get(0);
810 }
811 }
812
813 public MBCategory findByGroupId_Last(long groupId, OrderByComparator obc)
814 throws NoSuchCategoryException, SystemException {
815 int count = countByGroupId(groupId);
816
817 List<MBCategory> list = findByGroupId(groupId, count - 1, count, obc);
818
819 if (list.size() == 0) {
820 StringBuilder msg = new StringBuilder();
821
822 msg.append("No MBCategory exists with the key {");
823
824 msg.append("groupId=" + groupId);
825
826 msg.append(StringPool.CLOSE_CURLY_BRACE);
827
828 throw new NoSuchCategoryException(msg.toString());
829 }
830 else {
831 return list.get(0);
832 }
833 }
834
835 public MBCategory[] findByGroupId_PrevAndNext(long categoryId,
836 long groupId, OrderByComparator obc)
837 throws NoSuchCategoryException, SystemException {
838 MBCategory mbCategory = findByPrimaryKey(categoryId);
839
840 int count = countByGroupId(groupId);
841
842 Session session = null;
843
844 try {
845 session = openSession();
846
847 StringBuilder query = new StringBuilder();
848
849 query.append(
850 "FROM com.liferay.portlet.messageboards.model.MBCategory WHERE ");
851
852 query.append("groupId = ?");
853
854 query.append(" ");
855
856 if (obc != null) {
857 query.append("ORDER BY ");
858 query.append(obc.getOrderBy());
859 }
860
861 else {
862 query.append("ORDER BY ");
863
864 query.append("parentCategoryId ASC, ");
865 query.append("name ASC");
866 }
867
868 Query q = session.createQuery(query.toString());
869
870 QueryPos qPos = QueryPos.getInstance(q);
871
872 qPos.add(groupId);
873
874 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
875 mbCategory);
876
877 MBCategory[] array = new MBCategoryImpl[3];
878
879 array[0] = (MBCategory)objArray[0];
880 array[1] = (MBCategory)objArray[1];
881 array[2] = (MBCategory)objArray[2];
882
883 return array;
884 }
885 catch (Exception e) {
886 throw processException(e);
887 }
888 finally {
889 closeSession(session);
890 }
891 }
892
893 public List<MBCategory> findByCompanyId(long companyId)
894 throws SystemException {
895 boolean finderClassNameCacheEnabled = MBCategoryModelImpl.CACHE_ENABLED;
896 String finderClassName = MBCategory.class.getName();
897 String finderMethodName = "findByCompanyId";
898 String[] finderParams = new String[] { Long.class.getName() };
899 Object[] finderArgs = new Object[] { new Long(companyId) };
900
901 Object result = null;
902
903 if (finderClassNameCacheEnabled) {
904 result = FinderCacheUtil.getResult(finderClassName,
905 finderMethodName, finderParams, finderArgs, this);
906 }
907
908 if (result == null) {
909 Session session = null;
910
911 try {
912 session = openSession();
913
914 StringBuilder query = new StringBuilder();
915
916 query.append(
917 "FROM com.liferay.portlet.messageboards.model.MBCategory WHERE ");
918
919 query.append("companyId = ?");
920
921 query.append(" ");
922
923 query.append("ORDER BY ");
924
925 query.append("parentCategoryId ASC, ");
926 query.append("name ASC");
927
928 Query q = session.createQuery(query.toString());
929
930 QueryPos qPos = QueryPos.getInstance(q);
931
932 qPos.add(companyId);
933
934 List<MBCategory> list = q.list();
935
936 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
937 finderClassName, finderMethodName, finderParams,
938 finderArgs, list);
939
940 return list;
941 }
942 catch (Exception e) {
943 throw processException(e);
944 }
945 finally {
946 closeSession(session);
947 }
948 }
949 else {
950 return (List<MBCategory>)result;
951 }
952 }
953
954 public List<MBCategory> findByCompanyId(long companyId, int start, int end)
955 throws SystemException {
956 return findByCompanyId(companyId, start, end, null);
957 }
958
959 public List<MBCategory> findByCompanyId(long companyId, int start, int end,
960 OrderByComparator obc) throws SystemException {
961 boolean finderClassNameCacheEnabled = MBCategoryModelImpl.CACHE_ENABLED;
962 String finderClassName = MBCategory.class.getName();
963 String finderMethodName = "findByCompanyId";
964 String[] finderParams = new String[] {
965 Long.class.getName(),
966
967 "java.lang.Integer", "java.lang.Integer",
968 "com.liferay.portal.kernel.util.OrderByComparator"
969 };
970 Object[] finderArgs = new Object[] {
971 new Long(companyId),
972
973 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
974 };
975
976 Object result = null;
977
978 if (finderClassNameCacheEnabled) {
979 result = FinderCacheUtil.getResult(finderClassName,
980 finderMethodName, finderParams, finderArgs, this);
981 }
982
983 if (result == null) {
984 Session session = null;
985
986 try {
987 session = openSession();
988
989 StringBuilder query = new StringBuilder();
990
991 query.append(
992 "FROM com.liferay.portlet.messageboards.model.MBCategory WHERE ");
993
994 query.append("companyId = ?");
995
996 query.append(" ");
997
998 if (obc != null) {
999 query.append("ORDER BY ");
1000 query.append(obc.getOrderBy());
1001 }
1002
1003 else {
1004 query.append("ORDER BY ");
1005
1006 query.append("parentCategoryId ASC, ");
1007 query.append("name ASC");
1008 }
1009
1010 Query q = session.createQuery(query.toString());
1011
1012 QueryPos qPos = QueryPos.getInstance(q);
1013
1014 qPos.add(companyId);
1015
1016 List<MBCategory> list = (List<MBCategory>)QueryUtil.list(q,
1017 getDialect(), start, end);
1018
1019 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1020 finderClassName, finderMethodName, finderParams,
1021 finderArgs, list);
1022
1023 return list;
1024 }
1025 catch (Exception e) {
1026 throw processException(e);
1027 }
1028 finally {
1029 closeSession(session);
1030 }
1031 }
1032 else {
1033 return (List<MBCategory>)result;
1034 }
1035 }
1036
1037 public MBCategory findByCompanyId_First(long companyId,
1038 OrderByComparator obc) throws NoSuchCategoryException, SystemException {
1039 List<MBCategory> list = findByCompanyId(companyId, 0, 1, obc);
1040
1041 if (list.size() == 0) {
1042 StringBuilder msg = new StringBuilder();
1043
1044 msg.append("No MBCategory exists with the key {");
1045
1046 msg.append("companyId=" + companyId);
1047
1048 msg.append(StringPool.CLOSE_CURLY_BRACE);
1049
1050 throw new NoSuchCategoryException(msg.toString());
1051 }
1052 else {
1053 return list.get(0);
1054 }
1055 }
1056
1057 public MBCategory findByCompanyId_Last(long companyId, OrderByComparator obc)
1058 throws NoSuchCategoryException, SystemException {
1059 int count = countByCompanyId(companyId);
1060
1061 List<MBCategory> list = findByCompanyId(companyId, count - 1, count, obc);
1062
1063 if (list.size() == 0) {
1064 StringBuilder msg = new StringBuilder();
1065
1066 msg.append("No MBCategory exists with the key {");
1067
1068 msg.append("companyId=" + companyId);
1069
1070 msg.append(StringPool.CLOSE_CURLY_BRACE);
1071
1072 throw new NoSuchCategoryException(msg.toString());
1073 }
1074 else {
1075 return list.get(0);
1076 }
1077 }
1078
1079 public MBCategory[] findByCompanyId_PrevAndNext(long categoryId,
1080 long companyId, OrderByComparator obc)
1081 throws NoSuchCategoryException, SystemException {
1082 MBCategory mbCategory = findByPrimaryKey(categoryId);
1083
1084 int count = countByCompanyId(companyId);
1085
1086 Session session = null;
1087
1088 try {
1089 session = openSession();
1090
1091 StringBuilder query = new StringBuilder();
1092
1093 query.append(
1094 "FROM com.liferay.portlet.messageboards.model.MBCategory WHERE ");
1095
1096 query.append("companyId = ?");
1097
1098 query.append(" ");
1099
1100 if (obc != null) {
1101 query.append("ORDER BY ");
1102 query.append(obc.getOrderBy());
1103 }
1104
1105 else {
1106 query.append("ORDER BY ");
1107
1108 query.append("parentCategoryId ASC, ");
1109 query.append("name ASC");
1110 }
1111
1112 Query q = session.createQuery(query.toString());
1113
1114 QueryPos qPos = QueryPos.getInstance(q);
1115
1116 qPos.add(companyId);
1117
1118 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1119 mbCategory);
1120
1121 MBCategory[] array = new MBCategoryImpl[3];
1122
1123 array[0] = (MBCategory)objArray[0];
1124 array[1] = (MBCategory)objArray[1];
1125 array[2] = (MBCategory)objArray[2];
1126
1127 return array;
1128 }
1129 catch (Exception e) {
1130 throw processException(e);
1131 }
1132 finally {
1133 closeSession(session);
1134 }
1135 }
1136
1137 public List<MBCategory> findByG_P(long groupId, long parentCategoryId)
1138 throws SystemException {
1139 boolean finderClassNameCacheEnabled = MBCategoryModelImpl.CACHE_ENABLED;
1140 String finderClassName = MBCategory.class.getName();
1141 String finderMethodName = "findByG_P";
1142 String[] finderParams = new String[] {
1143 Long.class.getName(), Long.class.getName()
1144 };
1145 Object[] finderArgs = new Object[] {
1146 new Long(groupId), new Long(parentCategoryId)
1147 };
1148
1149 Object result = null;
1150
1151 if (finderClassNameCacheEnabled) {
1152 result = FinderCacheUtil.getResult(finderClassName,
1153 finderMethodName, finderParams, finderArgs, this);
1154 }
1155
1156 if (result == null) {
1157 Session session = null;
1158
1159 try {
1160 session = openSession();
1161
1162 StringBuilder query = new StringBuilder();
1163
1164 query.append(
1165 "FROM com.liferay.portlet.messageboards.model.MBCategory WHERE ");
1166
1167 query.append("groupId = ?");
1168
1169 query.append(" AND ");
1170
1171 query.append("parentCategoryId = ?");
1172
1173 query.append(" ");
1174
1175 query.append("ORDER BY ");
1176
1177 query.append("parentCategoryId ASC, ");
1178 query.append("name ASC");
1179
1180 Query q = session.createQuery(query.toString());
1181
1182 QueryPos qPos = QueryPos.getInstance(q);
1183
1184 qPos.add(groupId);
1185
1186 qPos.add(parentCategoryId);
1187
1188 List<MBCategory> list = q.list();
1189
1190 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1191 finderClassName, finderMethodName, finderParams,
1192 finderArgs, list);
1193
1194 return list;
1195 }
1196 catch (Exception e) {
1197 throw processException(e);
1198 }
1199 finally {
1200 closeSession(session);
1201 }
1202 }
1203 else {
1204 return (List<MBCategory>)result;
1205 }
1206 }
1207
1208 public List<MBCategory> findByG_P(long groupId, long parentCategoryId,
1209 int start, int end) throws SystemException {
1210 return findByG_P(groupId, parentCategoryId, start, end, null);
1211 }
1212
1213 public List<MBCategory> findByG_P(long groupId, long parentCategoryId,
1214 int start, int end, OrderByComparator obc) throws SystemException {
1215 boolean finderClassNameCacheEnabled = MBCategoryModelImpl.CACHE_ENABLED;
1216 String finderClassName = MBCategory.class.getName();
1217 String finderMethodName = "findByG_P";
1218 String[] finderParams = new String[] {
1219 Long.class.getName(), Long.class.getName(),
1220
1221 "java.lang.Integer", "java.lang.Integer",
1222 "com.liferay.portal.kernel.util.OrderByComparator"
1223 };
1224 Object[] finderArgs = new Object[] {
1225 new Long(groupId), new Long(parentCategoryId),
1226
1227 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1228 };
1229
1230 Object result = null;
1231
1232 if (finderClassNameCacheEnabled) {
1233 result = FinderCacheUtil.getResult(finderClassName,
1234 finderMethodName, finderParams, finderArgs, this);
1235 }
1236
1237 if (result == null) {
1238 Session session = null;
1239
1240 try {
1241 session = openSession();
1242
1243 StringBuilder query = new StringBuilder();
1244
1245 query.append(
1246 "FROM com.liferay.portlet.messageboards.model.MBCategory WHERE ");
1247
1248 query.append("groupId = ?");
1249
1250 query.append(" AND ");
1251
1252 query.append("parentCategoryId = ?");
1253
1254 query.append(" ");
1255
1256 if (obc != null) {
1257 query.append("ORDER BY ");
1258 query.append(obc.getOrderBy());
1259 }
1260
1261 else {
1262 query.append("ORDER BY ");
1263
1264 query.append("parentCategoryId ASC, ");
1265 query.append("name ASC");
1266 }
1267
1268 Query q = session.createQuery(query.toString());
1269
1270 QueryPos qPos = QueryPos.getInstance(q);
1271
1272 qPos.add(groupId);
1273
1274 qPos.add(parentCategoryId);
1275
1276 List<MBCategory> list = (List<MBCategory>)QueryUtil.list(q,
1277 getDialect(), start, end);
1278
1279 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1280 finderClassName, finderMethodName, finderParams,
1281 finderArgs, list);
1282
1283 return list;
1284 }
1285 catch (Exception e) {
1286 throw processException(e);
1287 }
1288 finally {
1289 closeSession(session);
1290 }
1291 }
1292 else {
1293 return (List<MBCategory>)result;
1294 }
1295 }
1296
1297 public MBCategory findByG_P_First(long groupId, long parentCategoryId,
1298 OrderByComparator obc) throws NoSuchCategoryException, SystemException {
1299 List<MBCategory> list = findByG_P(groupId, parentCategoryId, 0, 1, obc);
1300
1301 if (list.size() == 0) {
1302 StringBuilder msg = new StringBuilder();
1303
1304 msg.append("No MBCategory exists with the key {");
1305
1306 msg.append("groupId=" + groupId);
1307
1308 msg.append(", ");
1309 msg.append("parentCategoryId=" + parentCategoryId);
1310
1311 msg.append(StringPool.CLOSE_CURLY_BRACE);
1312
1313 throw new NoSuchCategoryException(msg.toString());
1314 }
1315 else {
1316 return list.get(0);
1317 }
1318 }
1319
1320 public MBCategory findByG_P_Last(long groupId, long parentCategoryId,
1321 OrderByComparator obc) throws NoSuchCategoryException, SystemException {
1322 int count = countByG_P(groupId, parentCategoryId);
1323
1324 List<MBCategory> list = findByG_P(groupId, parentCategoryId, count - 1,
1325 count, obc);
1326
1327 if (list.size() == 0) {
1328 StringBuilder msg = new StringBuilder();
1329
1330 msg.append("No MBCategory exists with the key {");
1331
1332 msg.append("groupId=" + groupId);
1333
1334 msg.append(", ");
1335 msg.append("parentCategoryId=" + parentCategoryId);
1336
1337 msg.append(StringPool.CLOSE_CURLY_BRACE);
1338
1339 throw new NoSuchCategoryException(msg.toString());
1340 }
1341 else {
1342 return list.get(0);
1343 }
1344 }
1345
1346 public MBCategory[] findByG_P_PrevAndNext(long categoryId, long groupId,
1347 long parentCategoryId, OrderByComparator obc)
1348 throws NoSuchCategoryException, SystemException {
1349 MBCategory mbCategory = findByPrimaryKey(categoryId);
1350
1351 int count = countByG_P(groupId, parentCategoryId);
1352
1353 Session session = null;
1354
1355 try {
1356 session = openSession();
1357
1358 StringBuilder query = new StringBuilder();
1359
1360 query.append(
1361 "FROM com.liferay.portlet.messageboards.model.MBCategory WHERE ");
1362
1363 query.append("groupId = ?");
1364
1365 query.append(" AND ");
1366
1367 query.append("parentCategoryId = ?");
1368
1369 query.append(" ");
1370
1371 if (obc != null) {
1372 query.append("ORDER BY ");
1373 query.append(obc.getOrderBy());
1374 }
1375
1376 else {
1377 query.append("ORDER BY ");
1378
1379 query.append("parentCategoryId ASC, ");
1380 query.append("name ASC");
1381 }
1382
1383 Query q = session.createQuery(query.toString());
1384
1385 QueryPos qPos = QueryPos.getInstance(q);
1386
1387 qPos.add(groupId);
1388
1389 qPos.add(parentCategoryId);
1390
1391 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1392 mbCategory);
1393
1394 MBCategory[] array = new MBCategoryImpl[3];
1395
1396 array[0] = (MBCategory)objArray[0];
1397 array[1] = (MBCategory)objArray[1];
1398 array[2] = (MBCategory)objArray[2];
1399
1400 return array;
1401 }
1402 catch (Exception e) {
1403 throw processException(e);
1404 }
1405 finally {
1406 closeSession(session);
1407 }
1408 }
1409
1410 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
1411 throws SystemException {
1412 Session session = null;
1413
1414 try {
1415 session = openSession();
1416
1417 dynamicQuery.compile(session);
1418
1419 return dynamicQuery.list();
1420 }
1421 catch (Exception e) {
1422 throw processException(e);
1423 }
1424 finally {
1425 closeSession(session);
1426 }
1427 }
1428
1429 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
1430 int start, int end) throws SystemException {
1431 Session session = null;
1432
1433 try {
1434 session = openSession();
1435
1436 dynamicQuery.setLimit(start, end);
1437
1438 dynamicQuery.compile(session);
1439
1440 return dynamicQuery.list();
1441 }
1442 catch (Exception e) {
1443 throw processException(e);
1444 }
1445 finally {
1446 closeSession(session);
1447 }
1448 }
1449
1450 public List<MBCategory> findAll() throws SystemException {
1451 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1452 }
1453
1454 public List<MBCategory> findAll(int start, int end)
1455 throws SystemException {
1456 return findAll(start, end, null);
1457 }
1458
1459 public List<MBCategory> findAll(int start, int end, OrderByComparator obc)
1460 throws SystemException {
1461 boolean finderClassNameCacheEnabled = MBCategoryModelImpl.CACHE_ENABLED;
1462 String finderClassName = MBCategory.class.getName();
1463 String finderMethodName = "findAll";
1464 String[] finderParams = new String[] {
1465 "java.lang.Integer", "java.lang.Integer",
1466 "com.liferay.portal.kernel.util.OrderByComparator"
1467 };
1468 Object[] finderArgs = new Object[] {
1469 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1470 };
1471
1472 Object result = null;
1473
1474 if (finderClassNameCacheEnabled) {
1475 result = FinderCacheUtil.getResult(finderClassName,
1476 finderMethodName, finderParams, finderArgs, this);
1477 }
1478
1479 if (result == null) {
1480 Session session = null;
1481
1482 try {
1483 session = openSession();
1484
1485 StringBuilder query = new StringBuilder();
1486
1487 query.append(
1488 "FROM com.liferay.portlet.messageboards.model.MBCategory ");
1489
1490 if (obc != null) {
1491 query.append("ORDER BY ");
1492 query.append(obc.getOrderBy());
1493 }
1494
1495 else {
1496 query.append("ORDER BY ");
1497
1498 query.append("parentCategoryId ASC, ");
1499 query.append("name ASC");
1500 }
1501
1502 Query q = session.createQuery(query.toString());
1503
1504 List<MBCategory> list = null;
1505
1506 if (obc == null) {
1507 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
1508 start, end, false);
1509
1510 Collections.sort(list);
1511 }
1512 else {
1513 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
1514 start, end);
1515 }
1516
1517 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1518 finderClassName, finderMethodName, finderParams,
1519 finderArgs, list);
1520
1521 return list;
1522 }
1523 catch (Exception e) {
1524 throw processException(e);
1525 }
1526 finally {
1527 closeSession(session);
1528 }
1529 }
1530 else {
1531 return (List<MBCategory>)result;
1532 }
1533 }
1534
1535 public void removeByUuid(String uuid) throws SystemException {
1536 for (MBCategory mbCategory : findByUuid(uuid)) {
1537 remove(mbCategory);
1538 }
1539 }
1540
1541 public void removeByUUID_G(String uuid, long groupId)
1542 throws NoSuchCategoryException, SystemException {
1543 MBCategory mbCategory = findByUUID_G(uuid, groupId);
1544
1545 remove(mbCategory);
1546 }
1547
1548 public void removeByGroupId(long groupId) throws SystemException {
1549 for (MBCategory mbCategory : findByGroupId(groupId)) {
1550 remove(mbCategory);
1551 }
1552 }
1553
1554 public void removeByCompanyId(long companyId) throws SystemException {
1555 for (MBCategory mbCategory : findByCompanyId(companyId)) {
1556 remove(mbCategory);
1557 }
1558 }
1559
1560 public void removeByG_P(long groupId, long parentCategoryId)
1561 throws SystemException {
1562 for (MBCategory mbCategory : findByG_P(groupId, parentCategoryId)) {
1563 remove(mbCategory);
1564 }
1565 }
1566
1567 public void removeAll() throws SystemException {
1568 for (MBCategory mbCategory : findAll()) {
1569 remove(mbCategory);
1570 }
1571 }
1572
1573 public int countByUuid(String uuid) throws SystemException {
1574 boolean finderClassNameCacheEnabled = MBCategoryModelImpl.CACHE_ENABLED;
1575 String finderClassName = MBCategory.class.getName();
1576 String finderMethodName = "countByUuid";
1577 String[] finderParams = new String[] { String.class.getName() };
1578 Object[] finderArgs = new Object[] { uuid };
1579
1580 Object result = null;
1581
1582 if (finderClassNameCacheEnabled) {
1583 result = FinderCacheUtil.getResult(finderClassName,
1584 finderMethodName, finderParams, finderArgs, this);
1585 }
1586
1587 if (result == null) {
1588 Session session = null;
1589
1590 try {
1591 session = openSession();
1592
1593 StringBuilder query = new StringBuilder();
1594
1595 query.append("SELECT COUNT(*) ");
1596 query.append(
1597 "FROM com.liferay.portlet.messageboards.model.MBCategory WHERE ");
1598
1599 if (uuid == null) {
1600 query.append("uuid_ IS NULL");
1601 }
1602 else {
1603 query.append("uuid_ = ?");
1604 }
1605
1606 query.append(" ");
1607
1608 Query q = session.createQuery(query.toString());
1609
1610 QueryPos qPos = QueryPos.getInstance(q);
1611
1612 if (uuid != null) {
1613 qPos.add(uuid);
1614 }
1615
1616 Long count = null;
1617
1618 Iterator<Long> itr = q.list().iterator();
1619
1620 if (itr.hasNext()) {
1621 count = itr.next();
1622 }
1623
1624 if (count == null) {
1625 count = new Long(0);
1626 }
1627
1628 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1629 finderClassName, finderMethodName, finderParams,
1630 finderArgs, count);
1631
1632 return count.intValue();
1633 }
1634 catch (Exception e) {
1635 throw processException(e);
1636 }
1637 finally {
1638 closeSession(session);
1639 }
1640 }
1641 else {
1642 return ((Long)result).intValue();
1643 }
1644 }
1645
1646 public int countByUUID_G(String uuid, long groupId)
1647 throws SystemException {
1648 boolean finderClassNameCacheEnabled = MBCategoryModelImpl.CACHE_ENABLED;
1649 String finderClassName = MBCategory.class.getName();
1650 String finderMethodName = "countByUUID_G";
1651 String[] finderParams = new String[] {
1652 String.class.getName(), Long.class.getName()
1653 };
1654 Object[] finderArgs = new Object[] { uuid, new Long(groupId) };
1655
1656 Object result = null;
1657
1658 if (finderClassNameCacheEnabled) {
1659 result = FinderCacheUtil.getResult(finderClassName,
1660 finderMethodName, finderParams, finderArgs, this);
1661 }
1662
1663 if (result == null) {
1664 Session session = null;
1665
1666 try {
1667 session = openSession();
1668
1669 StringBuilder query = new StringBuilder();
1670
1671 query.append("SELECT COUNT(*) ");
1672 query.append(
1673 "FROM com.liferay.portlet.messageboards.model.MBCategory WHERE ");
1674
1675 if (uuid == null) {
1676 query.append("uuid_ IS NULL");
1677 }
1678 else {
1679 query.append("uuid_ = ?");
1680 }
1681
1682 query.append(" AND ");
1683
1684 query.append("groupId = ?");
1685
1686 query.append(" ");
1687
1688 Query q = session.createQuery(query.toString());
1689
1690 QueryPos qPos = QueryPos.getInstance(q);
1691
1692 if (uuid != null) {
1693 qPos.add(uuid);
1694 }
1695
1696 qPos.add(groupId);
1697
1698 Long count = null;
1699
1700 Iterator<Long> itr = q.list().iterator();
1701
1702 if (itr.hasNext()) {
1703 count = itr.next();
1704 }
1705
1706 if (count == null) {
1707 count = new Long(0);
1708 }
1709
1710 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1711 finderClassName, finderMethodName, finderParams,
1712 finderArgs, count);
1713
1714 return count.intValue();
1715 }
1716 catch (Exception e) {
1717 throw processException(e);
1718 }
1719 finally {
1720 closeSession(session);
1721 }
1722 }
1723 else {
1724 return ((Long)result).intValue();
1725 }
1726 }
1727
1728 public int countByGroupId(long groupId) throws SystemException {
1729 boolean finderClassNameCacheEnabled = MBCategoryModelImpl.CACHE_ENABLED;
1730 String finderClassName = MBCategory.class.getName();
1731 String finderMethodName = "countByGroupId";
1732 String[] finderParams = new String[] { Long.class.getName() };
1733 Object[] finderArgs = new Object[] { new Long(groupId) };
1734
1735 Object result = null;
1736
1737 if (finderClassNameCacheEnabled) {
1738 result = FinderCacheUtil.getResult(finderClassName,
1739 finderMethodName, finderParams, finderArgs, this);
1740 }
1741
1742 if (result == null) {
1743 Session session = null;
1744
1745 try {
1746 session = openSession();
1747
1748 StringBuilder query = new StringBuilder();
1749
1750 query.append("SELECT COUNT(*) ");
1751 query.append(
1752 "FROM com.liferay.portlet.messageboards.model.MBCategory WHERE ");
1753
1754 query.append("groupId = ?");
1755
1756 query.append(" ");
1757
1758 Query q = session.createQuery(query.toString());
1759
1760 QueryPos qPos = QueryPos.getInstance(q);
1761
1762 qPos.add(groupId);
1763
1764 Long count = null;
1765
1766 Iterator<Long> itr = q.list().iterator();
1767
1768 if (itr.hasNext()) {
1769 count = itr.next();
1770 }
1771
1772 if (count == null) {
1773 count = new Long(0);
1774 }
1775
1776 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1777 finderClassName, finderMethodName, finderParams,
1778 finderArgs, count);
1779
1780 return count.intValue();
1781 }
1782 catch (Exception e) {
1783 throw processException(e);
1784 }
1785 finally {
1786 closeSession(session);
1787 }
1788 }
1789 else {
1790 return ((Long)result).intValue();
1791 }
1792 }
1793
1794 public int countByCompanyId(long companyId) throws SystemException {
1795 boolean finderClassNameCacheEnabled = MBCategoryModelImpl.CACHE_ENABLED;
1796 String finderClassName = MBCategory.class.getName();
1797 String finderMethodName = "countByCompanyId";
1798 String[] finderParams = new String[] { Long.class.getName() };
1799 Object[] finderArgs = new Object[] { new Long(companyId) };
1800
1801 Object result = null;
1802
1803 if (finderClassNameCacheEnabled) {
1804 result = FinderCacheUtil.getResult(finderClassName,
1805 finderMethodName, finderParams, finderArgs, this);
1806 }
1807
1808 if (result == null) {
1809 Session session = null;
1810
1811 try {
1812 session = openSession();
1813
1814 StringBuilder query = new StringBuilder();
1815
1816 query.append("SELECT COUNT(*) ");
1817 query.append(
1818 "FROM com.liferay.portlet.messageboards.model.MBCategory WHERE ");
1819
1820 query.append("companyId = ?");
1821
1822 query.append(" ");
1823
1824 Query q = session.createQuery(query.toString());
1825
1826 QueryPos qPos = QueryPos.getInstance(q);
1827
1828 qPos.add(companyId);
1829
1830 Long count = null;
1831
1832 Iterator<Long> itr = q.list().iterator();
1833
1834 if (itr.hasNext()) {
1835 count = itr.next();
1836 }
1837
1838 if (count == null) {
1839 count = new Long(0);
1840 }
1841
1842 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1843 finderClassName, finderMethodName, finderParams,
1844 finderArgs, count);
1845
1846 return count.intValue();
1847 }
1848 catch (Exception e) {
1849 throw processException(e);
1850 }
1851 finally {
1852 closeSession(session);
1853 }
1854 }
1855 else {
1856 return ((Long)result).intValue();
1857 }
1858 }
1859
1860 public int countByG_P(long groupId, long parentCategoryId)
1861 throws SystemException {
1862 boolean finderClassNameCacheEnabled = MBCategoryModelImpl.CACHE_ENABLED;
1863 String finderClassName = MBCategory.class.getName();
1864 String finderMethodName = "countByG_P";
1865 String[] finderParams = new String[] {
1866 Long.class.getName(), Long.class.getName()
1867 };
1868 Object[] finderArgs = new Object[] {
1869 new Long(groupId), new Long(parentCategoryId)
1870 };
1871
1872 Object result = null;
1873
1874 if (finderClassNameCacheEnabled) {
1875 result = FinderCacheUtil.getResult(finderClassName,
1876 finderMethodName, finderParams, finderArgs, this);
1877 }
1878
1879 if (result == null) {
1880 Session session = null;
1881
1882 try {
1883 session = openSession();
1884
1885 StringBuilder query = new StringBuilder();
1886
1887 query.append("SELECT COUNT(*) ");
1888 query.append(
1889 "FROM com.liferay.portlet.messageboards.model.MBCategory WHERE ");
1890
1891 query.append("groupId = ?");
1892
1893 query.append(" AND ");
1894
1895 query.append("parentCategoryId = ?");
1896
1897 query.append(" ");
1898
1899 Query q = session.createQuery(query.toString());
1900
1901 QueryPos qPos = QueryPos.getInstance(q);
1902
1903 qPos.add(groupId);
1904
1905 qPos.add(parentCategoryId);
1906
1907 Long count = null;
1908
1909 Iterator<Long> itr = q.list().iterator();
1910
1911 if (itr.hasNext()) {
1912 count = itr.next();
1913 }
1914
1915 if (count == null) {
1916 count = new Long(0);
1917 }
1918
1919 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1920 finderClassName, finderMethodName, finderParams,
1921 finderArgs, count);
1922
1923 return count.intValue();
1924 }
1925 catch (Exception e) {
1926 throw processException(e);
1927 }
1928 finally {
1929 closeSession(session);
1930 }
1931 }
1932 else {
1933 return ((Long)result).intValue();
1934 }
1935 }
1936
1937 public int countAll() throws SystemException {
1938 boolean finderClassNameCacheEnabled = MBCategoryModelImpl.CACHE_ENABLED;
1939 String finderClassName = MBCategory.class.getName();
1940 String finderMethodName = "countAll";
1941 String[] finderParams = new String[] { };
1942 Object[] finderArgs = new Object[] { };
1943
1944 Object result = null;
1945
1946 if (finderClassNameCacheEnabled) {
1947 result = FinderCacheUtil.getResult(finderClassName,
1948 finderMethodName, finderParams, finderArgs, this);
1949 }
1950
1951 if (result == null) {
1952 Session session = null;
1953
1954 try {
1955 session = openSession();
1956
1957 Query q = session.createQuery(
1958 "SELECT COUNT(*) FROM com.liferay.portlet.messageboards.model.MBCategory");
1959
1960 Long count = null;
1961
1962 Iterator<Long> itr = q.list().iterator();
1963
1964 if (itr.hasNext()) {
1965 count = itr.next();
1966 }
1967
1968 if (count == null) {
1969 count = new Long(0);
1970 }
1971
1972 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1973 finderClassName, finderMethodName, finderParams,
1974 finderArgs, count);
1975
1976 return count.intValue();
1977 }
1978 catch (Exception e) {
1979 throw processException(e);
1980 }
1981 finally {
1982 closeSession(session);
1983 }
1984 }
1985 else {
1986 return ((Long)result).intValue();
1987 }
1988 }
1989
1990 public void afterPropertiesSet() {
1991 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1992 com.liferay.portal.util.PropsUtil.get(
1993 "value.object.listener.com.liferay.portlet.messageboards.model.MBCategory")));
1994
1995 if (listenerClassNames.length > 0) {
1996 try {
1997 List<ModelListener> listenersList = new ArrayList<ModelListener>();
1998
1999 for (String listenerClassName : listenerClassNames) {
2000 listenersList.add((ModelListener)Class.forName(
2001 listenerClassName).newInstance());
2002 }
2003
2004 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2005 }
2006 catch (Exception e) {
2007 _log.error(e);
2008 }
2009 }
2010 }
2011
2012 @BeanReference(name = "com.liferay.portlet.messageboards.service.persistence.MBBanPersistence.impl")
2013 protected com.liferay.portlet.messageboards.service.persistence.MBBanPersistence mbBanPersistence;
2014 @BeanReference(name = "com.liferay.portlet.messageboards.service.persistence.MBCategoryPersistence.impl")
2015 protected com.liferay.portlet.messageboards.service.persistence.MBCategoryPersistence mbCategoryPersistence;
2016 @BeanReference(name = "com.liferay.portlet.messageboards.service.persistence.MBDiscussionPersistence.impl")
2017 protected com.liferay.portlet.messageboards.service.persistence.MBDiscussionPersistence mbDiscussionPersistence;
2018 @BeanReference(name = "com.liferay.portlet.messageboards.service.persistence.MBMailingListPersistence.impl")
2019 protected com.liferay.portlet.messageboards.service.persistence.MBMailingListPersistence mbMailingListPersistence;
2020 @BeanReference(name = "com.liferay.portlet.messageboards.service.persistence.MBMessagePersistence.impl")
2021 protected com.liferay.portlet.messageboards.service.persistence.MBMessagePersistence mbMessagePersistence;
2022 @BeanReference(name = "com.liferay.portlet.messageboards.service.persistence.MBMessageFlagPersistence.impl")
2023 protected com.liferay.portlet.messageboards.service.persistence.MBMessageFlagPersistence mbMessageFlagPersistence;
2024 @BeanReference(name = "com.liferay.portlet.messageboards.service.persistence.MBStatsUserPersistence.impl")
2025 protected com.liferay.portlet.messageboards.service.persistence.MBStatsUserPersistence mbStatsUserPersistence;
2026 @BeanReference(name = "com.liferay.portlet.messageboards.service.persistence.MBThreadPersistence.impl")
2027 protected com.liferay.portlet.messageboards.service.persistence.MBThreadPersistence mbThreadPersistence;
2028 @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence.impl")
2029 protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
2030 @BeanReference(name = "com.liferay.portal.service.persistence.SubscriptionPersistence.impl")
2031 protected com.liferay.portal.service.persistence.SubscriptionPersistence subscriptionPersistence;
2032 @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence.impl")
2033 protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
2034 @BeanReference(name = "com.liferay.portlet.tags.service.persistence.TagsEntryPersistence.impl")
2035 protected com.liferay.portlet.tags.service.persistence.TagsEntryPersistence tagsEntryPersistence;
2036 private static Log _log = LogFactoryUtil.getLog(MBCategoryPersistenceImpl.class);
2037}