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