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