1   /**
2    * Copyright (c) 2000-2007 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.OrderByComparator;
29  import com.liferay.portal.kernel.util.StringMaker;
30  import com.liferay.portal.kernel.util.StringPool;
31  import com.liferay.portal.service.persistence.BasePersistence;
32  import com.liferay.portal.spring.hibernate.FinderCache;
33  import com.liferay.portal.spring.hibernate.HibernateUtil;
34  
35  import com.liferay.portlet.journal.NoSuchStructureException;
36  import com.liferay.portlet.journal.model.JournalStructure;
37  import com.liferay.portlet.journal.model.impl.JournalStructureImpl;
38  
39  import com.liferay.util.dao.hibernate.QueryUtil;
40  
41  import org.apache.commons.logging.Log;
42  import org.apache.commons.logging.LogFactory;
43  
44  import org.hibernate.Query;
45  import org.hibernate.Session;
46  
47  import java.util.Collections;
48  import java.util.Iterator;
49  import java.util.List;
50  
51  /**
52   * <a href="JournalStructurePersistenceImpl.java.html"><b><i>View Source</i></b></a>
53   *
54   * @author Brian Wing Shun Chan
55   *
56   */
57  public class JournalStructurePersistenceImpl extends BasePersistence
58      implements JournalStructurePersistence {
59      public JournalStructure create(long id) {
60          JournalStructure journalStructure = new JournalStructureImpl();
61          journalStructure.setNew(true);
62          journalStructure.setPrimaryKey(id);
63  
64          return journalStructure;
65      }
66  
67      public JournalStructure remove(long id)
68          throws NoSuchStructureException, SystemException {
69          Session session = null;
70  
71          try {
72              session = openSession();
73  
74              JournalStructure journalStructure = (JournalStructure)session.get(JournalStructureImpl.class,
75                      new Long(id));
76  
77              if (journalStructure == null) {
78                  if (_log.isWarnEnabled()) {
79                      _log.warn(
80                          "No JournalStructure exists with the primary key " +
81                          id);
82                  }
83  
84                  throw new NoSuchStructureException(
85                      "No JournalStructure exists with the primary key " + id);
86              }
87  
88              return remove(journalStructure);
89          }
90          catch (NoSuchStructureException nsee) {
91              throw nsee;
92          }
93          catch (Exception e) {
94              throw HibernateUtil.processException(e);
95          }
96          finally {
97              closeSession(session);
98          }
99      }
100 
101     public JournalStructure remove(JournalStructure journalStructure)
102         throws SystemException {
103         Session session = null;
104 
105         try {
106             session = openSession();
107             session.delete(journalStructure);
108             session.flush();
109 
110             return journalStructure;
111         }
112         catch (Exception e) {
113             throw HibernateUtil.processException(e);
114         }
115         finally {
116             closeSession(session);
117             FinderCache.clearCache(JournalStructure.class.getName());
118         }
119     }
120 
121     public JournalStructure update(
122         com.liferay.portlet.journal.model.JournalStructure journalStructure)
123         throws SystemException {
124         return update(journalStructure, false);
125     }
126 
127     public JournalStructure update(
128         com.liferay.portlet.journal.model.JournalStructure journalStructure,
129         boolean merge) throws SystemException {
130         Session session = null;
131 
132         try {
133             session = openSession();
134 
135             if (merge) {
136                 session.merge(journalStructure);
137             }
138             else {
139                 if (journalStructure.isNew()) {
140                     session.save(journalStructure);
141                 }
142             }
143 
144             session.flush();
145             journalStructure.setNew(false);
146 
147             return journalStructure;
148         }
149         catch (Exception e) {
150             throw HibernateUtil.processException(e);
151         }
152         finally {
153             closeSession(session);
154             FinderCache.clearCache(JournalStructure.class.getName());
155         }
156     }
157 
158     public JournalStructure findByPrimaryKey(long id)
159         throws NoSuchStructureException, SystemException {
160         JournalStructure journalStructure = fetchByPrimaryKey(id);
161 
162         if (journalStructure == null) {
163             if (_log.isWarnEnabled()) {
164                 _log.warn("No JournalStructure exists with the primary key " +
165                     id);
166             }
167 
168             throw new NoSuchStructureException(
169                 "No JournalStructure exists with the primary key " + id);
170         }
171 
172         return journalStructure;
173     }
174 
175     public JournalStructure fetchByPrimaryKey(long id)
176         throws SystemException {
177         Session session = null;
178 
179         try {
180             session = openSession();
181 
182             return (JournalStructure)session.get(JournalStructureImpl.class,
183                 new Long(id));
184         }
185         catch (Exception e) {
186             throw HibernateUtil.processException(e);
187         }
188         finally {
189             closeSession(session);
190         }
191     }
192 
193     public List findByGroupId(long groupId) throws SystemException {
194         String finderClassName = JournalStructure.class.getName();
195         String finderMethodName = "findByGroupId";
196         String[] finderParams = new String[] { Long.class.getName() };
197         Object[] finderArgs = new Object[] { new Long(groupId) };
198         Object result = FinderCache.getResult(finderClassName,
199                 finderMethodName, finderParams, finderArgs, getSessionFactory());
200 
201         if (result == null) {
202             Session session = null;
203 
204             try {
205                 session = openSession();
206 
207                 StringMaker query = new StringMaker();
208                 query.append(
209                     "FROM com.liferay.portlet.journal.model.JournalStructure WHERE ");
210                 query.append("groupId = ?");
211                 query.append(" ");
212                 query.append("ORDER BY ");
213                 query.append("structureId ASC");
214 
215                 Query q = session.createQuery(query.toString());
216                 int queryPos = 0;
217                 q.setLong(queryPos++, groupId);
218 
219                 List list = q.list();
220                 FinderCache.putResult(finderClassName, finderMethodName,
221                     finderParams, finderArgs, list);
222 
223                 return list;
224             }
225             catch (Exception e) {
226                 throw HibernateUtil.processException(e);
227             }
228             finally {
229                 closeSession(session);
230             }
231         }
232         else {
233             return (List)result;
234         }
235     }
236 
237     public List findByGroupId(long groupId, int begin, int end)
238         throws SystemException {
239         return findByGroupId(groupId, begin, end, null);
240     }
241 
242     public List findByGroupId(long groupId, int begin, int end,
243         OrderByComparator obc) throws SystemException {
244         String finderClassName = JournalStructure.class.getName();
245         String finderMethodName = "findByGroupId";
246         String[] finderParams = new String[] {
247                 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
248                 "com.liferay.portal.kernel.util.OrderByComparator"
249             };
250         Object[] finderArgs = new Object[] {
251                 new Long(groupId), String.valueOf(begin), String.valueOf(end),
252                 String.valueOf(obc)
253             };
254         Object result = FinderCache.getResult(finderClassName,
255                 finderMethodName, finderParams, finderArgs, getSessionFactory());
256 
257         if (result == null) {
258             Session session = null;
259 
260             try {
261                 session = openSession();
262 
263                 StringMaker query = new StringMaker();
264                 query.append(
265                     "FROM com.liferay.portlet.journal.model.JournalStructure WHERE ");
266                 query.append("groupId = ?");
267                 query.append(" ");
268 
269                 if (obc != null) {
270                     query.append("ORDER BY ");
271                     query.append(obc.getOrderBy());
272                 }
273                 else {
274                     query.append("ORDER BY ");
275                     query.append("structureId ASC");
276                 }
277 
278                 Query q = session.createQuery(query.toString());
279                 int queryPos = 0;
280                 q.setLong(queryPos++, groupId);
281 
282                 List list = QueryUtil.list(q, getDialect(), begin, end);
283                 FinderCache.putResult(finderClassName, finderMethodName,
284                     finderParams, finderArgs, list);
285 
286                 return list;
287             }
288             catch (Exception e) {
289                 throw HibernateUtil.processException(e);
290             }
291             finally {
292                 closeSession(session);
293             }
294         }
295         else {
296             return (List)result;
297         }
298     }
299 
300     public JournalStructure findByGroupId_First(long groupId,
301         OrderByComparator obc) throws NoSuchStructureException, SystemException {
302         List list = findByGroupId(groupId, 0, 1, obc);
303 
304         if (list.size() == 0) {
305             StringMaker msg = new StringMaker();
306             msg.append("No JournalStructure exists with the key ");
307             msg.append(StringPool.OPEN_CURLY_BRACE);
308             msg.append("groupId=");
309             msg.append(groupId);
310             msg.append(StringPool.CLOSE_CURLY_BRACE);
311             throw new NoSuchStructureException(msg.toString());
312         }
313         else {
314             return (JournalStructure)list.get(0);
315         }
316     }
317 
318     public JournalStructure findByGroupId_Last(long groupId,
319         OrderByComparator obc) throws NoSuchStructureException, SystemException {
320         int count = countByGroupId(groupId);
321         List list = findByGroupId(groupId, count - 1, count, obc);
322 
323         if (list.size() == 0) {
324             StringMaker msg = new StringMaker();
325             msg.append("No JournalStructure exists with the key ");
326             msg.append(StringPool.OPEN_CURLY_BRACE);
327             msg.append("groupId=");
328             msg.append(groupId);
329             msg.append(StringPool.CLOSE_CURLY_BRACE);
330             throw new NoSuchStructureException(msg.toString());
331         }
332         else {
333             return (JournalStructure)list.get(0);
334         }
335     }
336 
337     public JournalStructure[] findByGroupId_PrevAndNext(long id, long groupId,
338         OrderByComparator obc) throws NoSuchStructureException, SystemException {
339         JournalStructure journalStructure = findByPrimaryKey(id);
340         int count = countByGroupId(groupId);
341         Session session = null;
342 
343         try {
344             session = openSession();
345 
346             StringMaker query = new StringMaker();
347             query.append(
348                 "FROM com.liferay.portlet.journal.model.JournalStructure WHERE ");
349             query.append("groupId = ?");
350             query.append(" ");
351 
352             if (obc != null) {
353                 query.append("ORDER BY ");
354                 query.append(obc.getOrderBy());
355             }
356             else {
357                 query.append("ORDER BY ");
358                 query.append("structureId ASC");
359             }
360 
361             Query q = session.createQuery(query.toString());
362             int queryPos = 0;
363             q.setLong(queryPos++, groupId);
364 
365             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
366                     journalStructure);
367             JournalStructure[] array = new JournalStructureImpl[3];
368             array[0] = (JournalStructure)objArray[0];
369             array[1] = (JournalStructure)objArray[1];
370             array[2] = (JournalStructure)objArray[2];
371 
372             return array;
373         }
374         catch (Exception e) {
375             throw HibernateUtil.processException(e);
376         }
377         finally {
378             closeSession(session);
379         }
380     }
381 
382     public List findByStructureId(String structureId) throws SystemException {
383         String finderClassName = JournalStructure.class.getName();
384         String finderMethodName = "findByStructureId";
385         String[] finderParams = new String[] { String.class.getName() };
386         Object[] finderArgs = new Object[] { structureId };
387         Object result = FinderCache.getResult(finderClassName,
388                 finderMethodName, finderParams, finderArgs, getSessionFactory());
389 
390         if (result == null) {
391             Session session = null;
392 
393             try {
394                 session = openSession();
395 
396                 StringMaker query = new StringMaker();
397                 query.append(
398                     "FROM com.liferay.portlet.journal.model.JournalStructure WHERE ");
399 
400                 if (structureId == null) {
401                     query.append("structureId IS NULL");
402                 }
403                 else {
404                     query.append("structureId = ?");
405                 }
406 
407                 query.append(" ");
408                 query.append("ORDER BY ");
409                 query.append("structureId ASC");
410 
411                 Query q = session.createQuery(query.toString());
412                 int queryPos = 0;
413 
414                 if (structureId != null) {
415                     q.setString(queryPos++, structureId);
416                 }
417 
418                 List list = q.list();
419                 FinderCache.putResult(finderClassName, finderMethodName,
420                     finderParams, finderArgs, list);
421 
422                 return list;
423             }
424             catch (Exception e) {
425                 throw HibernateUtil.processException(e);
426             }
427             finally {
428                 closeSession(session);
429             }
430         }
431         else {
432             return (List)result;
433         }
434     }
435 
436     public List findByStructureId(String structureId, int begin, int end)
437         throws SystemException {
438         return findByStructureId(structureId, begin, end, null);
439     }
440 
441     public List findByStructureId(String structureId, int begin, int end,
442         OrderByComparator obc) throws SystemException {
443         String finderClassName = JournalStructure.class.getName();
444         String finderMethodName = "findByStructureId";
445         String[] finderParams = new String[] {
446                 String.class.getName(), "java.lang.Integer", "java.lang.Integer",
447                 "com.liferay.portal.kernel.util.OrderByComparator"
448             };
449         Object[] finderArgs = new Object[] {
450                 structureId, String.valueOf(begin), String.valueOf(end),
451                 String.valueOf(obc)
452             };
453         Object result = FinderCache.getResult(finderClassName,
454                 finderMethodName, finderParams, finderArgs, getSessionFactory());
455 
456         if (result == null) {
457             Session session = null;
458 
459             try {
460                 session = openSession();
461 
462                 StringMaker query = new StringMaker();
463                 query.append(
464                     "FROM com.liferay.portlet.journal.model.JournalStructure WHERE ");
465 
466                 if (structureId == null) {
467                     query.append("structureId IS NULL");
468                 }
469                 else {
470                     query.append("structureId = ?");
471                 }
472 
473                 query.append(" ");
474 
475                 if (obc != null) {
476                     query.append("ORDER BY ");
477                     query.append(obc.getOrderBy());
478                 }
479                 else {
480                     query.append("ORDER BY ");
481                     query.append("structureId ASC");
482                 }
483 
484                 Query q = session.createQuery(query.toString());
485                 int queryPos = 0;
486 
487                 if (structureId != null) {
488                     q.setString(queryPos++, structureId);
489                 }
490 
491                 List list = QueryUtil.list(q, getDialect(), begin, end);
492                 FinderCache.putResult(finderClassName, finderMethodName,
493                     finderParams, finderArgs, list);
494 
495                 return list;
496             }
497             catch (Exception e) {
498                 throw HibernateUtil.processException(e);
499             }
500             finally {
501                 closeSession(session);
502             }
503         }
504         else {
505             return (List)result;
506         }
507     }
508 
509     public JournalStructure findByStructureId_First(String structureId,
510         OrderByComparator obc) throws NoSuchStructureException, SystemException {
511         List list = findByStructureId(structureId, 0, 1, obc);
512 
513         if (list.size() == 0) {
514             StringMaker msg = new StringMaker();
515             msg.append("No JournalStructure exists with the key ");
516             msg.append(StringPool.OPEN_CURLY_BRACE);
517             msg.append("structureId=");
518             msg.append(structureId);
519             msg.append(StringPool.CLOSE_CURLY_BRACE);
520             throw new NoSuchStructureException(msg.toString());
521         }
522         else {
523             return (JournalStructure)list.get(0);
524         }
525     }
526 
527     public JournalStructure findByStructureId_Last(String structureId,
528         OrderByComparator obc) throws NoSuchStructureException, SystemException {
529         int count = countByStructureId(structureId);
530         List list = findByStructureId(structureId, count - 1, count, obc);
531 
532         if (list.size() == 0) {
533             StringMaker msg = new StringMaker();
534             msg.append("No JournalStructure exists with the key ");
535             msg.append(StringPool.OPEN_CURLY_BRACE);
536             msg.append("structureId=");
537             msg.append(structureId);
538             msg.append(StringPool.CLOSE_CURLY_BRACE);
539             throw new NoSuchStructureException(msg.toString());
540         }
541         else {
542             return (JournalStructure)list.get(0);
543         }
544     }
545 
546     public JournalStructure[] findByStructureId_PrevAndNext(long id,
547         String structureId, OrderByComparator obc)
548         throws NoSuchStructureException, SystemException {
549         JournalStructure journalStructure = findByPrimaryKey(id);
550         int count = countByStructureId(structureId);
551         Session session = null;
552 
553         try {
554             session = openSession();
555 
556             StringMaker query = new StringMaker();
557             query.append(
558                 "FROM com.liferay.portlet.journal.model.JournalStructure WHERE ");
559 
560             if (structureId == null) {
561                 query.append("structureId IS NULL");
562             }
563             else {
564                 query.append("structureId = ?");
565             }
566 
567             query.append(" ");
568 
569             if (obc != null) {
570                 query.append("ORDER BY ");
571                 query.append(obc.getOrderBy());
572             }
573             else {
574                 query.append("ORDER BY ");
575                 query.append("structureId ASC");
576             }
577 
578             Query q = session.createQuery(query.toString());
579             int queryPos = 0;
580 
581             if (structureId != null) {
582                 q.setString(queryPos++, structureId);
583             }
584 
585             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
586                     journalStructure);
587             JournalStructure[] array = new JournalStructureImpl[3];
588             array[0] = (JournalStructure)objArray[0];
589             array[1] = (JournalStructure)objArray[1];
590             array[2] = (JournalStructure)objArray[2];
591 
592             return array;
593         }
594         catch (Exception e) {
595             throw HibernateUtil.processException(e);
596         }
597         finally {
598             closeSession(session);
599         }
600     }
601 
602     public JournalStructure findByG_S(long groupId, String structureId)
603         throws NoSuchStructureException, SystemException {
604         JournalStructure journalStructure = fetchByG_S(groupId, structureId);
605 
606         if (journalStructure == null) {
607             StringMaker msg = new StringMaker();
608             msg.append("No JournalStructure exists with the key ");
609             msg.append(StringPool.OPEN_CURLY_BRACE);
610             msg.append("groupId=");
611             msg.append(groupId);
612             msg.append(", ");
613             msg.append("structureId=");
614             msg.append(structureId);
615             msg.append(StringPool.CLOSE_CURLY_BRACE);
616 
617             if (_log.isWarnEnabled()) {
618                 _log.warn(msg.toString());
619             }
620 
621             throw new NoSuchStructureException(msg.toString());
622         }
623 
624         return journalStructure;
625     }
626 
627     public JournalStructure fetchByG_S(long groupId, String structureId)
628         throws SystemException {
629         String finderClassName = JournalStructure.class.getName();
630         String finderMethodName = "fetchByG_S";
631         String[] finderParams = new String[] {
632                 Long.class.getName(), String.class.getName()
633             };
634         Object[] finderArgs = new Object[] { new Long(groupId), structureId };
635         Object result = FinderCache.getResult(finderClassName,
636                 finderMethodName, finderParams, finderArgs, getSessionFactory());
637 
638         if (result == null) {
639             Session session = null;
640 
641             try {
642                 session = openSession();
643 
644                 StringMaker query = new StringMaker();
645                 query.append(
646                     "FROM com.liferay.portlet.journal.model.JournalStructure WHERE ");
647                 query.append("groupId = ?");
648                 query.append(" AND ");
649 
650                 if (structureId == null) {
651                     query.append("structureId IS NULL");
652                 }
653                 else {
654                     query.append("structureId = ?");
655                 }
656 
657                 query.append(" ");
658                 query.append("ORDER BY ");
659                 query.append("structureId ASC");
660 
661                 Query q = session.createQuery(query.toString());
662                 int queryPos = 0;
663                 q.setLong(queryPos++, groupId);
664 
665                 if (structureId != null) {
666                     q.setString(queryPos++, structureId);
667                 }
668 
669                 List list = q.list();
670                 FinderCache.putResult(finderClassName, finderMethodName,
671                     finderParams, finderArgs, list);
672 
673                 if (list.size() == 0) {
674                     return null;
675                 }
676                 else {
677                     return (JournalStructure)list.get(0);
678                 }
679             }
680             catch (Exception e) {
681                 throw HibernateUtil.processException(e);
682             }
683             finally {
684                 closeSession(session);
685             }
686         }
687         else {
688             List list = (List)result;
689 
690             if (list.size() == 0) {
691                 return null;
692             }
693             else {
694                 return (JournalStructure)list.get(0);
695             }
696         }
697     }
698 
699     public List findWithDynamicQuery(DynamicQueryInitializer queryInitializer)
700         throws SystemException {
701         Session session = null;
702 
703         try {
704             session = openSession();
705 
706             DynamicQuery query = queryInitializer.initialize(session);
707 
708             return query.list();
709         }
710         catch (Exception e) {
711             throw HibernateUtil.processException(e);
712         }
713         finally {
714             closeSession(session);
715         }
716     }
717 
718     public List findWithDynamicQuery(DynamicQueryInitializer queryInitializer,
719         int begin, int end) throws SystemException {
720         Session session = null;
721 
722         try {
723             session = openSession();
724 
725             DynamicQuery query = queryInitializer.initialize(session);
726             query.setLimit(begin, end);
727 
728             return query.list();
729         }
730         catch (Exception e) {
731             throw HibernateUtil.processException(e);
732         }
733         finally {
734             closeSession(session);
735         }
736     }
737 
738     public List findAll() throws SystemException {
739         return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
740     }
741 
742     public List findAll(int begin, int end) throws SystemException {
743         return findAll(begin, end, null);
744     }
745 
746     public List findAll(int begin, int end, OrderByComparator obc)
747         throws SystemException {
748         String finderClassName = JournalStructure.class.getName();
749         String finderMethodName = "findAll";
750         String[] finderParams = new String[] {
751                 "java.lang.Integer", "java.lang.Integer",
752                 "com.liferay.portal.kernel.util.OrderByComparator"
753             };
754         Object[] finderArgs = new Object[] {
755                 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
756             };
757         Object result = FinderCache.getResult(finderClassName,
758                 finderMethodName, finderParams, finderArgs, getSessionFactory());
759 
760         if (result == null) {
761             Session session = null;
762 
763             try {
764                 session = openSession();
765 
766                 StringMaker query = new StringMaker();
767                 query.append(
768                     "FROM com.liferay.portlet.journal.model.JournalStructure ");
769 
770                 if (obc != null) {
771                     query.append("ORDER BY ");
772                     query.append(obc.getOrderBy());
773                 }
774                 else {
775                     query.append("ORDER BY ");
776                     query.append("structureId ASC");
777                 }
778 
779                 Query q = session.createQuery(query.toString());
780                 List list = QueryUtil.list(q, getDialect(), begin, end);
781 
782                 if (obc == null) {
783                     Collections.sort(list);
784                 }
785 
786                 FinderCache.putResult(finderClassName, finderMethodName,
787                     finderParams, 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)result;
800         }
801     }
802 
803     public void removeByGroupId(long groupId) throws SystemException {
804         Iterator itr = findByGroupId(groupId).iterator();
805 
806         while (itr.hasNext()) {
807             JournalStructure journalStructure = (JournalStructure)itr.next();
808             remove(journalStructure);
809         }
810     }
811 
812     public void removeByStructureId(String structureId)
813         throws SystemException {
814         Iterator itr = findByStructureId(structureId).iterator();
815 
816         while (itr.hasNext()) {
817             JournalStructure journalStructure = (JournalStructure)itr.next();
818             remove(journalStructure);
819         }
820     }
821 
822     public void removeByG_S(long groupId, String structureId)
823         throws NoSuchStructureException, SystemException {
824         JournalStructure journalStructure = findByG_S(groupId, structureId);
825         remove(journalStructure);
826     }
827 
828     public void removeAll() throws SystemException {
829         Iterator itr = findAll().iterator();
830 
831         while (itr.hasNext()) {
832             remove((JournalStructure)itr.next());
833         }
834     }
835 
836     public int countByGroupId(long groupId) throws SystemException {
837         String finderClassName = JournalStructure.class.getName();
838         String finderMethodName = "countByGroupId";
839         String[] finderParams = new String[] { Long.class.getName() };
840         Object[] finderArgs = new Object[] { new Long(groupId) };
841         Object result = FinderCache.getResult(finderClassName,
842                 finderMethodName, finderParams, finderArgs, getSessionFactory());
843 
844         if (result == null) {
845             Session session = null;
846 
847             try {
848                 session = openSession();
849 
850                 StringMaker query = new StringMaker();
851                 query.append("SELECT COUNT(*) ");
852                 query.append(
853                     "FROM com.liferay.portlet.journal.model.JournalStructure WHERE ");
854                 query.append("groupId = ?");
855                 query.append(" ");
856 
857                 Query q = session.createQuery(query.toString());
858                 int queryPos = 0;
859                 q.setLong(queryPos++, groupId);
860 
861                 Long count = null;
862                 Iterator itr = q.list().iterator();
863 
864                 if (itr.hasNext()) {
865                     count = (Long)itr.next();
866                 }
867 
868                 if (count == null) {
869                     count = new Long(0);
870                 }
871 
872                 FinderCache.putResult(finderClassName, finderMethodName,
873                     finderParams, finderArgs, count);
874 
875                 return count.intValue();
876             }
877             catch (Exception e) {
878                 throw HibernateUtil.processException(e);
879             }
880             finally {
881                 closeSession(session);
882             }
883         }
884         else {
885             return ((Long)result).intValue();
886         }
887     }
888 
889     public int countByStructureId(String structureId) throws SystemException {
890         String finderClassName = JournalStructure.class.getName();
891         String finderMethodName = "countByStructureId";
892         String[] finderParams = new String[] { String.class.getName() };
893         Object[] finderArgs = new Object[] { structureId };
894         Object result = FinderCache.getResult(finderClassName,
895                 finderMethodName, finderParams, finderArgs, getSessionFactory());
896 
897         if (result == null) {
898             Session session = null;
899 
900             try {
901                 session = openSession();
902 
903                 StringMaker query = new StringMaker();
904                 query.append("SELECT COUNT(*) ");
905                 query.append(
906                     "FROM com.liferay.portlet.journal.model.JournalStructure WHERE ");
907 
908                 if (structureId == null) {
909                     query.append("structureId IS NULL");
910                 }
911                 else {
912                     query.append("structureId = ?");
913                 }
914 
915                 query.append(" ");
916 
917                 Query q = session.createQuery(query.toString());
918                 int queryPos = 0;
919 
920                 if (structureId != null) {
921                     q.setString(queryPos++, structureId);
922                 }
923 
924                 Long count = null;
925                 Iterator itr = q.list().iterator();
926 
927                 if (itr.hasNext()) {
928                     count = (Long)itr.next();
929                 }
930 
931                 if (count == null) {
932                     count = new Long(0);
933                 }
934 
935                 FinderCache.putResult(finderClassName, finderMethodName,
936                     finderParams, finderArgs, count);
937 
938                 return count.intValue();
939             }
940             catch (Exception e) {
941                 throw HibernateUtil.processException(e);
942             }
943             finally {
944                 closeSession(session);
945             }
946         }
947         else {
948             return ((Long)result).intValue();
949         }
950     }
951 
952     public int countByG_S(long groupId, String structureId)
953         throws SystemException {
954         String finderClassName = JournalStructure.class.getName();
955         String finderMethodName = "countByG_S";
956         String[] finderParams = new String[] {
957                 Long.class.getName(), String.class.getName()
958             };
959         Object[] finderArgs = new Object[] { new Long(groupId), structureId };
960         Object result = FinderCache.getResult(finderClassName,
961                 finderMethodName, finderParams, finderArgs, getSessionFactory());
962 
963         if (result == null) {
964             Session session = null;
965 
966             try {
967                 session = openSession();
968 
969                 StringMaker query = new StringMaker();
970                 query.append("SELECT COUNT(*) ");
971                 query.append(
972                     "FROM com.liferay.portlet.journal.model.JournalStructure WHERE ");
973                 query.append("groupId = ?");
974                 query.append(" AND ");
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                 Query q = session.createQuery(query.toString());
986                 int queryPos = 0;
987                 q.setLong(queryPos++, groupId);
988 
989                 if (structureId != null) {
990                     q.setString(queryPos++, structureId);
991                 }
992 
993                 Long count = null;
994                 Iterator itr = q.list().iterator();
995 
996                 if (itr.hasNext()) {
997                     count = (Long)itr.next();
998                 }
999 
1000                if (count == null) {
1001                    count = new Long(0);
1002                }
1003
1004                FinderCache.putResult(finderClassName, finderMethodName,
1005                    finderParams, finderArgs, count);
1006
1007                return count.intValue();
1008            }
1009            catch (Exception e) {
1010                throw HibernateUtil.processException(e);
1011            }
1012            finally {
1013                closeSession(session);
1014            }
1015        }
1016        else {
1017            return ((Long)result).intValue();
1018        }
1019    }
1020
1021    public int countAll() throws SystemException {
1022        String finderClassName = JournalStructure.class.getName();
1023        String finderMethodName = "countAll";
1024        String[] finderParams = new String[] {  };
1025        Object[] finderArgs = new Object[] {  };
1026        Object result = FinderCache.getResult(finderClassName,
1027                finderMethodName, finderParams, finderArgs, getSessionFactory());
1028
1029        if (result == null) {
1030            Session session = null;
1031
1032            try {
1033                session = openSession();
1034
1035                StringMaker query = new StringMaker();
1036                query.append("SELECT COUNT(*) ");
1037                query.append(
1038                    "FROM com.liferay.portlet.journal.model.JournalStructure");
1039
1040                Query q = session.createQuery(query.toString());
1041                Long count = null;
1042                Iterator itr = q.list().iterator();
1043
1044                if (itr.hasNext()) {
1045                    count = (Long)itr.next();
1046                }
1047
1048                if (count == null) {
1049                    count = new Long(0);
1050                }
1051
1052                FinderCache.putResult(finderClassName, finderMethodName,
1053                    finderParams, finderArgs, count);
1054
1055                return count.intValue();
1056            }
1057            catch (Exception e) {
1058                throw HibernateUtil.processException(e);
1059            }
1060            finally {
1061                closeSession(session);
1062            }
1063        }
1064        else {
1065            return ((Long)result).intValue();
1066        }
1067    }
1068
1069    protected void initDao() {
1070    }
1071
1072    private static Log _log = LogFactory.getLog(JournalStructurePersistenceImpl.class);
1073}