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