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