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.journal.service.persistence;
24  
25  import com.liferay.portal.SystemException;
26  import com.liferay.portal.kernel.dao.DynamicQuery;
27  import com.liferay.portal.kernel.dao.DynamicQueryInitializer;
28  import com.liferay.portal.kernel.util.GetterUtil;
29  import com.liferay.portal.kernel.util.OrderByComparator;
30  import com.liferay.portal.kernel.util.StringMaker;
31  import com.liferay.portal.kernel.util.StringPool;
32  import com.liferay.portal.kernel.util.Validator;
33  import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
34  import com.liferay.portal.model.ModelListener;
35  import com.liferay.portal.service.persistence.BasePersistence;
36  import com.liferay.portal.spring.hibernate.FinderCache;
37  import com.liferay.portal.spring.hibernate.HibernateUtil;
38  import com.liferay.portal.util.PropsUtil;
39  
40  import com.liferay.portlet.journal.NoSuchStructureException;
41  import com.liferay.portlet.journal.model.JournalStructure;
42  import com.liferay.portlet.journal.model.impl.JournalStructureImpl;
43  import com.liferay.portlet.journal.model.impl.JournalStructureModelImpl;
44  
45  import com.liferay.util.dao.hibernate.QueryUtil;
46  
47  import org.apache.commons.logging.Log;
48  import org.apache.commons.logging.LogFactory;
49  
50  import org.hibernate.Query;
51  import org.hibernate.Session;
52  
53  import java.util.Collections;
54  import java.util.Iterator;
55  import java.util.List;
56  
57  /**
58   * <a href="JournalStructurePersistenceImpl.java.html"><b><i>View Source</i></b></a>
59   *
60   * @author Brian Wing Shun Chan
61   *
62   */
63  public class JournalStructurePersistenceImpl extends BasePersistence
64      implements JournalStructurePersistence {
65      public JournalStructure create(long id) {
66          JournalStructure journalStructure = new JournalStructureImpl();
67  
68          journalStructure.setNew(true);
69          journalStructure.setPrimaryKey(id);
70  
71          String uuid = PortalUUIDUtil.generate();
72  
73          journalStructure.setUuid(uuid);
74  
75          return journalStructure;
76      }
77  
78      public JournalStructure remove(long id)
79          throws NoSuchStructureException, SystemException {
80          Session session = null;
81  
82          try {
83              session = openSession();
84  
85              JournalStructure journalStructure = (JournalStructure)session.get(JournalStructureImpl.class,
86                      new Long(id));
87  
88              if (journalStructure == null) {
89                  if (_log.isWarnEnabled()) {
90                      _log.warn(
91                          "No JournalStructure exists with the primary key " +
92                          id);
93                  }
94  
95                  throw new NoSuchStructureException(
96                      "No JournalStructure exists with the primary key " + id);
97              }
98  
99              return remove(journalStructure);
100         }
101         catch (NoSuchStructureException nsee) {
102             throw nsee;
103         }
104         catch (Exception e) {
105             throw HibernateUtil.processException(e);
106         }
107         finally {
108             closeSession(session);
109         }
110     }
111 
112     public JournalStructure remove(JournalStructure journalStructure)
113         throws SystemException {
114         ModelListener listener = _getListener();
115 
116         if (listener != null) {
117             listener.onBeforeRemove(journalStructure);
118         }
119 
120         journalStructure = removeImpl(journalStructure);
121 
122         if (listener != null) {
123             listener.onAfterRemove(journalStructure);
124         }
125 
126         return journalStructure;
127     }
128 
129     protected JournalStructure removeImpl(JournalStructure journalStructure)
130         throws SystemException {
131         Session session = null;
132 
133         try {
134             session = openSession();
135 
136             session.delete(journalStructure);
137 
138             session.flush();
139 
140             return journalStructure;
141         }
142         catch (Exception e) {
143             throw HibernateUtil.processException(e);
144         }
145         finally {
146             closeSession(session);
147 
148             FinderCache.clearCache(JournalStructure.class.getName());
149         }
150     }
151 
152     public JournalStructure update(JournalStructure journalStructure)
153         throws SystemException {
154         return update(journalStructure, false);
155     }
156 
157     public JournalStructure update(JournalStructure journalStructure,
158         boolean merge) throws SystemException {
159         ModelListener listener = _getListener();
160 
161         boolean isNew = journalStructure.isNew();
162 
163         if (listener != null) {
164             if (isNew) {
165                 listener.onBeforeCreate(journalStructure);
166             }
167             else {
168                 listener.onBeforeUpdate(journalStructure);
169             }
170         }
171 
172         journalStructure = updateImpl(journalStructure, merge);
173 
174         if (listener != null) {
175             if (isNew) {
176                 listener.onAfterCreate(journalStructure);
177             }
178             else {
179                 listener.onAfterUpdate(journalStructure);
180             }
181         }
182 
183         return journalStructure;
184     }
185 
186     public JournalStructure updateImpl(
187         com.liferay.portlet.journal.model.JournalStructure journalStructure,
188         boolean merge) throws SystemException {
189         if (Validator.isNull(journalStructure.getUuid())) {
190             String uuid = PortalUUIDUtil.generate();
191 
192             journalStructure.setUuid(uuid);
193         }
194 
195         Session session = null;
196 
197         try {
198             session = openSession();
199 
200             if (merge) {
201                 session.merge(journalStructure);
202             }
203             else {
204                 if (journalStructure.isNew()) {
205                     session.save(journalStructure);
206                 }
207             }
208 
209             session.flush();
210 
211             journalStructure.setNew(false);
212 
213             return journalStructure;
214         }
215         catch (Exception e) {
216             throw HibernateUtil.processException(e);
217         }
218         finally {
219             closeSession(session);
220 
221             FinderCache.clearCache(JournalStructure.class.getName());
222         }
223     }
224 
225     public JournalStructure findByPrimaryKey(long id)
226         throws NoSuchStructureException, SystemException {
227         JournalStructure journalStructure = fetchByPrimaryKey(id);
228 
229         if (journalStructure == null) {
230             if (_log.isWarnEnabled()) {
231                 _log.warn("No JournalStructure exists with the primary key " +
232                     id);
233             }
234 
235             throw new NoSuchStructureException(
236                 "No JournalStructure exists with the primary key " + id);
237         }
238 
239         return journalStructure;
240     }
241 
242     public JournalStructure fetchByPrimaryKey(long id)
243         throws SystemException {
244         Session session = null;
245 
246         try {
247             session = openSession();
248 
249             return (JournalStructure)session.get(JournalStructureImpl.class,
250                 new Long(id));
251         }
252         catch (Exception e) {
253             throw HibernateUtil.processException(e);
254         }
255         finally {
256             closeSession(session);
257         }
258     }
259 
260     public List findByUuid(String uuid) throws SystemException {
261         boolean finderClassNameCacheEnabled = JournalStructureModelImpl.CACHE_ENABLED;
262         String finderClassName = JournalStructure.class.getName();
263         String finderMethodName = "findByUuid";
264         String[] finderParams = new String[] { String.class.getName() };
265         Object[] finderArgs = new Object[] { uuid };
266 
267         Object result = null;
268 
269         if (finderClassNameCacheEnabled) {
270             result = FinderCache.getResult(finderClassName, finderMethodName,
271                     finderParams, finderArgs, getSessionFactory());
272         }
273 
274         if (result == null) {
275             Session session = null;
276 
277             try {
278                 session = openSession();
279 
280                 StringMaker query = new StringMaker();
281 
282                 query.append(
283                     "FROM com.liferay.portlet.journal.model.JournalStructure WHERE ");
284 
285                 if (uuid == null) {
286                     query.append("uuid_ IS NULL");
287                 }
288                 else {
289                     query.append("uuid_ = ?");
290                 }
291 
292                 query.append(" ");
293 
294                 query.append("ORDER BY ");
295 
296                 query.append("structureId ASC");
297 
298                 Query q = session.createQuery(query.toString());
299 
300                 int queryPos = 0;
301 
302                 if (uuid != null) {
303                     q.setString(queryPos++, uuid);
304                 }
305 
306                 List list = q.list();
307 
308                 FinderCache.putResult(finderClassNameCacheEnabled,
309                     finderClassName, finderMethodName, finderParams,
310                     finderArgs, list);
311 
312                 return list;
313             }
314             catch (Exception e) {
315                 throw HibernateUtil.processException(e);
316             }
317             finally {
318                 closeSession(session);
319             }
320         }
321         else {
322             return (List)result;
323         }
324     }
325 
326     public List findByUuid(String uuid, int begin, int end)
327         throws SystemException {
328         return findByUuid(uuid, begin, end, null);
329     }
330 
331     public List findByUuid(String uuid, int begin, int end,
332         OrderByComparator obc) throws SystemException {
333         boolean finderClassNameCacheEnabled = JournalStructureModelImpl.CACHE_ENABLED;
334         String finderClassName = JournalStructure.class.getName();
335         String finderMethodName = "findByUuid";
336         String[] finderParams = new String[] {
337                 String.class.getName(),
338                 
339                 "java.lang.Integer", "java.lang.Integer",
340                 "com.liferay.portal.kernel.util.OrderByComparator"
341             };
342         Object[] finderArgs = new Object[] {
343                 uuid,
344                 
345                 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
346             };
347 
348         Object result = null;
349 
350         if (finderClassNameCacheEnabled) {
351             result = FinderCache.getResult(finderClassName, finderMethodName,
352                     finderParams, finderArgs, getSessionFactory());
353         }
354 
355         if (result == null) {
356             Session session = null;
357 
358             try {
359                 session = openSession();
360 
361                 StringMaker query = new StringMaker();
362 
363                 query.append(
364                     "FROM com.liferay.portlet.journal.model.JournalStructure WHERE ");
365 
366                 if (uuid == null) {
367                     query.append("uuid_ IS NULL");
368                 }
369                 else {
370                     query.append("uuid_ = ?");
371                 }
372 
373                 query.append(" ");
374 
375                 if (obc != null) {
376                     query.append("ORDER BY ");
377                     query.append(obc.getOrderBy());
378                 }
379 
380                 else {
381                     query.append("ORDER BY ");
382 
383                     query.append("structureId ASC");
384                 }
385 
386                 Query q = session.createQuery(query.toString());
387 
388                 int queryPos = 0;
389 
390                 if (uuid != null) {
391                     q.setString(queryPos++, uuid);
392                 }
393 
394                 List list = QueryUtil.list(q, getDialect(), begin, end);
395 
396                 FinderCache.putResult(finderClassNameCacheEnabled,
397                     finderClassName, finderMethodName, finderParams,
398                     finderArgs, list);
399 
400                 return list;
401             }
402             catch (Exception e) {
403                 throw HibernateUtil.processException(e);
404             }
405             finally {
406                 closeSession(session);
407             }
408         }
409         else {
410             return (List)result;
411         }
412     }
413 
414     public JournalStructure findByUuid_First(String uuid, OrderByComparator obc)
415         throws NoSuchStructureException, SystemException {
416         List list = findByUuid(uuid, 0, 1, obc);
417 
418         if (list.size() == 0) {
419             StringMaker msg = new StringMaker();
420 
421             msg.append("No JournalStructure exists with the key {");
422 
423             msg.append("uuid=" + uuid);
424 
425             msg.append(StringPool.CLOSE_CURLY_BRACE);
426 
427             throw new NoSuchStructureException(msg.toString());
428         }
429         else {
430             return (JournalStructure)list.get(0);
431         }
432     }
433 
434     public JournalStructure findByUuid_Last(String uuid, OrderByComparator obc)
435         throws NoSuchStructureException, SystemException {
436         int count = countByUuid(uuid);
437 
438         List list = findByUuid(uuid, count - 1, count, obc);
439 
440         if (list.size() == 0) {
441             StringMaker msg = new StringMaker();
442 
443             msg.append("No JournalStructure exists with the key {");
444 
445             msg.append("uuid=" + uuid);
446 
447             msg.append(StringPool.CLOSE_CURLY_BRACE);
448 
449             throw new NoSuchStructureException(msg.toString());
450         }
451         else {
452             return (JournalStructure)list.get(0);
453         }
454     }
455 
456     public JournalStructure[] findByUuid_PrevAndNext(long id, String uuid,
457         OrderByComparator obc) throws NoSuchStructureException, SystemException {
458         JournalStructure journalStructure = findByPrimaryKey(id);
459 
460         int count = countByUuid(uuid);
461 
462         Session session = null;
463 
464         try {
465             session = openSession();
466 
467             StringMaker query = new StringMaker();
468 
469             query.append(
470                 "FROM com.liferay.portlet.journal.model.JournalStructure WHERE ");
471 
472             if (uuid == null) {
473                 query.append("uuid_ IS NULL");
474             }
475             else {
476                 query.append("uuid_ = ?");
477             }
478 
479             query.append(" ");
480 
481             if (obc != null) {
482                 query.append("ORDER BY ");
483                 query.append(obc.getOrderBy());
484             }
485 
486             else {
487                 query.append("ORDER BY ");
488 
489                 query.append("structureId ASC");
490             }
491 
492             Query q = session.createQuery(query.toString());
493 
494             int queryPos = 0;
495 
496             if (uuid != null) {
497                 q.setString(queryPos++, uuid);
498             }
499 
500             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
501                     journalStructure);
502 
503             JournalStructure[] array = new JournalStructureImpl[3];
504 
505             array[0] = (JournalStructure)objArray[0];
506             array[1] = (JournalStructure)objArray[1];
507             array[2] = (JournalStructure)objArray[2];
508 
509             return array;
510         }
511         catch (Exception e) {
512             throw HibernateUtil.processException(e);
513         }
514         finally {
515             closeSession(session);
516         }
517     }
518 
519     public JournalStructure findByUUID_G(String uuid, long groupId)
520         throws NoSuchStructureException, SystemException {
521         JournalStructure journalStructure = fetchByUUID_G(uuid, groupId);
522 
523         if (journalStructure == null) {
524             StringMaker msg = new StringMaker();
525 
526             msg.append("No JournalStructure exists with the key {");
527 
528             msg.append("uuid=" + uuid);
529 
530             msg.append(", ");
531             msg.append("groupId=" + groupId);
532 
533             msg.append(StringPool.CLOSE_CURLY_BRACE);
534 
535             if (_log.isWarnEnabled()) {
536                 _log.warn(msg.toString());
537             }
538 
539             throw new NoSuchStructureException(msg.toString());
540         }
541 
542         return journalStructure;
543     }
544 
545     public JournalStructure fetchByUUID_G(String uuid, long groupId)
546         throws SystemException {
547         boolean finderClassNameCacheEnabled = JournalStructureModelImpl.CACHE_ENABLED;
548         String finderClassName = JournalStructure.class.getName();
549         String finderMethodName = "fetchByUUID_G";
550         String[] finderParams = new String[] {
551                 String.class.getName(), Long.class.getName()
552             };
553         Object[] finderArgs = new Object[] { uuid, new Long(groupId) };
554 
555         Object result = null;
556 
557         if (finderClassNameCacheEnabled) {
558             result = FinderCache.getResult(finderClassName, finderMethodName,
559                     finderParams, finderArgs, getSessionFactory());
560         }
561 
562         if (result == null) {
563             Session session = null;
564 
565             try {
566                 session = openSession();
567 
568                 StringMaker query = new StringMaker();
569 
570                 query.append(
571                     "FROM com.liferay.portlet.journal.model.JournalStructure WHERE ");
572 
573                 if (uuid == null) {
574                     query.append("uuid_ IS NULL");
575                 }
576                 else {
577                     query.append("uuid_ = ?");
578                 }
579 
580                 query.append(" AND ");
581 
582                 query.append("groupId = ?");
583 
584                 query.append(" ");
585 
586                 query.append("ORDER BY ");
587 
588                 query.append("structureId ASC");
589 
590                 Query q = session.createQuery(query.toString());
591 
592                 int queryPos = 0;
593 
594                 if (uuid != null) {
595                     q.setString(queryPos++, uuid);
596                 }
597 
598                 q.setLong(queryPos++, groupId);
599 
600                 List list = q.list();
601 
602                 FinderCache.putResult(finderClassNameCacheEnabled,
603                     finderClassName, finderMethodName, finderParams,
604                     finderArgs, list);
605 
606                 if (list.size() == 0) {
607                     return null;
608                 }
609                 else {
610                     return (JournalStructure)list.get(0);
611                 }
612             }
613             catch (Exception e) {
614                 throw HibernateUtil.processException(e);
615             }
616             finally {
617                 closeSession(session);
618             }
619         }
620         else {
621             List list = (List)result;
622 
623             if (list.size() == 0) {
624                 return null;
625             }
626             else {
627                 return (JournalStructure)list.get(0);
628             }
629         }
630     }
631 
632     public List findByGroupId(long groupId) throws SystemException {
633         boolean finderClassNameCacheEnabled = JournalStructureModelImpl.CACHE_ENABLED;
634         String finderClassName = JournalStructure.class.getName();
635         String finderMethodName = "findByGroupId";
636         String[] finderParams = new String[] { Long.class.getName() };
637         Object[] finderArgs = new Object[] { new Long(groupId) };
638 
639         Object result = null;
640 
641         if (finderClassNameCacheEnabled) {
642             result = FinderCache.getResult(finderClassName, finderMethodName,
643                     finderParams, finderArgs, getSessionFactory());
644         }
645 
646         if (result == null) {
647             Session session = null;
648 
649             try {
650                 session = openSession();
651 
652                 StringMaker query = new StringMaker();
653 
654                 query.append(
655                     "FROM com.liferay.portlet.journal.model.JournalStructure WHERE ");
656 
657                 query.append("groupId = ?");
658 
659                 query.append(" ");
660 
661                 query.append("ORDER BY ");
662 
663                 query.append("structureId ASC");
664 
665                 Query q = session.createQuery(query.toString());
666 
667                 int queryPos = 0;
668 
669                 q.setLong(queryPos++, groupId);
670 
671                 List list = q.list();
672 
673                 FinderCache.putResult(finderClassNameCacheEnabled,
674                     finderClassName, finderMethodName, finderParams,
675                     finderArgs, list);
676 
677                 return list;
678             }
679             catch (Exception e) {
680                 throw HibernateUtil.processException(e);
681             }
682             finally {
683                 closeSession(session);
684             }
685         }
686         else {
687             return (List)result;
688         }
689     }
690 
691     public List findByGroupId(long groupId, int begin, int end)
692         throws SystemException {
693         return findByGroupId(groupId, begin, end, null);
694     }
695 
696     public List findByGroupId(long groupId, int begin, int end,
697         OrderByComparator obc) throws SystemException {
698         boolean finderClassNameCacheEnabled = JournalStructureModelImpl.CACHE_ENABLED;
699         String finderClassName = JournalStructure.class.getName();
700         String finderMethodName = "findByGroupId";
701         String[] finderParams = new String[] {
702                 Long.class.getName(),
703                 
704                 "java.lang.Integer", "java.lang.Integer",
705                 "com.liferay.portal.kernel.util.OrderByComparator"
706             };
707         Object[] finderArgs = new Object[] {
708                 new Long(groupId),
709                 
710                 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
711             };
712 
713         Object result = null;
714 
715         if (finderClassNameCacheEnabled) {
716             result = FinderCache.getResult(finderClassName, finderMethodName,
717                     finderParams, finderArgs, getSessionFactory());
718         }
719 
720         if (result == null) {
721             Session session = null;
722 
723             try {
724                 session = openSession();
725 
726                 StringMaker query = new StringMaker();
727 
728                 query.append(
729                     "FROM com.liferay.portlet.journal.model.JournalStructure WHERE ");
730 
731                 query.append("groupId = ?");
732 
733                 query.append(" ");
734 
735                 if (obc != null) {
736                     query.append("ORDER BY ");
737                     query.append(obc.getOrderBy());
738                 }
739 
740                 else {
741                     query.append("ORDER BY ");
742 
743                     query.append("structureId ASC");
744                 }
745 
746                 Query q = session.createQuery(query.toString());
747 
748                 int queryPos = 0;
749 
750                 q.setLong(queryPos++, groupId);
751 
752                 List list = QueryUtil.list(q, getDialect(), begin, end);
753 
754                 FinderCache.putResult(finderClassNameCacheEnabled,
755                     finderClassName, finderMethodName, finderParams,
756                     finderArgs, list);
757 
758                 return list;
759             }
760             catch (Exception e) {
761                 throw HibernateUtil.processException(e);
762             }
763             finally {
764                 closeSession(session);
765             }
766         }
767         else {
768             return (List)result;
769         }
770     }
771 
772     public JournalStructure findByGroupId_First(long groupId,
773         OrderByComparator obc) throws NoSuchStructureException, SystemException {
774         List list = findByGroupId(groupId, 0, 1, obc);
775 
776         if (list.size() == 0) {
777             StringMaker msg = new StringMaker();
778 
779             msg.append("No JournalStructure exists with the key {");
780 
781             msg.append("groupId=" + groupId);
782 
783             msg.append(StringPool.CLOSE_CURLY_BRACE);
784 
785             throw new NoSuchStructureException(msg.toString());
786         }
787         else {
788             return (JournalStructure)list.get(0);
789         }
790     }
791 
792     public JournalStructure findByGroupId_Last(long groupId,
793         OrderByComparator obc) throws NoSuchStructureException, SystemException {
794         int count = countByGroupId(groupId);
795 
796         List list = findByGroupId(groupId, count - 1, count, obc);
797 
798         if (list.size() == 0) {
799             StringMaker msg = new StringMaker();
800 
801             msg.append("No JournalStructure exists with the key {");
802 
803             msg.append("groupId=" + groupId);
804 
805             msg.append(StringPool.CLOSE_CURLY_BRACE);
806 
807             throw new NoSuchStructureException(msg.toString());
808         }
809         else {
810             return (JournalStructure)list.get(0);
811         }
812     }
813 
814     public JournalStructure[] findByGroupId_PrevAndNext(long id, long groupId,
815         OrderByComparator obc) throws NoSuchStructureException, SystemException {
816         JournalStructure journalStructure = findByPrimaryKey(id);
817 
818         int count = countByGroupId(groupId);
819 
820         Session session = null;
821 
822         try {
823             session = openSession();
824 
825             StringMaker query = new StringMaker();
826 
827             query.append(
828                 "FROM com.liferay.portlet.journal.model.JournalStructure WHERE ");
829 
830             query.append("groupId = ?");
831 
832             query.append(" ");
833 
834             if (obc != null) {
835                 query.append("ORDER BY ");
836                 query.append(obc.getOrderBy());
837             }
838 
839             else {
840                 query.append("ORDER BY ");
841 
842                 query.append("structureId ASC");
843             }
844 
845             Query q = session.createQuery(query.toString());
846 
847             int queryPos = 0;
848 
849             q.setLong(queryPos++, groupId);
850 
851             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
852                     journalStructure);
853 
854             JournalStructure[] array = new JournalStructureImpl[3];
855 
856             array[0] = (JournalStructure)objArray[0];
857             array[1] = (JournalStructure)objArray[1];
858             array[2] = (JournalStructure)objArray[2];
859 
860             return array;
861         }
862         catch (Exception e) {
863             throw HibernateUtil.processException(e);
864         }
865         finally {
866             closeSession(session);
867         }
868     }
869 
870     public List findByStructureId(String structureId) throws SystemException {
871         boolean finderClassNameCacheEnabled = JournalStructureModelImpl.CACHE_ENABLED;
872         String finderClassName = JournalStructure.class.getName();
873         String finderMethodName = "findByStructureId";
874         String[] finderParams = new String[] { String.class.getName() };
875         Object[] finderArgs = new Object[] { structureId };
876 
877         Object result = null;
878 
879         if (finderClassNameCacheEnabled) {
880             result = FinderCache.getResult(finderClassName, finderMethodName,
881                     finderParams, finderArgs, getSessionFactory());
882         }
883 
884         if (result == null) {
885             Session session = null;
886 
887             try {
888                 session = openSession();
889 
890                 StringMaker query = new StringMaker();
891 
892                 query.append(
893                     "FROM com.liferay.portlet.journal.model.JournalStructure WHERE ");
894 
895                 if (structureId == null) {
896                     query.append("structureId IS NULL");
897                 }
898                 else {
899                     query.append("structureId = ?");
900                 }
901 
902                 query.append(" ");
903 
904                 query.append("ORDER BY ");
905 
906                 query.append("structureId ASC");
907 
908                 Query q = session.createQuery(query.toString());
909 
910                 int queryPos = 0;
911 
912                 if (structureId != null) {
913                     q.setString(queryPos++, structureId);
914                 }
915 
916                 List list = q.list();
917 
918                 FinderCache.putResult(finderClassNameCacheEnabled,
919                     finderClassName, finderMethodName, finderParams,
920                     finderArgs, list);
921 
922                 return list;
923             }
924             catch (Exception e) {
925                 throw HibernateUtil.processException(e);
926             }
927             finally {
928                 closeSession(session);
929             }
930         }
931         else {
932             return (List)result;
933         }
934     }
935 
936     public List findByStructureId(String structureId, int begin, int end)
937         throws SystemException {
938         return findByStructureId(structureId, begin, end, null);
939     }
940 
941     public List findByStructureId(String structureId, int begin, int end,
942         OrderByComparator obc) throws SystemException {
943         boolean finderClassNameCacheEnabled = JournalStructureModelImpl.CACHE_ENABLED;
944         String finderClassName = JournalStructure.class.getName();
945         String finderMethodName = "findByStructureId";
946         String[] finderParams = new String[] {
947                 String.class.getName(),
948                 
949                 "java.lang.Integer", "java.lang.Integer",
950                 "com.liferay.portal.kernel.util.OrderByComparator"
951             };
952         Object[] finderArgs = new Object[] {
953                 structureId,
954                 
955                 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
956             };
957 
958         Object result = null;
959 
960         if (finderClassNameCacheEnabled) {
961             result = FinderCache.getResult(finderClassName, finderMethodName,
962                     finderParams, finderArgs, getSessionFactory());
963         }
964 
965         if (result == null) {
966             Session session = null;
967 
968             try {
969                 session = openSession();
970 
971                 StringMaker query = new StringMaker();
972 
973                 query.append(
974                     "FROM com.liferay.portlet.journal.model.JournalStructure WHERE ");
975 
976                 if (structureId == null) {
977                     query.append("structureId IS NULL");
978                 }
979                 else {
980                     query.append("structureId = ?");
981                 }
982 
983                 query.append(" ");
984 
985                 if (obc != null) {
986                     query.append("ORDER BY ");
987                     query.append(obc.getOrderBy());
988                 }
989 
990                 else {
991                     query.append("ORDER BY ");
992 
993                     query.append("structureId ASC");
994                 }
995 
996                 Query q = session.createQuery(query.toString());
997 
998                 int queryPos = 0;
999 
1000                if (structureId != null) {
1001                    q.setString(queryPos++, structureId);
1002                }
1003
1004                List list = QueryUtil.list(q, getDialect(), begin, end);
1005
1006                FinderCache.putResult(finderClassNameCacheEnabled,
1007                    finderClassName, finderMethodName, finderParams,
1008                    finderArgs, list);
1009
1010                return list;
1011            }
1012            catch (Exception e) {
1013                throw HibernateUtil.processException(e);
1014            }
1015            finally {
1016                closeSession(session);
1017            }
1018        }
1019        else {
1020            return (List)result;
1021        }
1022    }
1023
1024    public JournalStructure findByStructureId_First(String structureId,
1025        OrderByComparator obc) throws NoSuchStructureException, SystemException {
1026        List list = findByStructureId(structureId, 0, 1, obc);
1027
1028        if (list.size() == 0) {
1029            StringMaker msg = new StringMaker();
1030
1031            msg.append("No JournalStructure exists with the key {");
1032
1033            msg.append("structureId=" + structureId);
1034
1035            msg.append(StringPool.CLOSE_CURLY_BRACE);
1036
1037            throw new NoSuchStructureException(msg.toString());
1038        }
1039        else {
1040            return (JournalStructure)list.get(0);
1041        }
1042    }
1043
1044    public JournalStructure findByStructureId_Last(String structureId,
1045        OrderByComparator obc) throws NoSuchStructureException, SystemException {
1046        int count = countByStructureId(structureId);
1047
1048        List list = findByStructureId(structureId, count - 1, count, obc);
1049
1050        if (list.size() == 0) {
1051            StringMaker msg = new StringMaker();
1052
1053            msg.append("No JournalStructure exists with the key {");
1054
1055            msg.append("structureId=" + structureId);
1056
1057            msg.append(StringPool.CLOSE_CURLY_BRACE);
1058
1059            throw new NoSuchStructureException(msg.toString());
1060        }
1061        else {
1062            return (JournalStructure)list.get(0);
1063        }
1064    }
1065
1066    public JournalStructure[] findByStructureId_PrevAndNext(long id,
1067        String structureId, OrderByComparator obc)
1068        throws NoSuchStructureException, SystemException {
1069        JournalStructure journalStructure = findByPrimaryKey(id);
1070
1071        int count = countByStructureId(structureId);
1072
1073        Session session = null;
1074
1075        try {
1076            session = openSession();
1077
1078            StringMaker query = new StringMaker();
1079
1080            query.append(
1081                "FROM com.liferay.portlet.journal.model.JournalStructure WHERE ");
1082
1083            if (structureId == null) {
1084                query.append("structureId IS NULL");
1085            }
1086            else {
1087                query.append("structureId = ?");
1088            }
1089
1090            query.append(" ");
1091
1092            if (obc != null) {
1093                query.append("ORDER BY ");
1094                query.append(obc.getOrderBy());
1095            }
1096
1097            else {
1098                query.append("ORDER BY ");
1099
1100                query.append("structureId ASC");
1101            }
1102
1103            Query q = session.createQuery(query.toString());
1104
1105            int queryPos = 0;
1106
1107            if (structureId != null) {
1108                q.setString(queryPos++, structureId);
1109            }
1110
1111            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1112                    journalStructure);
1113
1114            JournalStructure[] array = new JournalStructureImpl[3];
1115
1116            array[0] = (JournalStructure)objArray[0];
1117            array[1] = (JournalStructure)objArray[1];
1118            array[2] = (JournalStructure)objArray[2];
1119
1120            return array;
1121        }
1122        catch (Exception e) {
1123            throw HibernateUtil.processException(e);
1124        }
1125        finally {
1126            closeSession(session);
1127        }
1128    }
1129
1130    public JournalStructure findByG_S(long groupId, String structureId)
1131        throws NoSuchStructureException, SystemException {
1132        JournalStructure journalStructure = fetchByG_S(groupId, structureId);
1133
1134        if (journalStructure == null) {
1135            StringMaker msg = new StringMaker();
1136
1137            msg.append("No JournalStructure exists with the key {");
1138
1139            msg.append("groupId=" + groupId);
1140
1141            msg.append(", ");
1142            msg.append("structureId=" + structureId);
1143
1144            msg.append(StringPool.CLOSE_CURLY_BRACE);
1145
1146            if (_log.isWarnEnabled()) {
1147                _log.warn(msg.toString());
1148            }
1149
1150            throw new NoSuchStructureException(msg.toString());
1151        }
1152
1153        return journalStructure;
1154    }
1155
1156    public JournalStructure fetchByG_S(long groupId, String structureId)
1157        throws SystemException {
1158        boolean finderClassNameCacheEnabled = JournalStructureModelImpl.CACHE_ENABLED;
1159        String finderClassName = JournalStructure.class.getName();
1160        String finderMethodName = "fetchByG_S";
1161        String[] finderParams = new String[] {
1162                Long.class.getName(), String.class.getName()
1163            };
1164        Object[] finderArgs = new Object[] { new Long(groupId), structureId };
1165
1166        Object result = null;
1167
1168        if (finderClassNameCacheEnabled) {
1169            result = FinderCache.getResult(finderClassName, finderMethodName,
1170                    finderParams, finderArgs, getSessionFactory());
1171        }
1172
1173        if (result == null) {
1174            Session session = null;
1175
1176            try {
1177                session = openSession();
1178
1179                StringMaker query = new StringMaker();
1180
1181                query.append(
1182                    "FROM com.liferay.portlet.journal.model.JournalStructure WHERE ");
1183
1184                query.append("groupId = ?");
1185
1186                query.append(" AND ");
1187
1188                if (structureId == null) {
1189                    query.append("structureId IS NULL");
1190                }
1191                else {
1192                    query.append("structureId = ?");
1193                }
1194
1195                query.append(" ");
1196
1197                query.append("ORDER BY ");
1198
1199                query.append("structureId ASC");
1200
1201                Query q = session.createQuery(query.toString());
1202
1203                int queryPos = 0;
1204
1205                q.setLong(queryPos++, groupId);
1206
1207                if (structureId != null) {
1208                    q.setString(queryPos++, structureId);
1209                }
1210
1211                List list = q.list();
1212
1213                FinderCache.putResult(finderClassNameCacheEnabled,
1214                    finderClassName, finderMethodName, finderParams,
1215                    finderArgs, list);
1216
1217                if (list.size() == 0) {
1218                    return null;
1219                }
1220                else {
1221                    return (JournalStructure)list.get(0);
1222                }
1223            }
1224            catch (Exception e) {
1225                throw HibernateUtil.processException(e);
1226            }
1227            finally {
1228                closeSession(session);
1229            }
1230        }
1231        else {
1232            List list = (List)result;
1233
1234            if (list.size() == 0) {
1235                return null;
1236            }
1237            else {
1238                return (JournalStructure)list.get(0);
1239            }
1240        }
1241    }
1242
1243    public List findWithDynamicQuery(DynamicQueryInitializer queryInitializer)
1244        throws SystemException {
1245        Session session = null;
1246
1247        try {
1248            session = openSession();
1249
1250            DynamicQuery query = queryInitializer.initialize(session);
1251
1252            return query.list();
1253        }
1254        catch (Exception e) {
1255            throw HibernateUtil.processException(e);
1256        }
1257        finally {
1258            closeSession(session);
1259        }
1260    }
1261
1262    public List findWithDynamicQuery(DynamicQueryInitializer queryInitializer,
1263        int begin, int end) throws SystemException {
1264        Session session = null;
1265
1266        try {
1267            session = openSession();
1268
1269            DynamicQuery query = queryInitializer.initialize(session);
1270
1271            query.setLimit(begin, end);
1272
1273            return query.list();
1274        }
1275        catch (Exception e) {
1276            throw HibernateUtil.processException(e);
1277        }
1278        finally {
1279            closeSession(session);
1280        }
1281    }
1282
1283    public List findAll() throws SystemException {
1284        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1285    }
1286
1287    public List findAll(int begin, int end) throws SystemException {
1288        return findAll(begin, end, null);
1289    }
1290
1291    public List findAll(int begin, int end, OrderByComparator obc)
1292        throws SystemException {
1293        boolean finderClassNameCacheEnabled = JournalStructureModelImpl.CACHE_ENABLED;
1294        String finderClassName = JournalStructure.class.getName();
1295        String finderMethodName = "findAll";
1296        String[] finderParams = new String[] {
1297                "java.lang.Integer", "java.lang.Integer",
1298                "com.liferay.portal.kernel.util.OrderByComparator"
1299            };
1300        Object[] finderArgs = new Object[] {
1301                String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
1302            };
1303
1304        Object result = null;
1305
1306        if (finderClassNameCacheEnabled) {
1307            result = FinderCache.getResult(finderClassName, finderMethodName,
1308                    finderParams, finderArgs, getSessionFactory());
1309        }
1310
1311        if (result == null) {
1312            Session session = null;
1313
1314            try {
1315                session = openSession();
1316
1317                StringMaker query = new StringMaker();
1318
1319                query.append(
1320                    "FROM com.liferay.portlet.journal.model.JournalStructure ");
1321
1322                if (obc != null) {
1323                    query.append("ORDER BY ");
1324                    query.append(obc.getOrderBy());
1325                }
1326
1327                else {
1328                    query.append("ORDER BY ");
1329
1330                    query.append("structureId ASC");
1331                }
1332
1333                Query q = session.createQuery(query.toString());
1334
1335                List list = QueryUtil.list(q, getDialect(), begin, end);
1336
1337                if (obc == null) {
1338                    Collections.sort(list);
1339                }
1340
1341                FinderCache.putResult(finderClassNameCacheEnabled,
1342                    finderClassName, finderMethodName, finderParams,
1343                    finderArgs, list);
1344
1345                return list;
1346            }
1347            catch (Exception e) {
1348                throw HibernateUtil.processException(e);
1349            }
1350            finally {
1351                closeSession(session);
1352            }
1353        }
1354        else {
1355            return (List)result;
1356        }
1357    }
1358
1359    public void removeByUuid(String uuid) throws SystemException {
1360        Iterator itr = findByUuid(uuid).iterator();
1361
1362        while (itr.hasNext()) {
1363            JournalStructure journalStructure = (JournalStructure)itr.next();
1364
1365            remove(journalStructure);
1366        }
1367    }
1368
1369    public void removeByUUID_G(String uuid, long groupId)
1370        throws NoSuchStructureException, SystemException {
1371        JournalStructure journalStructure = findByUUID_G(uuid, groupId);
1372
1373        remove(journalStructure);
1374    }
1375
1376    public void removeByGroupId(long groupId) throws SystemException {
1377        Iterator itr = findByGroupId(groupId).iterator();
1378
1379        while (itr.hasNext()) {
1380            JournalStructure journalStructure = (JournalStructure)itr.next();
1381
1382            remove(journalStructure);
1383        }
1384    }
1385
1386    public void removeByStructureId(String structureId)
1387        throws SystemException {
1388        Iterator itr = findByStructureId(structureId).iterator();
1389
1390        while (itr.hasNext()) {
1391            JournalStructure journalStructure = (JournalStructure)itr.next();
1392
1393            remove(journalStructure);
1394        }
1395    }
1396
1397    public void removeByG_S(long groupId, String structureId)
1398        throws NoSuchStructureException, SystemException {
1399        JournalStructure journalStructure = findByG_S(groupId, structureId);
1400
1401        remove(journalStructure);
1402    }
1403
1404    public void removeAll() throws SystemException {
1405        Iterator itr = findAll().iterator();
1406
1407        while (itr.hasNext()) {
1408            remove((JournalStructure)itr.next());
1409        }
1410    }
1411
1412    public int countByUuid(String uuid) throws SystemException {
1413        boolean finderClassNameCacheEnabled = JournalStructureModelImpl.CACHE_ENABLED;
1414        String finderClassName = JournalStructure.class.getName();
1415        String finderMethodName = "countByUuid";
1416        String[] finderParams = new String[] { String.class.getName() };
1417        Object[] finderArgs = new Object[] { uuid };
1418
1419        Object result = null;
1420
1421        if (finderClassNameCacheEnabled) {
1422            result = FinderCache.getResult(finderClassName, finderMethodName,
1423                    finderParams, finderArgs, getSessionFactory());
1424        }
1425
1426        if (result == null) {
1427            Session session = null;
1428
1429            try {
1430                session = openSession();
1431
1432                StringMaker query = new StringMaker();
1433
1434                query.append("SELECT COUNT(*) ");
1435                query.append(
1436                    "FROM com.liferay.portlet.journal.model.JournalStructure WHERE ");
1437
1438                if (uuid == null) {
1439                    query.append("uuid_ IS NULL");
1440                }
1441                else {
1442                    query.append("uuid_ = ?");
1443                }
1444
1445                query.append(" ");
1446
1447                Query q = session.createQuery(query.toString());
1448
1449                int queryPos = 0;
1450
1451                if (uuid != null) {
1452                    q.setString(queryPos++, uuid);
1453                }
1454
1455                Long count = null;
1456
1457                Iterator itr = q.list().iterator();
1458
1459                if (itr.hasNext()) {
1460                    count = (Long)itr.next();
1461                }
1462
1463                if (count == null) {
1464                    count = new Long(0);
1465                }
1466
1467                FinderCache.putResult(finderClassNameCacheEnabled,
1468                    finderClassName, finderMethodName, finderParams,
1469                    finderArgs, count);
1470
1471                return count.intValue();
1472            }
1473            catch (Exception e) {
1474                throw HibernateUtil.processException(e);
1475            }
1476            finally {
1477                closeSession(session);
1478            }
1479        }
1480        else {
1481            return ((Long)result).intValue();
1482        }
1483    }
1484
1485    public int countByUUID_G(String uuid, long groupId)
1486        throws SystemException {
1487        boolean finderClassNameCacheEnabled = JournalStructureModelImpl.CACHE_ENABLED;
1488        String finderClassName = JournalStructure.class.getName();
1489        String finderMethodName = "countByUUID_G";
1490        String[] finderParams = new String[] {
1491                String.class.getName(), Long.class.getName()
1492            };
1493        Object[] finderArgs = new Object[] { uuid, new Long(groupId) };
1494
1495        Object result = null;
1496
1497        if (finderClassNameCacheEnabled) {
1498            result = FinderCache.getResult(finderClassName, finderMethodName,
1499                    finderParams, finderArgs, getSessionFactory());
1500        }
1501
1502        if (result == null) {
1503            Session session = null;
1504
1505            try {
1506                session = openSession();
1507
1508                StringMaker query = new StringMaker();
1509
1510                query.append("SELECT COUNT(*) ");
1511                query.append(
1512                    "FROM com.liferay.portlet.journal.model.JournalStructure WHERE ");
1513
1514                if (uuid == null) {
1515                    query.append("uuid_ IS NULL");
1516                }
1517                else {
1518                    query.append("uuid_ = ?");
1519                }
1520
1521                query.append(" AND ");
1522
1523                query.append("groupId = ?");
1524
1525                query.append(" ");
1526
1527                Query q = session.createQuery(query.toString());
1528
1529                int queryPos = 0;
1530
1531                if (uuid != null) {
1532                    q.setString(queryPos++, uuid);
1533                }
1534
1535                q.setLong(queryPos++, groupId);
1536
1537                Long count = null;
1538
1539                Iterator itr = q.list().iterator();
1540
1541                if (itr.hasNext()) {
1542                    count = (Long)itr.next();
1543                }
1544
1545                if (count == null) {
1546                    count = new Long(0);
1547                }
1548
1549                FinderCache.putResult(finderClassNameCacheEnabled,
1550                    finderClassName, finderMethodName, finderParams,
1551                    finderArgs, count);
1552
1553                return count.intValue();
1554            }
1555            catch (Exception e) {
1556                throw HibernateUtil.processException(e);
1557            }
1558            finally {
1559                closeSession(session);
1560            }
1561        }
1562        else {
1563            return ((Long)result).intValue();
1564        }
1565    }
1566
1567    public int countByGroupId(long groupId) throws SystemException {
1568        boolean finderClassNameCacheEnabled = JournalStructureModelImpl.CACHE_ENABLED;
1569        String finderClassName = JournalStructure.class.getName();
1570        String finderMethodName = "countByGroupId";
1571        String[] finderParams = new String[] { Long.class.getName() };
1572        Object[] finderArgs = new Object[] { new Long(groupId) };
1573
1574        Object result = null;
1575
1576        if (finderClassNameCacheEnabled) {
1577            result = FinderCache.getResult(finderClassName, finderMethodName,
1578                    finderParams, finderArgs, getSessionFactory());
1579        }
1580
1581        if (result == null) {
1582            Session session = null;
1583
1584            try {
1585                session = openSession();
1586
1587                StringMaker query = new StringMaker();
1588
1589                query.append("SELECT COUNT(*) ");
1590                query.append(
1591                    "FROM com.liferay.portlet.journal.model.JournalStructure WHERE ");
1592
1593                query.append("groupId = ?");
1594
1595                query.append(" ");
1596
1597                Query q = session.createQuery(query.toString());
1598
1599                int queryPos = 0;
1600
1601                q.setLong(queryPos++, groupId);
1602
1603                Long count = null;
1604
1605                Iterator itr = q.list().iterator();
1606
1607                if (itr.hasNext()) {
1608                    count = (Long)itr.next();
1609                }
1610
1611                if (count == null) {
1612                    count = new Long(0);
1613                }
1614
1615                FinderCache.putResult(finderClassNameCacheEnabled,
1616                    finderClassName, finderMethodName, finderParams,
1617                    finderArgs, count);
1618
1619                return count.intValue();
1620            }
1621            catch (Exception e) {
1622                throw HibernateUtil.processException(e);
1623            }
1624            finally {
1625                closeSession(session);
1626            }
1627        }
1628        else {
1629            return ((Long)result).intValue();
1630        }
1631    }
1632
1633    public int countByStructureId(String structureId) throws SystemException {
1634        boolean finderClassNameCacheEnabled = JournalStructureModelImpl.CACHE_ENABLED;
1635        String finderClassName = JournalStructure.class.getName();
1636        String finderMethodName = "countByStructureId";
1637        String[] finderParams = new String[] { String.class.getName() };
1638        Object[] finderArgs = new Object[] { structureId };
1639
1640        Object result = null;
1641
1642        if (finderClassNameCacheEnabled) {
1643            result = FinderCache.getResult(finderClassName, finderMethodName,
1644                    finderParams, finderArgs, getSessionFactory());
1645        }
1646
1647        if (result == null) {
1648            Session session = null;
1649
1650            try {
1651                session = openSession();
1652
1653                StringMaker query = new StringMaker();
1654
1655                query.append("SELECT COUNT(*) ");
1656                query.append(
1657                    "FROM com.liferay.portlet.journal.model.JournalStructure WHERE ");
1658
1659                if (structureId == null) {
1660                    query.append("structureId IS NULL");
1661                }
1662                else {
1663                    query.append("structureId = ?");
1664                }
1665
1666                query.append(" ");
1667
1668                Query q = session.createQuery(query.toString());
1669
1670                int queryPos = 0;
1671
1672                if (structureId != null) {
1673                    q.setString(queryPos++, structureId);
1674                }
1675
1676                Long count = null;
1677
1678                Iterator itr = q.list().iterator();
1679
1680                if (itr.hasNext()) {
1681                    count = (Long)itr.next();
1682                }
1683
1684                if (count == null) {
1685                    count = new Long(0);
1686                }
1687
1688                FinderCache.putResult(finderClassNameCacheEnabled,
1689                    finderClassName, finderMethodName, finderParams,
1690                    finderArgs, count);
1691
1692                return count.intValue();
1693            }
1694            catch (Exception e) {
1695                throw HibernateUtil.processException(e);
1696            }
1697            finally {
1698                closeSession(session);
1699            }
1700        }
1701        else {
1702            return ((Long)result).intValue();
1703        }
1704    }
1705
1706    public int countByG_S(long groupId, String structureId)
1707        throws SystemException {
1708        boolean finderClassNameCacheEnabled = JournalStructureModelImpl.CACHE_ENABLED;
1709        String finderClassName = JournalStructure.class.getName();
1710        String finderMethodName = "countByG_S";
1711        String[] finderParams = new String[] {
1712                Long.class.getName(), String.class.getName()
1713            };
1714        Object[] finderArgs = new Object[] { new Long(groupId), structureId };
1715
1716        Object result = null;
1717
1718        if (finderClassNameCacheEnabled) {
1719            result = FinderCache.getResult(finderClassName, finderMethodName,
1720                    finderParams, finderArgs, getSessionFactory());
1721        }
1722
1723        if (result == null) {
1724            Session session = null;
1725
1726            try {
1727                session = openSession();
1728
1729                StringMaker query = new StringMaker();
1730
1731                query.append("SELECT COUNT(*) ");
1732                query.append(
1733                    "FROM com.liferay.portlet.journal.model.JournalStructure WHERE ");
1734
1735                query.append("groupId = ?");
1736
1737                query.append(" AND ");
1738
1739                if (structureId == null) {
1740                    query.append("structureId IS NULL");
1741                }
1742                else {
1743                    query.append("structureId = ?");
1744                }
1745
1746                query.append(" ");
1747
1748                Query q = session.createQuery(query.toString());
1749
1750                int queryPos = 0;
1751
1752                q.setLong(queryPos++, groupId);
1753
1754                if (structureId != null) {
1755                    q.setString(queryPos++, structureId);
1756                }
1757
1758                Long count = null;
1759
1760                Iterator itr = q.list().iterator();
1761
1762                if (itr.hasNext()) {
1763                    count = (Long)itr.next();
1764                }
1765
1766                if (count == null) {
1767                    count = new Long(0);
1768                }
1769
1770                FinderCache.putResult(finderClassNameCacheEnabled,
1771                    finderClassName, finderMethodName, finderParams,
1772                    finderArgs, count);
1773
1774                return count.intValue();
1775            }
1776            catch (Exception e) {
1777                throw HibernateUtil.processException(e);
1778            }
1779            finally {
1780                closeSession(session);
1781            }
1782        }
1783        else {
1784            return ((Long)result).intValue();
1785        }
1786    }
1787
1788    public int countAll() throws SystemException {
1789        boolean finderClassNameCacheEnabled = JournalStructureModelImpl.CACHE_ENABLED;
1790        String finderClassName = JournalStructure.class.getName();
1791        String finderMethodName = "countAll";
1792        String[] finderParams = new String[] {  };
1793        Object[] finderArgs = new Object[] {  };
1794
1795        Object result = null;
1796
1797        if (finderClassNameCacheEnabled) {
1798            result = FinderCache.getResult(finderClassName, finderMethodName,
1799                    finderParams, finderArgs, getSessionFactory());
1800        }
1801
1802        if (result == null) {
1803            Session session = null;
1804
1805            try {
1806                session = openSession();
1807
1808                Query q = session.createQuery(
1809                        "SELECT COUNT(*) FROM com.liferay.portlet.journal.model.JournalStructure");
1810
1811                Long count = null;
1812
1813                Iterator itr = q.list().iterator();
1814
1815                if (itr.hasNext()) {
1816                    count = (Long)itr.next();
1817                }
1818
1819                if (count == null) {
1820                    count = new Long(0);
1821                }
1822
1823                FinderCache.putResult(finderClassNameCacheEnabled,
1824                    finderClassName, finderMethodName, finderParams,
1825                    finderArgs, count);
1826
1827                return count.intValue();
1828            }
1829            catch (Exception e) {
1830                throw HibernateUtil.processException(e);
1831            }
1832            finally {
1833                closeSession(session);
1834            }
1835        }
1836        else {
1837            return ((Long)result).intValue();
1838        }
1839    }
1840
1841    protected void initDao() {
1842    }
1843
1844    private static ModelListener _getListener() {
1845        if (Validator.isNotNull(_LISTENER)) {
1846            try {
1847                return (ModelListener)Class.forName(_LISTENER).newInstance();
1848            }
1849            catch (Exception e) {
1850                _log.error(e);
1851            }
1852        }
1853
1854        return null;
1855    }
1856
1857    private static final String _LISTENER = GetterUtil.getString(PropsUtil.get(
1858                "value.object.listener.com.liferay.portlet.journal.model.JournalStructure"));
1859    private static Log _log = LogFactory.getLog(JournalStructurePersistenceImpl.class);
1860}