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