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