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.NoSuchArticleException;
49  import com.liferay.portlet.journal.model.JournalArticle;
50  import com.liferay.portlet.journal.model.impl.JournalArticleImpl;
51  import com.liferay.portlet.journal.model.impl.JournalArticleModelImpl;
52  
53  import java.util.ArrayList;
54  import java.util.Collections;
55  import java.util.List;
56  
57  /**
58   * <a href="JournalArticlePersistenceImpl.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       JournalArticlePersistence
67   * @see       JournalArticleUtil
68   * @generated
69   */
70  public class JournalArticlePersistenceImpl extends BasePersistenceImpl
71      implements JournalArticlePersistence {
72      public static final String FINDER_CLASS_NAME_ENTITY = JournalArticleImpl.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(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
76              JournalArticleModelImpl.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(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
80              JournalArticleModelImpl.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(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
89              JournalArticleModelImpl.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(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
93              JournalArticleModelImpl.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(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
97              JournalArticleModelImpl.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(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
101             JournalArticleModelImpl.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(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
105             JournalArticleModelImpl.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(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
114             JournalArticleModelImpl.FINDER_CACHE_ENABLED,
115             FINDER_CLASS_NAME_LIST, "countByGroupId",
116             new String[] { Long.class.getName() });
117     public static final FinderPath FINDER_PATH_FIND_BY_COMPANYID = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
118             JournalArticleModelImpl.FINDER_CACHE_ENABLED,
119             FINDER_CLASS_NAME_LIST, "findByCompanyId",
120             new String[] { Long.class.getName() });
121     public static final FinderPath FINDER_PATH_FIND_BY_OBC_COMPANYID = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
122             JournalArticleModelImpl.FINDER_CACHE_ENABLED,
123             FINDER_CLASS_NAME_LIST, "findByCompanyId",
124             new String[] {
125                 Long.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_COMPANYID = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
131             JournalArticleModelImpl.FINDER_CACHE_ENABLED,
132             FINDER_CLASS_NAME_LIST, "countByCompanyId",
133             new String[] { Long.class.getName() });
134     public static final FinderPath FINDER_PATH_FIND_BY_SMALLIMAGEID = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
135             JournalArticleModelImpl.FINDER_CACHE_ENABLED,
136             FINDER_CLASS_NAME_LIST, "findBySmallImageId",
137             new String[] { Long.class.getName() });
138     public static final FinderPath FINDER_PATH_FIND_BY_OBC_SMALLIMAGEID = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
139             JournalArticleModelImpl.FINDER_CACHE_ENABLED,
140             FINDER_CLASS_NAME_LIST, "findBySmallImageId",
141             new String[] {
142                 Long.class.getName(),
143                 
144             "java.lang.Integer", "java.lang.Integer",
145                 "com.liferay.portal.kernel.util.OrderByComparator"
146             });
147     public static final FinderPath FINDER_PATH_COUNT_BY_SMALLIMAGEID = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
148             JournalArticleModelImpl.FINDER_CACHE_ENABLED,
149             FINDER_CLASS_NAME_LIST, "countBySmallImageId",
150             new String[] { Long.class.getName() });
151     public static final FinderPath FINDER_PATH_FIND_BY_R_A = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
152             JournalArticleModelImpl.FINDER_CACHE_ENABLED,
153             FINDER_CLASS_NAME_LIST, "findByR_A",
154             new String[] { Long.class.getName(), Boolean.class.getName() });
155     public static final FinderPath FINDER_PATH_FIND_BY_OBC_R_A = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
156             JournalArticleModelImpl.FINDER_CACHE_ENABLED,
157             FINDER_CLASS_NAME_LIST, "findByR_A",
158             new String[] {
159                 Long.class.getName(), Boolean.class.getName(),
160                 
161             "java.lang.Integer", "java.lang.Integer",
162                 "com.liferay.portal.kernel.util.OrderByComparator"
163             });
164     public static final FinderPath FINDER_PATH_COUNT_BY_R_A = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
165             JournalArticleModelImpl.FINDER_CACHE_ENABLED,
166             FINDER_CLASS_NAME_LIST, "countByR_A",
167             new String[] { Long.class.getName(), Boolean.class.getName() });
168     public static final FinderPath FINDER_PATH_FIND_BY_G_A = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
169             JournalArticleModelImpl.FINDER_CACHE_ENABLED,
170             FINDER_CLASS_NAME_LIST, "findByG_A",
171             new String[] { Long.class.getName(), String.class.getName() });
172     public static final FinderPath FINDER_PATH_FIND_BY_OBC_G_A = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
173             JournalArticleModelImpl.FINDER_CACHE_ENABLED,
174             FINDER_CLASS_NAME_LIST, "findByG_A",
175             new String[] {
176                 Long.class.getName(), String.class.getName(),
177                 
178             "java.lang.Integer", "java.lang.Integer",
179                 "com.liferay.portal.kernel.util.OrderByComparator"
180             });
181     public static final FinderPath FINDER_PATH_COUNT_BY_G_A = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
182             JournalArticleModelImpl.FINDER_CACHE_ENABLED,
183             FINDER_CLASS_NAME_LIST, "countByG_A",
184             new String[] { Long.class.getName(), String.class.getName() });
185     public static final FinderPath FINDER_PATH_FIND_BY_G_S = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
186             JournalArticleModelImpl.FINDER_CACHE_ENABLED,
187             FINDER_CLASS_NAME_LIST, "findByG_S",
188             new String[] { Long.class.getName(), String.class.getName() });
189     public static final FinderPath FINDER_PATH_FIND_BY_OBC_G_S = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
190             JournalArticleModelImpl.FINDER_CACHE_ENABLED,
191             FINDER_CLASS_NAME_LIST, "findByG_S",
192             new String[] {
193                 Long.class.getName(), String.class.getName(),
194                 
195             "java.lang.Integer", "java.lang.Integer",
196                 "com.liferay.portal.kernel.util.OrderByComparator"
197             });
198     public static final FinderPath FINDER_PATH_COUNT_BY_G_S = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
199             JournalArticleModelImpl.FINDER_CACHE_ENABLED,
200             FINDER_CLASS_NAME_LIST, "countByG_S",
201             new String[] { Long.class.getName(), String.class.getName() });
202     public static final FinderPath FINDER_PATH_FIND_BY_G_T = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
203             JournalArticleModelImpl.FINDER_CACHE_ENABLED,
204             FINDER_CLASS_NAME_LIST, "findByG_T",
205             new String[] { Long.class.getName(), String.class.getName() });
206     public static final FinderPath FINDER_PATH_FIND_BY_OBC_G_T = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
207             JournalArticleModelImpl.FINDER_CACHE_ENABLED,
208             FINDER_CLASS_NAME_LIST, "findByG_T",
209             new String[] {
210                 Long.class.getName(), String.class.getName(),
211                 
212             "java.lang.Integer", "java.lang.Integer",
213                 "com.liferay.portal.kernel.util.OrderByComparator"
214             });
215     public static final FinderPath FINDER_PATH_COUNT_BY_G_T = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
216             JournalArticleModelImpl.FINDER_CACHE_ENABLED,
217             FINDER_CLASS_NAME_LIST, "countByG_T",
218             new String[] { Long.class.getName(), String.class.getName() });
219     public static final FinderPath FINDER_PATH_FETCH_BY_G_A_V = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
220             JournalArticleModelImpl.FINDER_CACHE_ENABLED,
221             FINDER_CLASS_NAME_ENTITY, "fetchByG_A_V",
222             new String[] {
223                 Long.class.getName(), String.class.getName(),
224                 Double.class.getName()
225             });
226     public static final FinderPath FINDER_PATH_COUNT_BY_G_A_V = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
227             JournalArticleModelImpl.FINDER_CACHE_ENABLED,
228             FINDER_CLASS_NAME_LIST, "countByG_A_V",
229             new String[] {
230                 Long.class.getName(), String.class.getName(),
231                 Double.class.getName()
232             });
233     public static final FinderPath FINDER_PATH_FIND_BY_G_A_A = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
234             JournalArticleModelImpl.FINDER_CACHE_ENABLED,
235             FINDER_CLASS_NAME_LIST, "findByG_A_A",
236             new String[] {
237                 Long.class.getName(), String.class.getName(),
238                 Boolean.class.getName()
239             });
240     public static final FinderPath FINDER_PATH_FIND_BY_OBC_G_A_A = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
241             JournalArticleModelImpl.FINDER_CACHE_ENABLED,
242             FINDER_CLASS_NAME_LIST, "findByG_A_A",
243             new String[] {
244                 Long.class.getName(), String.class.getName(),
245                 Boolean.class.getName(),
246                 
247             "java.lang.Integer", "java.lang.Integer",
248                 "com.liferay.portal.kernel.util.OrderByComparator"
249             });
250     public static final FinderPath FINDER_PATH_COUNT_BY_G_A_A = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
251             JournalArticleModelImpl.FINDER_CACHE_ENABLED,
252             FINDER_CLASS_NAME_LIST, "countByG_A_A",
253             new String[] {
254                 Long.class.getName(), String.class.getName(),
255                 Boolean.class.getName()
256             });
257     public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
258             JournalArticleModelImpl.FINDER_CACHE_ENABLED,
259             FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
260     public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
261             JournalArticleModelImpl.FINDER_CACHE_ENABLED,
262             FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
263 
264     public void cacheResult(JournalArticle journalArticle) {
265         EntityCacheUtil.putResult(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
266             JournalArticleImpl.class, journalArticle.getPrimaryKey(),
267             journalArticle);
268 
269         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
270             new Object[] {
271                 journalArticle.getUuid(), new Long(journalArticle.getGroupId())
272             }, journalArticle);
273 
274         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_A_V,
275             new Object[] {
276                 new Long(journalArticle.getGroupId()),
277                 
278             journalArticle.getArticleId(),
279                 new Double(journalArticle.getVersion())
280             }, journalArticle);
281     }
282 
283     public void cacheResult(List<JournalArticle> journalArticles) {
284         for (JournalArticle journalArticle : journalArticles) {
285             if (EntityCacheUtil.getResult(
286                         JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
287                         JournalArticleImpl.class,
288                         journalArticle.getPrimaryKey(), this) == null) {
289                 cacheResult(journalArticle);
290             }
291         }
292     }
293 
294     public void clearCache() {
295         CacheRegistry.clear(JournalArticleImpl.class.getName());
296         EntityCacheUtil.clearCache(JournalArticleImpl.class.getName());
297         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
298         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
299     }
300 
301     public JournalArticle create(long id) {
302         JournalArticle journalArticle = new JournalArticleImpl();
303 
304         journalArticle.setNew(true);
305         journalArticle.setPrimaryKey(id);
306 
307         String uuid = PortalUUIDUtil.generate();
308 
309         journalArticle.setUuid(uuid);
310 
311         return journalArticle;
312     }
313 
314     public JournalArticle remove(long id)
315         throws NoSuchArticleException, SystemException {
316         Session session = null;
317 
318         try {
319             session = openSession();
320 
321             JournalArticle journalArticle = (JournalArticle)session.get(JournalArticleImpl.class,
322                     new Long(id));
323 
324             if (journalArticle == null) {
325                 if (_log.isWarnEnabled()) {
326                     _log.warn("No JournalArticle exists with the primary key " +
327                         id);
328                 }
329 
330                 throw new NoSuchArticleException(
331                     "No JournalArticle exists with the primary key " + id);
332             }
333 
334             return remove(journalArticle);
335         }
336         catch (NoSuchArticleException nsee) {
337             throw nsee;
338         }
339         catch (Exception e) {
340             throw processException(e);
341         }
342         finally {
343             closeSession(session);
344         }
345     }
346 
347     public JournalArticle remove(JournalArticle journalArticle)
348         throws SystemException {
349         for (ModelListener<JournalArticle> listener : listeners) {
350             listener.onBeforeRemove(journalArticle);
351         }
352 
353         journalArticle = removeImpl(journalArticle);
354 
355         for (ModelListener<JournalArticle> listener : listeners) {
356             listener.onAfterRemove(journalArticle);
357         }
358 
359         return journalArticle;
360     }
361 
362     protected JournalArticle removeImpl(JournalArticle journalArticle)
363         throws SystemException {
364         Session session = null;
365 
366         try {
367             session = openSession();
368 
369             if (journalArticle.isCachedModel() || BatchSessionUtil.isEnabled()) {
370                 Object staleObject = session.get(JournalArticleImpl.class,
371                         journalArticle.getPrimaryKeyObj());
372 
373                 if (staleObject != null) {
374                     session.evict(staleObject);
375                 }
376             }
377 
378             session.delete(journalArticle);
379 
380             session.flush();
381         }
382         catch (Exception e) {
383             throw processException(e);
384         }
385         finally {
386             closeSession(session);
387         }
388 
389         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
390 
391         JournalArticleModelImpl journalArticleModelImpl = (JournalArticleModelImpl)journalArticle;
392 
393         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
394             new Object[] {
395                 journalArticleModelImpl.getOriginalUuid(),
396                 new Long(journalArticleModelImpl.getOriginalGroupId())
397             });
398 
399         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_A_V,
400             new Object[] {
401                 new Long(journalArticleModelImpl.getOriginalGroupId()),
402                 
403             journalArticleModelImpl.getOriginalArticleId(),
404                 new Double(journalArticleModelImpl.getOriginalVersion())
405             });
406 
407         EntityCacheUtil.removeResult(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
408             JournalArticleImpl.class, journalArticle.getPrimaryKey());
409 
410         return journalArticle;
411     }
412 
413     /**
414      * @deprecated Use {@link #update(JournalArticle, boolean merge)}.
415      */
416     public JournalArticle update(JournalArticle journalArticle)
417         throws SystemException {
418         if (_log.isWarnEnabled()) {
419             _log.warn(
420                 "Using the deprecated update(JournalArticle journalArticle) method. Use update(JournalArticle journalArticle, boolean merge) instead.");
421         }
422 
423         return update(journalArticle, false);
424     }
425 
426     /**
427      * Add, update, or merge, the entity. This method also calls the model
428      * listeners to trigger the proper events associated with adding, deleting,
429      * or updating an entity.
430      *
431      * @param  journalArticle the entity to add, update, or merge
432      * @param  merge boolean value for whether to merge the entity. The default
433      *         value is false. Setting merge to true is more expensive and
434      *         should only be true when journalArticle is transient. See
435      *         LEP-5473 for a detailed discussion of this method.
436      * @return the entity that was added, updated, or merged
437      */
438     public JournalArticle update(JournalArticle journalArticle, boolean merge)
439         throws SystemException {
440         boolean isNew = journalArticle.isNew();
441 
442         for (ModelListener<JournalArticle> listener : listeners) {
443             if (isNew) {
444                 listener.onBeforeCreate(journalArticle);
445             }
446             else {
447                 listener.onBeforeUpdate(journalArticle);
448             }
449         }
450 
451         journalArticle = updateImpl(journalArticle, merge);
452 
453         for (ModelListener<JournalArticle> listener : listeners) {
454             if (isNew) {
455                 listener.onAfterCreate(journalArticle);
456             }
457             else {
458                 listener.onAfterUpdate(journalArticle);
459             }
460         }
461 
462         return journalArticle;
463     }
464 
465     public JournalArticle updateImpl(
466         com.liferay.portlet.journal.model.JournalArticle journalArticle,
467         boolean merge) throws SystemException {
468         boolean isNew = journalArticle.isNew();
469 
470         JournalArticleModelImpl journalArticleModelImpl = (JournalArticleModelImpl)journalArticle;
471 
472         if (Validator.isNull(journalArticle.getUuid())) {
473             String uuid = PortalUUIDUtil.generate();
474 
475             journalArticle.setUuid(uuid);
476         }
477 
478         Session session = null;
479 
480         try {
481             session = openSession();
482 
483             BatchSessionUtil.update(session, journalArticle, merge);
484 
485             journalArticle.setNew(false);
486         }
487         catch (Exception e) {
488             throw processException(e);
489         }
490         finally {
491             closeSession(session);
492         }
493 
494         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
495 
496         EntityCacheUtil.putResult(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
497             JournalArticleImpl.class, journalArticle.getPrimaryKey(),
498             journalArticle);
499 
500         if (!isNew &&
501                 (!Validator.equals(journalArticle.getUuid(),
502                     journalArticleModelImpl.getOriginalUuid()) ||
503                 (journalArticle.getGroupId() != journalArticleModelImpl.getOriginalGroupId()))) {
504             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
505                 new Object[] {
506                     journalArticleModelImpl.getOriginalUuid(),
507                     new Long(journalArticleModelImpl.getOriginalGroupId())
508                 });
509         }
510 
511         if (isNew ||
512                 (!Validator.equals(journalArticle.getUuid(),
513                     journalArticleModelImpl.getOriginalUuid()) ||
514                 (journalArticle.getGroupId() != journalArticleModelImpl.getOriginalGroupId()))) {
515             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
516                 new Object[] {
517                     journalArticle.getUuid(),
518                     new Long(journalArticle.getGroupId())
519                 }, journalArticle);
520         }
521 
522         if (!isNew &&
523                 ((journalArticle.getGroupId() != journalArticleModelImpl.getOriginalGroupId()) ||
524                 !Validator.equals(journalArticle.getArticleId(),
525                     journalArticleModelImpl.getOriginalArticleId()) ||
526                 (journalArticle.getVersion() != journalArticleModelImpl.getOriginalVersion()))) {
527             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_A_V,
528                 new Object[] {
529                     new Long(journalArticleModelImpl.getOriginalGroupId()),
530                     
531                 journalArticleModelImpl.getOriginalArticleId(),
532                     new Double(journalArticleModelImpl.getOriginalVersion())
533                 });
534         }
535 
536         if (isNew ||
537                 ((journalArticle.getGroupId() != journalArticleModelImpl.getOriginalGroupId()) ||
538                 !Validator.equals(journalArticle.getArticleId(),
539                     journalArticleModelImpl.getOriginalArticleId()) ||
540                 (journalArticle.getVersion() != journalArticleModelImpl.getOriginalVersion()))) {
541             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_A_V,
542                 new Object[] {
543                     new Long(journalArticle.getGroupId()),
544                     
545                 journalArticle.getArticleId(),
546                     new Double(journalArticle.getVersion())
547                 }, journalArticle);
548         }
549 
550         return journalArticle;
551     }
552 
553     public JournalArticle findByPrimaryKey(long id)
554         throws NoSuchArticleException, SystemException {
555         JournalArticle journalArticle = fetchByPrimaryKey(id);
556 
557         if (journalArticle == null) {
558             if (_log.isWarnEnabled()) {
559                 _log.warn("No JournalArticle exists with the primary key " +
560                     id);
561             }
562 
563             throw new NoSuchArticleException(
564                 "No JournalArticle exists with the primary key " + id);
565         }
566 
567         return journalArticle;
568     }
569 
570     public JournalArticle fetchByPrimaryKey(long id) throws SystemException {
571         JournalArticle journalArticle = (JournalArticle)EntityCacheUtil.getResult(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
572                 JournalArticleImpl.class, id, this);
573 
574         if (journalArticle == null) {
575             Session session = null;
576 
577             try {
578                 session = openSession();
579 
580                 journalArticle = (JournalArticle)session.get(JournalArticleImpl.class,
581                         new Long(id));
582             }
583             catch (Exception e) {
584                 throw processException(e);
585             }
586             finally {
587                 if (journalArticle != null) {
588                     cacheResult(journalArticle);
589                 }
590 
591                 closeSession(session);
592             }
593         }
594 
595         return journalArticle;
596     }
597 
598     public List<JournalArticle> findByUuid(String uuid)
599         throws SystemException {
600         Object[] finderArgs = new Object[] { uuid };
601 
602         List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_UUID,
603                 finderArgs, this);
604 
605         if (list == null) {
606             Session session = null;
607 
608             try {
609                 session = openSession();
610 
611                 StringBuilder query = new StringBuilder();
612 
613                 query.append(
614                     "SELECT journalArticle FROM JournalArticle journalArticle WHERE ");
615 
616                 if (uuid == null) {
617                     query.append("journalArticle.uuid IS NULL");
618                 }
619                 else {
620                     query.append("journalArticle.uuid = ?");
621                 }
622 
623                 query.append(" ");
624 
625                 query.append("ORDER BY ");
626 
627                 query.append("journalArticle.articleId ASC, ");
628                 query.append("journalArticle.version DESC");
629 
630                 Query q = session.createQuery(query.toString());
631 
632                 QueryPos qPos = QueryPos.getInstance(q);
633 
634                 if (uuid != null) {
635                     qPos.add(uuid);
636                 }
637 
638                 list = q.list();
639             }
640             catch (Exception e) {
641                 throw processException(e);
642             }
643             finally {
644                 if (list == null) {
645                     list = new ArrayList<JournalArticle>();
646                 }
647 
648                 cacheResult(list);
649 
650                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_UUID, finderArgs,
651                     list);
652 
653                 closeSession(session);
654             }
655         }
656 
657         return list;
658     }
659 
660     public List<JournalArticle> findByUuid(String uuid, int start, int end)
661         throws SystemException {
662         return findByUuid(uuid, start, end, null);
663     }
664 
665     public List<JournalArticle> findByUuid(String uuid, int start, int end,
666         OrderByComparator obc) throws SystemException {
667         Object[] finderArgs = new Object[] {
668                 uuid,
669                 
670                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
671             };
672 
673         List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_UUID,
674                 finderArgs, this);
675 
676         if (list == null) {
677             Session session = null;
678 
679             try {
680                 session = openSession();
681 
682                 StringBuilder query = new StringBuilder();
683 
684                 query.append(
685                     "SELECT journalArticle FROM JournalArticle journalArticle WHERE ");
686 
687                 if (uuid == null) {
688                     query.append("journalArticle.uuid IS NULL");
689                 }
690                 else {
691                     query.append("journalArticle.uuid = ?");
692                 }
693 
694                 query.append(" ");
695 
696                 if (obc != null) {
697                     query.append("ORDER BY ");
698 
699                     String[] orderByFields = obc.getOrderByFields();
700 
701                     for (int i = 0; i < orderByFields.length; i++) {
702                         query.append("journalArticle.");
703                         query.append(orderByFields[i]);
704 
705                         if (obc.isAscending()) {
706                             query.append(" ASC");
707                         }
708                         else {
709                             query.append(" DESC");
710                         }
711 
712                         if ((i + 1) < orderByFields.length) {
713                             query.append(", ");
714                         }
715                     }
716                 }
717 
718                 else {
719                     query.append("ORDER BY ");
720 
721                     query.append("journalArticle.articleId ASC, ");
722                     query.append("journalArticle.version DESC");
723                 }
724 
725                 Query q = session.createQuery(query.toString());
726 
727                 QueryPos qPos = QueryPos.getInstance(q);
728 
729                 if (uuid != null) {
730                     qPos.add(uuid);
731                 }
732 
733                 list = (List<JournalArticle>)QueryUtil.list(q, getDialect(),
734                         start, end);
735             }
736             catch (Exception e) {
737                 throw processException(e);
738             }
739             finally {
740                 if (list == null) {
741                     list = new ArrayList<JournalArticle>();
742                 }
743 
744                 cacheResult(list);
745 
746                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_UUID,
747                     finderArgs, list);
748 
749                 closeSession(session);
750             }
751         }
752 
753         return list;
754     }
755 
756     public JournalArticle findByUuid_First(String uuid, OrderByComparator obc)
757         throws NoSuchArticleException, SystemException {
758         List<JournalArticle> list = findByUuid(uuid, 0, 1, obc);
759 
760         if (list.isEmpty()) {
761             StringBuilder msg = new StringBuilder();
762 
763             msg.append("No JournalArticle exists with the key {");
764 
765             msg.append("uuid=" + uuid);
766 
767             msg.append(StringPool.CLOSE_CURLY_BRACE);
768 
769             throw new NoSuchArticleException(msg.toString());
770         }
771         else {
772             return list.get(0);
773         }
774     }
775 
776     public JournalArticle findByUuid_Last(String uuid, OrderByComparator obc)
777         throws NoSuchArticleException, SystemException {
778         int count = countByUuid(uuid);
779 
780         List<JournalArticle> list = findByUuid(uuid, count - 1, count, obc);
781 
782         if (list.isEmpty()) {
783             StringBuilder msg = new StringBuilder();
784 
785             msg.append("No JournalArticle exists with the key {");
786 
787             msg.append("uuid=" + uuid);
788 
789             msg.append(StringPool.CLOSE_CURLY_BRACE);
790 
791             throw new NoSuchArticleException(msg.toString());
792         }
793         else {
794             return list.get(0);
795         }
796     }
797 
798     public JournalArticle[] findByUuid_PrevAndNext(long id, String uuid,
799         OrderByComparator obc) throws NoSuchArticleException, SystemException {
800         JournalArticle journalArticle = findByPrimaryKey(id);
801 
802         int count = countByUuid(uuid);
803 
804         Session session = null;
805 
806         try {
807             session = openSession();
808 
809             StringBuilder query = new StringBuilder();
810 
811             query.append(
812                 "SELECT journalArticle FROM JournalArticle journalArticle WHERE ");
813 
814             if (uuid == null) {
815                 query.append("journalArticle.uuid IS NULL");
816             }
817             else {
818                 query.append("journalArticle.uuid = ?");
819             }
820 
821             query.append(" ");
822 
823             if (obc != null) {
824                 query.append("ORDER BY ");
825 
826                 String[] orderByFields = obc.getOrderByFields();
827 
828                 for (int i = 0; i < orderByFields.length; i++) {
829                     query.append("journalArticle.");
830                     query.append(orderByFields[i]);
831 
832                     if (obc.isAscending()) {
833                         query.append(" ASC");
834                     }
835                     else {
836                         query.append(" DESC");
837                     }
838 
839                     if ((i + 1) < orderByFields.length) {
840                         query.append(", ");
841                     }
842                 }
843             }
844 
845             else {
846                 query.append("ORDER BY ");
847 
848                 query.append("journalArticle.articleId ASC, ");
849                 query.append("journalArticle.version DESC");
850             }
851 
852             Query q = session.createQuery(query.toString());
853 
854             QueryPos qPos = QueryPos.getInstance(q);
855 
856             if (uuid != null) {
857                 qPos.add(uuid);
858             }
859 
860             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
861                     journalArticle);
862 
863             JournalArticle[] array = new JournalArticleImpl[3];
864 
865             array[0] = (JournalArticle)objArray[0];
866             array[1] = (JournalArticle)objArray[1];
867             array[2] = (JournalArticle)objArray[2];
868 
869             return array;
870         }
871         catch (Exception e) {
872             throw processException(e);
873         }
874         finally {
875             closeSession(session);
876         }
877     }
878 
879     public JournalArticle findByUUID_G(String uuid, long groupId)
880         throws NoSuchArticleException, SystemException {
881         JournalArticle journalArticle = fetchByUUID_G(uuid, groupId);
882 
883         if (journalArticle == null) {
884             StringBuilder msg = new StringBuilder();
885 
886             msg.append("No JournalArticle exists with the key {");
887 
888             msg.append("uuid=" + uuid);
889 
890             msg.append(", ");
891             msg.append("groupId=" + groupId);
892 
893             msg.append(StringPool.CLOSE_CURLY_BRACE);
894 
895             if (_log.isWarnEnabled()) {
896                 _log.warn(msg.toString());
897             }
898 
899             throw new NoSuchArticleException(msg.toString());
900         }
901 
902         return journalArticle;
903     }
904 
905     public JournalArticle fetchByUUID_G(String uuid, long groupId)
906         throws SystemException {
907         return fetchByUUID_G(uuid, groupId, true);
908     }
909 
910     public JournalArticle fetchByUUID_G(String uuid, long groupId,
911         boolean retrieveFromCache) throws SystemException {
912         Object[] finderArgs = new Object[] { uuid, new Long(groupId) };
913 
914         Object result = null;
915 
916         if (retrieveFromCache) {
917             result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
918                     finderArgs, this);
919         }
920 
921         if (result == null) {
922             Session session = null;
923 
924             try {
925                 session = openSession();
926 
927                 StringBuilder query = new StringBuilder();
928 
929                 query.append(
930                     "SELECT journalArticle FROM JournalArticle journalArticle WHERE ");
931 
932                 if (uuid == null) {
933                     query.append("journalArticle.uuid IS NULL");
934                 }
935                 else {
936                     query.append("journalArticle.uuid = ?");
937                 }
938 
939                 query.append(" AND ");
940 
941                 query.append("journalArticle.groupId = ?");
942 
943                 query.append(" ");
944 
945                 query.append("ORDER BY ");
946 
947                 query.append("journalArticle.articleId ASC, ");
948                 query.append("journalArticle.version DESC");
949 
950                 Query q = session.createQuery(query.toString());
951 
952                 QueryPos qPos = QueryPos.getInstance(q);
953 
954                 if (uuid != null) {
955                     qPos.add(uuid);
956                 }
957 
958                 qPos.add(groupId);
959 
960                 List<JournalArticle> list = q.list();
961 
962                 result = list;
963 
964                 JournalArticle journalArticle = null;
965 
966                 if (list.isEmpty()) {
967                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
968                         finderArgs, list);
969                 }
970                 else {
971                     journalArticle = list.get(0);
972 
973                     cacheResult(journalArticle);
974 
975                     if ((journalArticle.getUuid() == null) ||
976                             !journalArticle.getUuid().equals(uuid) ||
977                             (journalArticle.getGroupId() != groupId)) {
978                         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
979                             finderArgs, journalArticle);
980                     }
981                 }
982 
983                 return journalArticle;
984             }
985             catch (Exception e) {
986                 throw processException(e);
987             }
988             finally {
989                 if (result == null) {
990                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
991                         finderArgs, new ArrayList<JournalArticle>());
992                 }
993 
994                 closeSession(session);
995             }
996         }
997         else {
998             if (result instanceof List<?>) {
999                 return null;
1000            }
1001            else {
1002                return (JournalArticle)result;
1003            }
1004        }
1005    }
1006
1007    public List<JournalArticle> findByGroupId(long groupId)
1008        throws SystemException {
1009        Object[] finderArgs = new Object[] { new Long(groupId) };
1010
1011        List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
1012                finderArgs, this);
1013
1014        if (list == null) {
1015            Session session = null;
1016
1017            try {
1018                session = openSession();
1019
1020                StringBuilder query = new StringBuilder();
1021
1022                query.append(
1023                    "SELECT journalArticle FROM JournalArticle journalArticle WHERE ");
1024
1025                query.append("journalArticle.groupId = ?");
1026
1027                query.append(" ");
1028
1029                query.append("ORDER BY ");
1030
1031                query.append("journalArticle.articleId ASC, ");
1032                query.append("journalArticle.version DESC");
1033
1034                Query q = session.createQuery(query.toString());
1035
1036                QueryPos qPos = QueryPos.getInstance(q);
1037
1038                qPos.add(groupId);
1039
1040                list = q.list();
1041            }
1042            catch (Exception e) {
1043                throw processException(e);
1044            }
1045            finally {
1046                if (list == null) {
1047                    list = new ArrayList<JournalArticle>();
1048                }
1049
1050                cacheResult(list);
1051
1052                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
1053                    finderArgs, list);
1054
1055                closeSession(session);
1056            }
1057        }
1058
1059        return list;
1060    }
1061
1062    public List<JournalArticle> findByGroupId(long groupId, int start, int end)
1063        throws SystemException {
1064        return findByGroupId(groupId, start, end, null);
1065    }
1066
1067    public List<JournalArticle> findByGroupId(long groupId, int start, int end,
1068        OrderByComparator obc) throws SystemException {
1069        Object[] finderArgs = new Object[] {
1070                new Long(groupId),
1071                
1072                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1073            };
1074
1075        List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_GROUPID,
1076                finderArgs, this);
1077
1078        if (list == null) {
1079            Session session = null;
1080
1081            try {
1082                session = openSession();
1083
1084                StringBuilder query = new StringBuilder();
1085
1086                query.append(
1087                    "SELECT journalArticle FROM JournalArticle journalArticle WHERE ");
1088
1089                query.append("journalArticle.groupId = ?");
1090
1091                query.append(" ");
1092
1093                if (obc != null) {
1094                    query.append("ORDER BY ");
1095
1096                    String[] orderByFields = obc.getOrderByFields();
1097
1098                    for (int i = 0; i < orderByFields.length; i++) {
1099                        query.append("journalArticle.");
1100                        query.append(orderByFields[i]);
1101
1102                        if (obc.isAscending()) {
1103                            query.append(" ASC");
1104                        }
1105                        else {
1106                            query.append(" DESC");
1107                        }
1108
1109                        if ((i + 1) < orderByFields.length) {
1110                            query.append(", ");
1111                        }
1112                    }
1113                }
1114
1115                else {
1116                    query.append("ORDER BY ");
1117
1118                    query.append("journalArticle.articleId ASC, ");
1119                    query.append("journalArticle.version DESC");
1120                }
1121
1122                Query q = session.createQuery(query.toString());
1123
1124                QueryPos qPos = QueryPos.getInstance(q);
1125
1126                qPos.add(groupId);
1127
1128                list = (List<JournalArticle>)QueryUtil.list(q, getDialect(),
1129                        start, end);
1130            }
1131            catch (Exception e) {
1132                throw processException(e);
1133            }
1134            finally {
1135                if (list == null) {
1136                    list = new ArrayList<JournalArticle>();
1137                }
1138
1139                cacheResult(list);
1140
1141                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_GROUPID,
1142                    finderArgs, list);
1143
1144                closeSession(session);
1145            }
1146        }
1147
1148        return list;
1149    }
1150
1151    public JournalArticle findByGroupId_First(long groupId,
1152        OrderByComparator obc) throws NoSuchArticleException, SystemException {
1153        List<JournalArticle> list = findByGroupId(groupId, 0, 1, obc);
1154
1155        if (list.isEmpty()) {
1156            StringBuilder msg = new StringBuilder();
1157
1158            msg.append("No JournalArticle exists with the key {");
1159
1160            msg.append("groupId=" + groupId);
1161
1162            msg.append(StringPool.CLOSE_CURLY_BRACE);
1163
1164            throw new NoSuchArticleException(msg.toString());
1165        }
1166        else {
1167            return list.get(0);
1168        }
1169    }
1170
1171    public JournalArticle findByGroupId_Last(long groupId, OrderByComparator obc)
1172        throws NoSuchArticleException, SystemException {
1173        int count = countByGroupId(groupId);
1174
1175        List<JournalArticle> list = findByGroupId(groupId, count - 1, count, obc);
1176
1177        if (list.isEmpty()) {
1178            StringBuilder msg = new StringBuilder();
1179
1180            msg.append("No JournalArticle exists with the key {");
1181
1182            msg.append("groupId=" + groupId);
1183
1184            msg.append(StringPool.CLOSE_CURLY_BRACE);
1185
1186            throw new NoSuchArticleException(msg.toString());
1187        }
1188        else {
1189            return list.get(0);
1190        }
1191    }
1192
1193    public JournalArticle[] findByGroupId_PrevAndNext(long id, long groupId,
1194        OrderByComparator obc) throws NoSuchArticleException, SystemException {
1195        JournalArticle journalArticle = findByPrimaryKey(id);
1196
1197        int count = countByGroupId(groupId);
1198
1199        Session session = null;
1200
1201        try {
1202            session = openSession();
1203
1204            StringBuilder query = new StringBuilder();
1205
1206            query.append(
1207                "SELECT journalArticle FROM JournalArticle journalArticle WHERE ");
1208
1209            query.append("journalArticle.groupId = ?");
1210
1211            query.append(" ");
1212
1213            if (obc != null) {
1214                query.append("ORDER BY ");
1215
1216                String[] orderByFields = obc.getOrderByFields();
1217
1218                for (int i = 0; i < orderByFields.length; i++) {
1219                    query.append("journalArticle.");
1220                    query.append(orderByFields[i]);
1221
1222                    if (obc.isAscending()) {
1223                        query.append(" ASC");
1224                    }
1225                    else {
1226                        query.append(" DESC");
1227                    }
1228
1229                    if ((i + 1) < orderByFields.length) {
1230                        query.append(", ");
1231                    }
1232                }
1233            }
1234
1235            else {
1236                query.append("ORDER BY ");
1237
1238                query.append("journalArticle.articleId ASC, ");
1239                query.append("journalArticle.version DESC");
1240            }
1241
1242            Query q = session.createQuery(query.toString());
1243
1244            QueryPos qPos = QueryPos.getInstance(q);
1245
1246            qPos.add(groupId);
1247
1248            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1249                    journalArticle);
1250
1251            JournalArticle[] array = new JournalArticleImpl[3];
1252
1253            array[0] = (JournalArticle)objArray[0];
1254            array[1] = (JournalArticle)objArray[1];
1255            array[2] = (JournalArticle)objArray[2];
1256
1257            return array;
1258        }
1259        catch (Exception e) {
1260            throw processException(e);
1261        }
1262        finally {
1263            closeSession(session);
1264        }
1265    }
1266
1267    public List<JournalArticle> findByCompanyId(long companyId)
1268        throws SystemException {
1269        Object[] finderArgs = new Object[] { new Long(companyId) };
1270
1271        List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
1272                finderArgs, this);
1273
1274        if (list == null) {
1275            Session session = null;
1276
1277            try {
1278                session = openSession();
1279
1280                StringBuilder query = new StringBuilder();
1281
1282                query.append(
1283                    "SELECT journalArticle FROM JournalArticle journalArticle WHERE ");
1284
1285                query.append("journalArticle.companyId = ?");
1286
1287                query.append(" ");
1288
1289                query.append("ORDER BY ");
1290
1291                query.append("journalArticle.articleId ASC, ");
1292                query.append("journalArticle.version DESC");
1293
1294                Query q = session.createQuery(query.toString());
1295
1296                QueryPos qPos = QueryPos.getInstance(q);
1297
1298                qPos.add(companyId);
1299
1300                list = q.list();
1301            }
1302            catch (Exception e) {
1303                throw processException(e);
1304            }
1305            finally {
1306                if (list == null) {
1307                    list = new ArrayList<JournalArticle>();
1308                }
1309
1310                cacheResult(list);
1311
1312                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
1313                    finderArgs, list);
1314
1315                closeSession(session);
1316            }
1317        }
1318
1319        return list;
1320    }
1321
1322    public List<JournalArticle> findByCompanyId(long companyId, int start,
1323        int end) throws SystemException {
1324        return findByCompanyId(companyId, start, end, null);
1325    }
1326
1327    public List<JournalArticle> findByCompanyId(long companyId, int start,
1328        int end, OrderByComparator obc) throws SystemException {
1329        Object[] finderArgs = new Object[] {
1330                new Long(companyId),
1331                
1332                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1333            };
1334
1335        List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_COMPANYID,
1336                finderArgs, this);
1337
1338        if (list == null) {
1339            Session session = null;
1340
1341            try {
1342                session = openSession();
1343
1344                StringBuilder query = new StringBuilder();
1345
1346                query.append(
1347                    "SELECT journalArticle FROM JournalArticle journalArticle WHERE ");
1348
1349                query.append("journalArticle.companyId = ?");
1350
1351                query.append(" ");
1352
1353                if (obc != null) {
1354                    query.append("ORDER BY ");
1355
1356                    String[] orderByFields = obc.getOrderByFields();
1357
1358                    for (int i = 0; i < orderByFields.length; i++) {
1359                        query.append("journalArticle.");
1360                        query.append(orderByFields[i]);
1361
1362                        if (obc.isAscending()) {
1363                            query.append(" ASC");
1364                        }
1365                        else {
1366                            query.append(" DESC");
1367                        }
1368
1369                        if ((i + 1) < orderByFields.length) {
1370                            query.append(", ");
1371                        }
1372                    }
1373                }
1374
1375                else {
1376                    query.append("ORDER BY ");
1377
1378                    query.append("journalArticle.articleId ASC, ");
1379                    query.append("journalArticle.version DESC");
1380                }
1381
1382                Query q = session.createQuery(query.toString());
1383
1384                QueryPos qPos = QueryPos.getInstance(q);
1385
1386                qPos.add(companyId);
1387
1388                list = (List<JournalArticle>)QueryUtil.list(q, getDialect(),
1389                        start, end);
1390            }
1391            catch (Exception e) {
1392                throw processException(e);
1393            }
1394            finally {
1395                if (list == null) {
1396                    list = new ArrayList<JournalArticle>();
1397                }
1398
1399                cacheResult(list);
1400
1401                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_COMPANYID,
1402                    finderArgs, list);
1403
1404                closeSession(session);
1405            }
1406        }
1407
1408        return list;
1409    }
1410
1411    public JournalArticle findByCompanyId_First(long companyId,
1412        OrderByComparator obc) throws NoSuchArticleException, SystemException {
1413        List<JournalArticle> list = findByCompanyId(companyId, 0, 1, obc);
1414
1415        if (list.isEmpty()) {
1416            StringBuilder msg = new StringBuilder();
1417
1418            msg.append("No JournalArticle exists with the key {");
1419
1420            msg.append("companyId=" + companyId);
1421
1422            msg.append(StringPool.CLOSE_CURLY_BRACE);
1423
1424            throw new NoSuchArticleException(msg.toString());
1425        }
1426        else {
1427            return list.get(0);
1428        }
1429    }
1430
1431    public JournalArticle findByCompanyId_Last(long companyId,
1432        OrderByComparator obc) throws NoSuchArticleException, SystemException {
1433        int count = countByCompanyId(companyId);
1434
1435        List<JournalArticle> list = findByCompanyId(companyId, count - 1,
1436                count, obc);
1437
1438        if (list.isEmpty()) {
1439            StringBuilder msg = new StringBuilder();
1440
1441            msg.append("No JournalArticle exists with the key {");
1442
1443            msg.append("companyId=" + companyId);
1444
1445            msg.append(StringPool.CLOSE_CURLY_BRACE);
1446
1447            throw new NoSuchArticleException(msg.toString());
1448        }
1449        else {
1450            return list.get(0);
1451        }
1452    }
1453
1454    public JournalArticle[] findByCompanyId_PrevAndNext(long id,
1455        long companyId, OrderByComparator obc)
1456        throws NoSuchArticleException, SystemException {
1457        JournalArticle journalArticle = findByPrimaryKey(id);
1458
1459        int count = countByCompanyId(companyId);
1460
1461        Session session = null;
1462
1463        try {
1464            session = openSession();
1465
1466            StringBuilder query = new StringBuilder();
1467
1468            query.append(
1469                "SELECT journalArticle FROM JournalArticle journalArticle WHERE ");
1470
1471            query.append("journalArticle.companyId = ?");
1472
1473            query.append(" ");
1474
1475            if (obc != null) {
1476                query.append("ORDER BY ");
1477
1478                String[] orderByFields = obc.getOrderByFields();
1479
1480                for (int i = 0; i < orderByFields.length; i++) {
1481                    query.append("journalArticle.");
1482                    query.append(orderByFields[i]);
1483
1484                    if (obc.isAscending()) {
1485                        query.append(" ASC");
1486                    }
1487                    else {
1488                        query.append(" DESC");
1489                    }
1490
1491                    if ((i + 1) < orderByFields.length) {
1492                        query.append(", ");
1493                    }
1494                }
1495            }
1496
1497            else {
1498                query.append("ORDER BY ");
1499
1500                query.append("journalArticle.articleId ASC, ");
1501                query.append("journalArticle.version DESC");
1502            }
1503
1504            Query q = session.createQuery(query.toString());
1505
1506            QueryPos qPos = QueryPos.getInstance(q);
1507
1508            qPos.add(companyId);
1509
1510            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1511                    journalArticle);
1512
1513            JournalArticle[] array = new JournalArticleImpl[3];
1514
1515            array[0] = (JournalArticle)objArray[0];
1516            array[1] = (JournalArticle)objArray[1];
1517            array[2] = (JournalArticle)objArray[2];
1518
1519            return array;
1520        }
1521        catch (Exception e) {
1522            throw processException(e);
1523        }
1524        finally {
1525            closeSession(session);
1526        }
1527    }
1528
1529    public List<JournalArticle> findBySmallImageId(long smallImageId)
1530        throws SystemException {
1531        Object[] finderArgs = new Object[] { new Long(smallImageId) };
1532
1533        List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_SMALLIMAGEID,
1534                finderArgs, this);
1535
1536        if (list == null) {
1537            Session session = null;
1538
1539            try {
1540                session = openSession();
1541
1542                StringBuilder query = new StringBuilder();
1543
1544                query.append(
1545                    "SELECT journalArticle FROM JournalArticle journalArticle WHERE ");
1546
1547                query.append("journalArticle.smallImageId = ?");
1548
1549                query.append(" ");
1550
1551                query.append("ORDER BY ");
1552
1553                query.append("journalArticle.articleId ASC, ");
1554                query.append("journalArticle.version DESC");
1555
1556                Query q = session.createQuery(query.toString());
1557
1558                QueryPos qPos = QueryPos.getInstance(q);
1559
1560                qPos.add(smallImageId);
1561
1562                list = q.list();
1563            }
1564            catch (Exception e) {
1565                throw processException(e);
1566            }
1567            finally {
1568                if (list == null) {
1569                    list = new ArrayList<JournalArticle>();
1570                }
1571
1572                cacheResult(list);
1573
1574                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_SMALLIMAGEID,
1575                    finderArgs, list);
1576
1577                closeSession(session);
1578            }
1579        }
1580
1581        return list;
1582    }
1583
1584    public List<JournalArticle> findBySmallImageId(long smallImageId,
1585        int start, int end) throws SystemException {
1586        return findBySmallImageId(smallImageId, start, end, null);
1587    }
1588
1589    public List<JournalArticle> findBySmallImageId(long smallImageId,
1590        int start, int end, OrderByComparator obc) throws SystemException {
1591        Object[] finderArgs = new Object[] {
1592                new Long(smallImageId),
1593                
1594                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1595            };
1596
1597        List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_SMALLIMAGEID,
1598                finderArgs, this);
1599
1600        if (list == null) {
1601            Session session = null;
1602
1603            try {
1604                session = openSession();
1605
1606                StringBuilder query = new StringBuilder();
1607
1608                query.append(
1609                    "SELECT journalArticle FROM JournalArticle journalArticle WHERE ");
1610
1611                query.append("journalArticle.smallImageId = ?");
1612
1613                query.append(" ");
1614
1615                if (obc != null) {
1616                    query.append("ORDER BY ");
1617
1618                    String[] orderByFields = obc.getOrderByFields();
1619
1620                    for (int i = 0; i < orderByFields.length; i++) {
1621                        query.append("journalArticle.");
1622                        query.append(orderByFields[i]);
1623
1624                        if (obc.isAscending()) {
1625                            query.append(" ASC");
1626                        }
1627                        else {
1628                            query.append(" DESC");
1629                        }
1630
1631                        if ((i + 1) < orderByFields.length) {
1632                            query.append(", ");
1633                        }
1634                    }
1635                }
1636
1637                else {
1638                    query.append("ORDER BY ");
1639
1640                    query.append("journalArticle.articleId ASC, ");
1641                    query.append("journalArticle.version DESC");
1642                }
1643
1644                Query q = session.createQuery(query.toString());
1645
1646                QueryPos qPos = QueryPos.getInstance(q);
1647
1648                qPos.add(smallImageId);
1649
1650                list = (List<JournalArticle>)QueryUtil.list(q, getDialect(),
1651                        start, end);
1652            }
1653            catch (Exception e) {
1654                throw processException(e);
1655            }
1656            finally {
1657                if (list == null) {
1658                    list = new ArrayList<JournalArticle>();
1659                }
1660
1661                cacheResult(list);
1662
1663                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_SMALLIMAGEID,
1664                    finderArgs, list);
1665
1666                closeSession(session);
1667            }
1668        }
1669
1670        return list;
1671    }
1672
1673    public JournalArticle findBySmallImageId_First(long smallImageId,
1674        OrderByComparator obc) throws NoSuchArticleException, SystemException {
1675        List<JournalArticle> list = findBySmallImageId(smallImageId, 0, 1, obc);
1676
1677        if (list.isEmpty()) {
1678            StringBuilder msg = new StringBuilder();
1679
1680            msg.append("No JournalArticle exists with the key {");
1681
1682            msg.append("smallImageId=" + smallImageId);
1683
1684            msg.append(StringPool.CLOSE_CURLY_BRACE);
1685
1686            throw new NoSuchArticleException(msg.toString());
1687        }
1688        else {
1689            return list.get(0);
1690        }
1691    }
1692
1693    public JournalArticle findBySmallImageId_Last(long smallImageId,
1694        OrderByComparator obc) throws NoSuchArticleException, SystemException {
1695        int count = countBySmallImageId(smallImageId);
1696
1697        List<JournalArticle> list = findBySmallImageId(smallImageId, count - 1,
1698                count, obc);
1699
1700        if (list.isEmpty()) {
1701            StringBuilder msg = new StringBuilder();
1702
1703            msg.append("No JournalArticle exists with the key {");
1704
1705            msg.append("smallImageId=" + smallImageId);
1706
1707            msg.append(StringPool.CLOSE_CURLY_BRACE);
1708
1709            throw new NoSuchArticleException(msg.toString());
1710        }
1711        else {
1712            return list.get(0);
1713        }
1714    }
1715
1716    public JournalArticle[] findBySmallImageId_PrevAndNext(long id,
1717        long smallImageId, OrderByComparator obc)
1718        throws NoSuchArticleException, SystemException {
1719        JournalArticle journalArticle = findByPrimaryKey(id);
1720
1721        int count = countBySmallImageId(smallImageId);
1722
1723        Session session = null;
1724
1725        try {
1726            session = openSession();
1727
1728            StringBuilder query = new StringBuilder();
1729
1730            query.append(
1731                "SELECT journalArticle FROM JournalArticle journalArticle WHERE ");
1732
1733            query.append("journalArticle.smallImageId = ?");
1734
1735            query.append(" ");
1736
1737            if (obc != null) {
1738                query.append("ORDER BY ");
1739
1740                String[] orderByFields = obc.getOrderByFields();
1741
1742                for (int i = 0; i < orderByFields.length; i++) {
1743                    query.append("journalArticle.");
1744                    query.append(orderByFields[i]);
1745
1746                    if (obc.isAscending()) {
1747                        query.append(" ASC");
1748                    }
1749                    else {
1750                        query.append(" DESC");
1751                    }
1752
1753                    if ((i + 1) < orderByFields.length) {
1754                        query.append(", ");
1755                    }
1756                }
1757            }
1758
1759            else {
1760                query.append("ORDER BY ");
1761
1762                query.append("journalArticle.articleId ASC, ");
1763                query.append("journalArticle.version DESC");
1764            }
1765
1766            Query q = session.createQuery(query.toString());
1767
1768            QueryPos qPos = QueryPos.getInstance(q);
1769
1770            qPos.add(smallImageId);
1771
1772            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1773                    journalArticle);
1774
1775            JournalArticle[] array = new JournalArticleImpl[3];
1776
1777            array[0] = (JournalArticle)objArray[0];
1778            array[1] = (JournalArticle)objArray[1];
1779            array[2] = (JournalArticle)objArray[2];
1780
1781            return array;
1782        }
1783        catch (Exception e) {
1784            throw processException(e);
1785        }
1786        finally {
1787            closeSession(session);
1788        }
1789    }
1790
1791    public List<JournalArticle> findByR_A(long resourcePrimKey, boolean approved)
1792        throws SystemException {
1793        Object[] finderArgs = new Object[] {
1794                new Long(resourcePrimKey), Boolean.valueOf(approved)
1795            };
1796
1797        List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_R_A,
1798                finderArgs, this);
1799
1800        if (list == null) {
1801            Session session = null;
1802
1803            try {
1804                session = openSession();
1805
1806                StringBuilder query = new StringBuilder();
1807
1808                query.append(
1809                    "SELECT journalArticle FROM JournalArticle journalArticle WHERE ");
1810
1811                query.append("journalArticle.resourcePrimKey = ?");
1812
1813                query.append(" AND ");
1814
1815                query.append("journalArticle.approved = ?");
1816
1817                query.append(" ");
1818
1819                query.append("ORDER BY ");
1820
1821                query.append("journalArticle.articleId ASC, ");
1822                query.append("journalArticle.version DESC");
1823
1824                Query q = session.createQuery(query.toString());
1825
1826                QueryPos qPos = QueryPos.getInstance(q);
1827
1828                qPos.add(resourcePrimKey);
1829
1830                qPos.add(approved);
1831
1832                list = q.list();
1833            }
1834            catch (Exception e) {
1835                throw processException(e);
1836            }
1837            finally {
1838                if (list == null) {
1839                    list = new ArrayList<JournalArticle>();
1840                }
1841
1842                cacheResult(list);
1843
1844                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_R_A, finderArgs,
1845                    list);
1846
1847                closeSession(session);
1848            }
1849        }
1850
1851        return list;
1852    }
1853
1854    public List<JournalArticle> findByR_A(long resourcePrimKey,
1855        boolean approved, int start, int end) throws SystemException {
1856        return findByR_A(resourcePrimKey, approved, start, end, null);
1857    }
1858
1859    public List<JournalArticle> findByR_A(long resourcePrimKey,
1860        boolean approved, int start, int end, OrderByComparator obc)
1861        throws SystemException {
1862        Object[] finderArgs = new Object[] {
1863                new Long(resourcePrimKey), Boolean.valueOf(approved),
1864                
1865                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1866            };
1867
1868        List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_R_A,
1869                finderArgs, this);
1870
1871        if (list == null) {
1872            Session session = null;
1873
1874            try {
1875                session = openSession();
1876
1877                StringBuilder query = new StringBuilder();
1878
1879                query.append(
1880                    "SELECT journalArticle FROM JournalArticle journalArticle WHERE ");
1881
1882                query.append("journalArticle.resourcePrimKey = ?");
1883
1884                query.append(" AND ");
1885
1886                query.append("journalArticle.approved = ?");
1887
1888                query.append(" ");
1889
1890                if (obc != null) {
1891                    query.append("ORDER BY ");
1892
1893                    String[] orderByFields = obc.getOrderByFields();
1894
1895                    for (int i = 0; i < orderByFields.length; i++) {
1896                        query.append("journalArticle.");
1897                        query.append(orderByFields[i]);
1898
1899                        if (obc.isAscending()) {
1900                            query.append(" ASC");
1901                        }
1902                        else {
1903                            query.append(" DESC");
1904                        }
1905
1906                        if ((i + 1) < orderByFields.length) {
1907                            query.append(", ");
1908                        }
1909                    }
1910                }
1911
1912                else {
1913                    query.append("ORDER BY ");
1914
1915                    query.append("journalArticle.articleId ASC, ");
1916                    query.append("journalArticle.version DESC");
1917                }
1918
1919                Query q = session.createQuery(query.toString());
1920
1921                QueryPos qPos = QueryPos.getInstance(q);
1922
1923                qPos.add(resourcePrimKey);
1924
1925                qPos.add(approved);
1926
1927                list = (List<JournalArticle>)QueryUtil.list(q, getDialect(),
1928                        start, end);
1929            }
1930            catch (Exception e) {
1931                throw processException(e);
1932            }
1933            finally {
1934                if (list == null) {
1935                    list = new ArrayList<JournalArticle>();
1936                }
1937
1938                cacheResult(list);
1939
1940                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_R_A,
1941                    finderArgs, list);
1942
1943                closeSession(session);
1944            }
1945        }
1946
1947        return list;
1948    }
1949
1950    public JournalArticle findByR_A_First(long resourcePrimKey,
1951        boolean approved, OrderByComparator obc)
1952        throws NoSuchArticleException, SystemException {
1953        List<JournalArticle> list = findByR_A(resourcePrimKey, approved, 0, 1,
1954                obc);
1955
1956        if (list.isEmpty()) {
1957            StringBuilder msg = new StringBuilder();
1958
1959            msg.append("No JournalArticle exists with the key {");
1960
1961            msg.append("resourcePrimKey=" + resourcePrimKey);
1962
1963            msg.append(", ");
1964            msg.append("approved=" + approved);
1965
1966            msg.append(StringPool.CLOSE_CURLY_BRACE);
1967
1968            throw new NoSuchArticleException(msg.toString());
1969        }
1970        else {
1971            return list.get(0);
1972        }
1973    }
1974
1975    public JournalArticle findByR_A_Last(long resourcePrimKey,
1976        boolean approved, OrderByComparator obc)
1977        throws NoSuchArticleException, SystemException {
1978        int count = countByR_A(resourcePrimKey, approved);
1979
1980        List<JournalArticle> list = findByR_A(resourcePrimKey, approved,
1981                count - 1, count, obc);
1982
1983        if (list.isEmpty()) {
1984            StringBuilder msg = new StringBuilder();
1985
1986            msg.append("No JournalArticle exists with the key {");
1987
1988            msg.append("resourcePrimKey=" + resourcePrimKey);
1989
1990            msg.append(", ");
1991            msg.append("approved=" + approved);
1992
1993            msg.append(StringPool.CLOSE_CURLY_BRACE);
1994
1995            throw new NoSuchArticleException(msg.toString());
1996        }
1997        else {
1998            return list.get(0);
1999        }
2000    }
2001
2002    public JournalArticle[] findByR_A_PrevAndNext(long id,
2003        long resourcePrimKey, boolean approved, OrderByComparator obc)
2004        throws NoSuchArticleException, SystemException {
2005        JournalArticle journalArticle = findByPrimaryKey(id);
2006
2007        int count = countByR_A(resourcePrimKey, approved);
2008
2009        Session session = null;
2010
2011        try {
2012            session = openSession();
2013
2014            StringBuilder query = new StringBuilder();
2015
2016            query.append(
2017                "SELECT journalArticle FROM JournalArticle journalArticle WHERE ");
2018
2019            query.append("journalArticle.resourcePrimKey = ?");
2020
2021            query.append(" AND ");
2022
2023            query.append("journalArticle.approved = ?");
2024
2025            query.append(" ");
2026
2027            if (obc != null) {
2028                query.append("ORDER BY ");
2029
2030                String[] orderByFields = obc.getOrderByFields();
2031
2032                for (int i = 0; i < orderByFields.length; i++) {
2033                    query.append("journalArticle.");
2034                    query.append(orderByFields[i]);
2035
2036                    if (obc.isAscending()) {
2037                        query.append(" ASC");
2038                    }
2039                    else {
2040                        query.append(" DESC");
2041                    }
2042
2043                    if ((i + 1) < orderByFields.length) {
2044                        query.append(", ");
2045                    }
2046                }
2047            }
2048
2049            else {
2050                query.append("ORDER BY ");
2051
2052                query.append("journalArticle.articleId ASC, ");
2053                query.append("journalArticle.version DESC");
2054            }
2055
2056            Query q = session.createQuery(query.toString());
2057
2058            QueryPos qPos = QueryPos.getInstance(q);
2059
2060            qPos.add(resourcePrimKey);
2061
2062            qPos.add(approved);
2063
2064            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
2065                    journalArticle);
2066
2067            JournalArticle[] array = new JournalArticleImpl[3];
2068
2069            array[0] = (JournalArticle)objArray[0];
2070            array[1] = (JournalArticle)objArray[1];
2071            array[2] = (JournalArticle)objArray[2];
2072
2073            return array;
2074        }
2075        catch (Exception e) {
2076            throw processException(e);
2077        }
2078        finally {
2079            closeSession(session);
2080        }
2081    }
2082
2083    public List<JournalArticle> findByG_A(long groupId, String articleId)
2084        throws SystemException {
2085        Object[] finderArgs = new Object[] { new Long(groupId), articleId };
2086
2087        List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_A,
2088                finderArgs, this);
2089
2090        if (list == null) {
2091            Session session = null;
2092
2093            try {
2094                session = openSession();
2095
2096                StringBuilder query = new StringBuilder();
2097
2098                query.append(
2099                    "SELECT journalArticle FROM JournalArticle journalArticle WHERE ");
2100
2101                query.append("journalArticle.groupId = ?");
2102
2103                query.append(" AND ");
2104
2105                if (articleId == null) {
2106                    query.append("journalArticle.articleId IS NULL");
2107                }
2108                else {
2109                    query.append("journalArticle.articleId = ?");
2110                }
2111
2112                query.append(" ");
2113
2114                query.append("ORDER BY ");
2115
2116                query.append("journalArticle.articleId ASC, ");
2117                query.append("journalArticle.version DESC");
2118
2119                Query q = session.createQuery(query.toString());
2120
2121                QueryPos qPos = QueryPos.getInstance(q);
2122
2123                qPos.add(groupId);
2124
2125                if (articleId != null) {
2126                    qPos.add(articleId);
2127                }
2128
2129                list = q.list();
2130            }
2131            catch (Exception e) {
2132                throw processException(e);
2133            }
2134            finally {
2135                if (list == null) {
2136                    list = new ArrayList<JournalArticle>();
2137                }
2138
2139                cacheResult(list);
2140
2141                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_A, finderArgs,
2142                    list);
2143
2144                closeSession(session);
2145            }
2146        }
2147
2148        return list;
2149    }
2150
2151    public List<JournalArticle> findByG_A(long groupId, String articleId,
2152        int start, int end) throws SystemException {
2153        return findByG_A(groupId, articleId, start, end, null);
2154    }
2155
2156    public List<JournalArticle> findByG_A(long groupId, String articleId,
2157        int start, int end, OrderByComparator obc) throws SystemException {
2158        Object[] finderArgs = new Object[] {
2159                new Long(groupId),
2160                
2161                articleId,
2162                
2163                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
2164            };
2165
2166        List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_G_A,
2167                finderArgs, this);
2168
2169        if (list == null) {
2170            Session session = null;
2171
2172            try {
2173                session = openSession();
2174
2175                StringBuilder query = new StringBuilder();
2176
2177                query.append(
2178                    "SELECT journalArticle FROM JournalArticle journalArticle WHERE ");
2179
2180                query.append("journalArticle.groupId = ?");
2181
2182                query.append(" AND ");
2183
2184                if (articleId == null) {
2185                    query.append("journalArticle.articleId IS NULL");
2186                }
2187                else {
2188                    query.append("journalArticle.articleId = ?");
2189                }
2190
2191                query.append(" ");
2192
2193                if (obc != null) {
2194                    query.append("ORDER BY ");
2195
2196                    String[] orderByFields = obc.getOrderByFields();
2197
2198                    for (int i = 0; i < orderByFields.length; i++) {
2199                        query.append("journalArticle.");
2200                        query.append(orderByFields[i]);
2201
2202                        if (obc.isAscending()) {
2203                            query.append(" ASC");
2204                        }
2205                        else {
2206                            query.append(" DESC");
2207                        }
2208
2209                        if ((i + 1) < orderByFields.length) {
2210                            query.append(", ");
2211                        }
2212                    }
2213                }
2214
2215                else {
2216                    query.append("ORDER BY ");
2217
2218                    query.append("journalArticle.articleId ASC, ");
2219                    query.append("journalArticle.version DESC");
2220                }
2221
2222                Query q = session.createQuery(query.toString());
2223
2224                QueryPos qPos = QueryPos.getInstance(q);
2225
2226                qPos.add(groupId);
2227
2228                if (articleId != null) {
2229                    qPos.add(articleId);
2230                }
2231
2232                list = (List<JournalArticle>)QueryUtil.list(q, getDialect(),
2233                        start, end);
2234            }
2235            catch (Exception e) {
2236                throw processException(e);
2237            }
2238            finally {
2239                if (list == null) {
2240                    list = new ArrayList<JournalArticle>();
2241                }
2242
2243                cacheResult(list);
2244
2245                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_G_A,
2246                    finderArgs, list);
2247
2248                closeSession(session);
2249            }
2250        }
2251
2252        return list;
2253    }
2254
2255    public JournalArticle findByG_A_First(long groupId, String articleId,
2256        OrderByComparator obc) throws NoSuchArticleException, SystemException {
2257        List<JournalArticle> list = findByG_A(groupId, articleId, 0, 1, obc);
2258
2259        if (list.isEmpty()) {
2260            StringBuilder msg = new StringBuilder();
2261
2262            msg.append("No JournalArticle exists with the key {");
2263
2264            msg.append("groupId=" + groupId);
2265
2266            msg.append(", ");
2267            msg.append("articleId=" + articleId);
2268
2269            msg.append(StringPool.CLOSE_CURLY_BRACE);
2270
2271            throw new NoSuchArticleException(msg.toString());
2272        }
2273        else {
2274            return list.get(0);
2275        }
2276    }
2277
2278    public JournalArticle findByG_A_Last(long groupId, String articleId,
2279        OrderByComparator obc) throws NoSuchArticleException, SystemException {
2280        int count = countByG_A(groupId, articleId);
2281
2282        List<JournalArticle> list = findByG_A(groupId, articleId, count - 1,
2283                count, obc);
2284
2285        if (list.isEmpty()) {
2286            StringBuilder msg = new StringBuilder();
2287
2288            msg.append("No JournalArticle exists with the key {");
2289
2290            msg.append("groupId=" + groupId);
2291
2292            msg.append(", ");
2293            msg.append("articleId=" + articleId);
2294
2295            msg.append(StringPool.CLOSE_CURLY_BRACE);
2296
2297            throw new NoSuchArticleException(msg.toString());
2298        }
2299        else {
2300            return list.get(0);
2301        }
2302    }
2303
2304    public JournalArticle[] findByG_A_PrevAndNext(long id, long groupId,
2305        String articleId, OrderByComparator obc)
2306        throws NoSuchArticleException, SystemException {
2307        JournalArticle journalArticle = findByPrimaryKey(id);
2308
2309        int count = countByG_A(groupId, articleId);
2310
2311        Session session = null;
2312
2313        try {
2314            session = openSession();
2315
2316            StringBuilder query = new StringBuilder();
2317
2318            query.append(
2319                "SELECT journalArticle FROM JournalArticle journalArticle WHERE ");
2320
2321            query.append("journalArticle.groupId = ?");
2322
2323            query.append(" AND ");
2324
2325            if (articleId == null) {
2326                query.append("journalArticle.articleId IS NULL");
2327            }
2328            else {
2329                query.append("journalArticle.articleId = ?");
2330            }
2331
2332            query.append(" ");
2333
2334            if (obc != null) {
2335                query.append("ORDER BY ");
2336
2337                String[] orderByFields = obc.getOrderByFields();
2338
2339                for (int i = 0; i < orderByFields.length; i++) {
2340                    query.append("journalArticle.");
2341                    query.append(orderByFields[i]);
2342
2343                    if (obc.isAscending()) {
2344                        query.append(" ASC");
2345                    }
2346                    else {
2347                        query.append(" DESC");
2348                    }
2349
2350                    if ((i + 1) < orderByFields.length) {
2351                        query.append(", ");
2352                    }
2353                }
2354            }
2355
2356            else {
2357                query.append("ORDER BY ");
2358
2359                query.append("journalArticle.articleId ASC, ");
2360                query.append("journalArticle.version DESC");
2361            }
2362
2363            Query q = session.createQuery(query.toString());
2364
2365            QueryPos qPos = QueryPos.getInstance(q);
2366
2367            qPos.add(groupId);
2368
2369            if (articleId != null) {
2370                qPos.add(articleId);
2371            }
2372
2373            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
2374                    journalArticle);
2375
2376            JournalArticle[] array = new JournalArticleImpl[3];
2377
2378            array[0] = (JournalArticle)objArray[0];
2379            array[1] = (JournalArticle)objArray[1];
2380            array[2] = (JournalArticle)objArray[2];
2381
2382            return array;
2383        }
2384        catch (Exception e) {
2385            throw processException(e);
2386        }
2387        finally {
2388            closeSession(session);
2389        }
2390    }
2391
2392    public List<JournalArticle> findByG_S(long groupId, String structureId)
2393        throws SystemException {
2394        Object[] finderArgs = new Object[] { new Long(groupId), structureId };
2395
2396        List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_S,
2397                finderArgs, this);
2398
2399        if (list == null) {
2400            Session session = null;
2401
2402            try {
2403                session = openSession();
2404
2405                StringBuilder query = new StringBuilder();
2406
2407                query.append(
2408                    "SELECT journalArticle FROM JournalArticle journalArticle WHERE ");
2409
2410                query.append("journalArticle.groupId = ?");
2411
2412                query.append(" AND ");
2413
2414                if (structureId == null) {
2415                    query.append("journalArticle.structureId IS NULL");
2416                }
2417                else {
2418                    query.append("journalArticle.structureId = ?");
2419                }
2420
2421                query.append(" ");
2422
2423                query.append("ORDER BY ");
2424
2425                query.append("journalArticle.articleId ASC, ");
2426                query.append("journalArticle.version DESC");
2427
2428                Query q = session.createQuery(query.toString());
2429
2430                QueryPos qPos = QueryPos.getInstance(q);
2431
2432                qPos.add(groupId);
2433
2434                if (structureId != null) {
2435                    qPos.add(structureId);
2436                }
2437
2438                list = q.list();
2439            }
2440            catch (Exception e) {
2441                throw processException(e);
2442            }
2443            finally {
2444                if (list == null) {
2445                    list = new ArrayList<JournalArticle>();
2446                }
2447
2448                cacheResult(list);
2449
2450                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_S, finderArgs,
2451                    list);
2452
2453                closeSession(session);
2454            }
2455        }
2456
2457        return list;
2458    }
2459
2460    public List<JournalArticle> findByG_S(long groupId, String structureId,
2461        int start, int end) throws SystemException {
2462        return findByG_S(groupId, structureId, start, end, null);
2463    }
2464
2465    public List<JournalArticle> findByG_S(long groupId, String structureId,
2466        int start, int end, OrderByComparator obc) throws SystemException {
2467        Object[] finderArgs = new Object[] {
2468                new Long(groupId),
2469                
2470                structureId,
2471                
2472                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
2473            };
2474
2475        List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_G_S,
2476                finderArgs, this);
2477
2478        if (list == null) {
2479            Session session = null;
2480
2481            try {
2482                session = openSession();
2483
2484                StringBuilder query = new StringBuilder();
2485
2486                query.append(
2487                    "SELECT journalArticle FROM JournalArticle journalArticle WHERE ");
2488
2489                query.append("journalArticle.groupId = ?");
2490
2491                query.append(" AND ");
2492
2493                if (structureId == null) {
2494                    query.append("journalArticle.structureId IS NULL");
2495                }
2496                else {
2497                    query.append("journalArticle.structureId = ?");
2498                }
2499
2500                query.append(" ");
2501
2502                if (obc != null) {
2503                    query.append("ORDER BY ");
2504
2505                    String[] orderByFields = obc.getOrderByFields();
2506
2507                    for (int i = 0; i < orderByFields.length; i++) {
2508                        query.append("journalArticle.");
2509                        query.append(orderByFields[i]);
2510
2511                        if (obc.isAscending()) {
2512                            query.append(" ASC");
2513                        }
2514                        else {
2515                            query.append(" DESC");
2516                        }
2517
2518                        if ((i + 1) < orderByFields.length) {
2519                            query.append(", ");
2520                        }
2521                    }
2522                }
2523
2524                else {
2525                    query.append("ORDER BY ");
2526
2527                    query.append("journalArticle.articleId ASC, ");
2528                    query.append("journalArticle.version DESC");
2529                }
2530
2531                Query q = session.createQuery(query.toString());
2532
2533                QueryPos qPos = QueryPos.getInstance(q);
2534
2535                qPos.add(groupId);
2536
2537                if (structureId != null) {
2538                    qPos.add(structureId);
2539                }
2540
2541                list = (List<JournalArticle>)QueryUtil.list(q, getDialect(),
2542                        start, end);
2543            }
2544            catch (Exception e) {
2545                throw processException(e);
2546            }
2547            finally {
2548                if (list == null) {
2549                    list = new ArrayList<JournalArticle>();
2550                }
2551
2552                cacheResult(list);
2553
2554                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_G_S,
2555                    finderArgs, list);
2556
2557                closeSession(session);
2558            }
2559        }
2560
2561        return list;
2562    }
2563
2564    public JournalArticle findByG_S_First(long groupId, String structureId,
2565        OrderByComparator obc) throws NoSuchArticleException, SystemException {
2566        List<JournalArticle> list = findByG_S(groupId, structureId, 0, 1, obc);
2567
2568        if (list.isEmpty()) {
2569            StringBuilder msg = new StringBuilder();
2570
2571            msg.append("No JournalArticle exists with the key {");
2572
2573            msg.append("groupId=" + groupId);
2574
2575            msg.append(", ");
2576            msg.append("structureId=" + structureId);
2577
2578            msg.append(StringPool.CLOSE_CURLY_BRACE);
2579
2580            throw new NoSuchArticleException(msg.toString());
2581        }
2582        else {
2583            return list.get(0);
2584        }
2585    }
2586
2587    public JournalArticle findByG_S_Last(long groupId, String structureId,
2588        OrderByComparator obc) throws NoSuchArticleException, SystemException {
2589        int count = countByG_S(groupId, structureId);
2590
2591        List<JournalArticle> list = findByG_S(groupId, structureId, count - 1,
2592                count, obc);
2593
2594        if (list.isEmpty()) {
2595            StringBuilder msg = new StringBuilder();
2596
2597            msg.append("No JournalArticle exists with the key {");
2598
2599            msg.append("groupId=" + groupId);
2600
2601            msg.append(", ");
2602            msg.append("structureId=" + structureId);
2603
2604            msg.append(StringPool.CLOSE_CURLY_BRACE);
2605
2606            throw new NoSuchArticleException(msg.toString());
2607        }
2608        else {
2609            return list.get(0);
2610        }
2611    }
2612
2613    public JournalArticle[] findByG_S_PrevAndNext(long id, long groupId,
2614        String structureId, OrderByComparator obc)
2615        throws NoSuchArticleException, SystemException {
2616        JournalArticle journalArticle = findByPrimaryKey(id);
2617
2618        int count = countByG_S(groupId, structureId);
2619
2620        Session session = null;
2621
2622        try {
2623            session = openSession();
2624
2625            StringBuilder query = new StringBuilder();
2626
2627            query.append(
2628                "SELECT journalArticle FROM JournalArticle journalArticle WHERE ");
2629
2630            query.append("journalArticle.groupId = ?");
2631
2632            query.append(" AND ");
2633
2634            if (structureId == null) {
2635                query.append("journalArticle.structureId IS NULL");
2636            }
2637            else {
2638                query.append("journalArticle.structureId = ?");
2639            }
2640
2641            query.append(" ");
2642
2643            if (obc != null) {
2644                query.append("ORDER BY ");
2645
2646                String[] orderByFields = obc.getOrderByFields();
2647
2648                for (int i = 0; i < orderByFields.length; i++) {
2649                    query.append("journalArticle.");
2650                    query.append(orderByFields[i]);
2651
2652                    if (obc.isAscending()) {
2653                        query.append(" ASC");
2654                    }
2655                    else {
2656                        query.append(" DESC");
2657                    }
2658
2659                    if ((i + 1) < orderByFields.length) {
2660                        query.append(", ");
2661                    }
2662                }
2663            }
2664
2665            else {
2666                query.append("ORDER BY ");
2667
2668                query.append("journalArticle.articleId ASC, ");
2669                query.append("journalArticle.version DESC");
2670            }
2671
2672            Query q = session.createQuery(query.toString());
2673
2674            QueryPos qPos = QueryPos.getInstance(q);
2675
2676            qPos.add(groupId);
2677
2678            if (structureId != null) {
2679                qPos.add(structureId);
2680            }
2681
2682            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
2683                    journalArticle);
2684
2685            JournalArticle[] array = new JournalArticleImpl[3];
2686
2687            array[0] = (JournalArticle)objArray[0];
2688            array[1] = (JournalArticle)objArray[1];
2689            array[2] = (JournalArticle)objArray[2];
2690
2691            return array;
2692        }
2693        catch (Exception e) {
2694            throw processException(e);
2695        }
2696        finally {
2697            closeSession(session);
2698        }
2699    }
2700
2701    public List<JournalArticle> findByG_T(long groupId, String templateId)
2702        throws SystemException {
2703        Object[] finderArgs = new Object[] { new Long(groupId), templateId };
2704
2705        List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_T,
2706                finderArgs, this);
2707
2708        if (list == null) {
2709            Session session = null;
2710
2711            try {
2712                session = openSession();
2713
2714                StringBuilder query = new StringBuilder();
2715
2716                query.append(
2717                    "SELECT journalArticle FROM JournalArticle journalArticle WHERE ");
2718
2719                query.append("journalArticle.groupId = ?");
2720
2721                query.append(" AND ");
2722
2723                if (templateId == null) {
2724                    query.append("journalArticle.templateId IS NULL");
2725                }
2726                else {
2727                    query.append("journalArticle.templateId = ?");
2728                }
2729
2730                query.append(" ");
2731
2732                query.append("ORDER BY ");
2733
2734                query.append("journalArticle.articleId ASC, ");
2735                query.append("journalArticle.version DESC");
2736
2737                Query q = session.createQuery(query.toString());
2738
2739                QueryPos qPos = QueryPos.getInstance(q);
2740
2741                qPos.add(groupId);
2742
2743                if (templateId != null) {
2744                    qPos.add(templateId);
2745                }
2746
2747                list = q.list();
2748            }
2749            catch (Exception e) {
2750                throw processException(e);
2751            }
2752            finally {
2753                if (list == null) {
2754                    list = new ArrayList<JournalArticle>();
2755                }
2756
2757                cacheResult(list);
2758
2759                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_T, finderArgs,
2760                    list);
2761
2762                closeSession(session);
2763            }
2764        }
2765
2766        return list;
2767    }
2768
2769    public List<JournalArticle> findByG_T(long groupId, String templateId,
2770        int start, int end) throws SystemException {
2771        return findByG_T(groupId, templateId, start, end, null);
2772    }
2773
2774    public List<JournalArticle> findByG_T(long groupId, String templateId,
2775        int start, int end, OrderByComparator obc) throws SystemException {
2776        Object[] finderArgs = new Object[] {
2777                new Long(groupId),
2778                
2779                templateId,
2780                
2781                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
2782            };
2783
2784        List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_G_T,
2785                finderArgs, this);
2786
2787        if (list == null) {
2788            Session session = null;
2789
2790            try {
2791                session = openSession();
2792
2793                StringBuilder query = new StringBuilder();
2794
2795                query.append(
2796                    "SELECT journalArticle FROM JournalArticle journalArticle WHERE ");
2797
2798                query.append("journalArticle.groupId = ?");
2799
2800                query.append(" AND ");
2801
2802                if (templateId == null) {
2803                    query.append("journalArticle.templateId IS NULL");
2804                }
2805                else {
2806                    query.append("journalArticle.templateId = ?");
2807                }
2808
2809                query.append(" ");
2810
2811                if (obc != null) {
2812                    query.append("ORDER BY ");
2813
2814                    String[] orderByFields = obc.getOrderByFields();
2815
2816                    for (int i = 0; i < orderByFields.length; i++) {
2817                        query.append("journalArticle.");
2818                        query.append(orderByFields[i]);
2819
2820                        if (obc.isAscending()) {
2821                            query.append(" ASC");
2822                        }
2823                        else {
2824                            query.append(" DESC");
2825                        }
2826
2827                        if ((i + 1) < orderByFields.length) {
2828                            query.append(", ");
2829                        }
2830                    }
2831                }
2832
2833                else {
2834                    query.append("ORDER BY ");
2835
2836                    query.append("journalArticle.articleId ASC, ");
2837                    query.append("journalArticle.version DESC");
2838                }
2839
2840                Query q = session.createQuery(query.toString());
2841
2842                QueryPos qPos = QueryPos.getInstance(q);
2843
2844                qPos.add(groupId);
2845
2846                if (templateId != null) {
2847                    qPos.add(templateId);
2848                }
2849
2850                list = (List<JournalArticle>)QueryUtil.list(q, getDialect(),
2851                        start, end);
2852            }
2853            catch (Exception e) {
2854                throw processException(e);
2855            }
2856            finally {
2857                if (list == null) {
2858                    list = new ArrayList<JournalArticle>();
2859                }
2860
2861                cacheResult(list);
2862
2863                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_G_T,
2864                    finderArgs, list);
2865
2866                closeSession(session);
2867            }
2868        }
2869
2870        return list;
2871    }
2872
2873    public JournalArticle findByG_T_First(long groupId, String templateId,
2874        OrderByComparator obc) throws NoSuchArticleException, SystemException {
2875        List<JournalArticle> list = findByG_T(groupId, templateId, 0, 1, obc);
2876
2877        if (list.isEmpty()) {
2878            StringBuilder msg = new StringBuilder();
2879
2880            msg.append("No JournalArticle exists with the key {");
2881
2882            msg.append("groupId=" + groupId);
2883
2884            msg.append(", ");
2885            msg.append("templateId=" + templateId);
2886
2887            msg.append(StringPool.CLOSE_CURLY_BRACE);
2888
2889            throw new NoSuchArticleException(msg.toString());
2890        }
2891        else {
2892            return list.get(0);
2893        }
2894    }
2895
2896    public JournalArticle findByG_T_Last(long groupId, String templateId,
2897        OrderByComparator obc) throws NoSuchArticleException, SystemException {
2898        int count = countByG_T(groupId, templateId);
2899
2900        List<JournalArticle> list = findByG_T(groupId, templateId, count - 1,
2901                count, obc);
2902
2903        if (list.isEmpty()) {
2904            StringBuilder msg = new StringBuilder();
2905
2906            msg.append("No JournalArticle exists with the key {");
2907
2908            msg.append("groupId=" + groupId);
2909
2910            msg.append(", ");
2911            msg.append("templateId=" + templateId);
2912
2913            msg.append(StringPool.CLOSE_CURLY_BRACE);
2914
2915            throw new NoSuchArticleException(msg.toString());
2916        }
2917        else {
2918            return list.get(0);
2919        }
2920    }
2921
2922    public JournalArticle[] findByG_T_PrevAndNext(long id, long groupId,
2923        String templateId, OrderByComparator obc)
2924        throws NoSuchArticleException, SystemException {
2925        JournalArticle journalArticle = findByPrimaryKey(id);
2926
2927        int count = countByG_T(groupId, templateId);
2928
2929        Session session = null;
2930
2931        try {
2932            session = openSession();
2933
2934            StringBuilder query = new StringBuilder();
2935
2936            query.append(
2937                "SELECT journalArticle FROM JournalArticle journalArticle WHERE ");
2938
2939            query.append("journalArticle.groupId = ?");
2940
2941            query.append(" AND ");
2942
2943            if (templateId == null) {
2944                query.append("journalArticle.templateId IS NULL");
2945            }
2946            else {
2947                query.append("journalArticle.templateId = ?");
2948            }
2949
2950            query.append(" ");
2951
2952            if (obc != null) {
2953                query.append("ORDER BY ");
2954
2955                String[] orderByFields = obc.getOrderByFields();
2956
2957                for (int i = 0; i < orderByFields.length; i++) {
2958                    query.append("journalArticle.");
2959                    query.append(orderByFields[i]);
2960
2961                    if (obc.isAscending()) {
2962                        query.append(" ASC");
2963                    }
2964                    else {
2965                        query.append(" DESC");
2966                    }
2967
2968                    if ((i + 1) < orderByFields.length) {
2969                        query.append(", ");
2970                    }
2971                }
2972            }
2973
2974            else {
2975                query.append("ORDER BY ");
2976
2977                query.append("journalArticle.articleId ASC, ");
2978                query.append("journalArticle.version DESC");
2979            }
2980
2981            Query q = session.createQuery(query.toString());
2982
2983            QueryPos qPos = QueryPos.getInstance(q);
2984
2985            qPos.add(groupId);
2986
2987            if (templateId != null) {
2988                qPos.add(templateId);
2989            }
2990
2991            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
2992                    journalArticle);
2993
2994            JournalArticle[] array = new JournalArticleImpl[3];
2995
2996            array[0] = (JournalArticle)objArray[0];
2997            array[1] = (JournalArticle)objArray[1];
2998            array[2] = (JournalArticle)objArray[2];
2999
3000            return array;
3001        }
3002        catch (Exception e) {
3003            throw processException(e);
3004        }
3005        finally {
3006            closeSession(session);
3007        }
3008    }
3009
3010    public JournalArticle findByG_A_V(long groupId, String articleId,
3011        double version) throws NoSuchArticleException, SystemException {
3012        JournalArticle journalArticle = fetchByG_A_V(groupId, articleId, version);
3013
3014        if (journalArticle == null) {
3015            StringBuilder msg = new StringBuilder();
3016
3017            msg.append("No JournalArticle exists with the key {");
3018
3019            msg.append("groupId=" + groupId);
3020
3021            msg.append(", ");
3022            msg.append("articleId=" + articleId);
3023
3024            msg.append(", ");
3025            msg.append("version=" + version);
3026
3027            msg.append(StringPool.CLOSE_CURLY_BRACE);
3028
3029            if (_log.isWarnEnabled()) {
3030                _log.warn(msg.toString());
3031            }
3032
3033            throw new NoSuchArticleException(msg.toString());
3034        }
3035
3036        return journalArticle;
3037    }
3038
3039    public JournalArticle fetchByG_A_V(long groupId, String articleId,
3040        double version) throws SystemException {
3041        return fetchByG_A_V(groupId, articleId, version, true);
3042    }
3043
3044    public JournalArticle fetchByG_A_V(long groupId, String articleId,
3045        double version, boolean retrieveFromCache) throws SystemException {
3046        Object[] finderArgs = new Object[] {
3047                new Long(groupId),
3048                
3049                articleId, new Double(version)
3050            };
3051
3052        Object result = null;
3053
3054        if (retrieveFromCache) {
3055            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_A_V,
3056                    finderArgs, this);
3057        }
3058
3059        if (result == null) {
3060            Session session = null;
3061
3062            try {
3063                session = openSession();
3064
3065                StringBuilder query = new StringBuilder();
3066
3067                query.append(
3068                    "SELECT journalArticle FROM JournalArticle journalArticle WHERE ");
3069
3070                query.append("journalArticle.groupId = ?");
3071
3072                query.append(" AND ");
3073
3074                if (articleId == null) {
3075                    query.append("journalArticle.articleId IS NULL");
3076                }
3077                else {
3078                    query.append("journalArticle.articleId = ?");
3079                }
3080
3081                query.append(" AND ");
3082
3083                query.append("journalArticle.version = ?");
3084
3085                query.append(" ");
3086
3087                query.append("ORDER BY ");
3088
3089                query.append("journalArticle.articleId ASC, ");
3090                query.append("journalArticle.version DESC");
3091
3092                Query q = session.createQuery(query.toString());
3093
3094                QueryPos qPos = QueryPos.getInstance(q);
3095
3096                qPos.add(groupId);
3097
3098                if (articleId != null) {
3099                    qPos.add(articleId);
3100                }
3101
3102                qPos.add(version);
3103
3104                List<JournalArticle> list = q.list();
3105
3106                result = list;
3107
3108                JournalArticle journalArticle = null;
3109
3110                if (list.isEmpty()) {
3111                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_A_V,
3112                        finderArgs, list);
3113                }
3114                else {
3115                    journalArticle = list.get(0);
3116
3117                    cacheResult(journalArticle);
3118
3119                    if ((journalArticle.getGroupId() != groupId) ||
3120                            (journalArticle.getArticleId() == null) ||
3121                            !journalArticle.getArticleId().equals(articleId) ||
3122                            (journalArticle.getVersion() != version)) {
3123                        FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_A_V,
3124                            finderArgs, journalArticle);
3125                    }
3126                }
3127
3128                return journalArticle;
3129            }
3130            catch (Exception e) {
3131                throw processException(e);
3132            }
3133            finally {
3134                if (result == null) {
3135                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_A_V,
3136                        finderArgs, new ArrayList<JournalArticle>());
3137                }
3138
3139                closeSession(session);
3140            }
3141        }
3142        else {
3143            if (result instanceof List<?>) {
3144                return null;
3145            }
3146            else {
3147                return (JournalArticle)result;
3148            }
3149        }
3150    }
3151
3152    public List<JournalArticle> findByG_A_A(long groupId, String articleId,
3153        boolean approved) throws SystemException {
3154        Object[] finderArgs = new Object[] {
3155                new Long(groupId),
3156                
3157                articleId, Boolean.valueOf(approved)
3158            };
3159
3160        List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_A_A,
3161                finderArgs, this);
3162
3163        if (list == null) {
3164            Session session = null;
3165
3166            try {
3167                session = openSession();
3168
3169                StringBuilder query = new StringBuilder();
3170
3171                query.append(
3172                    "SELECT journalArticle FROM JournalArticle journalArticle WHERE ");
3173
3174                query.append("journalArticle.groupId = ?");
3175
3176                query.append(" AND ");
3177
3178                if (articleId == null) {
3179                    query.append("journalArticle.articleId IS NULL");
3180                }
3181                else {
3182                    query.append("journalArticle.articleId = ?");
3183                }
3184
3185                query.append(" AND ");
3186
3187                query.append("journalArticle.approved = ?");
3188
3189                query.append(" ");
3190
3191                query.append("ORDER BY ");
3192
3193                query.append("journalArticle.articleId ASC, ");
3194                query.append("journalArticle.version DESC");
3195
3196                Query q = session.createQuery(query.toString());
3197
3198                QueryPos qPos = QueryPos.getInstance(q);
3199
3200                qPos.add(groupId);
3201
3202                if (articleId != null) {
3203                    qPos.add(articleId);
3204                }
3205
3206                qPos.add(approved);
3207
3208                list = q.list();
3209            }
3210            catch (Exception e) {
3211                throw processException(e);
3212            }
3213            finally {
3214                if (list == null) {
3215                    list = new ArrayList<JournalArticle>();
3216                }
3217
3218                cacheResult(list);
3219
3220                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_A_A,
3221                    finderArgs, list);
3222
3223                closeSession(session);
3224            }
3225        }
3226
3227        return list;
3228    }
3229
3230    public List<JournalArticle> findByG_A_A(long groupId, String articleId,
3231        boolean approved, int start, int end) throws SystemException {
3232        return findByG_A_A(groupId, articleId, approved, start, end, null);
3233    }
3234
3235    public List<JournalArticle> findByG_A_A(long groupId, String articleId,
3236        boolean approved, int start, int end, OrderByComparator obc)
3237        throws SystemException {
3238        Object[] finderArgs = new Object[] {
3239                new Long(groupId),
3240                
3241                articleId, Boolean.valueOf(approved),
3242                
3243                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
3244            };
3245
3246        List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_G_A_A,
3247                finderArgs, this);
3248
3249        if (list == null) {
3250            Session session = null;
3251
3252            try {
3253                session = openSession();
3254
3255                StringBuilder query = new StringBuilder();
3256
3257                query.append(
3258                    "SELECT journalArticle FROM JournalArticle journalArticle WHERE ");
3259
3260                query.append("journalArticle.groupId = ?");
3261
3262                query.append(" AND ");
3263
3264                if (articleId == null) {
3265                    query.append("journalArticle.articleId IS NULL");
3266                }
3267                else {
3268                    query.append("journalArticle.articleId = ?");
3269                }
3270
3271                query.append(" AND ");
3272
3273                query.append("journalArticle.approved = ?");
3274
3275                query.append(" ");
3276
3277                if (obc != null) {
3278                    query.append("ORDER BY ");
3279
3280                    String[] orderByFields = obc.getOrderByFields();
3281
3282                    for (int i = 0; i < orderByFields.length; i++) {
3283                        query.append("journalArticle.");
3284                        query.append(orderByFields[i]);
3285
3286                        if (obc.isAscending()) {
3287                            query.append(" ASC");
3288                        }
3289                        else {
3290                            query.append(" DESC");
3291                        }
3292
3293                        if ((i + 1) < orderByFields.length) {
3294                            query.append(", ");
3295                        }
3296                    }
3297                }
3298
3299                else {
3300                    query.append("ORDER BY ");
3301
3302                    query.append("journalArticle.articleId ASC, ");
3303                    query.append("journalArticle.version DESC");
3304                }
3305
3306                Query q = session.createQuery(query.toString());
3307
3308                QueryPos qPos = QueryPos.getInstance(q);
3309
3310                qPos.add(groupId);
3311
3312                if (articleId != null) {
3313                    qPos.add(articleId);
3314                }
3315
3316                qPos.add(approved);
3317
3318                list = (List<JournalArticle>)QueryUtil.list(q, getDialect(),
3319                        start, end);
3320            }
3321            catch (Exception e) {
3322                throw processException(e);
3323            }
3324            finally {
3325                if (list == null) {
3326                    list = new ArrayList<JournalArticle>();
3327                }
3328
3329                cacheResult(list);
3330
3331                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_G_A_A,
3332                    finderArgs, list);
3333
3334                closeSession(session);
3335            }
3336        }
3337
3338        return list;
3339    }
3340
3341    public JournalArticle findByG_A_A_First(long groupId, String articleId,
3342        boolean approved, OrderByComparator obc)
3343        throws NoSuchArticleException, SystemException {
3344        List<JournalArticle> list = findByG_A_A(groupId, articleId, approved,
3345                0, 1, obc);
3346
3347        if (list.isEmpty()) {
3348            StringBuilder msg = new StringBuilder();
3349
3350            msg.append("No JournalArticle exists with the key {");
3351
3352            msg.append("groupId=" + groupId);
3353
3354            msg.append(", ");
3355            msg.append("articleId=" + articleId);
3356
3357            msg.append(", ");
3358            msg.append("approved=" + approved);
3359
3360            msg.append(StringPool.CLOSE_CURLY_BRACE);
3361
3362            throw new NoSuchArticleException(msg.toString());
3363        }
3364        else {
3365            return list.get(0);
3366        }
3367    }
3368
3369    public JournalArticle findByG_A_A_Last(long groupId, String articleId,
3370        boolean approved, OrderByComparator obc)
3371        throws NoSuchArticleException, SystemException {
3372        int count = countByG_A_A(groupId, articleId, approved);
3373
3374        List<JournalArticle> list = findByG_A_A(groupId, articleId, approved,
3375                count - 1, count, obc);
3376
3377        if (list.isEmpty()) {
3378            StringBuilder msg = new StringBuilder();
3379
3380            msg.append("No JournalArticle exists with the key {");
3381
3382            msg.append("groupId=" + groupId);
3383
3384            msg.append(", ");
3385            msg.append("articleId=" + articleId);
3386
3387            msg.append(", ");
3388            msg.append("approved=" + approved);
3389
3390            msg.append(StringPool.CLOSE_CURLY_BRACE);
3391
3392            throw new NoSuchArticleException(msg.toString());
3393        }
3394        else {
3395            return list.get(0);
3396        }
3397    }
3398
3399    public JournalArticle[] findByG_A_A_PrevAndNext(long id, long groupId,
3400        String articleId, boolean approved, OrderByComparator obc)
3401        throws NoSuchArticleException, SystemException {
3402        JournalArticle journalArticle = findByPrimaryKey(id);
3403
3404        int count = countByG_A_A(groupId, articleId, approved);
3405
3406        Session session = null;
3407
3408        try {
3409            session = openSession();
3410
3411            StringBuilder query = new StringBuilder();
3412
3413            query.append(
3414                "SELECT journalArticle FROM JournalArticle journalArticle WHERE ");
3415
3416            query.append("journalArticle.groupId = ?");
3417
3418            query.append(" AND ");
3419
3420            if (articleId == null) {
3421                query.append("journalArticle.articleId IS NULL");
3422            }
3423            else {
3424                query.append("journalArticle.articleId = ?");
3425            }
3426
3427            query.append(" AND ");
3428
3429            query.append("journalArticle.approved = ?");
3430
3431            query.append(" ");
3432
3433            if (obc != null) {
3434                query.append("ORDER BY ");
3435
3436                String[] orderByFields = obc.getOrderByFields();
3437
3438                for (int i = 0; i < orderByFields.length; i++) {
3439                    query.append("journalArticle.");
3440                    query.append(orderByFields[i]);
3441
3442                    if (obc.isAscending()) {
3443                        query.append(" ASC");
3444                    }
3445                    else {
3446                        query.append(" DESC");
3447                    }
3448
3449                    if ((i + 1) < orderByFields.length) {
3450                        query.append(", ");
3451                    }
3452                }
3453            }
3454
3455            else {
3456                query.append("ORDER BY ");
3457
3458                query.append("journalArticle.articleId ASC, ");
3459                query.append("journalArticle.version DESC");
3460            }
3461
3462            Query q = session.createQuery(query.toString());
3463
3464            QueryPos qPos = QueryPos.getInstance(q);
3465
3466            qPos.add(groupId);
3467
3468            if (articleId != null) {
3469                qPos.add(articleId);
3470            }
3471
3472            qPos.add(approved);
3473
3474            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
3475                    journalArticle);
3476
3477            JournalArticle[] array = new JournalArticleImpl[3];
3478
3479            array[0] = (JournalArticle)objArray[0];
3480            array[1] = (JournalArticle)objArray[1];
3481            array[2] = (JournalArticle)objArray[2];
3482
3483            return array;
3484        }
3485        catch (Exception e) {
3486            throw processException(e);
3487        }
3488        finally {
3489            closeSession(session);
3490        }
3491    }
3492
3493    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
3494        throws SystemException {
3495        Session session = null;
3496
3497        try {
3498            session = openSession();
3499
3500            dynamicQuery.compile(session);
3501
3502            return dynamicQuery.list();
3503        }
3504        catch (Exception e) {
3505            throw processException(e);
3506        }
3507        finally {
3508            closeSession(session);
3509        }
3510    }
3511
3512    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
3513        int start, int end) throws SystemException {
3514        Session session = null;
3515
3516        try {
3517            session = openSession();
3518
3519            dynamicQuery.setLimit(start, end);
3520
3521            dynamicQuery.compile(session);
3522
3523            return dynamicQuery.list();
3524        }
3525        catch (Exception e) {
3526            throw processException(e);
3527        }
3528        finally {
3529            closeSession(session);
3530        }
3531    }
3532
3533    public List<JournalArticle> findAll() throws SystemException {
3534        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3535    }
3536
3537    public List<JournalArticle> findAll(int start, int end)
3538        throws SystemException {
3539        return findAll(start, end, null);
3540    }
3541
3542    public List<JournalArticle> findAll(int start, int end,
3543        OrderByComparator obc) throws SystemException {
3544        Object[] finderArgs = new Object[] {
3545                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
3546            };
3547
3548        List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
3549                finderArgs, this);
3550
3551        if (list == null) {
3552            Session session = null;
3553
3554            try {
3555                session = openSession();
3556
3557                StringBuilder query = new StringBuilder();
3558
3559                query.append(
3560                    "SELECT journalArticle FROM JournalArticle journalArticle ");
3561
3562                if (obc != null) {
3563                    query.append("ORDER BY ");
3564
3565                    String[] orderByFields = obc.getOrderByFields();
3566
3567                    for (int i = 0; i < orderByFields.length; i++) {
3568                        query.append("journalArticle.");
3569                        query.append(orderByFields[i]);
3570
3571                        if (obc.isAscending()) {
3572                            query.append(" ASC");
3573                        }
3574                        else {
3575                            query.append(" DESC");
3576                        }
3577
3578                        if ((i + 1) < orderByFields.length) {
3579                            query.append(", ");
3580                        }
3581                    }
3582                }
3583
3584                else {
3585                    query.append("ORDER BY ");
3586
3587                    query.append("journalArticle.articleId ASC, ");
3588                    query.append("journalArticle.version DESC");
3589                }
3590
3591                Query q = session.createQuery(query.toString());
3592
3593                if (obc == null) {
3594                    list = (List<JournalArticle>)QueryUtil.list(q,
3595                            getDialect(), start, end, false);
3596
3597                    Collections.sort(list);
3598                }
3599                else {
3600                    list = (List<JournalArticle>)QueryUtil.list(q,
3601                            getDialect(), start, end);
3602                }
3603            }
3604            catch (Exception e) {
3605                throw processException(e);
3606            }
3607            finally {
3608                if (list == null) {
3609                    list = new ArrayList<JournalArticle>();
3610                }
3611
3612                cacheResult(list);
3613
3614                FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
3615
3616                closeSession(session);
3617            }
3618        }
3619
3620        return list;
3621    }
3622
3623    public void removeByUuid(String uuid) throws SystemException {
3624        for (JournalArticle journalArticle : findByUuid(uuid)) {
3625            remove(journalArticle);
3626        }
3627    }
3628
3629    public void removeByUUID_G(String uuid, long groupId)
3630        throws NoSuchArticleException, SystemException {
3631        JournalArticle journalArticle = findByUUID_G(uuid, groupId);
3632
3633        remove(journalArticle);
3634    }
3635
3636    public void removeByGroupId(long groupId) throws SystemException {
3637        for (JournalArticle journalArticle : findByGroupId(groupId)) {
3638            remove(journalArticle);
3639        }
3640    }
3641
3642    public void removeByCompanyId(long companyId) throws SystemException {
3643        for (JournalArticle journalArticle : findByCompanyId(companyId)) {
3644            remove(journalArticle);
3645        }
3646    }
3647
3648    public void removeBySmallImageId(long smallImageId)
3649        throws SystemException {
3650        for (JournalArticle journalArticle : findBySmallImageId(smallImageId)) {
3651            remove(journalArticle);
3652        }
3653    }
3654
3655    public void removeByR_A(long resourcePrimKey, boolean approved)
3656        throws SystemException {
3657        for (JournalArticle journalArticle : findByR_A(resourcePrimKey, approved)) {
3658            remove(journalArticle);
3659        }
3660    }
3661
3662    public void removeByG_A(long groupId, String articleId)
3663        throws SystemException {
3664        for (JournalArticle journalArticle : findByG_A(groupId, articleId)) {
3665            remove(journalArticle);
3666        }
3667    }
3668
3669    public void removeByG_S(long groupId, String structureId)
3670        throws SystemException {
3671        for (JournalArticle journalArticle : findByG_S(groupId, structureId)) {
3672            remove(journalArticle);
3673        }
3674    }
3675
3676    public void removeByG_T(long groupId, String templateId)
3677        throws SystemException {
3678        for (JournalArticle journalArticle : findByG_T(groupId, templateId)) {
3679            remove(journalArticle);
3680        }
3681    }
3682
3683    public void removeByG_A_V(long groupId, String articleId, double version)
3684        throws NoSuchArticleException, SystemException {
3685        JournalArticle journalArticle = findByG_A_V(groupId, articleId, version);
3686
3687        remove(journalArticle);
3688    }
3689
3690    public void removeByG_A_A(long groupId, String articleId, boolean approved)
3691        throws SystemException {
3692        for (JournalArticle journalArticle : findByG_A_A(groupId, articleId,
3693                approved)) {
3694            remove(journalArticle);
3695        }
3696    }
3697
3698    public void removeAll() throws SystemException {
3699        for (JournalArticle journalArticle : findAll()) {
3700            remove(journalArticle);
3701        }
3702    }
3703
3704    public int countByUuid(String uuid) throws SystemException {
3705        Object[] finderArgs = new Object[] { uuid };
3706
3707        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
3708                finderArgs, this);
3709
3710        if (count == null) {
3711            Session session = null;
3712
3713            try {
3714                session = openSession();
3715
3716                StringBuilder query = new StringBuilder();
3717
3718                query.append("SELECT COUNT(journalArticle) ");
3719                query.append("FROM JournalArticle journalArticle WHERE ");
3720
3721                if (uuid == null) {
3722                    query.append("journalArticle.uuid IS NULL");
3723                }
3724                else {
3725                    query.append("journalArticle.uuid = ?");
3726                }
3727
3728                query.append(" ");
3729
3730                Query q = session.createQuery(query.toString());
3731
3732                QueryPos qPos = QueryPos.getInstance(q);
3733
3734                if (uuid != null) {
3735                    qPos.add(uuid);
3736                }
3737
3738                count = (Long)q.uniqueResult();
3739            }
3740            catch (Exception e) {
3741                throw processException(e);
3742            }
3743            finally {
3744                if (count == null) {
3745                    count = Long.valueOf(0);
3746                }
3747
3748                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
3749                    finderArgs, count);
3750
3751                closeSession(session);
3752            }
3753        }
3754
3755        return count.intValue();
3756    }
3757
3758    public int countByUUID_G(String uuid, long groupId)
3759        throws SystemException {
3760        Object[] finderArgs = new Object[] { uuid, new Long(groupId) };
3761
3762        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
3763                finderArgs, this);
3764
3765        if (count == null) {
3766            Session session = null;
3767
3768            try {
3769                session = openSession();
3770
3771                StringBuilder query = new StringBuilder();
3772
3773                query.append("SELECT COUNT(journalArticle) ");
3774                query.append("FROM JournalArticle journalArticle WHERE ");
3775
3776                if (uuid == null) {
3777                    query.append("journalArticle.uuid IS NULL");
3778                }
3779                else {
3780                    query.append("journalArticle.uuid = ?");
3781                }
3782
3783                query.append(" AND ");
3784
3785                query.append("journalArticle.groupId = ?");
3786
3787                query.append(" ");
3788
3789                Query q = session.createQuery(query.toString());
3790
3791                QueryPos qPos = QueryPos.getInstance(q);
3792
3793                if (uuid != null) {
3794                    qPos.add(uuid);
3795                }
3796
3797                qPos.add(groupId);
3798
3799                count = (Long)q.uniqueResult();
3800            }
3801            catch (Exception e) {
3802                throw processException(e);
3803            }
3804            finally {
3805                if (count == null) {
3806                    count = Long.valueOf(0);
3807                }
3808
3809                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
3810                    finderArgs, count);
3811
3812                closeSession(session);
3813            }
3814        }
3815
3816        return count.intValue();
3817    }
3818
3819    public int countByGroupId(long groupId) throws SystemException {
3820        Object[] finderArgs = new Object[] { new Long(groupId) };
3821
3822        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
3823                finderArgs, this);
3824
3825        if (count == null) {
3826            Session session = null;
3827
3828            try {
3829                session = openSession();
3830
3831                StringBuilder query = new StringBuilder();
3832
3833                query.append("SELECT COUNT(journalArticle) ");
3834                query.append("FROM JournalArticle journalArticle WHERE ");
3835
3836                query.append("journalArticle.groupId = ?");
3837
3838                query.append(" ");
3839
3840                Query q = session.createQuery(query.toString());
3841
3842                QueryPos qPos = QueryPos.getInstance(q);
3843
3844                qPos.add(groupId);
3845
3846                count = (Long)q.uniqueResult();
3847            }
3848            catch (Exception e) {
3849                throw processException(e);
3850            }
3851            finally {
3852                if (count == null) {
3853                    count = Long.valueOf(0);
3854                }
3855
3856                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
3857                    finderArgs, count);
3858
3859                closeSession(session);
3860            }
3861        }
3862
3863        return count.intValue();
3864    }
3865
3866    public int countByCompanyId(long companyId) throws SystemException {
3867        Object[] finderArgs = new Object[] { new Long(companyId) };
3868
3869        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
3870                finderArgs, this);
3871
3872        if (count == null) {
3873            Session session = null;
3874
3875            try {
3876                session = openSession();
3877
3878                StringBuilder query = new StringBuilder();
3879
3880                query.append("SELECT COUNT(journalArticle) ");
3881                query.append("FROM JournalArticle journalArticle WHERE ");
3882
3883                query.append("journalArticle.companyId = ?");
3884
3885                query.append(" ");
3886
3887                Query q = session.createQuery(query.toString());
3888
3889                QueryPos qPos = QueryPos.getInstance(q);
3890
3891                qPos.add(companyId);
3892
3893                count = (Long)q.uniqueResult();
3894            }
3895            catch (Exception e) {
3896                throw processException(e);
3897            }
3898            finally {
3899                if (count == null) {
3900                    count = Long.valueOf(0);
3901                }
3902
3903                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
3904                    finderArgs, count);
3905
3906                closeSession(session);
3907            }
3908        }
3909
3910        return count.intValue();
3911    }
3912
3913    public int countBySmallImageId(long smallImageId) throws SystemException {
3914        Object[] finderArgs = new Object[] { new Long(smallImageId) };
3915
3916        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_SMALLIMAGEID,
3917                finderArgs, this);
3918
3919        if (count == null) {
3920            Session session = null;
3921
3922            try {
3923                session = openSession();
3924
3925                StringBuilder query = new StringBuilder();
3926
3927                query.append("SELECT COUNT(journalArticle) ");
3928                query.append("FROM JournalArticle journalArticle WHERE ");
3929
3930                query.append("journalArticle.smallImageId = ?");
3931
3932                query.append(" ");
3933
3934                Query q = session.createQuery(query.toString());
3935
3936                QueryPos qPos = QueryPos.getInstance(q);
3937
3938                qPos.add(smallImageId);
3939
3940                count = (Long)q.uniqueResult();
3941            }
3942            catch (Exception e) {
3943                throw processException(e);
3944            }
3945            finally {
3946                if (count == null) {
3947                    count = Long.valueOf(0);
3948                }
3949
3950                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_SMALLIMAGEID,
3951                    finderArgs, count);
3952
3953                closeSession(session);
3954            }
3955        }
3956
3957        return count.intValue();
3958    }
3959
3960    public int countByR_A(long resourcePrimKey, boolean approved)
3961        throws SystemException {
3962        Object[] finderArgs = new Object[] {
3963                new Long(resourcePrimKey), Boolean.valueOf(approved)
3964            };
3965
3966        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_R_A,
3967                finderArgs, this);
3968
3969        if (count == null) {
3970            Session session = null;
3971
3972            try {
3973                session = openSession();
3974
3975                StringBuilder query = new StringBuilder();
3976
3977                query.append("SELECT COUNT(journalArticle) ");
3978                query.append("FROM JournalArticle journalArticle WHERE ");
3979
3980                query.append("journalArticle.resourcePrimKey = ?");
3981
3982                query.append(" AND ");
3983
3984                query.append("journalArticle.approved = ?");
3985
3986                query.append(" ");
3987
3988                Query q = session.createQuery(query.toString());
3989
3990                QueryPos qPos = QueryPos.getInstance(q);
3991
3992                qPos.add(resourcePrimKey);
3993
3994                qPos.add(approved);
3995
3996                count = (Long)q.uniqueResult();
3997            }
3998            catch (Exception e) {
3999                throw processException(e);
4000            }
4001            finally {
4002                if (count == null) {
4003                    count = Long.valueOf(0);
4004                }
4005
4006                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_R_A, finderArgs,
4007                    count);
4008
4009                closeSession(session);
4010            }
4011        }
4012
4013        return count.intValue();
4014    }
4015
4016    public int countByG_A(long groupId, String articleId)
4017        throws SystemException {
4018        Object[] finderArgs = new Object[] { new Long(groupId), articleId };
4019
4020        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_A,
4021                finderArgs, this);
4022
4023        if (count == null) {
4024            Session session = null;
4025
4026            try {
4027                session = openSession();
4028
4029                StringBuilder query = new StringBuilder();
4030
4031                query.append("SELECT COUNT(journalArticle) ");
4032                query.append("FROM JournalArticle journalArticle WHERE ");
4033
4034                query.append("journalArticle.groupId = ?");
4035
4036                query.append(" AND ");
4037
4038                if (articleId == null) {
4039                    query.append("journalArticle.articleId IS NULL");
4040                }
4041                else {
4042                    query.append("journalArticle.articleId = ?");
4043                }
4044
4045                query.append(" ");
4046
4047                Query q = session.createQuery(query.toString());
4048
4049                QueryPos qPos = QueryPos.getInstance(q);
4050
4051                qPos.add(groupId);
4052
4053                if (articleId != null) {
4054                    qPos.add(articleId);
4055                }
4056
4057                count = (Long)q.uniqueResult();
4058            }
4059            catch (Exception e) {
4060                throw processException(e);
4061            }
4062            finally {
4063                if (count == null) {
4064                    count = Long.valueOf(0);
4065                }
4066
4067                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_A, finderArgs,
4068                    count);
4069
4070                closeSession(session);
4071            }
4072        }
4073
4074        return count.intValue();
4075    }
4076
4077    public int countByG_S(long groupId, String structureId)
4078        throws SystemException {
4079        Object[] finderArgs = new Object[] { new Long(groupId), structureId };
4080
4081        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_S,
4082                finderArgs, this);
4083
4084        if (count == null) {
4085            Session session = null;
4086
4087            try {
4088                session = openSession();
4089
4090                StringBuilder query = new StringBuilder();
4091
4092                query.append("SELECT COUNT(journalArticle) ");
4093                query.append("FROM JournalArticle journalArticle WHERE ");
4094
4095                query.append("journalArticle.groupId = ?");
4096
4097                query.append(" AND ");
4098
4099                if (structureId == null) {
4100                    query.append("journalArticle.structureId IS NULL");
4101                }
4102                else {
4103                    query.append("journalArticle.structureId = ?");
4104                }
4105
4106                query.append(" ");
4107
4108                Query q = session.createQuery(query.toString());
4109
4110                QueryPos qPos = QueryPos.getInstance(q);
4111
4112                qPos.add(groupId);
4113
4114                if (structureId != null) {
4115                    qPos.add(structureId);
4116                }
4117
4118                count = (Long)q.uniqueResult();
4119            }
4120            catch (Exception e) {
4121                throw processException(e);
4122            }
4123            finally {
4124                if (count == null) {
4125                    count = Long.valueOf(0);
4126                }
4127
4128                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_S, finderArgs,
4129                    count);
4130
4131                closeSession(session);
4132            }
4133        }
4134
4135        return count.intValue();
4136    }
4137
4138    public int countByG_T(long groupId, String templateId)
4139        throws SystemException {
4140        Object[] finderArgs = new Object[] { new Long(groupId), templateId };
4141
4142        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_T,
4143                finderArgs, this);
4144
4145        if (count == null) {
4146            Session session = null;
4147
4148            try {
4149                session = openSession();
4150
4151                StringBuilder query = new StringBuilder();
4152
4153                query.append("SELECT COUNT(journalArticle) ");
4154                query.append("FROM JournalArticle journalArticle WHERE ");
4155
4156                query.append("journalArticle.groupId = ?");
4157
4158                query.append(" AND ");
4159
4160                if (templateId == null) {
4161                    query.append("journalArticle.templateId IS NULL");
4162                }
4163                else {
4164                    query.append("journalArticle.templateId = ?");
4165                }
4166
4167                query.append(" ");
4168
4169                Query q = session.createQuery(query.toString());
4170
4171                QueryPos qPos = QueryPos.getInstance(q);
4172
4173                qPos.add(groupId);
4174
4175                if (templateId != null) {
4176                    qPos.add(templateId);
4177                }
4178
4179                count = (Long)q.uniqueResult();
4180            }
4181            catch (Exception e) {
4182                throw processException(e);
4183            }
4184            finally {
4185                if (count == null) {
4186                    count = Long.valueOf(0);
4187                }
4188
4189                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_T, finderArgs,
4190                    count);
4191
4192                closeSession(session);
4193            }
4194        }
4195
4196        return count.intValue();
4197    }
4198
4199    public int countByG_A_V(long groupId, String articleId, double version)
4200        throws SystemException {
4201        Object[] finderArgs = new Object[] {
4202                new Long(groupId),
4203                
4204                articleId, new Double(version)
4205            };
4206
4207        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_A_V,
4208                finderArgs, this);
4209
4210        if (count == null) {
4211            Session session = null;
4212
4213            try {
4214                session = openSession();
4215
4216                StringBuilder query = new StringBuilder();
4217
4218                query.append("SELECT COUNT(journalArticle) ");
4219                query.append("FROM JournalArticle journalArticle WHERE ");
4220
4221                query.append("journalArticle.groupId = ?");
4222
4223                query.append(" AND ");
4224
4225                if (articleId == null) {
4226                    query.append("journalArticle.articleId IS NULL");
4227                }
4228                else {
4229                    query.append("journalArticle.articleId = ?");
4230                }
4231
4232                query.append(" AND ");
4233
4234                query.append("journalArticle.version = ?");
4235
4236                query.append(" ");
4237
4238                Query q = session.createQuery(query.toString());
4239
4240                QueryPos qPos = QueryPos.getInstance(q);
4241
4242                qPos.add(groupId);
4243
4244                if (articleId != null) {
4245                    qPos.add(articleId);
4246                }
4247
4248                qPos.add(version);
4249
4250                count = (Long)q.uniqueResult();
4251            }
4252            catch (Exception e) {
4253                throw processException(e);
4254            }
4255            finally {
4256                if (count == null) {
4257                    count = Long.valueOf(0);
4258                }
4259
4260                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_A_V,
4261                    finderArgs, count);
4262
4263                closeSession(session);
4264            }
4265        }
4266
4267        return count.intValue();
4268    }
4269
4270    public int countByG_A_A(long groupId, String articleId, boolean approved)
4271        throws SystemException {
4272        Object[] finderArgs = new Object[] {
4273                new Long(groupId),
4274                
4275                articleId, Boolean.valueOf(approved)
4276            };
4277
4278        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_A_A,
4279                finderArgs, this);
4280
4281        if (count == null) {
4282            Session session = null;
4283
4284            try {
4285                session = openSession();
4286
4287                StringBuilder query = new StringBuilder();
4288
4289                query.append("SELECT COUNT(journalArticle) ");
4290                query.append("FROM JournalArticle journalArticle WHERE ");
4291
4292                query.append("journalArticle.groupId = ?");
4293
4294                query.append(" AND ");
4295
4296                if (articleId == null) {
4297                    query.append("journalArticle.articleId IS NULL");
4298                }
4299                else {
4300                    query.append("journalArticle.articleId = ?");
4301                }
4302
4303                query.append(" AND ");
4304
4305                query.append("journalArticle.approved = ?");
4306
4307                query.append(" ");
4308
4309                Query q = session.createQuery(query.toString());
4310
4311                QueryPos qPos = QueryPos.getInstance(q);
4312
4313                qPos.add(groupId);
4314
4315                if (articleId != null) {
4316                    qPos.add(articleId);
4317                }
4318
4319                qPos.add(approved);
4320
4321                count = (Long)q.uniqueResult();
4322            }
4323            catch (Exception e) {
4324                throw processException(e);
4325            }
4326            finally {
4327                if (count == null) {
4328                    count = Long.valueOf(0);
4329                }
4330
4331                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_A_A,
4332                    finderArgs, count);
4333
4334                closeSession(session);
4335            }
4336        }
4337
4338        return count.intValue();
4339    }
4340
4341    public int countAll() throws SystemException {
4342        Object[] finderArgs = new Object[0];
4343
4344        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
4345                finderArgs, this);
4346
4347        if (count == null) {
4348            Session session = null;
4349
4350            try {
4351                session = openSession();
4352
4353                Query q = session.createQuery(
4354                        "SELECT COUNT(journalArticle) FROM JournalArticle journalArticle");
4355
4356                count = (Long)q.uniqueResult();
4357            }
4358            catch (Exception e) {
4359                throw processException(e);
4360            }
4361            finally {
4362                if (count == null) {
4363                    count = Long.valueOf(0);
4364                }
4365
4366                FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
4367                    count);
4368
4369                closeSession(session);
4370            }
4371        }
4372
4373        return count.intValue();
4374    }
4375
4376    public void afterPropertiesSet() {
4377        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
4378                    com.liferay.portal.util.PropsUtil.get(
4379                        "value.object.listener.com.liferay.portlet.journal.model.JournalArticle")));
4380
4381        if (listenerClassNames.length > 0) {
4382            try {
4383                List<ModelListener<JournalArticle>> listenersList = new ArrayList<ModelListener<JournalArticle>>();
4384
4385                for (String listenerClassName : listenerClassNames) {
4386                    listenersList.add((ModelListener<JournalArticle>)Class.forName(
4387                            listenerClassName).newInstance());
4388                }
4389
4390                listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
4391            }
4392            catch (Exception e) {
4393                _log.error(e);
4394            }
4395        }
4396    }
4397
4398    @BeanReference(name = "com.liferay.portlet.journal.service.persistence.JournalArticlePersistence.impl")
4399    protected com.liferay.portlet.journal.service.persistence.JournalArticlePersistence journalArticlePersistence;
4400    @BeanReference(name = "com.liferay.portlet.journal.service.persistence.JournalArticleImagePersistence.impl")
4401    protected com.liferay.portlet.journal.service.persistence.JournalArticleImagePersistence journalArticleImagePersistence;
4402    @BeanReference(name = "com.liferay.portlet.journal.service.persistence.JournalArticleResourcePersistence.impl")
4403    protected com.liferay.portlet.journal.service.persistence.JournalArticleResourcePersistence journalArticleResourcePersistence;
4404    @BeanReference(name = "com.liferay.portlet.journal.service.persistence.JournalContentSearchPersistence.impl")
4405    protected com.liferay.portlet.journal.service.persistence.JournalContentSearchPersistence journalContentSearchPersistence;
4406    @BeanReference(name = "com.liferay.portlet.journal.service.persistence.JournalFeedPersistence.impl")
4407    protected com.liferay.portlet.journal.service.persistence.JournalFeedPersistence journalFeedPersistence;
4408    @BeanReference(name = "com.liferay.portlet.journal.service.persistence.JournalStructurePersistence.impl")
4409    protected com.liferay.portlet.journal.service.persistence.JournalStructurePersistence journalStructurePersistence;
4410    @BeanReference(name = "com.liferay.portlet.journal.service.persistence.JournalTemplatePersistence.impl")
4411    protected com.liferay.portlet.journal.service.persistence.JournalTemplatePersistence journalTemplatePersistence;
4412    @BeanReference(name = "com.liferay.portal.service.persistence.CompanyPersistence.impl")
4413    protected com.liferay.portal.service.persistence.CompanyPersistence companyPersistence;
4414    @BeanReference(name = "com.liferay.portal.service.persistence.ImagePersistence.impl")
4415    protected com.liferay.portal.service.persistence.ImagePersistence imagePersistence;
4416    @BeanReference(name = "com.liferay.portal.service.persistence.PortletPreferencesPersistence.impl")
4417    protected com.liferay.portal.service.persistence.PortletPreferencesPersistence portletPreferencesPersistence;
4418    @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence.impl")
4419    protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
4420    @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence.impl")
4421    protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
4422    @BeanReference(name = "com.liferay.portlet.messageboards.service.persistence.MBMessagePersistence.impl")
4423    protected com.liferay.portlet.messageboards.service.persistence.MBMessagePersistence mbMessagePersistence;
4424    @BeanReference(name = "com.liferay.portlet.ratings.service.persistence.RatingsStatsPersistence.impl")
4425    protected com.liferay.portlet.ratings.service.persistence.RatingsStatsPersistence ratingsStatsPersistence;
4426    @BeanReference(name = "com.liferay.portlet.tags.service.persistence.TagsAssetPersistence.impl")
4427    protected com.liferay.portlet.tags.service.persistence.TagsAssetPersistence tagsAssetPersistence;
4428    @BeanReference(name = "com.liferay.portlet.tags.service.persistence.TagsEntryPersistence.impl")
4429    protected com.liferay.portlet.tags.service.persistence.TagsEntryPersistence tagsEntryPersistence;
4430    private static Log _log = LogFactoryUtil.getLog(JournalArticlePersistenceImpl.class);
4431}