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