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