1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   * 
13   */
14  
15  package com.liferay.portlet.messageboards.service.persistence;
16  
17  import com.liferay.portal.NoSuchModelException;
18  import com.liferay.portal.SystemException;
19  import com.liferay.portal.kernel.annotation.BeanReference;
20  import com.liferay.portal.kernel.cache.CacheRegistry;
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.log.Log;
29  import com.liferay.portal.kernel.log.LogFactoryUtil;
30  import com.liferay.portal.kernel.util.GetterUtil;
31  import com.liferay.portal.kernel.util.OrderByComparator;
32  import com.liferay.portal.kernel.util.StringBundler;
33  import com.liferay.portal.kernel.util.StringPool;
34  import com.liferay.portal.kernel.util.StringUtil;
35  import com.liferay.portal.kernel.util.Validator;
36  import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
37  import com.liferay.portal.model.ModelListener;
38  import com.liferay.portal.service.persistence.BatchSessionUtil;
39  import com.liferay.portal.service.persistence.ResourcePersistence;
40  import com.liferay.portal.service.persistence.UserPersistence;
41  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
42  
43  import com.liferay.portlet.messageboards.NoSuchMailingListException;
44  import com.liferay.portlet.messageboards.model.MBMailingList;
45  import com.liferay.portlet.messageboards.model.impl.MBMailingListImpl;
46  import com.liferay.portlet.messageboards.model.impl.MBMailingListModelImpl;
47  
48  import java.io.Serializable;
49  
50  import java.util.ArrayList;
51  import java.util.Collections;
52  import java.util.List;
53  
54  /**
55   * <a href="MBMailingListPersistenceImpl.java.html"><b><i>View Source</i></b></a>
56   *
57   * <p>
58   * ServiceBuilder generated this class. Modifications in this class will be
59   * overwritten the next time is generated.
60   * </p>
61   *
62   * @author    Brian Wing Shun Chan
63   * @see       MBMailingListPersistence
64   * @see       MBMailingListUtil
65   * @generated
66   */
67  public class MBMailingListPersistenceImpl extends BasePersistenceImpl<MBMailingList>
68      implements MBMailingListPersistence {
69      public static final String FINDER_CLASS_NAME_ENTITY = MBMailingListImpl.class.getName();
70      public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
71          ".List";
72      public static final FinderPath FINDER_PATH_FIND_BY_UUID = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
73              MBMailingListModelImpl.FINDER_CACHE_ENABLED,
74              FINDER_CLASS_NAME_LIST, "findByUuid",
75              new String[] { String.class.getName() });
76      public static final FinderPath FINDER_PATH_FIND_BY_OBC_UUID = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
77              MBMailingListModelImpl.FINDER_CACHE_ENABLED,
78              FINDER_CLASS_NAME_LIST, "findByUuid",
79              new String[] {
80                  String.class.getName(),
81                  
82              "java.lang.Integer", "java.lang.Integer",
83                  "com.liferay.portal.kernel.util.OrderByComparator"
84              });
85      public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
86              MBMailingListModelImpl.FINDER_CACHE_ENABLED,
87              FINDER_CLASS_NAME_LIST, "countByUuid",
88              new String[] { String.class.getName() });
89      public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
90              MBMailingListModelImpl.FINDER_CACHE_ENABLED,
91              FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
92              new String[] { String.class.getName(), Long.class.getName() });
93      public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
94              MBMailingListModelImpl.FINDER_CACHE_ENABLED,
95              FINDER_CLASS_NAME_LIST, "countByUUID_G",
96              new String[] { String.class.getName(), Long.class.getName() });
97      public static final FinderPath FINDER_PATH_FETCH_BY_CATEGORYID = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
98              MBMailingListModelImpl.FINDER_CACHE_ENABLED,
99              FINDER_CLASS_NAME_ENTITY, "fetchByCategoryId",
100             new String[] { Long.class.getName() });
101     public static final FinderPath FINDER_PATH_COUNT_BY_CATEGORYID = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
102             MBMailingListModelImpl.FINDER_CACHE_ENABLED,
103             FINDER_CLASS_NAME_LIST, "countByCategoryId",
104             new String[] { Long.class.getName() });
105     public static final FinderPath FINDER_PATH_FIND_BY_ACTIVE = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
106             MBMailingListModelImpl.FINDER_CACHE_ENABLED,
107             FINDER_CLASS_NAME_LIST, "findByActive",
108             new String[] { Boolean.class.getName() });
109     public static final FinderPath FINDER_PATH_FIND_BY_OBC_ACTIVE = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
110             MBMailingListModelImpl.FINDER_CACHE_ENABLED,
111             FINDER_CLASS_NAME_LIST, "findByActive",
112             new String[] {
113                 Boolean.class.getName(),
114                 
115             "java.lang.Integer", "java.lang.Integer",
116                 "com.liferay.portal.kernel.util.OrderByComparator"
117             });
118     public static final FinderPath FINDER_PATH_COUNT_BY_ACTIVE = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
119             MBMailingListModelImpl.FINDER_CACHE_ENABLED,
120             FINDER_CLASS_NAME_LIST, "countByActive",
121             new String[] { Boolean.class.getName() });
122     public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
123             MBMailingListModelImpl.FINDER_CACHE_ENABLED,
124             FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
125     public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
126             MBMailingListModelImpl.FINDER_CACHE_ENABLED,
127             FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
128 
129     public void cacheResult(MBMailingList mbMailingList) {
130         EntityCacheUtil.putResult(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
131             MBMailingListImpl.class, mbMailingList.getPrimaryKey(),
132             mbMailingList);
133 
134         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
135             new Object[] {
136                 mbMailingList.getUuid(), new Long(mbMailingList.getGroupId())
137             }, mbMailingList);
138 
139         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_CATEGORYID,
140             new Object[] { new Long(mbMailingList.getCategoryId()) },
141             mbMailingList);
142     }
143 
144     public void cacheResult(List<MBMailingList> mbMailingLists) {
145         for (MBMailingList mbMailingList : mbMailingLists) {
146             if (EntityCacheUtil.getResult(
147                         MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
148                         MBMailingListImpl.class, mbMailingList.getPrimaryKey(),
149                         this) == null) {
150                 cacheResult(mbMailingList);
151             }
152         }
153     }
154 
155     public void clearCache() {
156         CacheRegistry.clear(MBMailingListImpl.class.getName());
157         EntityCacheUtil.clearCache(MBMailingListImpl.class.getName());
158         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
159         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
160     }
161 
162     public MBMailingList create(long mailingListId) {
163         MBMailingList mbMailingList = new MBMailingListImpl();
164 
165         mbMailingList.setNew(true);
166         mbMailingList.setPrimaryKey(mailingListId);
167 
168         String uuid = PortalUUIDUtil.generate();
169 
170         mbMailingList.setUuid(uuid);
171 
172         return mbMailingList;
173     }
174 
175     public MBMailingList remove(Serializable primaryKey)
176         throws NoSuchModelException, SystemException {
177         return remove(((Long)primaryKey).longValue());
178     }
179 
180     public MBMailingList remove(long mailingListId)
181         throws NoSuchMailingListException, SystemException {
182         Session session = null;
183 
184         try {
185             session = openSession();
186 
187             MBMailingList mbMailingList = (MBMailingList)session.get(MBMailingListImpl.class,
188                     new Long(mailingListId));
189 
190             if (mbMailingList == null) {
191                 if (_log.isWarnEnabled()) {
192                     _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + mailingListId);
193                 }
194 
195                 throw new NoSuchMailingListException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
196                     mailingListId);
197             }
198 
199             return remove(mbMailingList);
200         }
201         catch (NoSuchMailingListException nsee) {
202             throw nsee;
203         }
204         catch (Exception e) {
205             throw processException(e);
206         }
207         finally {
208             closeSession(session);
209         }
210     }
211 
212     public MBMailingList remove(MBMailingList mbMailingList)
213         throws SystemException {
214         for (ModelListener<MBMailingList> listener : listeners) {
215             listener.onBeforeRemove(mbMailingList);
216         }
217 
218         mbMailingList = removeImpl(mbMailingList);
219 
220         for (ModelListener<MBMailingList> listener : listeners) {
221             listener.onAfterRemove(mbMailingList);
222         }
223 
224         return mbMailingList;
225     }
226 
227     protected MBMailingList removeImpl(MBMailingList mbMailingList)
228         throws SystemException {
229         mbMailingList = toUnwrappedModel(mbMailingList);
230 
231         Session session = null;
232 
233         try {
234             session = openSession();
235 
236             if (mbMailingList.isCachedModel() || BatchSessionUtil.isEnabled()) {
237                 Object staleObject = session.get(MBMailingListImpl.class,
238                         mbMailingList.getPrimaryKeyObj());
239 
240                 if (staleObject != null) {
241                     session.evict(staleObject);
242                 }
243             }
244 
245             session.delete(mbMailingList);
246 
247             session.flush();
248         }
249         catch (Exception e) {
250             throw processException(e);
251         }
252         finally {
253             closeSession(session);
254         }
255 
256         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
257 
258         MBMailingListModelImpl mbMailingListModelImpl = (MBMailingListModelImpl)mbMailingList;
259 
260         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
261             new Object[] {
262                 mbMailingListModelImpl.getOriginalUuid(),
263                 new Long(mbMailingListModelImpl.getOriginalGroupId())
264             });
265 
266         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_CATEGORYID,
267             new Object[] {
268                 new Long(mbMailingListModelImpl.getOriginalCategoryId())
269             });
270 
271         EntityCacheUtil.removeResult(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
272             MBMailingListImpl.class, mbMailingList.getPrimaryKey());
273 
274         return mbMailingList;
275     }
276 
277     /**
278      * @deprecated Use {@link BasePersistence#update(com.liferay.portal.model.BaseModel, boolean)}.
279      */
280     public MBMailingList update(MBMailingList mbMailingList)
281         throws SystemException {
282         if (_log.isWarnEnabled()) {
283             _log.warn(
284                 "Using the deprecated update(MBMailingList mbMailingList) method. Use update(MBMailingList mbMailingList, boolean merge) instead.");
285         }
286 
287         return update(mbMailingList, false);
288     }
289 
290     public MBMailingList updateImpl(
291         com.liferay.portlet.messageboards.model.MBMailingList mbMailingList,
292         boolean merge) throws SystemException {
293         mbMailingList = toUnwrappedModel(mbMailingList);
294 
295         boolean isNew = mbMailingList.isNew();
296 
297         MBMailingListModelImpl mbMailingListModelImpl = (MBMailingListModelImpl)mbMailingList;
298 
299         if (Validator.isNull(mbMailingList.getUuid())) {
300             String uuid = PortalUUIDUtil.generate();
301 
302             mbMailingList.setUuid(uuid);
303         }
304 
305         Session session = null;
306 
307         try {
308             session = openSession();
309 
310             BatchSessionUtil.update(session, mbMailingList, merge);
311 
312             mbMailingList.setNew(false);
313         }
314         catch (Exception e) {
315             throw processException(e);
316         }
317         finally {
318             closeSession(session);
319         }
320 
321         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
322 
323         EntityCacheUtil.putResult(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
324             MBMailingListImpl.class, mbMailingList.getPrimaryKey(),
325             mbMailingList);
326 
327         if (!isNew &&
328                 (!Validator.equals(mbMailingList.getUuid(),
329                     mbMailingListModelImpl.getOriginalUuid()) ||
330                 (mbMailingList.getGroupId() != mbMailingListModelImpl.getOriginalGroupId()))) {
331             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
332                 new Object[] {
333                     mbMailingListModelImpl.getOriginalUuid(),
334                     new Long(mbMailingListModelImpl.getOriginalGroupId())
335                 });
336         }
337 
338         if (isNew ||
339                 (!Validator.equals(mbMailingList.getUuid(),
340                     mbMailingListModelImpl.getOriginalUuid()) ||
341                 (mbMailingList.getGroupId() != mbMailingListModelImpl.getOriginalGroupId()))) {
342             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
343                 new Object[] {
344                     mbMailingList.getUuid(),
345                     new Long(mbMailingList.getGroupId())
346                 }, mbMailingList);
347         }
348 
349         if (!isNew &&
350                 (mbMailingList.getCategoryId() != mbMailingListModelImpl.getOriginalCategoryId())) {
351             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_CATEGORYID,
352                 new Object[] {
353                     new Long(mbMailingListModelImpl.getOriginalCategoryId())
354                 });
355         }
356 
357         if (isNew ||
358                 (mbMailingList.getCategoryId() != mbMailingListModelImpl.getOriginalCategoryId())) {
359             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_CATEGORYID,
360                 new Object[] { new Long(mbMailingList.getCategoryId()) },
361                 mbMailingList);
362         }
363 
364         return mbMailingList;
365     }
366 
367     protected MBMailingList toUnwrappedModel(MBMailingList mbMailingList) {
368         if (mbMailingList instanceof MBMailingListImpl) {
369             return mbMailingList;
370         }
371 
372         MBMailingListImpl mbMailingListImpl = new MBMailingListImpl();
373 
374         mbMailingListImpl.setNew(mbMailingList.isNew());
375         mbMailingListImpl.setPrimaryKey(mbMailingList.getPrimaryKey());
376 
377         mbMailingListImpl.setUuid(mbMailingList.getUuid());
378         mbMailingListImpl.setMailingListId(mbMailingList.getMailingListId());
379         mbMailingListImpl.setGroupId(mbMailingList.getGroupId());
380         mbMailingListImpl.setCompanyId(mbMailingList.getCompanyId());
381         mbMailingListImpl.setUserId(mbMailingList.getUserId());
382         mbMailingListImpl.setUserName(mbMailingList.getUserName());
383         mbMailingListImpl.setCreateDate(mbMailingList.getCreateDate());
384         mbMailingListImpl.setModifiedDate(mbMailingList.getModifiedDate());
385         mbMailingListImpl.setCategoryId(mbMailingList.getCategoryId());
386         mbMailingListImpl.setEmailAddress(mbMailingList.getEmailAddress());
387         mbMailingListImpl.setInProtocol(mbMailingList.getInProtocol());
388         mbMailingListImpl.setInServerName(mbMailingList.getInServerName());
389         mbMailingListImpl.setInServerPort(mbMailingList.getInServerPort());
390         mbMailingListImpl.setInUseSSL(mbMailingList.isInUseSSL());
391         mbMailingListImpl.setInUserName(mbMailingList.getInUserName());
392         mbMailingListImpl.setInPassword(mbMailingList.getInPassword());
393         mbMailingListImpl.setInReadInterval(mbMailingList.getInReadInterval());
394         mbMailingListImpl.setOutEmailAddress(mbMailingList.getOutEmailAddress());
395         mbMailingListImpl.setOutCustom(mbMailingList.isOutCustom());
396         mbMailingListImpl.setOutServerName(mbMailingList.getOutServerName());
397         mbMailingListImpl.setOutServerPort(mbMailingList.getOutServerPort());
398         mbMailingListImpl.setOutUseSSL(mbMailingList.isOutUseSSL());
399         mbMailingListImpl.setOutUserName(mbMailingList.getOutUserName());
400         mbMailingListImpl.setOutPassword(mbMailingList.getOutPassword());
401         mbMailingListImpl.setActive(mbMailingList.isActive());
402 
403         return mbMailingListImpl;
404     }
405 
406     public MBMailingList findByPrimaryKey(Serializable primaryKey)
407         throws NoSuchModelException, SystemException {
408         return findByPrimaryKey(((Long)primaryKey).longValue());
409     }
410 
411     public MBMailingList findByPrimaryKey(long mailingListId)
412         throws NoSuchMailingListException, SystemException {
413         MBMailingList mbMailingList = fetchByPrimaryKey(mailingListId);
414 
415         if (mbMailingList == null) {
416             if (_log.isWarnEnabled()) {
417                 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + mailingListId);
418             }
419 
420             throw new NoSuchMailingListException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
421                 mailingListId);
422         }
423 
424         return mbMailingList;
425     }
426 
427     public MBMailingList fetchByPrimaryKey(Serializable primaryKey)
428         throws SystemException {
429         return fetchByPrimaryKey(((Long)primaryKey).longValue());
430     }
431 
432     public MBMailingList fetchByPrimaryKey(long mailingListId)
433         throws SystemException {
434         MBMailingList mbMailingList = (MBMailingList)EntityCacheUtil.getResult(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
435                 MBMailingListImpl.class, mailingListId, this);
436 
437         if (mbMailingList == null) {
438             Session session = null;
439 
440             try {
441                 session = openSession();
442 
443                 mbMailingList = (MBMailingList)session.get(MBMailingListImpl.class,
444                         new Long(mailingListId));
445             }
446             catch (Exception e) {
447                 throw processException(e);
448             }
449             finally {
450                 if (mbMailingList != null) {
451                     cacheResult(mbMailingList);
452                 }
453 
454                 closeSession(session);
455             }
456         }
457 
458         return mbMailingList;
459     }
460 
461     public List<MBMailingList> findByUuid(String uuid)
462         throws SystemException {
463         Object[] finderArgs = new Object[] { uuid };
464 
465         List<MBMailingList> list = (List<MBMailingList>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_UUID,
466                 finderArgs, this);
467 
468         if (list == null) {
469             Session session = null;
470 
471             try {
472                 session = openSession();
473 
474                 StringBundler query = new StringBundler(2);
475 
476                 query.append(_SQL_SELECT_MBMAILINGLIST_WHERE);
477 
478                 if (uuid == null) {
479                     query.append(_FINDER_COLUMN_UUID_UUID_1);
480                 }
481                 else {
482                     if (uuid.equals(StringPool.BLANK)) {
483                         query.append(_FINDER_COLUMN_UUID_UUID_3);
484                     }
485                     else {
486                         query.append(_FINDER_COLUMN_UUID_UUID_2);
487                     }
488                 }
489 
490                 String sql = query.toString();
491 
492                 Query q = session.createQuery(sql);
493 
494                 QueryPos qPos = QueryPos.getInstance(q);
495 
496                 if (uuid != null) {
497                     qPos.add(uuid);
498                 }
499 
500                 list = q.list();
501             }
502             catch (Exception e) {
503                 throw processException(e);
504             }
505             finally {
506                 if (list == null) {
507                     list = new ArrayList<MBMailingList>();
508                 }
509 
510                 cacheResult(list);
511 
512                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_UUID, finderArgs,
513                     list);
514 
515                 closeSession(session);
516             }
517         }
518 
519         return list;
520     }
521 
522     public List<MBMailingList> findByUuid(String uuid, int start, int end)
523         throws SystemException {
524         return findByUuid(uuid, start, end, null);
525     }
526 
527     public List<MBMailingList> findByUuid(String uuid, int start, int end,
528         OrderByComparator orderByComparator) throws SystemException {
529         Object[] finderArgs = new Object[] {
530                 uuid,
531                 
532                 String.valueOf(start), String.valueOf(end),
533                 String.valueOf(orderByComparator)
534             };
535 
536         List<MBMailingList> list = (List<MBMailingList>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_UUID,
537                 finderArgs, this);
538 
539         if (list == null) {
540             Session session = null;
541 
542             try {
543                 session = openSession();
544 
545                 StringBundler query = null;
546 
547                 if (orderByComparator != null) {
548                     query = new StringBundler(3 +
549                             (orderByComparator.getOrderByFields().length * 3));
550                 }
551                 else {
552                     query = new StringBundler(2);
553                 }
554 
555                 query.append(_SQL_SELECT_MBMAILINGLIST_WHERE);
556 
557                 if (uuid == null) {
558                     query.append(_FINDER_COLUMN_UUID_UUID_1);
559                 }
560                 else {
561                     if (uuid.equals(StringPool.BLANK)) {
562                         query.append(_FINDER_COLUMN_UUID_UUID_3);
563                     }
564                     else {
565                         query.append(_FINDER_COLUMN_UUID_UUID_2);
566                     }
567                 }
568 
569                 if (orderByComparator != null) {
570                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
571                         orderByComparator);
572                 }
573 
574                 String sql = query.toString();
575 
576                 Query q = session.createQuery(sql);
577 
578                 QueryPos qPos = QueryPos.getInstance(q);
579 
580                 if (uuid != null) {
581                     qPos.add(uuid);
582                 }
583 
584                 list = (List<MBMailingList>)QueryUtil.list(q, getDialect(),
585                         start, end);
586             }
587             catch (Exception e) {
588                 throw processException(e);
589             }
590             finally {
591                 if (list == null) {
592                     list = new ArrayList<MBMailingList>();
593                 }
594 
595                 cacheResult(list);
596 
597                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_UUID,
598                     finderArgs, list);
599 
600                 closeSession(session);
601             }
602         }
603 
604         return list;
605     }
606 
607     public MBMailingList findByUuid_First(String uuid,
608         OrderByComparator orderByComparator)
609         throws NoSuchMailingListException, SystemException {
610         List<MBMailingList> list = findByUuid(uuid, 0, 1, orderByComparator);
611 
612         if (list.isEmpty()) {
613             StringBundler msg = new StringBundler(4);
614 
615             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
616 
617             msg.append("uuid=");
618             msg.append(uuid);
619 
620             msg.append(StringPool.CLOSE_CURLY_BRACE);
621 
622             throw new NoSuchMailingListException(msg.toString());
623         }
624         else {
625             return list.get(0);
626         }
627     }
628 
629     public MBMailingList findByUuid_Last(String uuid,
630         OrderByComparator orderByComparator)
631         throws NoSuchMailingListException, SystemException {
632         int count = countByUuid(uuid);
633 
634         List<MBMailingList> list = findByUuid(uuid, count - 1, count,
635                 orderByComparator);
636 
637         if (list.isEmpty()) {
638             StringBundler msg = new StringBundler(4);
639 
640             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
641 
642             msg.append("uuid=");
643             msg.append(uuid);
644 
645             msg.append(StringPool.CLOSE_CURLY_BRACE);
646 
647             throw new NoSuchMailingListException(msg.toString());
648         }
649         else {
650             return list.get(0);
651         }
652     }
653 
654     public MBMailingList[] findByUuid_PrevAndNext(long mailingListId,
655         String uuid, OrderByComparator orderByComparator)
656         throws NoSuchMailingListException, SystemException {
657         MBMailingList mbMailingList = findByPrimaryKey(mailingListId);
658 
659         int count = countByUuid(uuid);
660 
661         Session session = null;
662 
663         try {
664             session = openSession();
665 
666             StringBundler query = null;
667 
668             if (orderByComparator != null) {
669                 query = new StringBundler(3 +
670                         (orderByComparator.getOrderByFields().length * 3));
671             }
672             else {
673                 query = new StringBundler(2);
674             }
675 
676             query.append(_SQL_SELECT_MBMAILINGLIST_WHERE);
677 
678             if (uuid == null) {
679                 query.append(_FINDER_COLUMN_UUID_UUID_1);
680             }
681             else {
682                 if (uuid.equals(StringPool.BLANK)) {
683                     query.append(_FINDER_COLUMN_UUID_UUID_3);
684                 }
685                 else {
686                     query.append(_FINDER_COLUMN_UUID_UUID_2);
687                 }
688             }
689 
690             if (orderByComparator != null) {
691                 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
692                     orderByComparator);
693             }
694 
695             String sql = query.toString();
696 
697             Query q = session.createQuery(sql);
698 
699             QueryPos qPos = QueryPos.getInstance(q);
700 
701             if (uuid != null) {
702                 qPos.add(uuid);
703             }
704 
705             Object[] objArray = QueryUtil.getPrevAndNext(q, count,
706                     orderByComparator, mbMailingList);
707 
708             MBMailingList[] array = new MBMailingListImpl[3];
709 
710             array[0] = (MBMailingList)objArray[0];
711             array[1] = (MBMailingList)objArray[1];
712             array[2] = (MBMailingList)objArray[2];
713 
714             return array;
715         }
716         catch (Exception e) {
717             throw processException(e);
718         }
719         finally {
720             closeSession(session);
721         }
722     }
723 
724     public MBMailingList findByUUID_G(String uuid, long groupId)
725         throws NoSuchMailingListException, SystemException {
726         MBMailingList mbMailingList = fetchByUUID_G(uuid, groupId);
727 
728         if (mbMailingList == null) {
729             StringBundler msg = new StringBundler(6);
730 
731             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
732 
733             msg.append("uuid=");
734             msg.append(uuid);
735 
736             msg.append(", groupId=");
737             msg.append(groupId);
738 
739             msg.append(StringPool.CLOSE_CURLY_BRACE);
740 
741             if (_log.isWarnEnabled()) {
742                 _log.warn(msg.toString());
743             }
744 
745             throw new NoSuchMailingListException(msg.toString());
746         }
747 
748         return mbMailingList;
749     }
750 
751     public MBMailingList fetchByUUID_G(String uuid, long groupId)
752         throws SystemException {
753         return fetchByUUID_G(uuid, groupId, true);
754     }
755 
756     public MBMailingList fetchByUUID_G(String uuid, long groupId,
757         boolean retrieveFromCache) throws SystemException {
758         Object[] finderArgs = new Object[] { uuid, new Long(groupId) };
759 
760         Object result = null;
761 
762         if (retrieveFromCache) {
763             result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
764                     finderArgs, this);
765         }
766 
767         if (result == null) {
768             Session session = null;
769 
770             try {
771                 session = openSession();
772 
773                 StringBundler query = new StringBundler(3);
774 
775                 query.append(_SQL_SELECT_MBMAILINGLIST_WHERE);
776 
777                 if (uuid == null) {
778                     query.append(_FINDER_COLUMN_UUID_G_UUID_1);
779                 }
780                 else {
781                     if (uuid.equals(StringPool.BLANK)) {
782                         query.append(_FINDER_COLUMN_UUID_G_UUID_3);
783                     }
784                     else {
785                         query.append(_FINDER_COLUMN_UUID_G_UUID_2);
786                     }
787                 }
788 
789                 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
790 
791                 String sql = query.toString();
792 
793                 Query q = session.createQuery(sql);
794 
795                 QueryPos qPos = QueryPos.getInstance(q);
796 
797                 if (uuid != null) {
798                     qPos.add(uuid);
799                 }
800 
801                 qPos.add(groupId);
802 
803                 List<MBMailingList> list = q.list();
804 
805                 result = list;
806 
807                 MBMailingList mbMailingList = null;
808 
809                 if (list.isEmpty()) {
810                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
811                         finderArgs, list);
812                 }
813                 else {
814                     mbMailingList = list.get(0);
815 
816                     cacheResult(mbMailingList);
817 
818                     if ((mbMailingList.getUuid() == null) ||
819                             !mbMailingList.getUuid().equals(uuid) ||
820                             (mbMailingList.getGroupId() != groupId)) {
821                         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
822                             finderArgs, mbMailingList);
823                     }
824                 }
825 
826                 return mbMailingList;
827             }
828             catch (Exception e) {
829                 throw processException(e);
830             }
831             finally {
832                 if (result == null) {
833                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
834                         finderArgs, new ArrayList<MBMailingList>());
835                 }
836 
837                 closeSession(session);
838             }
839         }
840         else {
841             if (result instanceof List<?>) {
842                 return null;
843             }
844             else {
845                 return (MBMailingList)result;
846             }
847         }
848     }
849 
850     public MBMailingList findByCategoryId(long categoryId)
851         throws NoSuchMailingListException, SystemException {
852         MBMailingList mbMailingList = fetchByCategoryId(categoryId);
853 
854         if (mbMailingList == null) {
855             StringBundler msg = new StringBundler(4);
856 
857             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
858 
859             msg.append("categoryId=");
860             msg.append(categoryId);
861 
862             msg.append(StringPool.CLOSE_CURLY_BRACE);
863 
864             if (_log.isWarnEnabled()) {
865                 _log.warn(msg.toString());
866             }
867 
868             throw new NoSuchMailingListException(msg.toString());
869         }
870 
871         return mbMailingList;
872     }
873 
874     public MBMailingList fetchByCategoryId(long categoryId)
875         throws SystemException {
876         return fetchByCategoryId(categoryId, true);
877     }
878 
879     public MBMailingList fetchByCategoryId(long categoryId,
880         boolean retrieveFromCache) throws SystemException {
881         Object[] finderArgs = new Object[] { new Long(categoryId) };
882 
883         Object result = null;
884 
885         if (retrieveFromCache) {
886             result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_CATEGORYID,
887                     finderArgs, this);
888         }
889 
890         if (result == null) {
891             Session session = null;
892 
893             try {
894                 session = openSession();
895 
896                 StringBundler query = new StringBundler(2);
897 
898                 query.append(_SQL_SELECT_MBMAILINGLIST_WHERE);
899 
900                 query.append(_FINDER_COLUMN_CATEGORYID_CATEGORYID_2);
901 
902                 String sql = query.toString();
903 
904                 Query q = session.createQuery(sql);
905 
906                 QueryPos qPos = QueryPos.getInstance(q);
907 
908                 qPos.add(categoryId);
909 
910                 List<MBMailingList> list = q.list();
911 
912                 result = list;
913 
914                 MBMailingList mbMailingList = null;
915 
916                 if (list.isEmpty()) {
917                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_CATEGORYID,
918                         finderArgs, list);
919                 }
920                 else {
921                     mbMailingList = list.get(0);
922 
923                     cacheResult(mbMailingList);
924 
925                     if ((mbMailingList.getCategoryId() != categoryId)) {
926                         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_CATEGORYID,
927                             finderArgs, mbMailingList);
928                     }
929                 }
930 
931                 return mbMailingList;
932             }
933             catch (Exception e) {
934                 throw processException(e);
935             }
936             finally {
937                 if (result == null) {
938                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_CATEGORYID,
939                         finderArgs, new ArrayList<MBMailingList>());
940                 }
941 
942                 closeSession(session);
943             }
944         }
945         else {
946             if (result instanceof List<?>) {
947                 return null;
948             }
949             else {
950                 return (MBMailingList)result;
951             }
952         }
953     }
954 
955     public List<MBMailingList> findByActive(boolean active)
956         throws SystemException {
957         Object[] finderArgs = new Object[] { Boolean.valueOf(active) };
958 
959         List<MBMailingList> list = (List<MBMailingList>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_ACTIVE,
960                 finderArgs, this);
961 
962         if (list == null) {
963             Session session = null;
964 
965             try {
966                 session = openSession();
967 
968                 StringBundler query = new StringBundler(2);
969 
970                 query.append(_SQL_SELECT_MBMAILINGLIST_WHERE);
971 
972                 query.append(_FINDER_COLUMN_ACTIVE_ACTIVE_2);
973 
974                 String sql = query.toString();
975 
976                 Query q = session.createQuery(sql);
977 
978                 QueryPos qPos = QueryPos.getInstance(q);
979 
980                 qPos.add(active);
981 
982                 list = q.list();
983             }
984             catch (Exception e) {
985                 throw processException(e);
986             }
987             finally {
988                 if (list == null) {
989                     list = new ArrayList<MBMailingList>();
990                 }
991 
992                 cacheResult(list);
993 
994                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_ACTIVE,
995                     finderArgs, list);
996 
997                 closeSession(session);
998             }
999         }
1000
1001        return list;
1002    }
1003
1004    public List<MBMailingList> findByActive(boolean active, int start, int end)
1005        throws SystemException {
1006        return findByActive(active, start, end, null);
1007    }
1008
1009    public List<MBMailingList> findByActive(boolean active, int start, int end,
1010        OrderByComparator orderByComparator) throws SystemException {
1011        Object[] finderArgs = new Object[] {
1012                Boolean.valueOf(active),
1013                
1014                String.valueOf(start), String.valueOf(end),
1015                String.valueOf(orderByComparator)
1016            };
1017
1018        List<MBMailingList> list = (List<MBMailingList>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_ACTIVE,
1019                finderArgs, this);
1020
1021        if (list == null) {
1022            Session session = null;
1023
1024            try {
1025                session = openSession();
1026
1027                StringBundler query = null;
1028
1029                if (orderByComparator != null) {
1030                    query = new StringBundler(3 +
1031                            (orderByComparator.getOrderByFields().length * 3));
1032                }
1033                else {
1034                    query = new StringBundler(2);
1035                }
1036
1037                query.append(_SQL_SELECT_MBMAILINGLIST_WHERE);
1038
1039                query.append(_FINDER_COLUMN_ACTIVE_ACTIVE_2);
1040
1041                if (orderByComparator != null) {
1042                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1043                        orderByComparator);
1044                }
1045
1046                String sql = query.toString();
1047
1048                Query q = session.createQuery(sql);
1049
1050                QueryPos qPos = QueryPos.getInstance(q);
1051
1052                qPos.add(active);
1053
1054                list = (List<MBMailingList>)QueryUtil.list(q, getDialect(),
1055                        start, end);
1056            }
1057            catch (Exception e) {
1058                throw processException(e);
1059            }
1060            finally {
1061                if (list == null) {
1062                    list = new ArrayList<MBMailingList>();
1063                }
1064
1065                cacheResult(list);
1066
1067                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_ACTIVE,
1068                    finderArgs, list);
1069
1070                closeSession(session);
1071            }
1072        }
1073
1074        return list;
1075    }
1076
1077    public MBMailingList findByActive_First(boolean active,
1078        OrderByComparator orderByComparator)
1079        throws NoSuchMailingListException, SystemException {
1080        List<MBMailingList> list = findByActive(active, 0, 1, orderByComparator);
1081
1082        if (list.isEmpty()) {
1083            StringBundler msg = new StringBundler(4);
1084
1085            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1086
1087            msg.append("active=");
1088            msg.append(active);
1089
1090            msg.append(StringPool.CLOSE_CURLY_BRACE);
1091
1092            throw new NoSuchMailingListException(msg.toString());
1093        }
1094        else {
1095            return list.get(0);
1096        }
1097    }
1098
1099    public MBMailingList findByActive_Last(boolean active,
1100        OrderByComparator orderByComparator)
1101        throws NoSuchMailingListException, SystemException {
1102        int count = countByActive(active);
1103
1104        List<MBMailingList> list = findByActive(active, count - 1, count,
1105                orderByComparator);
1106
1107        if (list.isEmpty()) {
1108            StringBundler msg = new StringBundler(4);
1109
1110            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1111
1112            msg.append("active=");
1113            msg.append(active);
1114
1115            msg.append(StringPool.CLOSE_CURLY_BRACE);
1116
1117            throw new NoSuchMailingListException(msg.toString());
1118        }
1119        else {
1120            return list.get(0);
1121        }
1122    }
1123
1124    public MBMailingList[] findByActive_PrevAndNext(long mailingListId,
1125        boolean active, OrderByComparator orderByComparator)
1126        throws NoSuchMailingListException, SystemException {
1127        MBMailingList mbMailingList = findByPrimaryKey(mailingListId);
1128
1129        int count = countByActive(active);
1130
1131        Session session = null;
1132
1133        try {
1134            session = openSession();
1135
1136            StringBundler query = null;
1137
1138            if (orderByComparator != null) {
1139                query = new StringBundler(3 +
1140                        (orderByComparator.getOrderByFields().length * 3));
1141            }
1142            else {
1143                query = new StringBundler(2);
1144            }
1145
1146            query.append(_SQL_SELECT_MBMAILINGLIST_WHERE);
1147
1148            query.append(_FINDER_COLUMN_ACTIVE_ACTIVE_2);
1149
1150            if (orderByComparator != null) {
1151                appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1152                    orderByComparator);
1153            }
1154
1155            String sql = query.toString();
1156
1157            Query q = session.createQuery(sql);
1158
1159            QueryPos qPos = QueryPos.getInstance(q);
1160
1161            qPos.add(active);
1162
1163            Object[] objArray = QueryUtil.getPrevAndNext(q, count,
1164                    orderByComparator, mbMailingList);
1165
1166            MBMailingList[] array = new MBMailingListImpl[3];
1167
1168            array[0] = (MBMailingList)objArray[0];
1169            array[1] = (MBMailingList)objArray[1];
1170            array[2] = (MBMailingList)objArray[2];
1171
1172            return array;
1173        }
1174        catch (Exception e) {
1175            throw processException(e);
1176        }
1177        finally {
1178            closeSession(session);
1179        }
1180    }
1181
1182    public List<MBMailingList> findAll() throws SystemException {
1183        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1184    }
1185
1186    public List<MBMailingList> findAll(int start, int end)
1187        throws SystemException {
1188        return findAll(start, end, null);
1189    }
1190
1191    public List<MBMailingList> findAll(int start, int end,
1192        OrderByComparator orderByComparator) throws SystemException {
1193        Object[] finderArgs = new Object[] {
1194                String.valueOf(start), String.valueOf(end),
1195                String.valueOf(orderByComparator)
1196            };
1197
1198        List<MBMailingList> list = (List<MBMailingList>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1199                finderArgs, this);
1200
1201        if (list == null) {
1202            Session session = null;
1203
1204            try {
1205                session = openSession();
1206
1207                StringBundler query = null;
1208                String sql = null;
1209
1210                if (orderByComparator != null) {
1211                    query = new StringBundler(2 +
1212                            (orderByComparator.getOrderByFields().length * 3));
1213
1214                    query.append(_SQL_SELECT_MBMAILINGLIST);
1215
1216                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1217                        orderByComparator);
1218
1219                    sql = query.toString();
1220                }
1221
1222                sql = _SQL_SELECT_MBMAILINGLIST;
1223
1224                Query q = session.createQuery(sql);
1225
1226                if (orderByComparator == null) {
1227                    list = (List<MBMailingList>)QueryUtil.list(q, getDialect(),
1228                            start, end, false);
1229
1230                    Collections.sort(list);
1231                }
1232                else {
1233                    list = (List<MBMailingList>)QueryUtil.list(q, getDialect(),
1234                            start, end);
1235                }
1236            }
1237            catch (Exception e) {
1238                throw processException(e);
1239            }
1240            finally {
1241                if (list == null) {
1242                    list = new ArrayList<MBMailingList>();
1243                }
1244
1245                cacheResult(list);
1246
1247                FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1248
1249                closeSession(session);
1250            }
1251        }
1252
1253        return list;
1254    }
1255
1256    public void removeByUuid(String uuid) throws SystemException {
1257        for (MBMailingList mbMailingList : findByUuid(uuid)) {
1258            remove(mbMailingList);
1259        }
1260    }
1261
1262    public void removeByUUID_G(String uuid, long groupId)
1263        throws NoSuchMailingListException, SystemException {
1264        MBMailingList mbMailingList = findByUUID_G(uuid, groupId);
1265
1266        remove(mbMailingList);
1267    }
1268
1269    public void removeByCategoryId(long categoryId)
1270        throws NoSuchMailingListException, SystemException {
1271        MBMailingList mbMailingList = findByCategoryId(categoryId);
1272
1273        remove(mbMailingList);
1274    }
1275
1276    public void removeByActive(boolean active) throws SystemException {
1277        for (MBMailingList mbMailingList : findByActive(active)) {
1278            remove(mbMailingList);
1279        }
1280    }
1281
1282    public void removeAll() throws SystemException {
1283        for (MBMailingList mbMailingList : findAll()) {
1284            remove(mbMailingList);
1285        }
1286    }
1287
1288    public int countByUuid(String uuid) throws SystemException {
1289        Object[] finderArgs = new Object[] { uuid };
1290
1291        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
1292                finderArgs, this);
1293
1294        if (count == null) {
1295            Session session = null;
1296
1297            try {
1298                session = openSession();
1299
1300                StringBundler query = new StringBundler(2);
1301
1302                query.append(_SQL_COUNT_MBMAILINGLIST_WHERE);
1303
1304                if (uuid == null) {
1305                    query.append(_FINDER_COLUMN_UUID_UUID_1);
1306                }
1307                else {
1308                    if (uuid.equals(StringPool.BLANK)) {
1309                        query.append(_FINDER_COLUMN_UUID_UUID_3);
1310                    }
1311                    else {
1312                        query.append(_FINDER_COLUMN_UUID_UUID_2);
1313                    }
1314                }
1315
1316                String sql = query.toString();
1317
1318                Query q = session.createQuery(sql);
1319
1320                QueryPos qPos = QueryPos.getInstance(q);
1321
1322                if (uuid != null) {
1323                    qPos.add(uuid);
1324                }
1325
1326                count = (Long)q.uniqueResult();
1327            }
1328            catch (Exception e) {
1329                throw processException(e);
1330            }
1331            finally {
1332                if (count == null) {
1333                    count = Long.valueOf(0);
1334                }
1335
1336                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
1337                    finderArgs, count);
1338
1339                closeSession(session);
1340            }
1341        }
1342
1343        return count.intValue();
1344    }
1345
1346    public int countByUUID_G(String uuid, long groupId)
1347        throws SystemException {
1348        Object[] finderArgs = new Object[] { uuid, new Long(groupId) };
1349
1350        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
1351                finderArgs, this);
1352
1353        if (count == null) {
1354            Session session = null;
1355
1356            try {
1357                session = openSession();
1358
1359                StringBundler query = new StringBundler(3);
1360
1361                query.append(_SQL_COUNT_MBMAILINGLIST_WHERE);
1362
1363                if (uuid == null) {
1364                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
1365                }
1366                else {
1367                    if (uuid.equals(StringPool.BLANK)) {
1368                        query.append(_FINDER_COLUMN_UUID_G_UUID_3);
1369                    }
1370                    else {
1371                        query.append(_FINDER_COLUMN_UUID_G_UUID_2);
1372                    }
1373                }
1374
1375                query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
1376
1377                String sql = query.toString();
1378
1379                Query q = session.createQuery(sql);
1380
1381                QueryPos qPos = QueryPos.getInstance(q);
1382
1383                if (uuid != null) {
1384                    qPos.add(uuid);
1385                }
1386
1387                qPos.add(groupId);
1388
1389                count = (Long)q.uniqueResult();
1390            }
1391            catch (Exception e) {
1392                throw processException(e);
1393            }
1394            finally {
1395                if (count == null) {
1396                    count = Long.valueOf(0);
1397                }
1398
1399                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
1400                    finderArgs, count);
1401
1402                closeSession(session);
1403            }
1404        }
1405
1406        return count.intValue();
1407    }
1408
1409    public int countByCategoryId(long categoryId) throws SystemException {
1410        Object[] finderArgs = new Object[] { new Long(categoryId) };
1411
1412        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_CATEGORYID,
1413                finderArgs, this);
1414
1415        if (count == null) {
1416            Session session = null;
1417
1418            try {
1419                session = openSession();
1420
1421                StringBundler query = new StringBundler(2);
1422
1423                query.append(_SQL_COUNT_MBMAILINGLIST_WHERE);
1424
1425                query.append(_FINDER_COLUMN_CATEGORYID_CATEGORYID_2);
1426
1427                String sql = query.toString();
1428
1429                Query q = session.createQuery(sql);
1430
1431                QueryPos qPos = QueryPos.getInstance(q);
1432
1433                qPos.add(categoryId);
1434
1435                count = (Long)q.uniqueResult();
1436            }
1437            catch (Exception e) {
1438                throw processException(e);
1439            }
1440            finally {
1441                if (count == null) {
1442                    count = Long.valueOf(0);
1443                }
1444
1445                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_CATEGORYID,
1446                    finderArgs, count);
1447
1448                closeSession(session);
1449            }
1450        }
1451
1452        return count.intValue();
1453    }
1454
1455    public int countByActive(boolean active) throws SystemException {
1456        Object[] finderArgs = new Object[] { Boolean.valueOf(active) };
1457
1458        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ACTIVE,
1459                finderArgs, this);
1460
1461        if (count == null) {
1462            Session session = null;
1463
1464            try {
1465                session = openSession();
1466
1467                StringBundler query = new StringBundler(2);
1468
1469                query.append(_SQL_COUNT_MBMAILINGLIST_WHERE);
1470
1471                query.append(_FINDER_COLUMN_ACTIVE_ACTIVE_2);
1472
1473                String sql = query.toString();
1474
1475                Query q = session.createQuery(sql);
1476
1477                QueryPos qPos = QueryPos.getInstance(q);
1478
1479                qPos.add(active);
1480
1481                count = (Long)q.uniqueResult();
1482            }
1483            catch (Exception e) {
1484                throw processException(e);
1485            }
1486            finally {
1487                if (count == null) {
1488                    count = Long.valueOf(0);
1489                }
1490
1491                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ACTIVE,
1492                    finderArgs, count);
1493
1494                closeSession(session);
1495            }
1496        }
1497
1498        return count.intValue();
1499    }
1500
1501    public int countAll() throws SystemException {
1502        Object[] finderArgs = new Object[0];
1503
1504        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1505                finderArgs, this);
1506
1507        if (count == null) {
1508            Session session = null;
1509
1510            try {
1511                session = openSession();
1512
1513                Query q = session.createQuery(_SQL_COUNT_MBMAILINGLIST);
1514
1515                count = (Long)q.uniqueResult();
1516            }
1517            catch (Exception e) {
1518                throw processException(e);
1519            }
1520            finally {
1521                if (count == null) {
1522                    count = Long.valueOf(0);
1523                }
1524
1525                FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1526                    count);
1527
1528                closeSession(session);
1529            }
1530        }
1531
1532        return count.intValue();
1533    }
1534
1535    public void afterPropertiesSet() {
1536        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1537                    com.liferay.portal.util.PropsUtil.get(
1538                        "value.object.listener.com.liferay.portlet.messageboards.model.MBMailingList")));
1539
1540        if (listenerClassNames.length > 0) {
1541            try {
1542                List<ModelListener<MBMailingList>> listenersList = new ArrayList<ModelListener<MBMailingList>>();
1543
1544                for (String listenerClassName : listenerClassNames) {
1545                    listenersList.add((ModelListener<MBMailingList>)Class.forName(
1546                            listenerClassName).newInstance());
1547                }
1548
1549                listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1550            }
1551            catch (Exception e) {
1552                _log.error(e);
1553            }
1554        }
1555    }
1556
1557    @BeanReference(type = MBBanPersistence.class)
1558    protected MBBanPersistence mbBanPersistence;
1559    @BeanReference(type = MBCategoryPersistence.class)
1560    protected MBCategoryPersistence mbCategoryPersistence;
1561    @BeanReference(type = MBDiscussionPersistence.class)
1562    protected MBDiscussionPersistence mbDiscussionPersistence;
1563    @BeanReference(type = MBMailingListPersistence.class)
1564    protected MBMailingListPersistence mbMailingListPersistence;
1565    @BeanReference(type = MBMessagePersistence.class)
1566    protected MBMessagePersistence mbMessagePersistence;
1567    @BeanReference(type = MBMessageFlagPersistence.class)
1568    protected MBMessageFlagPersistence mbMessageFlagPersistence;
1569    @BeanReference(type = MBStatsUserPersistence.class)
1570    protected MBStatsUserPersistence mbStatsUserPersistence;
1571    @BeanReference(type = MBThreadPersistence.class)
1572    protected MBThreadPersistence mbThreadPersistence;
1573    @BeanReference(type = ResourcePersistence.class)
1574    protected ResourcePersistence resourcePersistence;
1575    @BeanReference(type = UserPersistence.class)
1576    protected UserPersistence userPersistence;
1577    private static final String _SQL_SELECT_MBMAILINGLIST = "SELECT mbMailingList FROM MBMailingList mbMailingList";
1578    private static final String _SQL_SELECT_MBMAILINGLIST_WHERE = "SELECT mbMailingList FROM MBMailingList mbMailingList WHERE ";
1579    private static final String _SQL_COUNT_MBMAILINGLIST = "SELECT COUNT(mbMailingList) FROM MBMailingList mbMailingList";
1580    private static final String _SQL_COUNT_MBMAILINGLIST_WHERE = "SELECT COUNT(mbMailingList) FROM MBMailingList mbMailingList WHERE ";
1581    private static final String _FINDER_COLUMN_UUID_UUID_1 = "mbMailingList.uuid IS NULL";
1582    private static final String _FINDER_COLUMN_UUID_UUID_2 = "mbMailingList.uuid = ?";
1583    private static final String _FINDER_COLUMN_UUID_UUID_3 = "(mbMailingList.uuid IS NULL OR mbMailingList.uuid = ?)";
1584    private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "mbMailingList.uuid IS NULL AND ";
1585    private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "mbMailingList.uuid = ? AND ";
1586    private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(mbMailingList.uuid IS NULL OR mbMailingList.uuid = ?) AND ";
1587    private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "mbMailingList.groupId = ?";
1588    private static final String _FINDER_COLUMN_CATEGORYID_CATEGORYID_2 = "mbMailingList.categoryId = ?";
1589    private static final String _FINDER_COLUMN_ACTIVE_ACTIVE_2 = "mbMailingList.active = ?";
1590    private static final String _ORDER_BY_ENTITY_ALIAS = "mbMailingList.";
1591    private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBMailingList exists with the primary key ";
1592    private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBMailingList exists with the key {";
1593    private static Log _log = LogFactoryUtil.getLog(MBMailingListPersistenceImpl.class);
1594}