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