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