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