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