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