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.OrderByComparator;
29 import com.liferay.portal.kernel.util.StringMaker;
30 import com.liferay.portal.kernel.util.StringPool;
31 import com.liferay.portal.service.persistence.BasePersistence;
32 import com.liferay.portal.spring.hibernate.FinderCache;
33 import com.liferay.portal.spring.hibernate.HibernateUtil;
34
35 import com.liferay.portlet.messageboards.NoSuchCategoryException;
36 import com.liferay.portlet.messageboards.model.MBCategory;
37 import com.liferay.portlet.messageboards.model.impl.MBCategoryImpl;
38
39 import com.liferay.util.dao.hibernate.QueryUtil;
40
41 import org.apache.commons.logging.Log;
42 import org.apache.commons.logging.LogFactory;
43
44 import org.hibernate.Query;
45 import org.hibernate.Session;
46
47 import java.util.Collections;
48 import java.util.Iterator;
49 import java.util.List;
50
51
57 public class MBCategoryPersistenceImpl extends BasePersistence
58 implements MBCategoryPersistence {
59 public MBCategory create(long categoryId) {
60 MBCategory mbCategory = new MBCategoryImpl();
61 mbCategory.setNew(true);
62 mbCategory.setPrimaryKey(categoryId);
63
64 return mbCategory;
65 }
66
67 public MBCategory remove(long categoryId)
68 throws NoSuchCategoryException, SystemException {
69 Session session = null;
70
71 try {
72 session = openSession();
73
74 MBCategory mbCategory = (MBCategory)session.get(MBCategoryImpl.class,
75 new Long(categoryId));
76
77 if (mbCategory == null) {
78 if (_log.isWarnEnabled()) {
79 _log.warn("No MBCategory exists with the primary key " +
80 categoryId);
81 }
82
83 throw new NoSuchCategoryException(
84 "No MBCategory exists with the primary key " + categoryId);
85 }
86
87 return remove(mbCategory);
88 }
89 catch (NoSuchCategoryException nsee) {
90 throw nsee;
91 }
92 catch (Exception e) {
93 throw HibernateUtil.processException(e);
94 }
95 finally {
96 closeSession(session);
97 }
98 }
99
100 public MBCategory remove(MBCategory mbCategory) throws SystemException {
101 Session session = null;
102
103 try {
104 session = openSession();
105 session.delete(mbCategory);
106 session.flush();
107
108 return mbCategory;
109 }
110 catch (Exception e) {
111 throw HibernateUtil.processException(e);
112 }
113 finally {
114 closeSession(session);
115 FinderCache.clearCache(MBCategory.class.getName());
116 }
117 }
118
119 public MBCategory update(
120 com.liferay.portlet.messageboards.model.MBCategory mbCategory)
121 throws SystemException {
122 return update(mbCategory, false);
123 }
124
125 public MBCategory update(
126 com.liferay.portlet.messageboards.model.MBCategory mbCategory,
127 boolean merge) throws SystemException {
128 Session session = null;
129
130 try {
131 session = openSession();
132
133 if (merge) {
134 session.merge(mbCategory);
135 }
136 else {
137 if (mbCategory.isNew()) {
138 session.save(mbCategory);
139 }
140 }
141
142 session.flush();
143 mbCategory.setNew(false);
144
145 return mbCategory;
146 }
147 catch (Exception e) {
148 throw HibernateUtil.processException(e);
149 }
150 finally {
151 closeSession(session);
152 FinderCache.clearCache(MBCategory.class.getName());
153 }
154 }
155
156 public MBCategory findByPrimaryKey(long categoryId)
157 throws NoSuchCategoryException, SystemException {
158 MBCategory mbCategory = fetchByPrimaryKey(categoryId);
159
160 if (mbCategory == null) {
161 if (_log.isWarnEnabled()) {
162 _log.warn("No MBCategory exists with the primary key " +
163 categoryId);
164 }
165
166 throw new NoSuchCategoryException(
167 "No MBCategory exists with the primary key " + categoryId);
168 }
169
170 return mbCategory;
171 }
172
173 public MBCategory fetchByPrimaryKey(long categoryId)
174 throws SystemException {
175 Session session = null;
176
177 try {
178 session = openSession();
179
180 return (MBCategory)session.get(MBCategoryImpl.class,
181 new Long(categoryId));
182 }
183 catch (Exception e) {
184 throw HibernateUtil.processException(e);
185 }
186 finally {
187 closeSession(session);
188 }
189 }
190
191 public List findByGroupId(long groupId) throws SystemException {
192 String finderClassName = MBCategory.class.getName();
193 String finderMethodName = "findByGroupId";
194 String[] finderParams = new String[] { Long.class.getName() };
195 Object[] finderArgs = new Object[] { new Long(groupId) };
196 Object result = FinderCache.getResult(finderClassName,
197 finderMethodName, finderParams, finderArgs, getSessionFactory());
198
199 if (result == null) {
200 Session session = null;
201
202 try {
203 session = openSession();
204
205 StringMaker query = new StringMaker();
206 query.append(
207 "FROM com.liferay.portlet.messageboards.model.MBCategory WHERE ");
208 query.append("groupId = ?");
209 query.append(" ");
210 query.append("ORDER BY ");
211 query.append("parentCategoryId ASC").append(", ");
212 query.append("name ASC");
213
214 Query q = session.createQuery(query.toString());
215 int queryPos = 0;
216 q.setLong(queryPos++, groupId);
217
218 List list = q.list();
219 FinderCache.putResult(finderClassName, finderMethodName,
220 finderParams, finderArgs, list);
221
222 return list;
223 }
224 catch (Exception e) {
225 throw HibernateUtil.processException(e);
226 }
227 finally {
228 closeSession(session);
229 }
230 }
231 else {
232 return (List)result;
233 }
234 }
235
236 public List findByGroupId(long groupId, int begin, int end)
237 throws SystemException {
238 return findByGroupId(groupId, begin, end, null);
239 }
240
241 public List findByGroupId(long groupId, int begin, int end,
242 OrderByComparator obc) throws SystemException {
243 String finderClassName = MBCategory.class.getName();
244 String finderMethodName = "findByGroupId";
245 String[] finderParams = new String[] {
246 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
247 "com.liferay.portal.kernel.util.OrderByComparator"
248 };
249 Object[] finderArgs = new Object[] {
250 new Long(groupId), String.valueOf(begin), String.valueOf(end),
251 String.valueOf(obc)
252 };
253 Object result = FinderCache.getResult(finderClassName,
254 finderMethodName, finderParams, finderArgs, getSessionFactory());
255
256 if (result == null) {
257 Session session = null;
258
259 try {
260 session = openSession();
261
262 StringMaker query = new StringMaker();
263 query.append(
264 "FROM com.liferay.portlet.messageboards.model.MBCategory WHERE ");
265 query.append("groupId = ?");
266 query.append(" ");
267
268 if (obc != null) {
269 query.append("ORDER BY ");
270 query.append(obc.getOrderBy());
271 }
272 else {
273 query.append("ORDER BY ");
274 query.append("parentCategoryId ASC").append(", ");
275 query.append("name ASC");
276 }
277
278 Query q = session.createQuery(query.toString());
279 int queryPos = 0;
280 q.setLong(queryPos++, groupId);
281
282 List list = QueryUtil.list(q, getDialect(), begin, end);
283 FinderCache.putResult(finderClassName, finderMethodName,
284 finderParams, finderArgs, list);
285
286 return list;
287 }
288 catch (Exception e) {
289 throw HibernateUtil.processException(e);
290 }
291 finally {
292 closeSession(session);
293 }
294 }
295 else {
296 return (List)result;
297 }
298 }
299
300 public MBCategory findByGroupId_First(long groupId, OrderByComparator obc)
301 throws NoSuchCategoryException, SystemException {
302 List list = findByGroupId(groupId, 0, 1, obc);
303
304 if (list.size() == 0) {
305 StringMaker msg = new StringMaker();
306 msg.append("No MBCategory exists with the key ");
307 msg.append(StringPool.OPEN_CURLY_BRACE);
308 msg.append("groupId=");
309 msg.append(groupId);
310 msg.append(StringPool.CLOSE_CURLY_BRACE);
311 throw new NoSuchCategoryException(msg.toString());
312 }
313 else {
314 return (MBCategory)list.get(0);
315 }
316 }
317
318 public MBCategory findByGroupId_Last(long groupId, OrderByComparator obc)
319 throws NoSuchCategoryException, SystemException {
320 int count = countByGroupId(groupId);
321 List list = findByGroupId(groupId, count - 1, count, obc);
322
323 if (list.size() == 0) {
324 StringMaker msg = new StringMaker();
325 msg.append("No MBCategory exists with the key ");
326 msg.append(StringPool.OPEN_CURLY_BRACE);
327 msg.append("groupId=");
328 msg.append(groupId);
329 msg.append(StringPool.CLOSE_CURLY_BRACE);
330 throw new NoSuchCategoryException(msg.toString());
331 }
332 else {
333 return (MBCategory)list.get(0);
334 }
335 }
336
337 public MBCategory[] findByGroupId_PrevAndNext(long categoryId,
338 long groupId, OrderByComparator obc)
339 throws NoSuchCategoryException, SystemException {
340 MBCategory mbCategory = findByPrimaryKey(categoryId);
341 int count = countByGroupId(groupId);
342 Session session = null;
343
344 try {
345 session = openSession();
346
347 StringMaker query = new StringMaker();
348 query.append(
349 "FROM com.liferay.portlet.messageboards.model.MBCategory WHERE ");
350 query.append("groupId = ?");
351 query.append(" ");
352
353 if (obc != null) {
354 query.append("ORDER BY ");
355 query.append(obc.getOrderBy());
356 }
357 else {
358 query.append("ORDER BY ");
359 query.append("parentCategoryId ASC").append(", ");
360 query.append("name ASC");
361 }
362
363 Query q = session.createQuery(query.toString());
364 int queryPos = 0;
365 q.setLong(queryPos++, groupId);
366
367 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
368 mbCategory);
369 MBCategory[] array = new MBCategoryImpl[3];
370 array[0] = (MBCategory)objArray[0];
371 array[1] = (MBCategory)objArray[1];
372 array[2] = (MBCategory)objArray[2];
373
374 return array;
375 }
376 catch (Exception e) {
377 throw HibernateUtil.processException(e);
378 }
379 finally {
380 closeSession(session);
381 }
382 }
383
384 public List findByCompanyId(long companyId) throws SystemException {
385 String finderClassName = MBCategory.class.getName();
386 String finderMethodName = "findByCompanyId";
387 String[] finderParams = new String[] { Long.class.getName() };
388 Object[] finderArgs = new Object[] { new Long(companyId) };
389 Object result = FinderCache.getResult(finderClassName,
390 finderMethodName, finderParams, finderArgs, getSessionFactory());
391
392 if (result == null) {
393 Session session = null;
394
395 try {
396 session = openSession();
397
398 StringMaker query = new StringMaker();
399 query.append(
400 "FROM com.liferay.portlet.messageboards.model.MBCategory WHERE ");
401 query.append("companyId = ?");
402 query.append(" ");
403 query.append("ORDER BY ");
404 query.append("parentCategoryId ASC").append(", ");
405 query.append("name ASC");
406
407 Query q = session.createQuery(query.toString());
408 int queryPos = 0;
409 q.setLong(queryPos++, companyId);
410
411 List list = q.list();
412 FinderCache.putResult(finderClassName, finderMethodName,
413 finderParams, finderArgs, list);
414
415 return list;
416 }
417 catch (Exception e) {
418 throw HibernateUtil.processException(e);
419 }
420 finally {
421 closeSession(session);
422 }
423 }
424 else {
425 return (List)result;
426 }
427 }
428
429 public List findByCompanyId(long companyId, int begin, int end)
430 throws SystemException {
431 return findByCompanyId(companyId, begin, end, null);
432 }
433
434 public List findByCompanyId(long companyId, int begin, int end,
435 OrderByComparator obc) throws SystemException {
436 String finderClassName = MBCategory.class.getName();
437 String finderMethodName = "findByCompanyId";
438 String[] finderParams = new String[] {
439 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
440 "com.liferay.portal.kernel.util.OrderByComparator"
441 };
442 Object[] finderArgs = new Object[] {
443 new Long(companyId), String.valueOf(begin), String.valueOf(end),
444 String.valueOf(obc)
445 };
446 Object result = FinderCache.getResult(finderClassName,
447 finderMethodName, finderParams, finderArgs, getSessionFactory());
448
449 if (result == null) {
450 Session session = null;
451
452 try {
453 session = openSession();
454
455 StringMaker query = new StringMaker();
456 query.append(
457 "FROM com.liferay.portlet.messageboards.model.MBCategory WHERE ");
458 query.append("companyId = ?");
459 query.append(" ");
460
461 if (obc != null) {
462 query.append("ORDER BY ");
463 query.append(obc.getOrderBy());
464 }
465 else {
466 query.append("ORDER BY ");
467 query.append("parentCategoryId ASC").append(", ");
468 query.append("name ASC");
469 }
470
471 Query q = session.createQuery(query.toString());
472 int queryPos = 0;
473 q.setLong(queryPos++, companyId);
474
475 List list = QueryUtil.list(q, getDialect(), begin, end);
476 FinderCache.putResult(finderClassName, finderMethodName,
477 finderParams, finderArgs, list);
478
479 return list;
480 }
481 catch (Exception e) {
482 throw HibernateUtil.processException(e);
483 }
484 finally {
485 closeSession(session);
486 }
487 }
488 else {
489 return (List)result;
490 }
491 }
492
493 public MBCategory findByCompanyId_First(long companyId,
494 OrderByComparator obc) throws NoSuchCategoryException, SystemException {
495 List list = findByCompanyId(companyId, 0, 1, obc);
496
497 if (list.size() == 0) {
498 StringMaker msg = new StringMaker();
499 msg.append("No MBCategory exists with the key ");
500 msg.append(StringPool.OPEN_CURLY_BRACE);
501 msg.append("companyId=");
502 msg.append(companyId);
503 msg.append(StringPool.CLOSE_CURLY_BRACE);
504 throw new NoSuchCategoryException(msg.toString());
505 }
506 else {
507 return (MBCategory)list.get(0);
508 }
509 }
510
511 public MBCategory findByCompanyId_Last(long companyId, OrderByComparator obc)
512 throws NoSuchCategoryException, SystemException {
513 int count = countByCompanyId(companyId);
514 List list = findByCompanyId(companyId, count - 1, count, obc);
515
516 if (list.size() == 0) {
517 StringMaker msg = new StringMaker();
518 msg.append("No MBCategory exists with the key ");
519 msg.append(StringPool.OPEN_CURLY_BRACE);
520 msg.append("companyId=");
521 msg.append(companyId);
522 msg.append(StringPool.CLOSE_CURLY_BRACE);
523 throw new NoSuchCategoryException(msg.toString());
524 }
525 else {
526 return (MBCategory)list.get(0);
527 }
528 }
529
530 public MBCategory[] findByCompanyId_PrevAndNext(long categoryId,
531 long companyId, OrderByComparator obc)
532 throws NoSuchCategoryException, SystemException {
533 MBCategory mbCategory = findByPrimaryKey(categoryId);
534 int count = countByCompanyId(companyId);
535 Session session = null;
536
537 try {
538 session = openSession();
539
540 StringMaker query = new StringMaker();
541 query.append(
542 "FROM com.liferay.portlet.messageboards.model.MBCategory WHERE ");
543 query.append("companyId = ?");
544 query.append(" ");
545
546 if (obc != null) {
547 query.append("ORDER BY ");
548 query.append(obc.getOrderBy());
549 }
550 else {
551 query.append("ORDER BY ");
552 query.append("parentCategoryId ASC").append(", ");
553 query.append("name ASC");
554 }
555
556 Query q = session.createQuery(query.toString());
557 int queryPos = 0;
558 q.setLong(queryPos++, companyId);
559
560 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
561 mbCategory);
562 MBCategory[] array = new MBCategoryImpl[3];
563 array[0] = (MBCategory)objArray[0];
564 array[1] = (MBCategory)objArray[1];
565 array[2] = (MBCategory)objArray[2];
566
567 return array;
568 }
569 catch (Exception e) {
570 throw HibernateUtil.processException(e);
571 }
572 finally {
573 closeSession(session);
574 }
575 }
576
577 public List findByG_P(long groupId, long parentCategoryId)
578 throws SystemException {
579 String finderClassName = MBCategory.class.getName();
580 String finderMethodName = "findByG_P";
581 String[] finderParams = new String[] {
582 Long.class.getName(), Long.class.getName()
583 };
584 Object[] finderArgs = new Object[] {
585 new Long(groupId), new Long(parentCategoryId)
586 };
587 Object result = FinderCache.getResult(finderClassName,
588 finderMethodName, finderParams, finderArgs, getSessionFactory());
589
590 if (result == null) {
591 Session session = null;
592
593 try {
594 session = openSession();
595
596 StringMaker query = new StringMaker();
597 query.append(
598 "FROM com.liferay.portlet.messageboards.model.MBCategory WHERE ");
599 query.append("groupId = ?");
600 query.append(" AND ");
601 query.append("parentCategoryId = ?");
602 query.append(" ");
603 query.append("ORDER BY ");
604 query.append("parentCategoryId ASC").append(", ");
605 query.append("name ASC");
606
607 Query q = session.createQuery(query.toString());
608 int queryPos = 0;
609 q.setLong(queryPos++, groupId);
610 q.setLong(queryPos++, parentCategoryId);
611
612 List list = q.list();
613 FinderCache.putResult(finderClassName, finderMethodName,
614 finderParams, finderArgs, list);
615
616 return list;
617 }
618 catch (Exception e) {
619 throw HibernateUtil.processException(e);
620 }
621 finally {
622 closeSession(session);
623 }
624 }
625 else {
626 return (List)result;
627 }
628 }
629
630 public List findByG_P(long groupId, long parentCategoryId, int begin,
631 int end) throws SystemException {
632 return findByG_P(groupId, parentCategoryId, begin, end, null);
633 }
634
635 public List findByG_P(long groupId, long parentCategoryId, int begin,
636 int end, OrderByComparator obc) throws SystemException {
637 String finderClassName = MBCategory.class.getName();
638 String finderMethodName = "findByG_P";
639 String[] finderParams = new String[] {
640 Long.class.getName(), Long.class.getName(), "java.lang.Integer",
641 "java.lang.Integer",
642 "com.liferay.portal.kernel.util.OrderByComparator"
643 };
644 Object[] finderArgs = new Object[] {
645 new Long(groupId), new Long(parentCategoryId),
646 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
647 };
648 Object result = FinderCache.getResult(finderClassName,
649 finderMethodName, finderParams, finderArgs, getSessionFactory());
650
651 if (result == null) {
652 Session session = null;
653
654 try {
655 session = openSession();
656
657 StringMaker query = new StringMaker();
658 query.append(
659 "FROM com.liferay.portlet.messageboards.model.MBCategory WHERE ");
660 query.append("groupId = ?");
661 query.append(" AND ");
662 query.append("parentCategoryId = ?");
663 query.append(" ");
664
665 if (obc != null) {
666 query.append("ORDER BY ");
667 query.append(obc.getOrderBy());
668 }
669 else {
670 query.append("ORDER BY ");
671 query.append("parentCategoryId ASC").append(", ");
672 query.append("name ASC");
673 }
674
675 Query q = session.createQuery(query.toString());
676 int queryPos = 0;
677 q.setLong(queryPos++, groupId);
678 q.setLong(queryPos++, parentCategoryId);
679
680 List list = QueryUtil.list(q, getDialect(), begin, end);
681 FinderCache.putResult(finderClassName, finderMethodName,
682 finderParams, finderArgs, list);
683
684 return list;
685 }
686 catch (Exception e) {
687 throw HibernateUtil.processException(e);
688 }
689 finally {
690 closeSession(session);
691 }
692 }
693 else {
694 return (List)result;
695 }
696 }
697
698 public MBCategory findByG_P_First(long groupId, long parentCategoryId,
699 OrderByComparator obc) throws NoSuchCategoryException, SystemException {
700 List list = findByG_P(groupId, parentCategoryId, 0, 1, obc);
701
702 if (list.size() == 0) {
703 StringMaker msg = new StringMaker();
704 msg.append("No MBCategory exists with the key ");
705 msg.append(StringPool.OPEN_CURLY_BRACE);
706 msg.append("groupId=");
707 msg.append(groupId);
708 msg.append(", ");
709 msg.append("parentCategoryId=");
710 msg.append(parentCategoryId);
711 msg.append(StringPool.CLOSE_CURLY_BRACE);
712 throw new NoSuchCategoryException(msg.toString());
713 }
714 else {
715 return (MBCategory)list.get(0);
716 }
717 }
718
719 public MBCategory findByG_P_Last(long groupId, long parentCategoryId,
720 OrderByComparator obc) throws NoSuchCategoryException, SystemException {
721 int count = countByG_P(groupId, parentCategoryId);
722 List list = findByG_P(groupId, parentCategoryId, count - 1, count, obc);
723
724 if (list.size() == 0) {
725 StringMaker msg = new StringMaker();
726 msg.append("No MBCategory exists with the key ");
727 msg.append(StringPool.OPEN_CURLY_BRACE);
728 msg.append("groupId=");
729 msg.append(groupId);
730 msg.append(", ");
731 msg.append("parentCategoryId=");
732 msg.append(parentCategoryId);
733 msg.append(StringPool.CLOSE_CURLY_BRACE);
734 throw new NoSuchCategoryException(msg.toString());
735 }
736 else {
737 return (MBCategory)list.get(0);
738 }
739 }
740
741 public MBCategory[] findByG_P_PrevAndNext(long categoryId, long groupId,
742 long parentCategoryId, OrderByComparator obc)
743 throws NoSuchCategoryException, SystemException {
744 MBCategory mbCategory = findByPrimaryKey(categoryId);
745 int count = countByG_P(groupId, parentCategoryId);
746 Session session = null;
747
748 try {
749 session = openSession();
750
751 StringMaker query = new StringMaker();
752 query.append(
753 "FROM com.liferay.portlet.messageboards.model.MBCategory WHERE ");
754 query.append("groupId = ?");
755 query.append(" AND ");
756 query.append("parentCategoryId = ?");
757 query.append(" ");
758
759 if (obc != null) {
760 query.append("ORDER BY ");
761 query.append(obc.getOrderBy());
762 }
763 else {
764 query.append("ORDER BY ");
765 query.append("parentCategoryId ASC").append(", ");
766 query.append("name ASC");
767 }
768
769 Query q = session.createQuery(query.toString());
770 int queryPos = 0;
771 q.setLong(queryPos++, groupId);
772 q.setLong(queryPos++, parentCategoryId);
773
774 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
775 mbCategory);
776 MBCategory[] array = new MBCategoryImpl[3];
777 array[0] = (MBCategory)objArray[0];
778 array[1] = (MBCategory)objArray[1];
779 array[2] = (MBCategory)objArray[2];
780
781 return array;
782 }
783 catch (Exception e) {
784 throw HibernateUtil.processException(e);
785 }
786 finally {
787 closeSession(session);
788 }
789 }
790
791 public List findWithDynamicQuery(DynamicQueryInitializer queryInitializer)
792 throws SystemException {
793 Session session = null;
794
795 try {
796 session = openSession();
797
798 DynamicQuery query = queryInitializer.initialize(session);
799
800 return query.list();
801 }
802 catch (Exception e) {
803 throw HibernateUtil.processException(e);
804 }
805 finally {
806 closeSession(session);
807 }
808 }
809
810 public List findWithDynamicQuery(DynamicQueryInitializer queryInitializer,
811 int begin, int end) throws SystemException {
812 Session session = null;
813
814 try {
815 session = openSession();
816
817 DynamicQuery query = queryInitializer.initialize(session);
818 query.setLimit(begin, end);
819
820 return query.list();
821 }
822 catch (Exception e) {
823 throw HibernateUtil.processException(e);
824 }
825 finally {
826 closeSession(session);
827 }
828 }
829
830 public List findAll() throws SystemException {
831 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
832 }
833
834 public List findAll(int begin, int end) throws SystemException {
835 return findAll(begin, end, null);
836 }
837
838 public List findAll(int begin, int end, OrderByComparator obc)
839 throws SystemException {
840 String finderClassName = MBCategory.class.getName();
841 String finderMethodName = "findAll";
842 String[] finderParams = new String[] {
843 "java.lang.Integer", "java.lang.Integer",
844 "com.liferay.portal.kernel.util.OrderByComparator"
845 };
846 Object[] finderArgs = new Object[] {
847 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
848 };
849 Object result = FinderCache.getResult(finderClassName,
850 finderMethodName, finderParams, finderArgs, getSessionFactory());
851
852 if (result == null) {
853 Session session = null;
854
855 try {
856 session = openSession();
857
858 StringMaker query = new StringMaker();
859 query.append(
860 "FROM com.liferay.portlet.messageboards.model.MBCategory ");
861
862 if (obc != null) {
863 query.append("ORDER BY ");
864 query.append(obc.getOrderBy());
865 }
866 else {
867 query.append("ORDER BY ");
868 query.append("parentCategoryId ASC").append(", ");
869 query.append("name ASC");
870 }
871
872 Query q = session.createQuery(query.toString());
873 List list = QueryUtil.list(q, getDialect(), begin, end);
874
875 if (obc == null) {
876 Collections.sort(list);
877 }
878
879 FinderCache.putResult(finderClassName, finderMethodName,
880 finderParams, finderArgs, list);
881
882 return list;
883 }
884 catch (Exception e) {
885 throw HibernateUtil.processException(e);
886 }
887 finally {
888 closeSession(session);
889 }
890 }
891 else {
892 return (List)result;
893 }
894 }
895
896 public void removeByGroupId(long groupId) throws SystemException {
897 Iterator itr = findByGroupId(groupId).iterator();
898
899 while (itr.hasNext()) {
900 MBCategory mbCategory = (MBCategory)itr.next();
901 remove(mbCategory);
902 }
903 }
904
905 public void removeByCompanyId(long companyId) throws SystemException {
906 Iterator itr = findByCompanyId(companyId).iterator();
907
908 while (itr.hasNext()) {
909 MBCategory mbCategory = (MBCategory)itr.next();
910 remove(mbCategory);
911 }
912 }
913
914 public void removeByG_P(long groupId, long parentCategoryId)
915 throws SystemException {
916 Iterator itr = findByG_P(groupId, parentCategoryId).iterator();
917
918 while (itr.hasNext()) {
919 MBCategory mbCategory = (MBCategory)itr.next();
920 remove(mbCategory);
921 }
922 }
923
924 public void removeAll() throws SystemException {
925 Iterator itr = findAll().iterator();
926
927 while (itr.hasNext()) {
928 remove((MBCategory)itr.next());
929 }
930 }
931
932 public int countByGroupId(long groupId) throws SystemException {
933 String finderClassName = MBCategory.class.getName();
934 String finderMethodName = "countByGroupId";
935 String[] finderParams = new String[] { Long.class.getName() };
936 Object[] finderArgs = new Object[] { new Long(groupId) };
937 Object result = FinderCache.getResult(finderClassName,
938 finderMethodName, finderParams, finderArgs, getSessionFactory());
939
940 if (result == null) {
941 Session session = null;
942
943 try {
944 session = openSession();
945
946 StringMaker query = new StringMaker();
947 query.append("SELECT COUNT(*) ");
948 query.append(
949 "FROM com.liferay.portlet.messageboards.model.MBCategory WHERE ");
950 query.append("groupId = ?");
951 query.append(" ");
952
953 Query q = session.createQuery(query.toString());
954 int queryPos = 0;
955 q.setLong(queryPos++, groupId);
956
957 Long count = null;
958 Iterator itr = q.list().iterator();
959
960 if (itr.hasNext()) {
961 count = (Long)itr.next();
962 }
963
964 if (count == null) {
965 count = new Long(0);
966 }
967
968 FinderCache.putResult(finderClassName, finderMethodName,
969 finderParams, finderArgs, count);
970
971 return count.intValue();
972 }
973 catch (Exception e) {
974 throw HibernateUtil.processException(e);
975 }
976 finally {
977 closeSession(session);
978 }
979 }
980 else {
981 return ((Long)result).intValue();
982 }
983 }
984
985 public int countByCompanyId(long companyId) throws SystemException {
986 String finderClassName = MBCategory.class.getName();
987 String finderMethodName = "countByCompanyId";
988 String[] finderParams = new String[] { Long.class.getName() };
989 Object[] finderArgs = new Object[] { new Long(companyId) };
990 Object result = FinderCache.getResult(finderClassName,
991 finderMethodName, finderParams, finderArgs, getSessionFactory());
992
993 if (result == null) {
994 Session session = null;
995
996 try {
997 session = openSession();
998
999 StringMaker query = new StringMaker();
1000 query.append("SELECT COUNT(*) ");
1001 query.append(
1002 "FROM com.liferay.portlet.messageboards.model.MBCategory WHERE ");
1003 query.append("companyId = ?");
1004 query.append(" ");
1005
1006 Query q = session.createQuery(query.toString());
1007 int queryPos = 0;
1008 q.setLong(queryPos++, companyId);
1009
1010 Long count = null;
1011 Iterator itr = q.list().iterator();
1012
1013 if (itr.hasNext()) {
1014 count = (Long)itr.next();
1015 }
1016
1017 if (count == null) {
1018 count = new Long(0);
1019 }
1020
1021 FinderCache.putResult(finderClassName, finderMethodName,
1022 finderParams, finderArgs, count);
1023
1024 return count.intValue();
1025 }
1026 catch (Exception e) {
1027 throw HibernateUtil.processException(e);
1028 }
1029 finally {
1030 closeSession(session);
1031 }
1032 }
1033 else {
1034 return ((Long)result).intValue();
1035 }
1036 }
1037
1038 public int countByG_P(long groupId, long parentCategoryId)
1039 throws SystemException {
1040 String finderClassName = MBCategory.class.getName();
1041 String finderMethodName = "countByG_P";
1042 String[] finderParams = new String[] {
1043 Long.class.getName(), Long.class.getName()
1044 };
1045 Object[] finderArgs = new Object[] {
1046 new Long(groupId), new Long(parentCategoryId)
1047 };
1048 Object result = FinderCache.getResult(finderClassName,
1049 finderMethodName, finderParams, finderArgs, getSessionFactory());
1050
1051 if (result == null) {
1052 Session session = null;
1053
1054 try {
1055 session = openSession();
1056
1057 StringMaker query = new StringMaker();
1058 query.append("SELECT COUNT(*) ");
1059 query.append(
1060 "FROM com.liferay.portlet.messageboards.model.MBCategory WHERE ");
1061 query.append("groupId = ?");
1062 query.append(" AND ");
1063 query.append("parentCategoryId = ?");
1064 query.append(" ");
1065
1066 Query q = session.createQuery(query.toString());
1067 int queryPos = 0;
1068 q.setLong(queryPos++, groupId);
1069 q.setLong(queryPos++, parentCategoryId);
1070
1071 Long count = null;
1072 Iterator itr = q.list().iterator();
1073
1074 if (itr.hasNext()) {
1075 count = (Long)itr.next();
1076 }
1077
1078 if (count == null) {
1079 count = new Long(0);
1080 }
1081
1082 FinderCache.putResult(finderClassName, finderMethodName,
1083 finderParams, finderArgs, count);
1084
1085 return count.intValue();
1086 }
1087 catch (Exception e) {
1088 throw HibernateUtil.processException(e);
1089 }
1090 finally {
1091 closeSession(session);
1092 }
1093 }
1094 else {
1095 return ((Long)result).intValue();
1096 }
1097 }
1098
1099 public int countAll() throws SystemException {
1100 String finderClassName = MBCategory.class.getName();
1101 String finderMethodName = "countAll";
1102 String[] finderParams = new String[] { };
1103 Object[] finderArgs = new Object[] { };
1104 Object result = FinderCache.getResult(finderClassName,
1105 finderMethodName, finderParams, finderArgs, getSessionFactory());
1106
1107 if (result == null) {
1108 Session session = null;
1109
1110 try {
1111 session = openSession();
1112
1113 StringMaker query = new StringMaker();
1114 query.append("SELECT COUNT(*) ");
1115 query.append(
1116 "FROM com.liferay.portlet.messageboards.model.MBCategory");
1117
1118 Query q = session.createQuery(query.toString());
1119 Long count = null;
1120 Iterator itr = q.list().iterator();
1121
1122 if (itr.hasNext()) {
1123 count = (Long)itr.next();
1124 }
1125
1126 if (count == null) {
1127 count = new Long(0);
1128 }
1129
1130 FinderCache.putResult(finderClassName, finderMethodName,
1131 finderParams, finderArgs, count);
1132
1133 return count.intValue();
1134 }
1135 catch (Exception e) {
1136 throw HibernateUtil.processException(e);
1137 }
1138 finally {
1139 closeSession(session);
1140 }
1141 }
1142 else {
1143 return ((Long)result).intValue();
1144 }
1145 }
1146
1147 protected void initDao() {
1148 }
1149
1150 private static Log _log = LogFactory.getLog(MBCategoryPersistenceImpl.class);
1151}