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