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