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