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