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