1   /**
2    * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portlet.blogs.service.persistence;
24  
25  import com.liferay.portal.SystemException;
26  import com.liferay.portal.kernel.dao.orm.DynamicQuery;
27  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
28  import com.liferay.portal.kernel.dao.orm.Query;
29  import com.liferay.portal.kernel.dao.orm.QueryPos;
30  import com.liferay.portal.kernel.dao.orm.QueryUtil;
31  import com.liferay.portal.kernel.dao.orm.Session;
32  import com.liferay.portal.kernel.util.CalendarUtil;
33  import com.liferay.portal.kernel.util.GetterUtil;
34  import com.liferay.portal.kernel.util.ListUtil;
35  import com.liferay.portal.kernel.util.OrderByComparator;
36  import com.liferay.portal.kernel.util.StringPool;
37  import com.liferay.portal.kernel.util.StringUtil;
38  import com.liferay.portal.kernel.util.Validator;
39  import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
40  import com.liferay.portal.model.ModelListener;
41  import com.liferay.portal.service.persistence.BatchSessionUtil;
42  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
43  
44  import com.liferay.portlet.blogs.NoSuchEntryException;
45  import com.liferay.portlet.blogs.model.BlogsEntry;
46  import com.liferay.portlet.blogs.model.impl.BlogsEntryImpl;
47  import com.liferay.portlet.blogs.model.impl.BlogsEntryModelImpl;
48  
49  import org.apache.commons.logging.Log;
50  import org.apache.commons.logging.LogFactory;
51  
52  import java.util.ArrayList;
53  import java.util.Collections;
54  import java.util.Date;
55  import java.util.Iterator;
56  import java.util.List;
57  
58  /**
59   * <a href="BlogsEntryPersistenceImpl.java.html"><b><i>View Source</i></b></a>
60   *
61   * @author Brian Wing Shun Chan
62   *
63   */
64  public class BlogsEntryPersistenceImpl extends BasePersistenceImpl
65      implements BlogsEntryPersistence {
66      public BlogsEntry create(long entryId) {
67          BlogsEntry blogsEntry = new BlogsEntryImpl();
68  
69          blogsEntry.setNew(true);
70          blogsEntry.setPrimaryKey(entryId);
71  
72          String uuid = PortalUUIDUtil.generate();
73  
74          blogsEntry.setUuid(uuid);
75  
76          return blogsEntry;
77      }
78  
79      public BlogsEntry remove(long entryId)
80          throws NoSuchEntryException, SystemException {
81          Session session = null;
82  
83          try {
84              session = openSession();
85  
86              BlogsEntry blogsEntry = (BlogsEntry)session.get(BlogsEntryImpl.class,
87                      new Long(entryId));
88  
89              if (blogsEntry == null) {
90                  if (_log.isWarnEnabled()) {
91                      _log.warn("No BlogsEntry exists with the primary key " +
92                          entryId);
93                  }
94  
95                  throw new NoSuchEntryException(
96                      "No BlogsEntry exists with the primary key " + entryId);
97              }
98  
99              return remove(blogsEntry);
100         }
101         catch (NoSuchEntryException nsee) {
102             throw nsee;
103         }
104         catch (Exception e) {
105             throw processException(e);
106         }
107         finally {
108             closeSession(session);
109         }
110     }
111 
112     public BlogsEntry remove(BlogsEntry blogsEntry) throws SystemException {
113         if (_listeners.length > 0) {
114             for (ModelListener listener : _listeners) {
115                 listener.onBeforeRemove(blogsEntry);
116             }
117         }
118 
119         blogsEntry = removeImpl(blogsEntry);
120 
121         if (_listeners.length > 0) {
122             for (ModelListener listener : _listeners) {
123                 listener.onAfterRemove(blogsEntry);
124             }
125         }
126 
127         return blogsEntry;
128     }
129 
130     protected BlogsEntry removeImpl(BlogsEntry blogsEntry)
131         throws SystemException {
132         Session session = null;
133 
134         try {
135             session = openSession();
136 
137             if (BatchSessionUtil.isEnabled()) {
138                 Object staleObject = session.get(BlogsEntryImpl.class,
139                         blogsEntry.getPrimaryKeyObj());
140 
141                 if (staleObject != null) {
142                     session.evict(staleObject);
143                 }
144             }
145 
146             session.delete(blogsEntry);
147 
148             session.flush();
149 
150             return blogsEntry;
151         }
152         catch (Exception e) {
153             throw processException(e);
154         }
155         finally {
156             closeSession(session);
157 
158             FinderCacheUtil.clearCache(BlogsEntry.class.getName());
159         }
160     }
161 
162     /**
163      * @deprecated Use <code>update(BlogsEntry blogsEntry, boolean merge)</code>.
164      */
165     public BlogsEntry update(BlogsEntry blogsEntry) throws SystemException {
166         if (_log.isWarnEnabled()) {
167             _log.warn(
168                 "Using the deprecated update(BlogsEntry blogsEntry) method. Use update(BlogsEntry blogsEntry, boolean merge) instead.");
169         }
170 
171         return update(blogsEntry, false);
172     }
173 
174     /**
175      * Add, update, or merge, the entity. This method also calls the model
176      * listeners to trigger the proper events associated with adding, deleting,
177      * or updating an entity.
178      *
179      * @param        blogsEntry the entity to add, update, or merge
180      * @param        merge boolean value for whether to merge the entity. The
181      *                default value is false. Setting merge to true is more
182      *                expensive and should only be true when blogsEntry is
183      *                transient. See LEP-5473 for a detailed discussion of this
184      *                method.
185      * @return        true if the portlet can be displayed via Ajax
186      */
187     public BlogsEntry update(BlogsEntry blogsEntry, boolean merge)
188         throws SystemException {
189         boolean isNew = blogsEntry.isNew();
190 
191         if (_listeners.length > 0) {
192             for (ModelListener listener : _listeners) {
193                 if (isNew) {
194                     listener.onBeforeCreate(blogsEntry);
195                 }
196                 else {
197                     listener.onBeforeUpdate(blogsEntry);
198                 }
199             }
200         }
201 
202         blogsEntry = updateImpl(blogsEntry, merge);
203 
204         if (_listeners.length > 0) {
205             for (ModelListener listener : _listeners) {
206                 if (isNew) {
207                     listener.onAfterCreate(blogsEntry);
208                 }
209                 else {
210                     listener.onAfterUpdate(blogsEntry);
211                 }
212             }
213         }
214 
215         return blogsEntry;
216     }
217 
218     public BlogsEntry updateImpl(
219         com.liferay.portlet.blogs.model.BlogsEntry blogsEntry, boolean merge)
220         throws SystemException {
221         if (Validator.isNull(blogsEntry.getUuid())) {
222             String uuid = PortalUUIDUtil.generate();
223 
224             blogsEntry.setUuid(uuid);
225         }
226 
227         Session session = null;
228 
229         try {
230             session = openSession();
231 
232             BatchSessionUtil.update(session, blogsEntry, merge);
233 
234             blogsEntry.setNew(false);
235 
236             return blogsEntry;
237         }
238         catch (Exception e) {
239             throw processException(e);
240         }
241         finally {
242             closeSession(session);
243 
244             FinderCacheUtil.clearCache(BlogsEntry.class.getName());
245         }
246     }
247 
248     public BlogsEntry findByPrimaryKey(long entryId)
249         throws NoSuchEntryException, SystemException {
250         BlogsEntry blogsEntry = fetchByPrimaryKey(entryId);
251 
252         if (blogsEntry == null) {
253             if (_log.isWarnEnabled()) {
254                 _log.warn("No BlogsEntry exists with the primary key " +
255                     entryId);
256             }
257 
258             throw new NoSuchEntryException(
259                 "No BlogsEntry exists with the primary key " + entryId);
260         }
261 
262         return blogsEntry;
263     }
264 
265     public BlogsEntry fetchByPrimaryKey(long entryId) throws SystemException {
266         Session session = null;
267 
268         try {
269             session = openSession();
270 
271             return (BlogsEntry)session.get(BlogsEntryImpl.class,
272                 new Long(entryId));
273         }
274         catch (Exception e) {
275             throw processException(e);
276         }
277         finally {
278             closeSession(session);
279         }
280     }
281 
282     public List<BlogsEntry> findByUuid(String uuid) throws SystemException {
283         boolean finderClassNameCacheEnabled = BlogsEntryModelImpl.CACHE_ENABLED;
284         String finderClassName = BlogsEntry.class.getName();
285         String finderMethodName = "findByUuid";
286         String[] finderParams = new String[] { String.class.getName() };
287         Object[] finderArgs = new Object[] { uuid };
288 
289         Object result = null;
290 
291         if (finderClassNameCacheEnabled) {
292             result = FinderCacheUtil.getResult(finderClassName,
293                     finderMethodName, finderParams, finderArgs, this);
294         }
295 
296         if (result == null) {
297             Session session = null;
298 
299             try {
300                 session = openSession();
301 
302                 StringBuilder query = new StringBuilder();
303 
304                 query.append(
305                     "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
306 
307                 if (uuid == null) {
308                     query.append("uuid_ IS NULL");
309                 }
310                 else {
311                     query.append("uuid_ = ?");
312                 }
313 
314                 query.append(" ");
315 
316                 query.append("ORDER BY ");
317 
318                 query.append("displayDate DESC");
319 
320                 Query q = session.createQuery(query.toString());
321 
322                 QueryPos qPos = QueryPos.getInstance(q);
323 
324                 if (uuid != null) {
325                     qPos.add(uuid);
326                 }
327 
328                 List<BlogsEntry> list = q.list();
329 
330                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
331                     finderClassName, finderMethodName, finderParams,
332                     finderArgs, list);
333 
334                 return list;
335             }
336             catch (Exception e) {
337                 throw processException(e);
338             }
339             finally {
340                 closeSession(session);
341             }
342         }
343         else {
344             return (List<BlogsEntry>)result;
345         }
346     }
347 
348     public List<BlogsEntry> findByUuid(String uuid, int start, int end)
349         throws SystemException {
350         return findByUuid(uuid, start, end, null);
351     }
352 
353     public List<BlogsEntry> findByUuid(String uuid, int start, int end,
354         OrderByComparator obc) throws SystemException {
355         boolean finderClassNameCacheEnabled = BlogsEntryModelImpl.CACHE_ENABLED;
356         String finderClassName = BlogsEntry.class.getName();
357         String finderMethodName = "findByUuid";
358         String[] finderParams = new String[] {
359                 String.class.getName(),
360                 
361                 "java.lang.Integer", "java.lang.Integer",
362                 "com.liferay.portal.kernel.util.OrderByComparator"
363             };
364         Object[] finderArgs = new Object[] {
365                 uuid,
366                 
367                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
368             };
369 
370         Object result = null;
371 
372         if (finderClassNameCacheEnabled) {
373             result = FinderCacheUtil.getResult(finderClassName,
374                     finderMethodName, finderParams, finderArgs, this);
375         }
376 
377         if (result == null) {
378             Session session = null;
379 
380             try {
381                 session = openSession();
382 
383                 StringBuilder query = new StringBuilder();
384 
385                 query.append(
386                     "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
387 
388                 if (uuid == null) {
389                     query.append("uuid_ IS NULL");
390                 }
391                 else {
392                     query.append("uuid_ = ?");
393                 }
394 
395                 query.append(" ");
396 
397                 if (obc != null) {
398                     query.append("ORDER BY ");
399                     query.append(obc.getOrderBy());
400                 }
401 
402                 else {
403                     query.append("ORDER BY ");
404 
405                     query.append("displayDate DESC");
406                 }
407 
408                 Query q = session.createQuery(query.toString());
409 
410                 QueryPos qPos = QueryPos.getInstance(q);
411 
412                 if (uuid != null) {
413                     qPos.add(uuid);
414                 }
415 
416                 List<BlogsEntry> list = (List<BlogsEntry>)QueryUtil.list(q,
417                         getDialect(), start, end);
418 
419                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
420                     finderClassName, finderMethodName, finderParams,
421                     finderArgs, list);
422 
423                 return list;
424             }
425             catch (Exception e) {
426                 throw processException(e);
427             }
428             finally {
429                 closeSession(session);
430             }
431         }
432         else {
433             return (List<BlogsEntry>)result;
434         }
435     }
436 
437     public BlogsEntry findByUuid_First(String uuid, OrderByComparator obc)
438         throws NoSuchEntryException, SystemException {
439         List<BlogsEntry> list = findByUuid(uuid, 0, 1, obc);
440 
441         if (list.size() == 0) {
442             StringBuilder msg = new StringBuilder();
443 
444             msg.append("No BlogsEntry exists with the key {");
445 
446             msg.append("uuid=" + uuid);
447 
448             msg.append(StringPool.CLOSE_CURLY_BRACE);
449 
450             throw new NoSuchEntryException(msg.toString());
451         }
452         else {
453             return list.get(0);
454         }
455     }
456 
457     public BlogsEntry findByUuid_Last(String uuid, OrderByComparator obc)
458         throws NoSuchEntryException, SystemException {
459         int count = countByUuid(uuid);
460 
461         List<BlogsEntry> list = findByUuid(uuid, count - 1, count, obc);
462 
463         if (list.size() == 0) {
464             StringBuilder msg = new StringBuilder();
465 
466             msg.append("No BlogsEntry exists with the key {");
467 
468             msg.append("uuid=" + uuid);
469 
470             msg.append(StringPool.CLOSE_CURLY_BRACE);
471 
472             throw new NoSuchEntryException(msg.toString());
473         }
474         else {
475             return list.get(0);
476         }
477     }
478 
479     public BlogsEntry[] findByUuid_PrevAndNext(long entryId, String uuid,
480         OrderByComparator obc) throws NoSuchEntryException, SystemException {
481         BlogsEntry blogsEntry = findByPrimaryKey(entryId);
482 
483         int count = countByUuid(uuid);
484 
485         Session session = null;
486 
487         try {
488             session = openSession();
489 
490             StringBuilder query = new StringBuilder();
491 
492             query.append(
493                 "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
494 
495             if (uuid == null) {
496                 query.append("uuid_ IS NULL");
497             }
498             else {
499                 query.append("uuid_ = ?");
500             }
501 
502             query.append(" ");
503 
504             if (obc != null) {
505                 query.append("ORDER BY ");
506                 query.append(obc.getOrderBy());
507             }
508 
509             else {
510                 query.append("ORDER BY ");
511 
512                 query.append("displayDate DESC");
513             }
514 
515             Query q = session.createQuery(query.toString());
516 
517             QueryPos qPos = QueryPos.getInstance(q);
518 
519             if (uuid != null) {
520                 qPos.add(uuid);
521             }
522 
523             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
524                     blogsEntry);
525 
526             BlogsEntry[] array = new BlogsEntryImpl[3];
527 
528             array[0] = (BlogsEntry)objArray[0];
529             array[1] = (BlogsEntry)objArray[1];
530             array[2] = (BlogsEntry)objArray[2];
531 
532             return array;
533         }
534         catch (Exception e) {
535             throw processException(e);
536         }
537         finally {
538             closeSession(session);
539         }
540     }
541 
542     public BlogsEntry findByUUID_G(String uuid, long groupId)
543         throws NoSuchEntryException, SystemException {
544         BlogsEntry blogsEntry = fetchByUUID_G(uuid, groupId);
545 
546         if (blogsEntry == null) {
547             StringBuilder msg = new StringBuilder();
548 
549             msg.append("No BlogsEntry exists with the key {");
550 
551             msg.append("uuid=" + uuid);
552 
553             msg.append(", ");
554             msg.append("groupId=" + groupId);
555 
556             msg.append(StringPool.CLOSE_CURLY_BRACE);
557 
558             if (_log.isWarnEnabled()) {
559                 _log.warn(msg.toString());
560             }
561 
562             throw new NoSuchEntryException(msg.toString());
563         }
564 
565         return blogsEntry;
566     }
567 
568     public BlogsEntry fetchByUUID_G(String uuid, long groupId)
569         throws SystemException {
570         boolean finderClassNameCacheEnabled = BlogsEntryModelImpl.CACHE_ENABLED;
571         String finderClassName = BlogsEntry.class.getName();
572         String finderMethodName = "fetchByUUID_G";
573         String[] finderParams = new String[] {
574                 String.class.getName(), Long.class.getName()
575             };
576         Object[] finderArgs = new Object[] { uuid, new Long(groupId) };
577 
578         Object result = null;
579 
580         if (finderClassNameCacheEnabled) {
581             result = FinderCacheUtil.getResult(finderClassName,
582                     finderMethodName, finderParams, finderArgs, this);
583         }
584 
585         if (result == null) {
586             Session session = null;
587 
588             try {
589                 session = openSession();
590 
591                 StringBuilder query = new StringBuilder();
592 
593                 query.append(
594                     "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
595 
596                 if (uuid == null) {
597                     query.append("uuid_ IS NULL");
598                 }
599                 else {
600                     query.append("uuid_ = ?");
601                 }
602 
603                 query.append(" AND ");
604 
605                 query.append("groupId = ?");
606 
607                 query.append(" ");
608 
609                 query.append("ORDER BY ");
610 
611                 query.append("displayDate DESC");
612 
613                 Query q = session.createQuery(query.toString());
614 
615                 QueryPos qPos = QueryPos.getInstance(q);
616 
617                 if (uuid != null) {
618                     qPos.add(uuid);
619                 }
620 
621                 qPos.add(groupId);
622 
623                 List<BlogsEntry> list = q.list();
624 
625                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
626                     finderClassName, finderMethodName, finderParams,
627                     finderArgs, list);
628 
629                 if (list.size() == 0) {
630                     return null;
631                 }
632                 else {
633                     return list.get(0);
634                 }
635             }
636             catch (Exception e) {
637                 throw processException(e);
638             }
639             finally {
640                 closeSession(session);
641             }
642         }
643         else {
644             List<BlogsEntry> list = (List<BlogsEntry>)result;
645 
646             if (list.size() == 0) {
647                 return null;
648             }
649             else {
650                 return list.get(0);
651             }
652         }
653     }
654 
655     public List<BlogsEntry> findByGroupId(long groupId)
656         throws SystemException {
657         boolean finderClassNameCacheEnabled = BlogsEntryModelImpl.CACHE_ENABLED;
658         String finderClassName = BlogsEntry.class.getName();
659         String finderMethodName = "findByGroupId";
660         String[] finderParams = new String[] { Long.class.getName() };
661         Object[] finderArgs = new Object[] { new Long(groupId) };
662 
663         Object result = null;
664 
665         if (finderClassNameCacheEnabled) {
666             result = FinderCacheUtil.getResult(finderClassName,
667                     finderMethodName, finderParams, finderArgs, this);
668         }
669 
670         if (result == null) {
671             Session session = null;
672 
673             try {
674                 session = openSession();
675 
676                 StringBuilder query = new StringBuilder();
677 
678                 query.append(
679                     "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
680 
681                 query.append("groupId = ?");
682 
683                 query.append(" ");
684 
685                 query.append("ORDER BY ");
686 
687                 query.append("displayDate DESC");
688 
689                 Query q = session.createQuery(query.toString());
690 
691                 QueryPos qPos = QueryPos.getInstance(q);
692 
693                 qPos.add(groupId);
694 
695                 List<BlogsEntry> list = q.list();
696 
697                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
698                     finderClassName, finderMethodName, finderParams,
699                     finderArgs, list);
700 
701                 return list;
702             }
703             catch (Exception e) {
704                 throw processException(e);
705             }
706             finally {
707                 closeSession(session);
708             }
709         }
710         else {
711             return (List<BlogsEntry>)result;
712         }
713     }
714 
715     public List<BlogsEntry> findByGroupId(long groupId, int start, int end)
716         throws SystemException {
717         return findByGroupId(groupId, start, end, null);
718     }
719 
720     public List<BlogsEntry> findByGroupId(long groupId, int start, int end,
721         OrderByComparator obc) throws SystemException {
722         boolean finderClassNameCacheEnabled = BlogsEntryModelImpl.CACHE_ENABLED;
723         String finderClassName = BlogsEntry.class.getName();
724         String finderMethodName = "findByGroupId";
725         String[] finderParams = new String[] {
726                 Long.class.getName(),
727                 
728                 "java.lang.Integer", "java.lang.Integer",
729                 "com.liferay.portal.kernel.util.OrderByComparator"
730             };
731         Object[] finderArgs = new Object[] {
732                 new Long(groupId),
733                 
734                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
735             };
736 
737         Object result = null;
738 
739         if (finderClassNameCacheEnabled) {
740             result = FinderCacheUtil.getResult(finderClassName,
741                     finderMethodName, finderParams, finderArgs, this);
742         }
743 
744         if (result == null) {
745             Session session = null;
746 
747             try {
748                 session = openSession();
749 
750                 StringBuilder query = new StringBuilder();
751 
752                 query.append(
753                     "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
754 
755                 query.append("groupId = ?");
756 
757                 query.append(" ");
758 
759                 if (obc != null) {
760                     query.append("ORDER BY ");
761                     query.append(obc.getOrderBy());
762                 }
763 
764                 else {
765                     query.append("ORDER BY ");
766 
767                     query.append("displayDate DESC");
768                 }
769 
770                 Query q = session.createQuery(query.toString());
771 
772                 QueryPos qPos = QueryPos.getInstance(q);
773 
774                 qPos.add(groupId);
775 
776                 List<BlogsEntry> list = (List<BlogsEntry>)QueryUtil.list(q,
777                         getDialect(), start, end);
778 
779                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
780                     finderClassName, finderMethodName, finderParams,
781                     finderArgs, list);
782 
783                 return list;
784             }
785             catch (Exception e) {
786                 throw processException(e);
787             }
788             finally {
789                 closeSession(session);
790             }
791         }
792         else {
793             return (List<BlogsEntry>)result;
794         }
795     }
796 
797     public BlogsEntry findByGroupId_First(long groupId, OrderByComparator obc)
798         throws NoSuchEntryException, SystemException {
799         List<BlogsEntry> list = findByGroupId(groupId, 0, 1, obc);
800 
801         if (list.size() == 0) {
802             StringBuilder msg = new StringBuilder();
803 
804             msg.append("No BlogsEntry exists with the key {");
805 
806             msg.append("groupId=" + groupId);
807 
808             msg.append(StringPool.CLOSE_CURLY_BRACE);
809 
810             throw new NoSuchEntryException(msg.toString());
811         }
812         else {
813             return list.get(0);
814         }
815     }
816 
817     public BlogsEntry findByGroupId_Last(long groupId, OrderByComparator obc)
818         throws NoSuchEntryException, SystemException {
819         int count = countByGroupId(groupId);
820 
821         List<BlogsEntry> list = findByGroupId(groupId, count - 1, count, obc);
822 
823         if (list.size() == 0) {
824             StringBuilder msg = new StringBuilder();
825 
826             msg.append("No BlogsEntry exists with the key {");
827 
828             msg.append("groupId=" + groupId);
829 
830             msg.append(StringPool.CLOSE_CURLY_BRACE);
831 
832             throw new NoSuchEntryException(msg.toString());
833         }
834         else {
835             return list.get(0);
836         }
837     }
838 
839     public BlogsEntry[] findByGroupId_PrevAndNext(long entryId, long groupId,
840         OrderByComparator obc) throws NoSuchEntryException, SystemException {
841         BlogsEntry blogsEntry = findByPrimaryKey(entryId);
842 
843         int count = countByGroupId(groupId);
844 
845         Session session = null;
846 
847         try {
848             session = openSession();
849 
850             StringBuilder query = new StringBuilder();
851 
852             query.append(
853                 "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
854 
855             query.append("groupId = ?");
856 
857             query.append(" ");
858 
859             if (obc != null) {
860                 query.append("ORDER BY ");
861                 query.append(obc.getOrderBy());
862             }
863 
864             else {
865                 query.append("ORDER BY ");
866 
867                 query.append("displayDate DESC");
868             }
869 
870             Query q = session.createQuery(query.toString());
871 
872             QueryPos qPos = QueryPos.getInstance(q);
873 
874             qPos.add(groupId);
875 
876             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
877                     blogsEntry);
878 
879             BlogsEntry[] array = new BlogsEntryImpl[3];
880 
881             array[0] = (BlogsEntry)objArray[0];
882             array[1] = (BlogsEntry)objArray[1];
883             array[2] = (BlogsEntry)objArray[2];
884 
885             return array;
886         }
887         catch (Exception e) {
888             throw processException(e);
889         }
890         finally {
891             closeSession(session);
892         }
893     }
894 
895     public List<BlogsEntry> findByCompanyId(long companyId)
896         throws SystemException {
897         boolean finderClassNameCacheEnabled = BlogsEntryModelImpl.CACHE_ENABLED;
898         String finderClassName = BlogsEntry.class.getName();
899         String finderMethodName = "findByCompanyId";
900         String[] finderParams = new String[] { Long.class.getName() };
901         Object[] finderArgs = new Object[] { new Long(companyId) };
902 
903         Object result = null;
904 
905         if (finderClassNameCacheEnabled) {
906             result = FinderCacheUtil.getResult(finderClassName,
907                     finderMethodName, finderParams, finderArgs, this);
908         }
909 
910         if (result == null) {
911             Session session = null;
912 
913             try {
914                 session = openSession();
915 
916                 StringBuilder query = new StringBuilder();
917 
918                 query.append(
919                     "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
920 
921                 query.append("companyId = ?");
922 
923                 query.append(" ");
924 
925                 query.append("ORDER BY ");
926 
927                 query.append("displayDate DESC");
928 
929                 Query q = session.createQuery(query.toString());
930 
931                 QueryPos qPos = QueryPos.getInstance(q);
932 
933                 qPos.add(companyId);
934 
935                 List<BlogsEntry> list = q.list();
936 
937                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
938                     finderClassName, finderMethodName, finderParams,
939                     finderArgs, list);
940 
941                 return list;
942             }
943             catch (Exception e) {
944                 throw processException(e);
945             }
946             finally {
947                 closeSession(session);
948             }
949         }
950         else {
951             return (List<BlogsEntry>)result;
952         }
953     }
954 
955     public List<BlogsEntry> findByCompanyId(long companyId, int start, int end)
956         throws SystemException {
957         return findByCompanyId(companyId, start, end, null);
958     }
959 
960     public List<BlogsEntry> findByCompanyId(long companyId, int start, int end,
961         OrderByComparator obc) throws SystemException {
962         boolean finderClassNameCacheEnabled = BlogsEntryModelImpl.CACHE_ENABLED;
963         String finderClassName = BlogsEntry.class.getName();
964         String finderMethodName = "findByCompanyId";
965         String[] finderParams = new String[] {
966                 Long.class.getName(),
967                 
968                 "java.lang.Integer", "java.lang.Integer",
969                 "com.liferay.portal.kernel.util.OrderByComparator"
970             };
971         Object[] finderArgs = new Object[] {
972                 new Long(companyId),
973                 
974                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
975             };
976 
977         Object result = null;
978 
979         if (finderClassNameCacheEnabled) {
980             result = FinderCacheUtil.getResult(finderClassName,
981                     finderMethodName, finderParams, finderArgs, this);
982         }
983 
984         if (result == null) {
985             Session session = null;
986 
987             try {
988                 session = openSession();
989 
990                 StringBuilder query = new StringBuilder();
991 
992                 query.append(
993                     "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
994 
995                 query.append("companyId = ?");
996 
997                 query.append(" ");
998 
999                 if (obc != null) {
1000                    query.append("ORDER BY ");
1001                    query.append(obc.getOrderBy());
1002                }
1003
1004                else {
1005                    query.append("ORDER BY ");
1006
1007                    query.append("displayDate DESC");
1008                }
1009
1010                Query q = session.createQuery(query.toString());
1011
1012                QueryPos qPos = QueryPos.getInstance(q);
1013
1014                qPos.add(companyId);
1015
1016                List<BlogsEntry> list = (List<BlogsEntry>)QueryUtil.list(q,
1017                        getDialect(), start, end);
1018
1019                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1020                    finderClassName, finderMethodName, finderParams,
1021                    finderArgs, list);
1022
1023                return list;
1024            }
1025            catch (Exception e) {
1026                throw processException(e);
1027            }
1028            finally {
1029                closeSession(session);
1030            }
1031        }
1032        else {
1033            return (List<BlogsEntry>)result;
1034        }
1035    }
1036
1037    public BlogsEntry findByCompanyId_First(long companyId,
1038        OrderByComparator obc) throws NoSuchEntryException, SystemException {
1039        List<BlogsEntry> list = findByCompanyId(companyId, 0, 1, obc);
1040
1041        if (list.size() == 0) {
1042            StringBuilder msg = new StringBuilder();
1043
1044            msg.append("No BlogsEntry exists with the key {");
1045
1046            msg.append("companyId=" + companyId);
1047
1048            msg.append(StringPool.CLOSE_CURLY_BRACE);
1049
1050            throw new NoSuchEntryException(msg.toString());
1051        }
1052        else {
1053            return list.get(0);
1054        }
1055    }
1056
1057    public BlogsEntry findByCompanyId_Last(long companyId, OrderByComparator obc)
1058        throws NoSuchEntryException, SystemException {
1059        int count = countByCompanyId(companyId);
1060
1061        List<BlogsEntry> list = findByCompanyId(companyId, count - 1, count, obc);
1062
1063        if (list.size() == 0) {
1064            StringBuilder msg = new StringBuilder();
1065
1066            msg.append("No BlogsEntry exists with the key {");
1067
1068            msg.append("companyId=" + companyId);
1069
1070            msg.append(StringPool.CLOSE_CURLY_BRACE);
1071
1072            throw new NoSuchEntryException(msg.toString());
1073        }
1074        else {
1075            return list.get(0);
1076        }
1077    }
1078
1079    public BlogsEntry[] findByCompanyId_PrevAndNext(long entryId,
1080        long companyId, OrderByComparator obc)
1081        throws NoSuchEntryException, SystemException {
1082        BlogsEntry blogsEntry = findByPrimaryKey(entryId);
1083
1084        int count = countByCompanyId(companyId);
1085
1086        Session session = null;
1087
1088        try {
1089            session = openSession();
1090
1091            StringBuilder query = new StringBuilder();
1092
1093            query.append(
1094                "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
1095
1096            query.append("companyId = ?");
1097
1098            query.append(" ");
1099
1100            if (obc != null) {
1101                query.append("ORDER BY ");
1102                query.append(obc.getOrderBy());
1103            }
1104
1105            else {
1106                query.append("ORDER BY ");
1107
1108                query.append("displayDate DESC");
1109            }
1110
1111            Query q = session.createQuery(query.toString());
1112
1113            QueryPos qPos = QueryPos.getInstance(q);
1114
1115            qPos.add(companyId);
1116
1117            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1118                    blogsEntry);
1119
1120            BlogsEntry[] array = new BlogsEntryImpl[3];
1121
1122            array[0] = (BlogsEntry)objArray[0];
1123            array[1] = (BlogsEntry)objArray[1];
1124            array[2] = (BlogsEntry)objArray[2];
1125
1126            return array;
1127        }
1128        catch (Exception e) {
1129            throw processException(e);
1130        }
1131        finally {
1132            closeSession(session);
1133        }
1134    }
1135
1136    public List<BlogsEntry> findByG_U(long groupId, long userId)
1137        throws SystemException {
1138        boolean finderClassNameCacheEnabled = BlogsEntryModelImpl.CACHE_ENABLED;
1139        String finderClassName = BlogsEntry.class.getName();
1140        String finderMethodName = "findByG_U";
1141        String[] finderParams = new String[] {
1142                Long.class.getName(), Long.class.getName()
1143            };
1144        Object[] finderArgs = new Object[] { new Long(groupId), new Long(userId) };
1145
1146        Object result = null;
1147
1148        if (finderClassNameCacheEnabled) {
1149            result = FinderCacheUtil.getResult(finderClassName,
1150                    finderMethodName, finderParams, finderArgs, this);
1151        }
1152
1153        if (result == null) {
1154            Session session = null;
1155
1156            try {
1157                session = openSession();
1158
1159                StringBuilder query = new StringBuilder();
1160
1161                query.append(
1162                    "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
1163
1164                query.append("groupId = ?");
1165
1166                query.append(" AND ");
1167
1168                query.append("userId = ?");
1169
1170                query.append(" ");
1171
1172                query.append("ORDER BY ");
1173
1174                query.append("displayDate DESC");
1175
1176                Query q = session.createQuery(query.toString());
1177
1178                QueryPos qPos = QueryPos.getInstance(q);
1179
1180                qPos.add(groupId);
1181
1182                qPos.add(userId);
1183
1184                List<BlogsEntry> list = q.list();
1185
1186                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1187                    finderClassName, finderMethodName, finderParams,
1188                    finderArgs, list);
1189
1190                return list;
1191            }
1192            catch (Exception e) {
1193                throw processException(e);
1194            }
1195            finally {
1196                closeSession(session);
1197            }
1198        }
1199        else {
1200            return (List<BlogsEntry>)result;
1201        }
1202    }
1203
1204    public List<BlogsEntry> findByG_U(long groupId, long userId, int start,
1205        int end) throws SystemException {
1206        return findByG_U(groupId, userId, start, end, null);
1207    }
1208
1209    public List<BlogsEntry> findByG_U(long groupId, long userId, int start,
1210        int end, OrderByComparator obc) throws SystemException {
1211        boolean finderClassNameCacheEnabled = BlogsEntryModelImpl.CACHE_ENABLED;
1212        String finderClassName = BlogsEntry.class.getName();
1213        String finderMethodName = "findByG_U";
1214        String[] finderParams = new String[] {
1215                Long.class.getName(), Long.class.getName(),
1216                
1217                "java.lang.Integer", "java.lang.Integer",
1218                "com.liferay.portal.kernel.util.OrderByComparator"
1219            };
1220        Object[] finderArgs = new Object[] {
1221                new Long(groupId), new Long(userId),
1222                
1223                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1224            };
1225
1226        Object result = null;
1227
1228        if (finderClassNameCacheEnabled) {
1229            result = FinderCacheUtil.getResult(finderClassName,
1230                    finderMethodName, finderParams, finderArgs, this);
1231        }
1232
1233        if (result == null) {
1234            Session session = null;
1235
1236            try {
1237                session = openSession();
1238
1239                StringBuilder query = new StringBuilder();
1240
1241                query.append(
1242                    "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
1243
1244                query.append("groupId = ?");
1245
1246                query.append(" AND ");
1247
1248                query.append("userId = ?");
1249
1250                query.append(" ");
1251
1252                if (obc != null) {
1253                    query.append("ORDER BY ");
1254                    query.append(obc.getOrderBy());
1255                }
1256
1257                else {
1258                    query.append("ORDER BY ");
1259
1260                    query.append("displayDate DESC");
1261                }
1262
1263                Query q = session.createQuery(query.toString());
1264
1265                QueryPos qPos = QueryPos.getInstance(q);
1266
1267                qPos.add(groupId);
1268
1269                qPos.add(userId);
1270
1271                List<BlogsEntry> list = (List<BlogsEntry>)QueryUtil.list(q,
1272                        getDialect(), start, end);
1273
1274                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1275                    finderClassName, finderMethodName, finderParams,
1276                    finderArgs, list);
1277
1278                return list;
1279            }
1280            catch (Exception e) {
1281                throw processException(e);
1282            }
1283            finally {
1284                closeSession(session);
1285            }
1286        }
1287        else {
1288            return (List<BlogsEntry>)result;
1289        }
1290    }
1291
1292    public BlogsEntry findByG_U_First(long groupId, long userId,
1293        OrderByComparator obc) throws NoSuchEntryException, SystemException {
1294        List<BlogsEntry> list = findByG_U(groupId, userId, 0, 1, obc);
1295
1296        if (list.size() == 0) {
1297            StringBuilder msg = new StringBuilder();
1298
1299            msg.append("No BlogsEntry exists with the key {");
1300
1301            msg.append("groupId=" + groupId);
1302
1303            msg.append(", ");
1304            msg.append("userId=" + userId);
1305
1306            msg.append(StringPool.CLOSE_CURLY_BRACE);
1307
1308            throw new NoSuchEntryException(msg.toString());
1309        }
1310        else {
1311            return list.get(0);
1312        }
1313    }
1314
1315    public BlogsEntry findByG_U_Last(long groupId, long userId,
1316        OrderByComparator obc) throws NoSuchEntryException, SystemException {
1317        int count = countByG_U(groupId, userId);
1318
1319        List<BlogsEntry> list = findByG_U(groupId, userId, count - 1, count, obc);
1320
1321        if (list.size() == 0) {
1322            StringBuilder msg = new StringBuilder();
1323
1324            msg.append("No BlogsEntry exists with the key {");
1325
1326            msg.append("groupId=" + groupId);
1327
1328            msg.append(", ");
1329            msg.append("userId=" + userId);
1330
1331            msg.append(StringPool.CLOSE_CURLY_BRACE);
1332
1333            throw new NoSuchEntryException(msg.toString());
1334        }
1335        else {
1336            return list.get(0);
1337        }
1338    }
1339
1340    public BlogsEntry[] findByG_U_PrevAndNext(long entryId, long groupId,
1341        long userId, OrderByComparator obc)
1342        throws NoSuchEntryException, SystemException {
1343        BlogsEntry blogsEntry = findByPrimaryKey(entryId);
1344
1345        int count = countByG_U(groupId, userId);
1346
1347        Session session = null;
1348
1349        try {
1350            session = openSession();
1351
1352            StringBuilder query = new StringBuilder();
1353
1354            query.append(
1355                "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
1356
1357            query.append("groupId = ?");
1358
1359            query.append(" AND ");
1360
1361            query.append("userId = ?");
1362
1363            query.append(" ");
1364
1365            if (obc != null) {
1366                query.append("ORDER BY ");
1367                query.append(obc.getOrderBy());
1368            }
1369
1370            else {
1371                query.append("ORDER BY ");
1372
1373                query.append("displayDate DESC");
1374            }
1375
1376            Query q = session.createQuery(query.toString());
1377
1378            QueryPos qPos = QueryPos.getInstance(q);
1379
1380            qPos.add(groupId);
1381
1382            qPos.add(userId);
1383
1384            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1385                    blogsEntry);
1386
1387            BlogsEntry[] array = new BlogsEntryImpl[3];
1388
1389            array[0] = (BlogsEntry)objArray[0];
1390            array[1] = (BlogsEntry)objArray[1];
1391            array[2] = (BlogsEntry)objArray[2];
1392
1393            return array;
1394        }
1395        catch (Exception e) {
1396            throw processException(e);
1397        }
1398        finally {
1399            closeSession(session);
1400        }
1401    }
1402
1403    public BlogsEntry findByG_UT(long groupId, String urlTitle)
1404        throws NoSuchEntryException, SystemException {
1405        BlogsEntry blogsEntry = fetchByG_UT(groupId, urlTitle);
1406
1407        if (blogsEntry == null) {
1408            StringBuilder msg = new StringBuilder();
1409
1410            msg.append("No BlogsEntry exists with the key {");
1411
1412            msg.append("groupId=" + groupId);
1413
1414            msg.append(", ");
1415            msg.append("urlTitle=" + urlTitle);
1416
1417            msg.append(StringPool.CLOSE_CURLY_BRACE);
1418
1419            if (_log.isWarnEnabled()) {
1420                _log.warn(msg.toString());
1421            }
1422
1423            throw new NoSuchEntryException(msg.toString());
1424        }
1425
1426        return blogsEntry;
1427    }
1428
1429    public BlogsEntry fetchByG_UT(long groupId, String urlTitle)
1430        throws SystemException {
1431        boolean finderClassNameCacheEnabled = BlogsEntryModelImpl.CACHE_ENABLED;
1432        String finderClassName = BlogsEntry.class.getName();
1433        String finderMethodName = "fetchByG_UT";
1434        String[] finderParams = new String[] {
1435                Long.class.getName(), String.class.getName()
1436            };
1437        Object[] finderArgs = new Object[] { new Long(groupId), urlTitle };
1438
1439        Object result = null;
1440
1441        if (finderClassNameCacheEnabled) {
1442            result = FinderCacheUtil.getResult(finderClassName,
1443                    finderMethodName, finderParams, finderArgs, this);
1444        }
1445
1446        if (result == null) {
1447            Session session = null;
1448
1449            try {
1450                session = openSession();
1451
1452                StringBuilder query = new StringBuilder();
1453
1454                query.append(
1455                    "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
1456
1457                query.append("groupId = ?");
1458
1459                query.append(" AND ");
1460
1461                if (urlTitle == null) {
1462                    query.append("urlTitle IS NULL");
1463                }
1464                else {
1465                    query.append("urlTitle = ?");
1466                }
1467
1468                query.append(" ");
1469
1470                query.append("ORDER BY ");
1471
1472                query.append("displayDate DESC");
1473
1474                Query q = session.createQuery(query.toString());
1475
1476                QueryPos qPos = QueryPos.getInstance(q);
1477
1478                qPos.add(groupId);
1479
1480                if (urlTitle != null) {
1481                    qPos.add(urlTitle);
1482                }
1483
1484                List<BlogsEntry> list = q.list();
1485
1486                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1487                    finderClassName, finderMethodName, finderParams,
1488                    finderArgs, list);
1489
1490                if (list.size() == 0) {
1491                    return null;
1492                }
1493                else {
1494                    return list.get(0);
1495                }
1496            }
1497            catch (Exception e) {
1498                throw processException(e);
1499            }
1500            finally {
1501                closeSession(session);
1502            }
1503        }
1504        else {
1505            List<BlogsEntry> list = (List<BlogsEntry>)result;
1506
1507            if (list.size() == 0) {
1508                return null;
1509            }
1510            else {
1511                return list.get(0);
1512            }
1513        }
1514    }
1515
1516    public List<BlogsEntry> findByG_D_D(long groupId, Date displayDate,
1517        boolean draft) throws SystemException {
1518        boolean finderClassNameCacheEnabled = BlogsEntryModelImpl.CACHE_ENABLED;
1519        String finderClassName = BlogsEntry.class.getName();
1520        String finderMethodName = "findByG_D_D";
1521        String[] finderParams = new String[] {
1522                Long.class.getName(), Date.class.getName(),
1523                Boolean.class.getName()
1524            };
1525        Object[] finderArgs = new Object[] {
1526                new Long(groupId),
1527                
1528                displayDate, Boolean.valueOf(draft)
1529            };
1530
1531        Object result = null;
1532
1533        if (finderClassNameCacheEnabled) {
1534            result = FinderCacheUtil.getResult(finderClassName,
1535                    finderMethodName, finderParams, finderArgs, this);
1536        }
1537
1538        if (result == null) {
1539            Session session = null;
1540
1541            try {
1542                session = openSession();
1543
1544                StringBuilder query = new StringBuilder();
1545
1546                query.append(
1547                    "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
1548
1549                query.append("groupId = ?");
1550
1551                query.append(" AND ");
1552
1553                if (displayDate == null) {
1554                    query.append("displayDate < null");
1555                }
1556                else {
1557                    query.append("displayDate < ?");
1558                }
1559
1560                query.append(" AND ");
1561
1562                query.append("draft = ?");
1563
1564                query.append(" ");
1565
1566                query.append("ORDER BY ");
1567
1568                query.append("displayDate DESC");
1569
1570                Query q = session.createQuery(query.toString());
1571
1572                QueryPos qPos = QueryPos.getInstance(q);
1573
1574                qPos.add(groupId);
1575
1576                if (displayDate != null) {
1577                    qPos.add(CalendarUtil.getTimestamp(displayDate));
1578                }
1579
1580                qPos.add(draft);
1581
1582                List<BlogsEntry> list = q.list();
1583
1584                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1585                    finderClassName, finderMethodName, finderParams,
1586                    finderArgs, list);
1587
1588                return list;
1589            }
1590            catch (Exception e) {
1591                throw processException(e);
1592            }
1593            finally {
1594                closeSession(session);
1595            }
1596        }
1597        else {
1598            return (List<BlogsEntry>)result;
1599        }
1600    }
1601
1602    public List<BlogsEntry> findByG_D_D(long groupId, Date displayDate,
1603        boolean draft, int start, int end) throws SystemException {
1604        return findByG_D_D(groupId, displayDate, draft, start, end, null);
1605    }
1606
1607    public List<BlogsEntry> findByG_D_D(long groupId, Date displayDate,
1608        boolean draft, int start, int end, OrderByComparator obc)
1609        throws SystemException {
1610        boolean finderClassNameCacheEnabled = BlogsEntryModelImpl.CACHE_ENABLED;
1611        String finderClassName = BlogsEntry.class.getName();
1612        String finderMethodName = "findByG_D_D";
1613        String[] finderParams = new String[] {
1614                Long.class.getName(), Date.class.getName(),
1615                Boolean.class.getName(),
1616                
1617                "java.lang.Integer", "java.lang.Integer",
1618                "com.liferay.portal.kernel.util.OrderByComparator"
1619            };
1620        Object[] finderArgs = new Object[] {
1621                new Long(groupId),
1622                
1623                displayDate, Boolean.valueOf(draft),
1624                
1625                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1626            };
1627
1628        Object result = null;
1629
1630        if (finderClassNameCacheEnabled) {
1631            result = FinderCacheUtil.getResult(finderClassName,
1632                    finderMethodName, finderParams, finderArgs, this);
1633        }
1634
1635        if (result == null) {
1636            Session session = null;
1637
1638            try {
1639                session = openSession();
1640
1641                StringBuilder query = new StringBuilder();
1642
1643                query.append(
1644                    "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
1645
1646                query.append("groupId = ?");
1647
1648                query.append(" AND ");
1649
1650                if (displayDate == null) {
1651                    query.append("displayDate < null");
1652                }
1653                else {
1654                    query.append("displayDate < ?");
1655                }
1656
1657                query.append(" AND ");
1658
1659                query.append("draft = ?");
1660
1661                query.append(" ");
1662
1663                if (obc != null) {
1664                    query.append("ORDER BY ");
1665                    query.append(obc.getOrderBy());
1666                }
1667
1668                else {
1669                    query.append("ORDER BY ");
1670
1671                    query.append("displayDate DESC");
1672                }
1673
1674                Query q = session.createQuery(query.toString());
1675
1676                QueryPos qPos = QueryPos.getInstance(q);
1677
1678                qPos.add(groupId);
1679
1680                if (displayDate != null) {
1681                    qPos.add(CalendarUtil.getTimestamp(displayDate));
1682                }
1683
1684                qPos.add(draft);
1685
1686                List<BlogsEntry> list = (List<BlogsEntry>)QueryUtil.list(q,
1687                        getDialect(), start, end);
1688
1689                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1690                    finderClassName, finderMethodName, finderParams,
1691                    finderArgs, list);
1692
1693                return list;
1694            }
1695            catch (Exception e) {
1696                throw processException(e);
1697            }
1698            finally {
1699                closeSession(session);
1700            }
1701        }
1702        else {
1703            return (List<BlogsEntry>)result;
1704        }
1705    }
1706
1707    public BlogsEntry findByG_D_D_First(long groupId, Date displayDate,
1708        boolean draft, OrderByComparator obc)
1709        throws NoSuchEntryException, SystemException {
1710        List<BlogsEntry> list = findByG_D_D(groupId, displayDate, draft, 0, 1,
1711                obc);
1712
1713        if (list.size() == 0) {
1714            StringBuilder msg = new StringBuilder();
1715
1716            msg.append("No BlogsEntry exists with the key {");
1717
1718            msg.append("groupId=" + groupId);
1719
1720            msg.append(", ");
1721            msg.append("displayDate=" + displayDate);
1722
1723            msg.append(", ");
1724            msg.append("draft=" + draft);
1725
1726            msg.append(StringPool.CLOSE_CURLY_BRACE);
1727
1728            throw new NoSuchEntryException(msg.toString());
1729        }
1730        else {
1731            return list.get(0);
1732        }
1733    }
1734
1735    public BlogsEntry findByG_D_D_Last(long groupId, Date displayDate,
1736        boolean draft, OrderByComparator obc)
1737        throws NoSuchEntryException, SystemException {
1738        int count = countByG_D_D(groupId, displayDate, draft);
1739
1740        List<BlogsEntry> list = findByG_D_D(groupId, displayDate, draft,
1741                count - 1, count, obc);
1742
1743        if (list.size() == 0) {
1744            StringBuilder msg = new StringBuilder();
1745
1746            msg.append("No BlogsEntry exists with the key {");
1747
1748            msg.append("groupId=" + groupId);
1749
1750            msg.append(", ");
1751            msg.append("displayDate=" + displayDate);
1752
1753            msg.append(", ");
1754            msg.append("draft=" + draft);
1755
1756            msg.append(StringPool.CLOSE_CURLY_BRACE);
1757
1758            throw new NoSuchEntryException(msg.toString());
1759        }
1760        else {
1761            return list.get(0);
1762        }
1763    }
1764
1765    public BlogsEntry[] findByG_D_D_PrevAndNext(long entryId, long groupId,
1766        Date displayDate, boolean draft, OrderByComparator obc)
1767        throws NoSuchEntryException, SystemException {
1768        BlogsEntry blogsEntry = findByPrimaryKey(entryId);
1769
1770        int count = countByG_D_D(groupId, displayDate, draft);
1771
1772        Session session = null;
1773
1774        try {
1775            session = openSession();
1776
1777            StringBuilder query = new StringBuilder();
1778
1779            query.append(
1780                "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
1781
1782            query.append("groupId = ?");
1783
1784            query.append(" AND ");
1785
1786            if (displayDate == null) {
1787                query.append("displayDate < null");
1788            }
1789            else {
1790                query.append("displayDate < ?");
1791            }
1792
1793            query.append(" AND ");
1794
1795            query.append("draft = ?");
1796
1797            query.append(" ");
1798
1799            if (obc != null) {
1800                query.append("ORDER BY ");
1801                query.append(obc.getOrderBy());
1802            }
1803
1804            else {
1805                query.append("ORDER BY ");
1806
1807                query.append("displayDate DESC");
1808            }
1809
1810            Query q = session.createQuery(query.toString());
1811
1812            QueryPos qPos = QueryPos.getInstance(q);
1813
1814            qPos.add(groupId);
1815
1816            if (displayDate != null) {
1817                qPos.add(CalendarUtil.getTimestamp(displayDate));
1818            }
1819
1820            qPos.add(draft);
1821
1822            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1823                    blogsEntry);
1824
1825            BlogsEntry[] array = new BlogsEntryImpl[3];
1826
1827            array[0] = (BlogsEntry)objArray[0];
1828            array[1] = (BlogsEntry)objArray[1];
1829            array[2] = (BlogsEntry)objArray[2];
1830
1831            return array;
1832        }
1833        catch (Exception e) {
1834            throw processException(e);
1835        }
1836        finally {
1837            closeSession(session);
1838        }
1839    }
1840
1841    public List<BlogsEntry> findByC_D_D(long companyId, Date displayDate,
1842        boolean draft) throws SystemException {
1843        boolean finderClassNameCacheEnabled = BlogsEntryModelImpl.CACHE_ENABLED;
1844        String finderClassName = BlogsEntry.class.getName();
1845        String finderMethodName = "findByC_D_D";
1846        String[] finderParams = new String[] {
1847                Long.class.getName(), Date.class.getName(),
1848                Boolean.class.getName()
1849            };
1850        Object[] finderArgs = new Object[] {
1851                new Long(companyId),
1852                
1853                displayDate, Boolean.valueOf(draft)
1854            };
1855
1856        Object result = null;
1857
1858        if (finderClassNameCacheEnabled) {
1859            result = FinderCacheUtil.getResult(finderClassName,
1860                    finderMethodName, finderParams, finderArgs, this);
1861        }
1862
1863        if (result == null) {
1864            Session session = null;
1865
1866            try {
1867                session = openSession();
1868
1869                StringBuilder query = new StringBuilder();
1870
1871                query.append(
1872                    "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
1873
1874                query.append("companyId = ?");
1875
1876                query.append(" AND ");
1877
1878                if (displayDate == null) {
1879                    query.append("displayDate < null");
1880                }
1881                else {
1882                    query.append("displayDate < ?");
1883                }
1884
1885                query.append(" AND ");
1886
1887                query.append("draft = ?");
1888
1889                query.append(" ");
1890
1891                query.append("ORDER BY ");
1892
1893                query.append("displayDate DESC");
1894
1895                Query q = session.createQuery(query.toString());
1896
1897                QueryPos qPos = QueryPos.getInstance(q);
1898
1899                qPos.add(companyId);
1900
1901                if (displayDate != null) {
1902                    qPos.add(CalendarUtil.getTimestamp(displayDate));
1903                }
1904
1905                qPos.add(draft);
1906
1907                List<BlogsEntry> list = q.list();
1908
1909                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1910                    finderClassName, finderMethodName, finderParams,
1911                    finderArgs, list);
1912
1913                return list;
1914            }
1915            catch (Exception e) {
1916                throw processException(e);
1917            }
1918            finally {
1919                closeSession(session);
1920            }
1921        }
1922        else {
1923            return (List<BlogsEntry>)result;
1924        }
1925    }
1926
1927    public List<BlogsEntry> findByC_D_D(long companyId, Date displayDate,
1928        boolean draft, int start, int end) throws SystemException {
1929        return findByC_D_D(companyId, displayDate, draft, start, end, null);
1930    }
1931
1932    public List<BlogsEntry> findByC_D_D(long companyId, Date displayDate,
1933        boolean draft, int start, int end, OrderByComparator obc)
1934        throws SystemException {
1935        boolean finderClassNameCacheEnabled = BlogsEntryModelImpl.CACHE_ENABLED;
1936        String finderClassName = BlogsEntry.class.getName();
1937        String finderMethodName = "findByC_D_D";
1938        String[] finderParams = new String[] {
1939                Long.class.getName(), Date.class.getName(),
1940                Boolean.class.getName(),
1941                
1942                "java.lang.Integer", "java.lang.Integer",
1943                "com.liferay.portal.kernel.util.OrderByComparator"
1944            };
1945        Object[] finderArgs = new Object[] {
1946                new Long(companyId),
1947                
1948                displayDate, Boolean.valueOf(draft),
1949                
1950                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1951            };
1952
1953        Object result = null;
1954
1955        if (finderClassNameCacheEnabled) {
1956            result = FinderCacheUtil.getResult(finderClassName,
1957                    finderMethodName, finderParams, finderArgs, this);
1958        }
1959
1960        if (result == null) {
1961            Session session = null;
1962
1963            try {
1964                session = openSession();
1965
1966                StringBuilder query = new StringBuilder();
1967
1968                query.append(
1969                    "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
1970
1971                query.append("companyId = ?");
1972
1973                query.append(" AND ");
1974
1975                if (displayDate == null) {
1976                    query.append("displayDate < null");
1977                }
1978                else {
1979                    query.append("displayDate < ?");
1980                }
1981
1982                query.append(" AND ");
1983
1984                query.append("draft = ?");
1985
1986                query.append(" ");
1987
1988                if (obc != null) {
1989                    query.append("ORDER BY ");
1990                    query.append(obc.getOrderBy());
1991                }
1992
1993                else {
1994                    query.append("ORDER BY ");
1995
1996                    query.append("displayDate DESC");
1997                }
1998
1999                Query q = session.createQuery(query.toString());
2000
2001                QueryPos qPos = QueryPos.getInstance(q);
2002
2003                qPos.add(companyId);
2004
2005                if (displayDate != null) {
2006                    qPos.add(CalendarUtil.getTimestamp(displayDate));
2007                }
2008
2009                qPos.add(draft);
2010
2011                List<BlogsEntry> list = (List<BlogsEntry>)QueryUtil.list(q,
2012                        getDialect(), start, end);
2013
2014                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2015                    finderClassName, finderMethodName, finderParams,
2016                    finderArgs, list);
2017
2018                return list;
2019            }
2020            catch (Exception e) {
2021                throw processException(e);
2022            }
2023            finally {
2024                closeSession(session);
2025            }
2026        }
2027        else {
2028            return (List<BlogsEntry>)result;
2029        }
2030    }
2031
2032    public BlogsEntry findByC_D_D_First(long companyId, Date displayDate,
2033        boolean draft, OrderByComparator obc)
2034        throws NoSuchEntryException, SystemException {
2035        List<BlogsEntry> list = findByC_D_D(companyId, displayDate, draft, 0,
2036                1, obc);
2037
2038        if (list.size() == 0) {
2039            StringBuilder msg = new StringBuilder();
2040
2041            msg.append("No BlogsEntry exists with the key {");
2042
2043            msg.append("companyId=" + companyId);
2044
2045            msg.append(", ");
2046            msg.append("displayDate=" + displayDate);
2047
2048            msg.append(", ");
2049            msg.append("draft=" + draft);
2050
2051            msg.append(StringPool.CLOSE_CURLY_BRACE);
2052
2053            throw new NoSuchEntryException(msg.toString());
2054        }
2055        else {
2056            return list.get(0);
2057        }
2058    }
2059
2060    public BlogsEntry findByC_D_D_Last(long companyId, Date displayDate,
2061        boolean draft, OrderByComparator obc)
2062        throws NoSuchEntryException, SystemException {
2063        int count = countByC_D_D(companyId, displayDate, draft);
2064
2065        List<BlogsEntry> list = findByC_D_D(companyId, displayDate, draft,
2066                count - 1, count, obc);
2067
2068        if (list.size() == 0) {
2069            StringBuilder msg = new StringBuilder();
2070
2071            msg.append("No BlogsEntry exists with the key {");
2072
2073            msg.append("companyId=" + companyId);
2074
2075            msg.append(", ");
2076            msg.append("displayDate=" + displayDate);
2077
2078            msg.append(", ");
2079            msg.append("draft=" + draft);
2080
2081            msg.append(StringPool.CLOSE_CURLY_BRACE);
2082
2083            throw new NoSuchEntryException(msg.toString());
2084        }
2085        else {
2086            return list.get(0);
2087        }
2088    }
2089
2090    public BlogsEntry[] findByC_D_D_PrevAndNext(long entryId, long companyId,
2091        Date displayDate, boolean draft, OrderByComparator obc)
2092        throws NoSuchEntryException, SystemException {
2093        BlogsEntry blogsEntry = findByPrimaryKey(entryId);
2094
2095        int count = countByC_D_D(companyId, displayDate, draft);
2096
2097        Session session = null;
2098
2099        try {
2100            session = openSession();
2101
2102            StringBuilder query = new StringBuilder();
2103
2104            query.append(
2105                "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
2106
2107            query.append("companyId = ?");
2108
2109            query.append(" AND ");
2110
2111            if (displayDate == null) {
2112                query.append("displayDate < null");
2113            }
2114            else {
2115                query.append("displayDate < ?");
2116            }
2117
2118            query.append(" AND ");
2119
2120            query.append("draft = ?");
2121
2122            query.append(" ");
2123
2124            if (obc != null) {
2125                query.append("ORDER BY ");
2126                query.append(obc.getOrderBy());
2127            }
2128
2129            else {
2130                query.append("ORDER BY ");
2131
2132                query.append("displayDate DESC");
2133            }
2134
2135            Query q = session.createQuery(query.toString());
2136
2137            QueryPos qPos = QueryPos.getInstance(q);
2138
2139            qPos.add(companyId);
2140
2141            if (displayDate != null) {
2142                qPos.add(CalendarUtil.getTimestamp(displayDate));
2143            }
2144
2145            qPos.add(draft);
2146
2147            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
2148                    blogsEntry);
2149
2150            BlogsEntry[] array = new BlogsEntryImpl[3];
2151
2152            array[0] = (BlogsEntry)objArray[0];
2153            array[1] = (BlogsEntry)objArray[1];
2154            array[2] = (BlogsEntry)objArray[2];
2155
2156            return array;
2157        }
2158        catch (Exception e) {
2159            throw processException(e);
2160        }
2161        finally {
2162            closeSession(session);
2163        }
2164    }
2165
2166    public List<BlogsEntry> findByG_U_D_D(long groupId, long userId,
2167        Date displayDate, boolean draft) throws SystemException {
2168        boolean finderClassNameCacheEnabled = BlogsEntryModelImpl.CACHE_ENABLED;
2169        String finderClassName = BlogsEntry.class.getName();
2170        String finderMethodName = "findByG_U_D_D";
2171        String[] finderParams = new String[] {
2172                Long.class.getName(), Long.class.getName(), Date.class.getName(),
2173                Boolean.class.getName()
2174            };
2175        Object[] finderArgs = new Object[] {
2176                new Long(groupId), new Long(userId),
2177                
2178                displayDate, Boolean.valueOf(draft)
2179            };
2180
2181        Object result = null;
2182
2183        if (finderClassNameCacheEnabled) {
2184            result = FinderCacheUtil.getResult(finderClassName,
2185                    finderMethodName, finderParams, finderArgs, this);
2186        }
2187
2188        if (result == null) {
2189            Session session = null;
2190
2191            try {
2192                session = openSession();
2193
2194                StringBuilder query = new StringBuilder();
2195
2196                query.append(
2197                    "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
2198
2199                query.append("groupId = ?");
2200
2201                query.append(" AND ");
2202
2203                query.append("userId = ?");
2204
2205                query.append(" AND ");
2206
2207                if (displayDate == null) {
2208                    query.append("displayDate < null");
2209                }
2210                else {
2211                    query.append("displayDate < ?");
2212                }
2213
2214                query.append(" AND ");
2215
2216                query.append("draft = ?");
2217
2218                query.append(" ");
2219
2220                query.append("ORDER BY ");
2221
2222                query.append("displayDate DESC");
2223
2224                Query q = session.createQuery(query.toString());
2225
2226                QueryPos qPos = QueryPos.getInstance(q);
2227
2228                qPos.add(groupId);
2229
2230                qPos.add(userId);
2231
2232                if (displayDate != null) {
2233                    qPos.add(CalendarUtil.getTimestamp(displayDate));
2234                }
2235
2236                qPos.add(draft);
2237
2238                List<BlogsEntry> list = q.list();
2239
2240                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2241                    finderClassName, finderMethodName, finderParams,
2242                    finderArgs, list);
2243
2244                return list;
2245            }
2246            catch (Exception e) {
2247                throw processException(e);
2248            }
2249            finally {
2250                closeSession(session);
2251            }
2252        }
2253        else {
2254            return (List<BlogsEntry>)result;
2255        }
2256    }
2257
2258    public List<BlogsEntry> findByG_U_D_D(long groupId, long userId,
2259        Date displayDate, boolean draft, int start, int end)
2260        throws SystemException {
2261        return findByG_U_D_D(groupId, userId, displayDate, draft, start, end,
2262            null);
2263    }
2264
2265    public List<BlogsEntry> findByG_U_D_D(long groupId, long userId,
2266        Date displayDate, boolean draft, int start, int end,
2267        OrderByComparator obc) throws SystemException {
2268        boolean finderClassNameCacheEnabled = BlogsEntryModelImpl.CACHE_ENABLED;
2269        String finderClassName = BlogsEntry.class.getName();
2270        String finderMethodName = "findByG_U_D_D";
2271        String[] finderParams = new String[] {
2272                Long.class.getName(), Long.class.getName(), Date.class.getName(),
2273                Boolean.class.getName(),
2274                
2275                "java.lang.Integer", "java.lang.Integer",
2276                "com.liferay.portal.kernel.util.OrderByComparator"
2277            };
2278        Object[] finderArgs = new Object[] {
2279                new Long(groupId), new Long(userId),
2280                
2281                displayDate, Boolean.valueOf(draft),
2282                
2283                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
2284            };
2285
2286        Object result = null;
2287
2288        if (finderClassNameCacheEnabled) {
2289            result = FinderCacheUtil.getResult(finderClassName,
2290                    finderMethodName, finderParams, finderArgs, this);
2291        }
2292
2293        if (result == null) {
2294            Session session = null;
2295
2296            try {
2297                session = openSession();
2298
2299                StringBuilder query = new StringBuilder();
2300
2301                query.append(
2302                    "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
2303
2304                query.append("groupId = ?");
2305
2306                query.append(" AND ");
2307
2308                query.append("userId = ?");
2309
2310                query.append(" AND ");
2311
2312                if (displayDate == null) {
2313                    query.append("displayDate < null");
2314                }
2315                else {
2316                    query.append("displayDate < ?");
2317                }
2318
2319                query.append(" AND ");
2320
2321                query.append("draft = ?");
2322
2323                query.append(" ");
2324
2325                if (obc != null) {
2326                    query.append("ORDER BY ");
2327                    query.append(obc.getOrderBy());
2328                }
2329
2330                else {
2331                    query.append("ORDER BY ");
2332
2333                    query.append("displayDate DESC");
2334                }
2335
2336                Query q = session.createQuery(query.toString());
2337
2338                QueryPos qPos = QueryPos.getInstance(q);
2339
2340                qPos.add(groupId);
2341
2342                qPos.add(userId);
2343
2344                if (displayDate != null) {
2345                    qPos.add(CalendarUtil.getTimestamp(displayDate));
2346                }
2347
2348                qPos.add(draft);
2349
2350                List<BlogsEntry> list = (List<BlogsEntry>)QueryUtil.list(q,
2351                        getDialect(), start, end);
2352
2353                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2354                    finderClassName, finderMethodName, finderParams,
2355                    finderArgs, list);
2356
2357                return list;
2358            }
2359            catch (Exception e) {
2360                throw processException(e);
2361            }
2362            finally {
2363                closeSession(session);
2364            }
2365        }
2366        else {
2367            return (List<BlogsEntry>)result;
2368        }
2369    }
2370
2371    public BlogsEntry findByG_U_D_D_First(long groupId, long userId,
2372        Date displayDate, boolean draft, OrderByComparator obc)
2373        throws NoSuchEntryException, SystemException {
2374        List<BlogsEntry> list = findByG_U_D_D(groupId, userId, displayDate,
2375                draft, 0, 1, obc);
2376
2377        if (list.size() == 0) {
2378            StringBuilder msg = new StringBuilder();
2379
2380            msg.append("No BlogsEntry exists with the key {");
2381
2382            msg.append("groupId=" + groupId);
2383
2384            msg.append(", ");
2385            msg.append("userId=" + userId);
2386
2387            msg.append(", ");
2388            msg.append("displayDate=" + displayDate);
2389
2390            msg.append(", ");
2391            msg.append("draft=" + draft);
2392
2393            msg.append(StringPool.CLOSE_CURLY_BRACE);
2394
2395            throw new NoSuchEntryException(msg.toString());
2396        }
2397        else {
2398            return list.get(0);
2399        }
2400    }
2401
2402    public BlogsEntry findByG_U_D_D_Last(long groupId, long userId,
2403        Date displayDate, boolean draft, OrderByComparator obc)
2404        throws NoSuchEntryException, SystemException {
2405        int count = countByG_U_D_D(groupId, userId, displayDate, draft);
2406
2407        List<BlogsEntry> list = findByG_U_D_D(groupId, userId, displayDate,
2408                draft, count - 1, count, obc);
2409
2410        if (list.size() == 0) {
2411            StringBuilder msg = new StringBuilder();
2412
2413            msg.append("No BlogsEntry exists with the key {");
2414
2415            msg.append("groupId=" + groupId);
2416
2417            msg.append(", ");
2418            msg.append("userId=" + userId);
2419
2420            msg.append(", ");
2421            msg.append("displayDate=" + displayDate);
2422
2423            msg.append(", ");
2424            msg.append("draft=" + draft);
2425
2426            msg.append(StringPool.CLOSE_CURLY_BRACE);
2427
2428            throw new NoSuchEntryException(msg.toString());
2429        }
2430        else {
2431            return list.get(0);
2432        }
2433    }
2434
2435    public BlogsEntry[] findByG_U_D_D_PrevAndNext(long entryId, long groupId,
2436        long userId, Date displayDate, boolean draft, OrderByComparator obc)
2437        throws NoSuchEntryException, SystemException {
2438        BlogsEntry blogsEntry = findByPrimaryKey(entryId);
2439
2440        int count = countByG_U_D_D(groupId, userId, displayDate, draft);
2441
2442        Session session = null;
2443
2444        try {
2445            session = openSession();
2446
2447            StringBuilder query = new StringBuilder();
2448
2449            query.append(
2450                "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
2451
2452            query.append("groupId = ?");
2453
2454            query.append(" AND ");
2455
2456            query.append("userId = ?");
2457
2458            query.append(" AND ");
2459
2460            if (displayDate == null) {
2461                query.append("displayDate < null");
2462            }
2463            else {
2464                query.append("displayDate < ?");
2465            }
2466
2467            query.append(" AND ");
2468
2469            query.append("draft = ?");
2470
2471            query.append(" ");
2472
2473            if (obc != null) {
2474                query.append("ORDER BY ");
2475                query.append(obc.getOrderBy());
2476            }
2477
2478            else {
2479                query.append("ORDER BY ");
2480
2481                query.append("displayDate DESC");
2482            }
2483
2484            Query q = session.createQuery(query.toString());
2485
2486            QueryPos qPos = QueryPos.getInstance(q);
2487
2488            qPos.add(groupId);
2489
2490            qPos.add(userId);
2491
2492            if (displayDate != null) {
2493                qPos.add(CalendarUtil.getTimestamp(displayDate));
2494            }
2495
2496            qPos.add(draft);
2497
2498            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
2499                    blogsEntry);
2500
2501            BlogsEntry[] array = new BlogsEntryImpl[3];
2502
2503            array[0] = (BlogsEntry)objArray[0];
2504            array[1] = (BlogsEntry)objArray[1];
2505            array[2] = (BlogsEntry)objArray[2];
2506
2507            return array;
2508        }
2509        catch (Exception e) {
2510            throw processException(e);
2511        }
2512        finally {
2513            closeSession(session);
2514        }
2515    }
2516
2517    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
2518        throws SystemException {
2519        Session session = null;
2520
2521        try {
2522            session = openSession();
2523
2524            dynamicQuery.compile(session);
2525
2526            return dynamicQuery.list();
2527        }
2528        catch (Exception e) {
2529            throw processException(e);
2530        }
2531        finally {
2532            closeSession(session);
2533        }
2534    }
2535
2536    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
2537        int start, int end) throws SystemException {
2538        Session session = null;
2539
2540        try {
2541            session = openSession();
2542
2543            dynamicQuery.setLimit(start, end);
2544
2545            dynamicQuery.compile(session);
2546
2547            return dynamicQuery.list();
2548        }
2549        catch (Exception e) {
2550            throw processException(e);
2551        }
2552        finally {
2553            closeSession(session);
2554        }
2555    }
2556
2557    public List<BlogsEntry> findAll() throws SystemException {
2558        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2559    }
2560
2561    public List<BlogsEntry> findAll(int start, int end)
2562        throws SystemException {
2563        return findAll(start, end, null);
2564    }
2565
2566    public List<BlogsEntry> findAll(int start, int end, OrderByComparator obc)
2567        throws SystemException {
2568        boolean finderClassNameCacheEnabled = BlogsEntryModelImpl.CACHE_ENABLED;
2569        String finderClassName = BlogsEntry.class.getName();
2570        String finderMethodName = "findAll";
2571        String[] finderParams = new String[] {
2572                "java.lang.Integer", "java.lang.Integer",
2573                "com.liferay.portal.kernel.util.OrderByComparator"
2574            };
2575        Object[] finderArgs = new Object[] {
2576                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
2577            };
2578
2579        Object result = null;
2580
2581        if (finderClassNameCacheEnabled) {
2582            result = FinderCacheUtil.getResult(finderClassName,
2583                    finderMethodName, finderParams, finderArgs, this);
2584        }
2585
2586        if (result == null) {
2587            Session session = null;
2588
2589            try {
2590                session = openSession();
2591
2592                StringBuilder query = new StringBuilder();
2593
2594                query.append("FROM com.liferay.portlet.blogs.model.BlogsEntry ");
2595
2596                if (obc != null) {
2597                    query.append("ORDER BY ");
2598                    query.append(obc.getOrderBy());
2599                }
2600
2601                else {
2602                    query.append("ORDER BY ");
2603
2604                    query.append("displayDate DESC");
2605                }
2606
2607                Query q = session.createQuery(query.toString());
2608
2609                List<BlogsEntry> list = null;
2610
2611                if (obc == null) {
2612                    list = (List<BlogsEntry>)QueryUtil.list(q, getDialect(),
2613                            start, end, false);
2614
2615                    Collections.sort(list);
2616                }
2617                else {
2618                    list = (List<BlogsEntry>)QueryUtil.list(q, getDialect(),
2619                            start, end);
2620                }
2621
2622                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2623                    finderClassName, finderMethodName, finderParams,
2624                    finderArgs, list);
2625
2626                return list;
2627            }
2628            catch (Exception e) {
2629                throw processException(e);
2630            }
2631            finally {
2632                closeSession(session);
2633            }
2634        }
2635        else {
2636            return (List<BlogsEntry>)result;
2637        }
2638    }
2639
2640    public void removeByUuid(String uuid) throws SystemException {
2641        for (BlogsEntry blogsEntry : findByUuid(uuid)) {
2642            remove(blogsEntry);
2643        }
2644    }
2645
2646    public void removeByUUID_G(String uuid, long groupId)
2647        throws NoSuchEntryException, SystemException {
2648        BlogsEntry blogsEntry = findByUUID_G(uuid, groupId);
2649
2650        remove(blogsEntry);
2651    }
2652
2653    public void removeByGroupId(long groupId) throws SystemException {
2654        for (BlogsEntry blogsEntry : findByGroupId(groupId)) {
2655            remove(blogsEntry);
2656        }
2657    }
2658
2659    public void removeByCompanyId(long companyId) throws SystemException {
2660        for (BlogsEntry blogsEntry : findByCompanyId(companyId)) {
2661            remove(blogsEntry);
2662        }
2663    }
2664
2665    public void removeByG_U(long groupId, long userId)
2666        throws SystemException {
2667        for (BlogsEntry blogsEntry : findByG_U(groupId, userId)) {
2668            remove(blogsEntry);
2669        }
2670    }
2671
2672    public void removeByG_UT(long groupId, String urlTitle)
2673        throws NoSuchEntryException, SystemException {
2674        BlogsEntry blogsEntry = findByG_UT(groupId, urlTitle);
2675
2676        remove(blogsEntry);
2677    }
2678
2679    public void removeByG_D_D(long groupId, Date displayDate, boolean draft)
2680        throws SystemException {
2681        for (BlogsEntry blogsEntry : findByG_D_D(groupId, displayDate, draft)) {
2682            remove(blogsEntry);
2683        }
2684    }
2685
2686    public void removeByC_D_D(long companyId, Date displayDate, boolean draft)
2687        throws SystemException {
2688        for (BlogsEntry blogsEntry : findByC_D_D(companyId, displayDate, draft)) {
2689            remove(blogsEntry);
2690        }
2691    }
2692
2693    public void removeByG_U_D_D(long groupId, long userId, Date displayDate,
2694        boolean draft) throws SystemException {
2695        for (BlogsEntry blogsEntry : findByG_U_D_D(groupId, userId,
2696                displayDate, draft)) {
2697            remove(blogsEntry);
2698        }
2699    }
2700
2701    public void removeAll() throws SystemException {
2702        for (BlogsEntry blogsEntry : findAll()) {
2703            remove(blogsEntry);
2704        }
2705    }
2706
2707    public int countByUuid(String uuid) throws SystemException {
2708        boolean finderClassNameCacheEnabled = BlogsEntryModelImpl.CACHE_ENABLED;
2709        String finderClassName = BlogsEntry.class.getName();
2710        String finderMethodName = "countByUuid";
2711        String[] finderParams = new String[] { String.class.getName() };
2712        Object[] finderArgs = new Object[] { uuid };
2713
2714        Object result = null;
2715
2716        if (finderClassNameCacheEnabled) {
2717            result = FinderCacheUtil.getResult(finderClassName,
2718                    finderMethodName, finderParams, finderArgs, this);
2719        }
2720
2721        if (result == null) {
2722            Session session = null;
2723
2724            try {
2725                session = openSession();
2726
2727                StringBuilder query = new StringBuilder();
2728
2729                query.append("SELECT COUNT(*) ");
2730                query.append(
2731                    "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
2732
2733                if (uuid == null) {
2734                    query.append("uuid_ IS NULL");
2735                }
2736                else {
2737                    query.append("uuid_ = ?");
2738                }
2739
2740                query.append(" ");
2741
2742                Query q = session.createQuery(query.toString());
2743
2744                QueryPos qPos = QueryPos.getInstance(q);
2745
2746                if (uuid != null) {
2747                    qPos.add(uuid);
2748                }
2749
2750                Long count = null;
2751
2752                Iterator<Long> itr = q.list().iterator();
2753
2754                if (itr.hasNext()) {
2755                    count = itr.next();
2756                }
2757
2758                if (count == null) {
2759                    count = new Long(0);
2760                }
2761
2762                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2763                    finderClassName, finderMethodName, finderParams,
2764                    finderArgs, count);
2765
2766                return count.intValue();
2767            }
2768            catch (Exception e) {
2769                throw processException(e);
2770            }
2771            finally {
2772                closeSession(session);
2773            }
2774        }
2775        else {
2776            return ((Long)result).intValue();
2777        }
2778    }
2779
2780    public int countByUUID_G(String uuid, long groupId)
2781        throws SystemException {
2782        boolean finderClassNameCacheEnabled = BlogsEntryModelImpl.CACHE_ENABLED;
2783        String finderClassName = BlogsEntry.class.getName();
2784        String finderMethodName = "countByUUID_G";
2785        String[] finderParams = new String[] {
2786                String.class.getName(), Long.class.getName()
2787            };
2788        Object[] finderArgs = new Object[] { uuid, new Long(groupId) };
2789
2790        Object result = null;
2791
2792        if (finderClassNameCacheEnabled) {
2793            result = FinderCacheUtil.getResult(finderClassName,
2794                    finderMethodName, finderParams, finderArgs, this);
2795        }
2796
2797        if (result == null) {
2798            Session session = null;
2799
2800            try {
2801                session = openSession();
2802
2803                StringBuilder query = new StringBuilder();
2804
2805                query.append("SELECT COUNT(*) ");
2806                query.append(
2807                    "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
2808
2809                if (uuid == null) {
2810                    query.append("uuid_ IS NULL");
2811                }
2812                else {
2813                    query.append("uuid_ = ?");
2814                }
2815
2816                query.append(" AND ");
2817
2818                query.append("groupId = ?");
2819
2820                query.append(" ");
2821
2822                Query q = session.createQuery(query.toString());
2823
2824                QueryPos qPos = QueryPos.getInstance(q);
2825
2826                if (uuid != null) {
2827                    qPos.add(uuid);
2828                }
2829
2830                qPos.add(groupId);
2831
2832                Long count = null;
2833
2834                Iterator<Long> itr = q.list().iterator();
2835
2836                if (itr.hasNext()) {
2837                    count = itr.next();
2838                }
2839
2840                if (count == null) {
2841                    count = new Long(0);
2842                }
2843
2844                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2845                    finderClassName, finderMethodName, finderParams,
2846                    finderArgs, count);
2847
2848                return count.intValue();
2849            }
2850            catch (Exception e) {
2851                throw processException(e);
2852            }
2853            finally {
2854                closeSession(session);
2855            }
2856        }
2857        else {
2858            return ((Long)result).intValue();
2859        }
2860    }
2861
2862    public int countByGroupId(long groupId) throws SystemException {
2863        boolean finderClassNameCacheEnabled = BlogsEntryModelImpl.CACHE_ENABLED;
2864        String finderClassName = BlogsEntry.class.getName();
2865        String finderMethodName = "countByGroupId";
2866        String[] finderParams = new String[] { Long.class.getName() };
2867        Object[] finderArgs = new Object[] { new Long(groupId) };
2868
2869        Object result = null;
2870
2871        if (finderClassNameCacheEnabled) {
2872            result = FinderCacheUtil.getResult(finderClassName,
2873                    finderMethodName, finderParams, finderArgs, this);
2874        }
2875
2876        if (result == null) {
2877            Session session = null;
2878
2879            try {
2880                session = openSession();
2881
2882                StringBuilder query = new StringBuilder();
2883
2884                query.append("SELECT COUNT(*) ");
2885                query.append(
2886                    "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
2887
2888                query.append("groupId = ?");
2889
2890                query.append(" ");
2891
2892                Query q = session.createQuery(query.toString());
2893
2894                QueryPos qPos = QueryPos.getInstance(q);
2895
2896                qPos.add(groupId);
2897
2898                Long count = null;
2899
2900                Iterator<Long> itr = q.list().iterator();
2901
2902                if (itr.hasNext()) {
2903                    count = itr.next();
2904                }
2905
2906                if (count == null) {
2907                    count = new Long(0);
2908                }
2909
2910                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2911                    finderClassName, finderMethodName, finderParams,
2912                    finderArgs, count);
2913
2914                return count.intValue();
2915            }
2916            catch (Exception e) {
2917                throw processException(e);
2918            }
2919            finally {
2920                closeSession(session);
2921            }
2922        }
2923        else {
2924            return ((Long)result).intValue();
2925        }
2926    }
2927
2928    public int countByCompanyId(long companyId) throws SystemException {
2929        boolean finderClassNameCacheEnabled = BlogsEntryModelImpl.CACHE_ENABLED;
2930        String finderClassName = BlogsEntry.class.getName();
2931        String finderMethodName = "countByCompanyId";
2932        String[] finderParams = new String[] { Long.class.getName() };
2933        Object[] finderArgs = new Object[] { new Long(companyId) };
2934
2935        Object result = null;
2936
2937        if (finderClassNameCacheEnabled) {
2938            result = FinderCacheUtil.getResult(finderClassName,
2939                    finderMethodName, finderParams, finderArgs, this);
2940        }
2941
2942        if (result == null) {
2943            Session session = null;
2944
2945            try {
2946                session = openSession();
2947
2948                StringBuilder query = new StringBuilder();
2949
2950                query.append("SELECT COUNT(*) ");
2951                query.append(
2952                    "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
2953
2954                query.append("companyId = ?");
2955
2956                query.append(" ");
2957
2958                Query q = session.createQuery(query.toString());
2959
2960                QueryPos qPos = QueryPos.getInstance(q);
2961
2962                qPos.add(companyId);
2963
2964                Long count = null;
2965
2966                Iterator<Long> itr = q.list().iterator();
2967
2968                if (itr.hasNext()) {
2969                    count = itr.next();
2970                }
2971
2972                if (count == null) {
2973                    count = new Long(0);
2974                }
2975
2976                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2977                    finderClassName, finderMethodName, finderParams,
2978                    finderArgs, count);
2979
2980                return count.intValue();
2981            }
2982            catch (Exception e) {
2983                throw processException(e);
2984            }
2985            finally {
2986                closeSession(session);
2987            }
2988        }
2989        else {
2990            return ((Long)result).intValue();
2991        }
2992    }
2993
2994    public int countByG_U(long groupId, long userId) throws SystemException {
2995        boolean finderClassNameCacheEnabled = BlogsEntryModelImpl.CACHE_ENABLED;
2996        String finderClassName = BlogsEntry.class.getName();
2997        String finderMethodName = "countByG_U";
2998        String[] finderParams = new String[] {
2999                Long.class.getName(), Long.class.getName()
3000            };
3001        Object[] finderArgs = new Object[] { new Long(groupId), new Long(userId) };
3002
3003        Object result = null;
3004
3005        if (finderClassNameCacheEnabled) {
3006            result = FinderCacheUtil.getResult(finderClassName,
3007                    finderMethodName, finderParams, finderArgs, this);
3008        }
3009
3010        if (result == null) {
3011            Session session = null;
3012
3013            try {
3014                session = openSession();
3015
3016                StringBuilder query = new StringBuilder();
3017
3018                query.append("SELECT COUNT(*) ");
3019                query.append(
3020                    "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
3021
3022                query.append("groupId = ?");
3023
3024                query.append(" AND ");
3025
3026                query.append("userId = ?");
3027
3028                query.append(" ");
3029
3030                Query q = session.createQuery(query.toString());
3031
3032                QueryPos qPos = QueryPos.getInstance(q);
3033
3034                qPos.add(groupId);
3035
3036                qPos.add(userId);
3037
3038                Long count = null;
3039
3040                Iterator<Long> itr = q.list().iterator();
3041
3042                if (itr.hasNext()) {
3043                    count = itr.next();
3044                }
3045
3046                if (count == null) {
3047                    count = new Long(0);
3048                }
3049
3050                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
3051                    finderClassName, finderMethodName, finderParams,
3052                    finderArgs, count);
3053
3054                return count.intValue();
3055            }
3056            catch (Exception e) {
3057                throw processException(e);
3058            }
3059            finally {
3060                closeSession(session);
3061            }
3062        }
3063        else {
3064            return ((Long)result).intValue();
3065        }
3066    }
3067
3068    public int countByG_UT(long groupId, String urlTitle)
3069        throws SystemException {
3070        boolean finderClassNameCacheEnabled = BlogsEntryModelImpl.CACHE_ENABLED;
3071        String finderClassName = BlogsEntry.class.getName();
3072        String finderMethodName = "countByG_UT";
3073        String[] finderParams = new String[] {
3074                Long.class.getName(), String.class.getName()
3075            };
3076        Object[] finderArgs = new Object[] { new Long(groupId), urlTitle };
3077
3078        Object result = null;
3079
3080        if (finderClassNameCacheEnabled) {
3081            result = FinderCacheUtil.getResult(finderClassName,
3082                    finderMethodName, finderParams, finderArgs, this);
3083        }
3084
3085        if (result == null) {
3086            Session session = null;
3087
3088            try {
3089                session = openSession();
3090
3091                StringBuilder query = new StringBuilder();
3092
3093                query.append("SELECT COUNT(*) ");
3094                query.append(
3095                    "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
3096
3097                query.append("groupId = ?");
3098
3099                query.append(" AND ");
3100
3101                if (urlTitle == null) {
3102                    query.append("urlTitle IS NULL");
3103                }
3104                else {
3105                    query.append("urlTitle = ?");
3106                }
3107
3108                query.append(" ");
3109
3110                Query q = session.createQuery(query.toString());
3111
3112                QueryPos qPos = QueryPos.getInstance(q);
3113
3114                qPos.add(groupId);
3115
3116                if (urlTitle != null) {
3117                    qPos.add(urlTitle);
3118                }
3119
3120                Long count = null;
3121
3122                Iterator<Long> itr = q.list().iterator();
3123
3124                if (itr.hasNext()) {
3125                    count = itr.next();
3126                }
3127
3128                if (count == null) {
3129                    count = new Long(0);
3130                }
3131
3132                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
3133                    finderClassName, finderMethodName, finderParams,
3134                    finderArgs, count);
3135
3136                return count.intValue();
3137            }
3138            catch (Exception e) {
3139                throw processException(e);
3140            }
3141            finally {
3142                closeSession(session);
3143            }
3144        }
3145        else {
3146            return ((Long)result).intValue();
3147        }
3148    }
3149
3150    public int countByG_D_D(long groupId, Date displayDate, boolean draft)
3151        throws SystemException {
3152        boolean finderClassNameCacheEnabled = BlogsEntryModelImpl.CACHE_ENABLED;
3153        String finderClassName = BlogsEntry.class.getName();
3154        String finderMethodName = "countByG_D_D";
3155        String[] finderParams = new String[] {
3156                Long.class.getName(), Date.class.getName(),
3157                Boolean.class.getName()
3158            };
3159        Object[] finderArgs = new Object[] {
3160                new Long(groupId),
3161                
3162                displayDate, Boolean.valueOf(draft)
3163            };
3164
3165        Object result = null;
3166
3167        if (finderClassNameCacheEnabled) {
3168            result = FinderCacheUtil.getResult(finderClassName,
3169                    finderMethodName, finderParams, finderArgs, this);
3170        }
3171
3172        if (result == null) {
3173            Session session = null;
3174
3175            try {
3176                session = openSession();
3177
3178                StringBuilder query = new StringBuilder();
3179
3180                query.append("SELECT COUNT(*) ");
3181                query.append(
3182                    "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
3183
3184                query.append("groupId = ?");
3185
3186                query.append(" AND ");
3187
3188                if (displayDate == null) {
3189                    query.append("displayDate < null");
3190                }
3191                else {
3192                    query.append("displayDate < ?");
3193                }
3194
3195                query.append(" AND ");
3196
3197                query.append("draft = ?");
3198
3199                query.append(" ");
3200
3201                Query q = session.createQuery(query.toString());
3202
3203                QueryPos qPos = QueryPos.getInstance(q);
3204
3205                qPos.add(groupId);
3206
3207                if (displayDate != null) {
3208                    qPos.add(CalendarUtil.getTimestamp(displayDate));
3209                }
3210
3211                qPos.add(draft);
3212
3213                Long count = null;
3214
3215                Iterator<Long> itr = q.list().iterator();
3216
3217                if (itr.hasNext()) {
3218                    count = itr.next();
3219                }
3220
3221                if (count == null) {
3222                    count = new Long(0);
3223                }
3224
3225                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
3226                    finderClassName, finderMethodName, finderParams,
3227                    finderArgs, count);
3228
3229                return count.intValue();
3230            }
3231            catch (Exception e) {
3232                throw processException(e);
3233            }
3234            finally {
3235                closeSession(session);
3236            }
3237        }
3238        else {
3239            return ((Long)result).intValue();
3240        }
3241    }
3242
3243    public int countByC_D_D(long companyId, Date displayDate, boolean draft)
3244        throws SystemException {
3245        boolean finderClassNameCacheEnabled = BlogsEntryModelImpl.CACHE_ENABLED;
3246        String finderClassName = BlogsEntry.class.getName();
3247        String finderMethodName = "countByC_D_D";
3248        String[] finderParams = new String[] {
3249                Long.class.getName(), Date.class.getName(),
3250                Boolean.class.getName()
3251            };
3252        Object[] finderArgs = new Object[] {
3253                new Long(companyId),
3254                
3255                displayDate, Boolean.valueOf(draft)
3256            };
3257
3258        Object result = null;
3259
3260        if (finderClassNameCacheEnabled) {
3261            result = FinderCacheUtil.getResult(finderClassName,
3262                    finderMethodName, finderParams, finderArgs, this);
3263        }
3264
3265        if (result == null) {
3266            Session session = null;
3267
3268            try {
3269                session = openSession();
3270
3271                StringBuilder query = new StringBuilder();
3272
3273                query.append("SELECT COUNT(*) ");
3274                query.append(
3275                    "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
3276
3277                query.append("companyId = ?");
3278
3279                query.append(" AND ");
3280
3281                if (displayDate == null) {
3282                    query.append("displayDate < null");
3283                }
3284                else {
3285                    query.append("displayDate < ?");
3286                }
3287
3288                query.append(" AND ");
3289
3290                query.append("draft = ?");
3291
3292                query.append(" ");
3293
3294                Query q = session.createQuery(query.toString());
3295
3296                QueryPos qPos = QueryPos.getInstance(q);
3297
3298                qPos.add(companyId);
3299
3300                if (displayDate != null) {
3301                    qPos.add(CalendarUtil.getTimestamp(displayDate));
3302                }
3303
3304                qPos.add(draft);
3305
3306                Long count = null;
3307
3308                Iterator<Long> itr = q.list().iterator();
3309
3310                if (itr.hasNext()) {
3311                    count = itr.next();
3312                }
3313
3314                if (count == null) {
3315                    count = new Long(0);
3316                }
3317
3318                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
3319                    finderClassName, finderMethodName, finderParams,
3320                    finderArgs, count);
3321
3322                return count.intValue();
3323            }
3324            catch (Exception e) {
3325                throw processException(e);
3326            }
3327            finally {
3328                closeSession(session);
3329            }
3330        }
3331        else {
3332            return ((Long)result).intValue();
3333        }
3334    }
3335
3336    public int countByG_U_D_D(long groupId, long userId, Date displayDate,
3337        boolean draft) throws SystemException {
3338        boolean finderClassNameCacheEnabled = BlogsEntryModelImpl.CACHE_ENABLED;
3339        String finderClassName = BlogsEntry.class.getName();
3340        String finderMethodName = "countByG_U_D_D";
3341        String[] finderParams = new String[] {
3342                Long.class.getName(), Long.class.getName(), Date.class.getName(),
3343                Boolean.class.getName()
3344            };
3345        Object[] finderArgs = new Object[] {
3346                new Long(groupId), new Long(userId),
3347                
3348                displayDate, Boolean.valueOf(draft)
3349            };
3350
3351        Object result = null;
3352
3353        if (finderClassNameCacheEnabled) {
3354            result = FinderCacheUtil.getResult(finderClassName,
3355                    finderMethodName, finderParams, finderArgs, this);
3356        }
3357
3358        if (result == null) {
3359            Session session = null;
3360
3361            try {
3362                session = openSession();
3363
3364                StringBuilder query = new StringBuilder();
3365
3366                query.append("SELECT COUNT(*) ");
3367                query.append(
3368                    "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
3369
3370                query.append("groupId = ?");
3371
3372                query.append(" AND ");
3373
3374                query.append("userId = ?");
3375
3376                query.append(" AND ");
3377
3378                if (displayDate == null) {
3379                    query.append("displayDate < null");
3380                }
3381                else {
3382                    query.append("displayDate < ?");
3383                }
3384
3385                query.append(" AND ");
3386
3387                query.append("draft = ?");
3388
3389                query.append(" ");
3390
3391                Query q = session.createQuery(query.toString());
3392
3393                QueryPos qPos = QueryPos.getInstance(q);
3394
3395                qPos.add(groupId);
3396
3397                qPos.add(userId);
3398
3399                if (displayDate != null) {
3400                    qPos.add(CalendarUtil.getTimestamp(displayDate));
3401                }
3402
3403                qPos.add(draft);
3404
3405                Long count = null;
3406
3407                Iterator<Long> itr = q.list().iterator();
3408
3409                if (itr.hasNext()) {
3410                    count = itr.next();
3411                }
3412
3413                if (count == null) {
3414                    count = new Long(0);
3415                }
3416
3417                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
3418                    finderClassName, finderMethodName, finderParams,
3419                    finderArgs, count);
3420
3421                return count.intValue();
3422            }
3423            catch (Exception e) {
3424                throw processException(e);
3425            }
3426            finally {
3427                closeSession(session);
3428            }
3429        }
3430        else {
3431            return ((Long)result).intValue();
3432        }
3433    }
3434
3435    public int countAll() throws SystemException {
3436        boolean finderClassNameCacheEnabled = BlogsEntryModelImpl.CACHE_ENABLED;
3437        String finderClassName = BlogsEntry.class.getName();
3438        String finderMethodName = "countAll";
3439        String[] finderParams = new String[] {  };
3440        Object[] finderArgs = new Object[] {  };
3441
3442        Object result = null;
3443
3444        if (finderClassNameCacheEnabled) {
3445            result = FinderCacheUtil.getResult(finderClassName,
3446                    finderMethodName, finderParams, finderArgs, this);
3447        }
3448
3449        if (result == null) {
3450            Session session = null;
3451
3452            try {
3453                session = openSession();
3454
3455                Query q = session.createQuery(
3456                        "SELECT COUNT(*) FROM com.liferay.portlet.blogs.model.BlogsEntry");
3457
3458                Long count = null;
3459
3460                Iterator<Long> itr = q.list().iterator();
3461
3462                if (itr.hasNext()) {
3463                    count = itr.next();
3464                }
3465
3466                if (count == null) {
3467                    count = new Long(0);
3468                }
3469
3470                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
3471                    finderClassName, finderMethodName, finderParams,
3472                    finderArgs, count);
3473
3474                return count.intValue();
3475            }
3476            catch (Exception e) {
3477                throw processException(e);
3478            }
3479            finally {
3480                closeSession(session);
3481            }
3482        }
3483        else {
3484            return ((Long)result).intValue();
3485        }
3486    }
3487
3488    public void registerListener(ModelListener listener) {
3489        List<ModelListener> listeners = ListUtil.fromArray(_listeners);
3490
3491        listeners.add(listener);
3492
3493        _listeners = listeners.toArray(new ModelListener[listeners.size()]);
3494    }
3495
3496    public void unregisterListener(ModelListener listener) {
3497        List<ModelListener> listeners = ListUtil.fromArray(_listeners);
3498
3499        listeners.remove(listener);
3500
3501        _listeners = listeners.toArray(new ModelListener[listeners.size()]);
3502    }
3503
3504    public void afterPropertiesSet() {
3505        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
3506                    com.liferay.portal.util.PropsUtil.get(
3507                        "value.object.listener.com.liferay.portlet.blogs.model.BlogsEntry")));
3508
3509        if (listenerClassNames.length > 0) {
3510            try {
3511                List<ModelListener> listeners = new ArrayList<ModelListener>();
3512
3513                for (String listenerClassName : listenerClassNames) {
3514                    listeners.add((ModelListener)Class.forName(
3515                            listenerClassName).newInstance());
3516                }
3517
3518                _listeners = listeners.toArray(new ModelListener[listeners.size()]);
3519            }
3520            catch (Exception e) {
3521                _log.error(e);
3522            }
3523        }
3524    }
3525
3526    private static Log _log = LogFactory.getLog(BlogsEntryPersistenceImpl.class);
3527    private ModelListener[] _listeners = new ModelListener[0];
3528}