001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.journal.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.annotation.BeanReference;
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.Session;
027    import com.liferay.portal.kernel.exception.SystemException;
028    import com.liferay.portal.kernel.log.Log;
029    import com.liferay.portal.kernel.log.LogFactoryUtil;
030    import com.liferay.portal.kernel.util.GetterUtil;
031    import com.liferay.portal.kernel.util.InstanceFactory;
032    import com.liferay.portal.kernel.util.OrderByComparator;
033    import com.liferay.portal.kernel.util.StringBundler;
034    import com.liferay.portal.kernel.util.StringPool;
035    import com.liferay.portal.kernel.util.StringUtil;
036    import com.liferay.portal.kernel.util.Validator;
037    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
038    import com.liferay.portal.model.ModelListener;
039    import com.liferay.portal.service.persistence.BatchSessionUtil;
040    import com.liferay.portal.service.persistence.ResourcePersistence;
041    import com.liferay.portal.service.persistence.UserPersistence;
042    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
043    
044    import com.liferay.portlet.journal.NoSuchArticleResourceException;
045    import com.liferay.portlet.journal.model.JournalArticleResource;
046    import com.liferay.portlet.journal.model.impl.JournalArticleResourceImpl;
047    import com.liferay.portlet.journal.model.impl.JournalArticleResourceModelImpl;
048    
049    import java.io.Serializable;
050    
051    import java.util.ArrayList;
052    import java.util.Collections;
053    import java.util.List;
054    
055    /**
056     * The persistence implementation for the journal article resource service.
057     *
058     * <p>
059     * Never modify or reference this class directly. Always use {@link JournalArticleResourceUtil} to access the journal article resource persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
060     * </p>
061     *
062     * <p>
063     * Caching information and settings can be found in <code>portal.properties</code>
064     * </p>
065     *
066     * @author Brian Wing Shun Chan
067     * @see JournalArticleResourcePersistence
068     * @see JournalArticleResourceUtil
069     * @generated
070     */
071    public class JournalArticleResourcePersistenceImpl extends BasePersistenceImpl<JournalArticleResource>
072            implements JournalArticleResourcePersistence {
073            public static final String FINDER_CLASS_NAME_ENTITY = JournalArticleResourceImpl.class.getName();
074            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
075                    ".List";
076            public static final FinderPath FINDER_PATH_FIND_BY_UUID = new FinderPath(JournalArticleResourceModelImpl.ENTITY_CACHE_ENABLED,
077                            JournalArticleResourceModelImpl.FINDER_CACHE_ENABLED,
078                            FINDER_CLASS_NAME_LIST, "findByUuid",
079                            new String[] {
080                                    String.class.getName(),
081                                    
082                            "java.lang.Integer", "java.lang.Integer",
083                                    "com.liferay.portal.kernel.util.OrderByComparator"
084                            });
085            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(JournalArticleResourceModelImpl.ENTITY_CACHE_ENABLED,
086                            JournalArticleResourceModelImpl.FINDER_CACHE_ENABLED,
087                            FINDER_CLASS_NAME_LIST, "countByUuid",
088                            new String[] { String.class.getName() });
089            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(JournalArticleResourceModelImpl.ENTITY_CACHE_ENABLED,
090                            JournalArticleResourceModelImpl.FINDER_CACHE_ENABLED,
091                            FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
092                            new String[] { String.class.getName(), Long.class.getName() });
093            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(JournalArticleResourceModelImpl.ENTITY_CACHE_ENABLED,
094                            JournalArticleResourceModelImpl.FINDER_CACHE_ENABLED,
095                            FINDER_CLASS_NAME_LIST, "countByUUID_G",
096                            new String[] { String.class.getName(), Long.class.getName() });
097            public static final FinderPath FINDER_PATH_FIND_BY_GROUPID = new FinderPath(JournalArticleResourceModelImpl.ENTITY_CACHE_ENABLED,
098                            JournalArticleResourceModelImpl.FINDER_CACHE_ENABLED,
099                            FINDER_CLASS_NAME_LIST, "findByGroupId",
100                            new String[] {
101                                    Long.class.getName(),
102                                    
103                            "java.lang.Integer", "java.lang.Integer",
104                                    "com.liferay.portal.kernel.util.OrderByComparator"
105                            });
106            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(JournalArticleResourceModelImpl.ENTITY_CACHE_ENABLED,
107                            JournalArticleResourceModelImpl.FINDER_CACHE_ENABLED,
108                            FINDER_CLASS_NAME_LIST, "countByGroupId",
109                            new String[] { Long.class.getName() });
110            public static final FinderPath FINDER_PATH_FETCH_BY_G_A = new FinderPath(JournalArticleResourceModelImpl.ENTITY_CACHE_ENABLED,
111                            JournalArticleResourceModelImpl.FINDER_CACHE_ENABLED,
112                            FINDER_CLASS_NAME_ENTITY, "fetchByG_A",
113                            new String[] { Long.class.getName(), String.class.getName() });
114            public static final FinderPath FINDER_PATH_COUNT_BY_G_A = new FinderPath(JournalArticleResourceModelImpl.ENTITY_CACHE_ENABLED,
115                            JournalArticleResourceModelImpl.FINDER_CACHE_ENABLED,
116                            FINDER_CLASS_NAME_LIST, "countByG_A",
117                            new String[] { Long.class.getName(), String.class.getName() });
118            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(JournalArticleResourceModelImpl.ENTITY_CACHE_ENABLED,
119                            JournalArticleResourceModelImpl.FINDER_CACHE_ENABLED,
120                            FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
121            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(JournalArticleResourceModelImpl.ENTITY_CACHE_ENABLED,
122                            JournalArticleResourceModelImpl.FINDER_CACHE_ENABLED,
123                            FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
124    
125            /**
126             * Caches the journal article resource in the entity cache if it is enabled.
127             *
128             * @param journalArticleResource the journal article resource to cache
129             */
130            public void cacheResult(JournalArticleResource journalArticleResource) {
131                    EntityCacheUtil.putResult(JournalArticleResourceModelImpl.ENTITY_CACHE_ENABLED,
132                            JournalArticleResourceImpl.class,
133                            journalArticleResource.getPrimaryKey(), journalArticleResource);
134    
135                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
136                            new Object[] {
137                                    journalArticleResource.getUuid(),
138                                    new Long(journalArticleResource.getGroupId())
139                            }, journalArticleResource);
140    
141                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_A,
142                            new Object[] {
143                                    new Long(journalArticleResource.getGroupId()),
144                                    
145                            journalArticleResource.getArticleId()
146                            }, journalArticleResource);
147            }
148    
149            /**
150             * Caches the journal article resources in the entity cache if it is enabled.
151             *
152             * @param journalArticleResources the journal article resources to cache
153             */
154            public void cacheResult(
155                    List<JournalArticleResource> journalArticleResources) {
156                    for (JournalArticleResource journalArticleResource : journalArticleResources) {
157                            if (EntityCacheUtil.getResult(
158                                                    JournalArticleResourceModelImpl.ENTITY_CACHE_ENABLED,
159                                                    JournalArticleResourceImpl.class,
160                                                    journalArticleResource.getPrimaryKey(), this) == null) {
161                                    cacheResult(journalArticleResource);
162                            }
163                    }
164            }
165    
166            /**
167             * Clears the cache for all journal article resources.
168             *
169             * <p>
170             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
171             * </p>
172             */
173            public void clearCache() {
174                    CacheRegistryUtil.clear(JournalArticleResourceImpl.class.getName());
175                    EntityCacheUtil.clearCache(JournalArticleResourceImpl.class.getName());
176                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
177                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
178            }
179    
180            /**
181             * Clears the cache for the journal article resource.
182             *
183             * <p>
184             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
185             * </p>
186             */
187            public void clearCache(JournalArticleResource journalArticleResource) {
188                    EntityCacheUtil.removeResult(JournalArticleResourceModelImpl.ENTITY_CACHE_ENABLED,
189                            JournalArticleResourceImpl.class,
190                            journalArticleResource.getPrimaryKey());
191    
192                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
193                            new Object[] {
194                                    journalArticleResource.getUuid(),
195                                    new Long(journalArticleResource.getGroupId())
196                            });
197    
198                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_A,
199                            new Object[] {
200                                    new Long(journalArticleResource.getGroupId()),
201                                    
202                            journalArticleResource.getArticleId()
203                            });
204            }
205    
206            /**
207             * Creates a new journal article resource with the primary key. Does not add the journal article resource to the database.
208             *
209             * @param resourcePrimKey the primary key for the new journal article resource
210             * @return the new journal article resource
211             */
212            public JournalArticleResource create(long resourcePrimKey) {
213                    JournalArticleResource journalArticleResource = new JournalArticleResourceImpl();
214    
215                    journalArticleResource.setNew(true);
216                    journalArticleResource.setPrimaryKey(resourcePrimKey);
217    
218                    String uuid = PortalUUIDUtil.generate();
219    
220                    journalArticleResource.setUuid(uuid);
221    
222                    return journalArticleResource;
223            }
224    
225            /**
226             * Removes the journal article resource with the primary key from the database. Also notifies the appropriate model listeners.
227             *
228             * @param primaryKey the primary key of the journal article resource to remove
229             * @return the journal article resource that was removed
230             * @throws com.liferay.portal.NoSuchModelException if a journal article resource with the primary key could not be found
231             * @throws SystemException if a system exception occurred
232             */
233            public JournalArticleResource remove(Serializable primaryKey)
234                    throws NoSuchModelException, SystemException {
235                    return remove(((Long)primaryKey).longValue());
236            }
237    
238            /**
239             * Removes the journal article resource with the primary key from the database. Also notifies the appropriate model listeners.
240             *
241             * @param resourcePrimKey the primary key of the journal article resource to remove
242             * @return the journal article resource that was removed
243             * @throws com.liferay.portlet.journal.NoSuchArticleResourceException if a journal article resource with the primary key could not be found
244             * @throws SystemException if a system exception occurred
245             */
246            public JournalArticleResource remove(long resourcePrimKey)
247                    throws NoSuchArticleResourceException, SystemException {
248                    Session session = null;
249    
250                    try {
251                            session = openSession();
252    
253                            JournalArticleResource journalArticleResource = (JournalArticleResource)session.get(JournalArticleResourceImpl.class,
254                                            new Long(resourcePrimKey));
255    
256                            if (journalArticleResource == null) {
257                                    if (_log.isWarnEnabled()) {
258                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
259                                                    resourcePrimKey);
260                                    }
261    
262                                    throw new NoSuchArticleResourceException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
263                                            resourcePrimKey);
264                            }
265    
266                            return remove(journalArticleResource);
267                    }
268                    catch (NoSuchArticleResourceException nsee) {
269                            throw nsee;
270                    }
271                    catch (Exception e) {
272                            throw processException(e);
273                    }
274                    finally {
275                            closeSession(session);
276                    }
277            }
278    
279            protected JournalArticleResource removeImpl(
280                    JournalArticleResource journalArticleResource)
281                    throws SystemException {
282                    journalArticleResource = toUnwrappedModel(journalArticleResource);
283    
284                    Session session = null;
285    
286                    try {
287                            session = openSession();
288    
289                            BatchSessionUtil.delete(session, journalArticleResource);
290                    }
291                    catch (Exception e) {
292                            throw processException(e);
293                    }
294                    finally {
295                            closeSession(session);
296                    }
297    
298                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
299    
300                    JournalArticleResourceModelImpl journalArticleResourceModelImpl = (JournalArticleResourceModelImpl)journalArticleResource;
301    
302                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
303                            new Object[] {
304                                    journalArticleResourceModelImpl.getUuid(),
305                                    new Long(journalArticleResourceModelImpl.getGroupId())
306                            });
307    
308                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_A,
309                            new Object[] {
310                                    new Long(journalArticleResourceModelImpl.getGroupId()),
311                                    
312                            journalArticleResourceModelImpl.getArticleId()
313                            });
314    
315                    EntityCacheUtil.removeResult(JournalArticleResourceModelImpl.ENTITY_CACHE_ENABLED,
316                            JournalArticleResourceImpl.class,
317                            journalArticleResource.getPrimaryKey());
318    
319                    return journalArticleResource;
320            }
321    
322            public JournalArticleResource updateImpl(
323                    com.liferay.portlet.journal.model.JournalArticleResource journalArticleResource,
324                    boolean merge) throws SystemException {
325                    journalArticleResource = toUnwrappedModel(journalArticleResource);
326    
327                    boolean isNew = journalArticleResource.isNew();
328    
329                    JournalArticleResourceModelImpl journalArticleResourceModelImpl = (JournalArticleResourceModelImpl)journalArticleResource;
330    
331                    if (Validator.isNull(journalArticleResource.getUuid())) {
332                            String uuid = PortalUUIDUtil.generate();
333    
334                            journalArticleResource.setUuid(uuid);
335                    }
336    
337                    Session session = null;
338    
339                    try {
340                            session = openSession();
341    
342                            BatchSessionUtil.update(session, journalArticleResource, merge);
343    
344                            journalArticleResource.setNew(false);
345                    }
346                    catch (Exception e) {
347                            throw processException(e);
348                    }
349                    finally {
350                            closeSession(session);
351                    }
352    
353                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
354    
355                    EntityCacheUtil.putResult(JournalArticleResourceModelImpl.ENTITY_CACHE_ENABLED,
356                            JournalArticleResourceImpl.class,
357                            journalArticleResource.getPrimaryKey(), journalArticleResource);
358    
359                    if (!isNew &&
360                                    (!Validator.equals(journalArticleResource.getUuid(),
361                                            journalArticleResourceModelImpl.getOriginalUuid()) ||
362                                    (journalArticleResource.getGroupId() != journalArticleResourceModelImpl.getOriginalGroupId()))) {
363                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
364                                    new Object[] {
365                                            journalArticleResourceModelImpl.getOriginalUuid(),
366                                            new Long(journalArticleResourceModelImpl.getOriginalGroupId())
367                                    });
368                    }
369    
370                    if (isNew ||
371                                    (!Validator.equals(journalArticleResource.getUuid(),
372                                            journalArticleResourceModelImpl.getOriginalUuid()) ||
373                                    (journalArticleResource.getGroupId() != journalArticleResourceModelImpl.getOriginalGroupId()))) {
374                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
375                                    new Object[] {
376                                            journalArticleResource.getUuid(),
377                                            new Long(journalArticleResource.getGroupId())
378                                    }, journalArticleResource);
379                    }
380    
381                    if (!isNew &&
382                                    ((journalArticleResource.getGroupId() != journalArticleResourceModelImpl.getOriginalGroupId()) ||
383                                    !Validator.equals(journalArticleResource.getArticleId(),
384                                            journalArticleResourceModelImpl.getOriginalArticleId()))) {
385                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_A,
386                                    new Object[] {
387                                            new Long(journalArticleResourceModelImpl.getOriginalGroupId()),
388                                            
389                                    journalArticleResourceModelImpl.getOriginalArticleId()
390                                    });
391                    }
392    
393                    if (isNew ||
394                                    ((journalArticleResource.getGroupId() != journalArticleResourceModelImpl.getOriginalGroupId()) ||
395                                    !Validator.equals(journalArticleResource.getArticleId(),
396                                            journalArticleResourceModelImpl.getOriginalArticleId()))) {
397                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_A,
398                                    new Object[] {
399                                            new Long(journalArticleResource.getGroupId()),
400                                            
401                                    journalArticleResource.getArticleId()
402                                    }, journalArticleResource);
403                    }
404    
405                    return journalArticleResource;
406            }
407    
408            protected JournalArticleResource toUnwrappedModel(
409                    JournalArticleResource journalArticleResource) {
410                    if (journalArticleResource instanceof JournalArticleResourceImpl) {
411                            return journalArticleResource;
412                    }
413    
414                    JournalArticleResourceImpl journalArticleResourceImpl = new JournalArticleResourceImpl();
415    
416                    journalArticleResourceImpl.setNew(journalArticleResource.isNew());
417                    journalArticleResourceImpl.setPrimaryKey(journalArticleResource.getPrimaryKey());
418    
419                    journalArticleResourceImpl.setUuid(journalArticleResource.getUuid());
420                    journalArticleResourceImpl.setResourcePrimKey(journalArticleResource.getResourcePrimKey());
421                    journalArticleResourceImpl.setGroupId(journalArticleResource.getGroupId());
422                    journalArticleResourceImpl.setArticleId(journalArticleResource.getArticleId());
423    
424                    return journalArticleResourceImpl;
425            }
426    
427            /**
428             * Finds the journal article resource with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
429             *
430             * @param primaryKey the primary key of the journal article resource to find
431             * @return the journal article resource
432             * @throws com.liferay.portal.NoSuchModelException if a journal article resource with the primary key could not be found
433             * @throws SystemException if a system exception occurred
434             */
435            public JournalArticleResource findByPrimaryKey(Serializable primaryKey)
436                    throws NoSuchModelException, SystemException {
437                    return findByPrimaryKey(((Long)primaryKey).longValue());
438            }
439    
440            /**
441             * Finds the journal article resource with the primary key or throws a {@link com.liferay.portlet.journal.NoSuchArticleResourceException} if it could not be found.
442             *
443             * @param resourcePrimKey the primary key of the journal article resource to find
444             * @return the journal article resource
445             * @throws com.liferay.portlet.journal.NoSuchArticleResourceException if a journal article resource with the primary key could not be found
446             * @throws SystemException if a system exception occurred
447             */
448            public JournalArticleResource findByPrimaryKey(long resourcePrimKey)
449                    throws NoSuchArticleResourceException, SystemException {
450                    JournalArticleResource journalArticleResource = fetchByPrimaryKey(resourcePrimKey);
451    
452                    if (journalArticleResource == null) {
453                            if (_log.isWarnEnabled()) {
454                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + resourcePrimKey);
455                            }
456    
457                            throw new NoSuchArticleResourceException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
458                                    resourcePrimKey);
459                    }
460    
461                    return journalArticleResource;
462            }
463    
464            /**
465             * Finds the journal article resource with the primary key or returns <code>null</code> if it could not be found.
466             *
467             * @param primaryKey the primary key of the journal article resource to find
468             * @return the journal article resource, or <code>null</code> if a journal article resource with the primary key could not be found
469             * @throws SystemException if a system exception occurred
470             */
471            public JournalArticleResource fetchByPrimaryKey(Serializable primaryKey)
472                    throws SystemException {
473                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
474            }
475    
476            /**
477             * Finds the journal article resource with the primary key or returns <code>null</code> if it could not be found.
478             *
479             * @param resourcePrimKey the primary key of the journal article resource to find
480             * @return the journal article resource, or <code>null</code> if a journal article resource with the primary key could not be found
481             * @throws SystemException if a system exception occurred
482             */
483            public JournalArticleResource fetchByPrimaryKey(long resourcePrimKey)
484                    throws SystemException {
485                    JournalArticleResource journalArticleResource = (JournalArticleResource)EntityCacheUtil.getResult(JournalArticleResourceModelImpl.ENTITY_CACHE_ENABLED,
486                                    JournalArticleResourceImpl.class, resourcePrimKey, this);
487    
488                    if (journalArticleResource == null) {
489                            Session session = null;
490    
491                            try {
492                                    session = openSession();
493    
494                                    journalArticleResource = (JournalArticleResource)session.get(JournalArticleResourceImpl.class,
495                                                    new Long(resourcePrimKey));
496                            }
497                            catch (Exception e) {
498                                    throw processException(e);
499                            }
500                            finally {
501                                    if (journalArticleResource != null) {
502                                            cacheResult(journalArticleResource);
503                                    }
504    
505                                    closeSession(session);
506                            }
507                    }
508    
509                    return journalArticleResource;
510            }
511    
512            /**
513             * Finds all the journal article resources where uuid = &#63;.
514             *
515             * @param uuid the uuid to search with
516             * @return the matching journal article resources
517             * @throws SystemException if a system exception occurred
518             */
519            public List<JournalArticleResource> findByUuid(String uuid)
520                    throws SystemException {
521                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
522            }
523    
524            /**
525             * Finds a range of all the journal article resources where uuid = &#63;.
526             *
527             * <p>
528             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
529             * </p>
530             *
531             * @param uuid the uuid to search with
532             * @param start the lower bound of the range of journal article resources to return
533             * @param end the upper bound of the range of journal article resources to return (not inclusive)
534             * @return the range of matching journal article resources
535             * @throws SystemException if a system exception occurred
536             */
537            public List<JournalArticleResource> findByUuid(String uuid, int start,
538                    int end) throws SystemException {
539                    return findByUuid(uuid, start, end, null);
540            }
541    
542            /**
543             * Finds an ordered range of all the journal article resources where uuid = &#63;.
544             *
545             * <p>
546             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
547             * </p>
548             *
549             * @param uuid the uuid to search with
550             * @param start the lower bound of the range of journal article resources to return
551             * @param end the upper bound of the range of journal article resources to return (not inclusive)
552             * @param orderByComparator the comparator to order the results by
553             * @return the ordered range of matching journal article resources
554             * @throws SystemException if a system exception occurred
555             */
556            public List<JournalArticleResource> findByUuid(String uuid, int start,
557                    int end, OrderByComparator orderByComparator) throws SystemException {
558                    Object[] finderArgs = new Object[] {
559                                    uuid,
560                                    
561                                    String.valueOf(start), String.valueOf(end),
562                                    String.valueOf(orderByComparator)
563                            };
564    
565                    List<JournalArticleResource> list = (List<JournalArticleResource>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_UUID,
566                                    finderArgs, this);
567    
568                    if (list == null) {
569                            StringBundler query = null;
570    
571                            if (orderByComparator != null) {
572                                    query = new StringBundler(3 +
573                                                    (orderByComparator.getOrderByFields().length * 3));
574                            }
575                            else {
576                                    query = new StringBundler(2);
577                            }
578    
579                            query.append(_SQL_SELECT_JOURNALARTICLERESOURCE_WHERE);
580    
581                            if (uuid == null) {
582                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
583                            }
584                            else {
585                                    if (uuid.equals(StringPool.BLANK)) {
586                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
587                                    }
588                                    else {
589                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
590                                    }
591                            }
592    
593                            if (orderByComparator != null) {
594                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
595                                            orderByComparator);
596                            }
597    
598                            String sql = query.toString();
599    
600                            Session session = null;
601    
602                            try {
603                                    session = openSession();
604    
605                                    Query q = session.createQuery(sql);
606    
607                                    QueryPos qPos = QueryPos.getInstance(q);
608    
609                                    if (uuid != null) {
610                                            qPos.add(uuid);
611                                    }
612    
613                                    list = (List<JournalArticleResource>)QueryUtil.list(q,
614                                                    getDialect(), start, end);
615                            }
616                            catch (Exception e) {
617                                    throw processException(e);
618                            }
619                            finally {
620                                    if (list == null) {
621                                            FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_UUID,
622                                                    finderArgs);
623                                    }
624                                    else {
625                                            cacheResult(list);
626    
627                                            FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_UUID,
628                                                    finderArgs, list);
629                                    }
630    
631                                    closeSession(session);
632                            }
633                    }
634    
635                    return list;
636            }
637    
638            /**
639             * Finds the first journal article resource in the ordered set where uuid = &#63;.
640             *
641             * <p>
642             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
643             * </p>
644             *
645             * @param uuid the uuid to search with
646             * @param orderByComparator the comparator to order the set by
647             * @return the first matching journal article resource
648             * @throws com.liferay.portlet.journal.NoSuchArticleResourceException if a matching journal article resource could not be found
649             * @throws SystemException if a system exception occurred
650             */
651            public JournalArticleResource findByUuid_First(String uuid,
652                    OrderByComparator orderByComparator)
653                    throws NoSuchArticleResourceException, SystemException {
654                    List<JournalArticleResource> list = findByUuid(uuid, 0, 1,
655                                    orderByComparator);
656    
657                    if (list.isEmpty()) {
658                            StringBundler msg = new StringBundler(4);
659    
660                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
661    
662                            msg.append("uuid=");
663                            msg.append(uuid);
664    
665                            msg.append(StringPool.CLOSE_CURLY_BRACE);
666    
667                            throw new NoSuchArticleResourceException(msg.toString());
668                    }
669                    else {
670                            return list.get(0);
671                    }
672            }
673    
674            /**
675             * Finds the last journal article resource in the ordered set where uuid = &#63;.
676             *
677             * <p>
678             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
679             * </p>
680             *
681             * @param uuid the uuid to search with
682             * @param orderByComparator the comparator to order the set by
683             * @return the last matching journal article resource
684             * @throws com.liferay.portlet.journal.NoSuchArticleResourceException if a matching journal article resource could not be found
685             * @throws SystemException if a system exception occurred
686             */
687            public JournalArticleResource findByUuid_Last(String uuid,
688                    OrderByComparator orderByComparator)
689                    throws NoSuchArticleResourceException, SystemException {
690                    int count = countByUuid(uuid);
691    
692                    List<JournalArticleResource> list = findByUuid(uuid, count - 1, count,
693                                    orderByComparator);
694    
695                    if (list.isEmpty()) {
696                            StringBundler msg = new StringBundler(4);
697    
698                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
699    
700                            msg.append("uuid=");
701                            msg.append(uuid);
702    
703                            msg.append(StringPool.CLOSE_CURLY_BRACE);
704    
705                            throw new NoSuchArticleResourceException(msg.toString());
706                    }
707                    else {
708                            return list.get(0);
709                    }
710            }
711    
712            /**
713             * Finds the journal article resources before and after the current journal article resource in the ordered set where uuid = &#63;.
714             *
715             * <p>
716             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
717             * </p>
718             *
719             * @param resourcePrimKey the primary key of the current journal article resource
720             * @param uuid the uuid to search with
721             * @param orderByComparator the comparator to order the set by
722             * @return the previous, current, and next journal article resource
723             * @throws com.liferay.portlet.journal.NoSuchArticleResourceException if a journal article resource with the primary key could not be found
724             * @throws SystemException if a system exception occurred
725             */
726            public JournalArticleResource[] findByUuid_PrevAndNext(
727                    long resourcePrimKey, String uuid, OrderByComparator orderByComparator)
728                    throws NoSuchArticleResourceException, SystemException {
729                    JournalArticleResource journalArticleResource = findByPrimaryKey(resourcePrimKey);
730    
731                    Session session = null;
732    
733                    try {
734                            session = openSession();
735    
736                            JournalArticleResource[] array = new JournalArticleResourceImpl[3];
737    
738                            array[0] = getByUuid_PrevAndNext(session, journalArticleResource,
739                                            uuid, orderByComparator, true);
740    
741                            array[1] = journalArticleResource;
742    
743                            array[2] = getByUuid_PrevAndNext(session, journalArticleResource,
744                                            uuid, orderByComparator, false);
745    
746                            return array;
747                    }
748                    catch (Exception e) {
749                            throw processException(e);
750                    }
751                    finally {
752                            closeSession(session);
753                    }
754            }
755    
756            protected JournalArticleResource getByUuid_PrevAndNext(Session session,
757                    JournalArticleResource journalArticleResource, String uuid,
758                    OrderByComparator orderByComparator, boolean previous) {
759                    StringBundler query = null;
760    
761                    if (orderByComparator != null) {
762                            query = new StringBundler(6 +
763                                            (orderByComparator.getOrderByFields().length * 6));
764                    }
765                    else {
766                            query = new StringBundler(3);
767                    }
768    
769                    query.append(_SQL_SELECT_JOURNALARTICLERESOURCE_WHERE);
770    
771                    if (uuid == null) {
772                            query.append(_FINDER_COLUMN_UUID_UUID_1);
773                    }
774                    else {
775                            if (uuid.equals(StringPool.BLANK)) {
776                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
777                            }
778                            else {
779                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
780                            }
781                    }
782    
783                    if (orderByComparator != null) {
784                            String[] orderByFields = orderByComparator.getOrderByFields();
785    
786                            if (orderByFields.length > 0) {
787                                    query.append(WHERE_AND);
788                            }
789    
790                            for (int i = 0; i < orderByFields.length; i++) {
791                                    query.append(_ORDER_BY_ENTITY_ALIAS);
792                                    query.append(orderByFields[i]);
793    
794                                    if ((i + 1) < orderByFields.length) {
795                                            if (orderByComparator.isAscending() ^ previous) {
796                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
797                                            }
798                                            else {
799                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
800                                            }
801                                    }
802                                    else {
803                                            if (orderByComparator.isAscending() ^ previous) {
804                                                    query.append(WHERE_GREATER_THAN);
805                                            }
806                                            else {
807                                                    query.append(WHERE_LESSER_THAN);
808                                            }
809                                    }
810                            }
811    
812                            query.append(ORDER_BY_CLAUSE);
813    
814                            for (int i = 0; i < orderByFields.length; i++) {
815                                    query.append(_ORDER_BY_ENTITY_ALIAS);
816                                    query.append(orderByFields[i]);
817    
818                                    if ((i + 1) < orderByFields.length) {
819                                            if (orderByComparator.isAscending() ^ previous) {
820                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
821                                            }
822                                            else {
823                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
824                                            }
825                                    }
826                                    else {
827                                            if (orderByComparator.isAscending() ^ previous) {
828                                                    query.append(ORDER_BY_ASC);
829                                            }
830                                            else {
831                                                    query.append(ORDER_BY_DESC);
832                                            }
833                                    }
834                            }
835                    }
836    
837                    String sql = query.toString();
838    
839                    Query q = session.createQuery(sql);
840    
841                    q.setFirstResult(0);
842                    q.setMaxResults(2);
843    
844                    QueryPos qPos = QueryPos.getInstance(q);
845    
846                    if (uuid != null) {
847                            qPos.add(uuid);
848                    }
849    
850                    if (orderByComparator != null) {
851                            Object[] values = orderByComparator.getOrderByValues(journalArticleResource);
852    
853                            for (Object value : values) {
854                                    qPos.add(value);
855                            }
856                    }
857    
858                    List<JournalArticleResource> list = q.list();
859    
860                    if (list.size() == 2) {
861                            return list.get(1);
862                    }
863                    else {
864                            return null;
865                    }
866            }
867    
868            /**
869             * Finds the journal article resource where uuid = &#63; and groupId = &#63; or throws a {@link com.liferay.portlet.journal.NoSuchArticleResourceException} if it could not be found.
870             *
871             * @param uuid the uuid to search with
872             * @param groupId the group id to search with
873             * @return the matching journal article resource
874             * @throws com.liferay.portlet.journal.NoSuchArticleResourceException if a matching journal article resource could not be found
875             * @throws SystemException if a system exception occurred
876             */
877            public JournalArticleResource findByUUID_G(String uuid, long groupId)
878                    throws NoSuchArticleResourceException, SystemException {
879                    JournalArticleResource journalArticleResource = fetchByUUID_G(uuid,
880                                    groupId);
881    
882                    if (journalArticleResource == null) {
883                            StringBundler msg = new StringBundler(6);
884    
885                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
886    
887                            msg.append("uuid=");
888                            msg.append(uuid);
889    
890                            msg.append(", groupId=");
891                            msg.append(groupId);
892    
893                            msg.append(StringPool.CLOSE_CURLY_BRACE);
894    
895                            if (_log.isWarnEnabled()) {
896                                    _log.warn(msg.toString());
897                            }
898    
899                            throw new NoSuchArticleResourceException(msg.toString());
900                    }
901    
902                    return journalArticleResource;
903            }
904    
905            /**
906             * Finds the journal article resource where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
907             *
908             * @param uuid the uuid to search with
909             * @param groupId the group id to search with
910             * @return the matching journal article resource, or <code>null</code> if a matching journal article resource could not be found
911             * @throws SystemException if a system exception occurred
912             */
913            public JournalArticleResource fetchByUUID_G(String uuid, long groupId)
914                    throws SystemException {
915                    return fetchByUUID_G(uuid, groupId, true);
916            }
917    
918            /**
919             * Finds the journal article resource where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
920             *
921             * @param uuid the uuid to search with
922             * @param groupId the group id to search with
923             * @return the matching journal article resource, or <code>null</code> if a matching journal article resource could not be found
924             * @throws SystemException if a system exception occurred
925             */
926            public JournalArticleResource fetchByUUID_G(String uuid, long groupId,
927                    boolean retrieveFromCache) throws SystemException {
928                    Object[] finderArgs = new Object[] { uuid, groupId };
929    
930                    Object result = null;
931    
932                    if (retrieveFromCache) {
933                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
934                                            finderArgs, this);
935                    }
936    
937                    if (result == null) {
938                            StringBundler query = new StringBundler(3);
939    
940                            query.append(_SQL_SELECT_JOURNALARTICLERESOURCE_WHERE);
941    
942                            if (uuid == null) {
943                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
944                            }
945                            else {
946                                    if (uuid.equals(StringPool.BLANK)) {
947                                            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
948                                    }
949                                    else {
950                                            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
951                                    }
952                            }
953    
954                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
955    
956                            String sql = query.toString();
957    
958                            Session session = null;
959    
960                            try {
961                                    session = openSession();
962    
963                                    Query q = session.createQuery(sql);
964    
965                                    QueryPos qPos = QueryPos.getInstance(q);
966    
967                                    if (uuid != null) {
968                                            qPos.add(uuid);
969                                    }
970    
971                                    qPos.add(groupId);
972    
973                                    List<JournalArticleResource> list = q.list();
974    
975                                    result = list;
976    
977                                    JournalArticleResource journalArticleResource = null;
978    
979                                    if (list.isEmpty()) {
980                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
981                                                    finderArgs, list);
982                                    }
983                                    else {
984                                            journalArticleResource = list.get(0);
985    
986                                            cacheResult(journalArticleResource);
987    
988                                            if ((journalArticleResource.getUuid() == null) ||
989                                                            !journalArticleResource.getUuid().equals(uuid) ||
990                                                            (journalArticleResource.getGroupId() != groupId)) {
991                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
992                                                            finderArgs, journalArticleResource);
993                                            }
994                                    }
995    
996                                    return journalArticleResource;
997                            }
998                            catch (Exception e) {
999                                    throw processException(e);
1000                            }
1001                            finally {
1002                                    if (result == null) {
1003                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
1004                                                    finderArgs);
1005                                    }
1006    
1007                                    closeSession(session);
1008                            }
1009                    }
1010                    else {
1011                            if (result instanceof List<?>) {
1012                                    return null;
1013                            }
1014                            else {
1015                                    return (JournalArticleResource)result;
1016                            }
1017                    }
1018            }
1019    
1020            /**
1021             * Finds all the journal article resources where groupId = &#63;.
1022             *
1023             * @param groupId the group id to search with
1024             * @return the matching journal article resources
1025             * @throws SystemException if a system exception occurred
1026             */
1027            public List<JournalArticleResource> findByGroupId(long groupId)
1028                    throws SystemException {
1029                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1030            }
1031    
1032            /**
1033             * Finds a range of all the journal article resources where groupId = &#63;.
1034             *
1035             * <p>
1036             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1037             * </p>
1038             *
1039             * @param groupId the group id to search with
1040             * @param start the lower bound of the range of journal article resources to return
1041             * @param end the upper bound of the range of journal article resources to return (not inclusive)
1042             * @return the range of matching journal article resources
1043             * @throws SystemException if a system exception occurred
1044             */
1045            public List<JournalArticleResource> findByGroupId(long groupId, int start,
1046                    int end) throws SystemException {
1047                    return findByGroupId(groupId, start, end, null);
1048            }
1049    
1050            /**
1051             * Finds an ordered range of all the journal article resources where groupId = &#63;.
1052             *
1053             * <p>
1054             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1055             * </p>
1056             *
1057             * @param groupId the group id to search with
1058             * @param start the lower bound of the range of journal article resources to return
1059             * @param end the upper bound of the range of journal article resources to return (not inclusive)
1060             * @param orderByComparator the comparator to order the results by
1061             * @return the ordered range of matching journal article resources
1062             * @throws SystemException if a system exception occurred
1063             */
1064            public List<JournalArticleResource> findByGroupId(long groupId, int start,
1065                    int end, OrderByComparator orderByComparator) throws SystemException {
1066                    Object[] finderArgs = new Object[] {
1067                                    groupId,
1068                                    
1069                                    String.valueOf(start), String.valueOf(end),
1070                                    String.valueOf(orderByComparator)
1071                            };
1072    
1073                    List<JournalArticleResource> list = (List<JournalArticleResource>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
1074                                    finderArgs, this);
1075    
1076                    if (list == null) {
1077                            StringBundler query = null;
1078    
1079                            if (orderByComparator != null) {
1080                                    query = new StringBundler(3 +
1081                                                    (orderByComparator.getOrderByFields().length * 3));
1082                            }
1083                            else {
1084                                    query = new StringBundler(2);
1085                            }
1086    
1087                            query.append(_SQL_SELECT_JOURNALARTICLERESOURCE_WHERE);
1088    
1089                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1090    
1091                            if (orderByComparator != null) {
1092                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1093                                            orderByComparator);
1094                            }
1095    
1096                            String sql = query.toString();
1097    
1098                            Session session = null;
1099    
1100                            try {
1101                                    session = openSession();
1102    
1103                                    Query q = session.createQuery(sql);
1104    
1105                                    QueryPos qPos = QueryPos.getInstance(q);
1106    
1107                                    qPos.add(groupId);
1108    
1109                                    list = (List<JournalArticleResource>)QueryUtil.list(q,
1110                                                    getDialect(), start, end);
1111                            }
1112                            catch (Exception e) {
1113                                    throw processException(e);
1114                            }
1115                            finally {
1116                                    if (list == null) {
1117                                            FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_GROUPID,
1118                                                    finderArgs);
1119                                    }
1120                                    else {
1121                                            cacheResult(list);
1122    
1123                                            FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
1124                                                    finderArgs, list);
1125                                    }
1126    
1127                                    closeSession(session);
1128                            }
1129                    }
1130    
1131                    return list;
1132            }
1133    
1134            /**
1135             * Finds the first journal article resource in the ordered set where groupId = &#63;.
1136             *
1137             * <p>
1138             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1139             * </p>
1140             *
1141             * @param groupId the group id to search with
1142             * @param orderByComparator the comparator to order the set by
1143             * @return the first matching journal article resource
1144             * @throws com.liferay.portlet.journal.NoSuchArticleResourceException if a matching journal article resource could not be found
1145             * @throws SystemException if a system exception occurred
1146             */
1147            public JournalArticleResource findByGroupId_First(long groupId,
1148                    OrderByComparator orderByComparator)
1149                    throws NoSuchArticleResourceException, SystemException {
1150                    List<JournalArticleResource> list = findByGroupId(groupId, 0, 1,
1151                                    orderByComparator);
1152    
1153                    if (list.isEmpty()) {
1154                            StringBundler msg = new StringBundler(4);
1155    
1156                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1157    
1158                            msg.append("groupId=");
1159                            msg.append(groupId);
1160    
1161                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1162    
1163                            throw new NoSuchArticleResourceException(msg.toString());
1164                    }
1165                    else {
1166                            return list.get(0);
1167                    }
1168            }
1169    
1170            /**
1171             * Finds the last journal article resource in the ordered set where groupId = &#63;.
1172             *
1173             * <p>
1174             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1175             * </p>
1176             *
1177             * @param groupId the group id to search with
1178             * @param orderByComparator the comparator to order the set by
1179             * @return the last matching journal article resource
1180             * @throws com.liferay.portlet.journal.NoSuchArticleResourceException if a matching journal article resource could not be found
1181             * @throws SystemException if a system exception occurred
1182             */
1183            public JournalArticleResource findByGroupId_Last(long groupId,
1184                    OrderByComparator orderByComparator)
1185                    throws NoSuchArticleResourceException, SystemException {
1186                    int count = countByGroupId(groupId);
1187    
1188                    List<JournalArticleResource> list = findByGroupId(groupId, count - 1,
1189                                    count, orderByComparator);
1190    
1191                    if (list.isEmpty()) {
1192                            StringBundler msg = new StringBundler(4);
1193    
1194                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1195    
1196                            msg.append("groupId=");
1197                            msg.append(groupId);
1198    
1199                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1200    
1201                            throw new NoSuchArticleResourceException(msg.toString());
1202                    }
1203                    else {
1204                            return list.get(0);
1205                    }
1206            }
1207    
1208            /**
1209             * Finds the journal article resources before and after the current journal article resource in the ordered set where groupId = &#63;.
1210             *
1211             * <p>
1212             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1213             * </p>
1214             *
1215             * @param resourcePrimKey the primary key of the current journal article resource
1216             * @param groupId the group id to search with
1217             * @param orderByComparator the comparator to order the set by
1218             * @return the previous, current, and next journal article resource
1219             * @throws com.liferay.portlet.journal.NoSuchArticleResourceException if a journal article resource with the primary key could not be found
1220             * @throws SystemException if a system exception occurred
1221             */
1222            public JournalArticleResource[] findByGroupId_PrevAndNext(
1223                    long resourcePrimKey, long groupId, OrderByComparator orderByComparator)
1224                    throws NoSuchArticleResourceException, SystemException {
1225                    JournalArticleResource journalArticleResource = findByPrimaryKey(resourcePrimKey);
1226    
1227                    Session session = null;
1228    
1229                    try {
1230                            session = openSession();
1231    
1232                            JournalArticleResource[] array = new JournalArticleResourceImpl[3];
1233    
1234                            array[0] = getByGroupId_PrevAndNext(session,
1235                                            journalArticleResource, groupId, orderByComparator, true);
1236    
1237                            array[1] = journalArticleResource;
1238    
1239                            array[2] = getByGroupId_PrevAndNext(session,
1240                                            journalArticleResource, groupId, orderByComparator, false);
1241    
1242                            return array;
1243                    }
1244                    catch (Exception e) {
1245                            throw processException(e);
1246                    }
1247                    finally {
1248                            closeSession(session);
1249                    }
1250            }
1251    
1252            protected JournalArticleResource getByGroupId_PrevAndNext(Session session,
1253                    JournalArticleResource journalArticleResource, long groupId,
1254                    OrderByComparator orderByComparator, boolean previous) {
1255                    StringBundler query = null;
1256    
1257                    if (orderByComparator != null) {
1258                            query = new StringBundler(6 +
1259                                            (orderByComparator.getOrderByFields().length * 6));
1260                    }
1261                    else {
1262                            query = new StringBundler(3);
1263                    }
1264    
1265                    query.append(_SQL_SELECT_JOURNALARTICLERESOURCE_WHERE);
1266    
1267                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1268    
1269                    if (orderByComparator != null) {
1270                            String[] orderByFields = orderByComparator.getOrderByFields();
1271    
1272                            if (orderByFields.length > 0) {
1273                                    query.append(WHERE_AND);
1274                            }
1275    
1276                            for (int i = 0; i < orderByFields.length; i++) {
1277                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1278                                    query.append(orderByFields[i]);
1279    
1280                                    if ((i + 1) < orderByFields.length) {
1281                                            if (orderByComparator.isAscending() ^ previous) {
1282                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1283                                            }
1284                                            else {
1285                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1286                                            }
1287                                    }
1288                                    else {
1289                                            if (orderByComparator.isAscending() ^ previous) {
1290                                                    query.append(WHERE_GREATER_THAN);
1291                                            }
1292                                            else {
1293                                                    query.append(WHERE_LESSER_THAN);
1294                                            }
1295                                    }
1296                            }
1297    
1298                            query.append(ORDER_BY_CLAUSE);
1299    
1300                            for (int i = 0; i < orderByFields.length; i++) {
1301                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1302                                    query.append(orderByFields[i]);
1303    
1304                                    if ((i + 1) < orderByFields.length) {
1305                                            if (orderByComparator.isAscending() ^ previous) {
1306                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1307                                            }
1308                                            else {
1309                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1310                                            }
1311                                    }
1312                                    else {
1313                                            if (orderByComparator.isAscending() ^ previous) {
1314                                                    query.append(ORDER_BY_ASC);
1315                                            }
1316                                            else {
1317                                                    query.append(ORDER_BY_DESC);
1318                                            }
1319                                    }
1320                            }
1321                    }
1322    
1323                    String sql = query.toString();
1324    
1325                    Query q = session.createQuery(sql);
1326    
1327                    q.setFirstResult(0);
1328                    q.setMaxResults(2);
1329    
1330                    QueryPos qPos = QueryPos.getInstance(q);
1331    
1332                    qPos.add(groupId);
1333    
1334                    if (orderByComparator != null) {
1335                            Object[] values = orderByComparator.getOrderByValues(journalArticleResource);
1336    
1337                            for (Object value : values) {
1338                                    qPos.add(value);
1339                            }
1340                    }
1341    
1342                    List<JournalArticleResource> list = q.list();
1343    
1344                    if (list.size() == 2) {
1345                            return list.get(1);
1346                    }
1347                    else {
1348                            return null;
1349                    }
1350            }
1351    
1352            /**
1353             * Finds the journal article resource where groupId = &#63; and articleId = &#63; or throws a {@link com.liferay.portlet.journal.NoSuchArticleResourceException} if it could not be found.
1354             *
1355             * @param groupId the group id to search with
1356             * @param articleId the article id to search with
1357             * @return the matching journal article resource
1358             * @throws com.liferay.portlet.journal.NoSuchArticleResourceException if a matching journal article resource could not be found
1359             * @throws SystemException if a system exception occurred
1360             */
1361            public JournalArticleResource findByG_A(long groupId, String articleId)
1362                    throws NoSuchArticleResourceException, SystemException {
1363                    JournalArticleResource journalArticleResource = fetchByG_A(groupId,
1364                                    articleId);
1365    
1366                    if (journalArticleResource == null) {
1367                            StringBundler msg = new StringBundler(6);
1368    
1369                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1370    
1371                            msg.append("groupId=");
1372                            msg.append(groupId);
1373    
1374                            msg.append(", articleId=");
1375                            msg.append(articleId);
1376    
1377                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1378    
1379                            if (_log.isWarnEnabled()) {
1380                                    _log.warn(msg.toString());
1381                            }
1382    
1383                            throw new NoSuchArticleResourceException(msg.toString());
1384                    }
1385    
1386                    return journalArticleResource;
1387            }
1388    
1389            /**
1390             * Finds the journal article resource where groupId = &#63; and articleId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
1391             *
1392             * @param groupId the group id to search with
1393             * @param articleId the article id to search with
1394             * @return the matching journal article resource, or <code>null</code> if a matching journal article resource could not be found
1395             * @throws SystemException if a system exception occurred
1396             */
1397            public JournalArticleResource fetchByG_A(long groupId, String articleId)
1398                    throws SystemException {
1399                    return fetchByG_A(groupId, articleId, true);
1400            }
1401    
1402            /**
1403             * Finds the journal article resource where groupId = &#63; and articleId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
1404             *
1405             * @param groupId the group id to search with
1406             * @param articleId the article id to search with
1407             * @return the matching journal article resource, or <code>null</code> if a matching journal article resource could not be found
1408             * @throws SystemException if a system exception occurred
1409             */
1410            public JournalArticleResource fetchByG_A(long groupId, String articleId,
1411                    boolean retrieveFromCache) throws SystemException {
1412                    Object[] finderArgs = new Object[] { groupId, articleId };
1413    
1414                    Object result = null;
1415    
1416                    if (retrieveFromCache) {
1417                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_A,
1418                                            finderArgs, this);
1419                    }
1420    
1421                    if (result == null) {
1422                            StringBundler query = new StringBundler(3);
1423    
1424                            query.append(_SQL_SELECT_JOURNALARTICLERESOURCE_WHERE);
1425    
1426                            query.append(_FINDER_COLUMN_G_A_GROUPID_2);
1427    
1428                            if (articleId == null) {
1429                                    query.append(_FINDER_COLUMN_G_A_ARTICLEID_1);
1430                            }
1431                            else {
1432                                    if (articleId.equals(StringPool.BLANK)) {
1433                                            query.append(_FINDER_COLUMN_G_A_ARTICLEID_3);
1434                                    }
1435                                    else {
1436                                            query.append(_FINDER_COLUMN_G_A_ARTICLEID_2);
1437                                    }
1438                            }
1439    
1440                            String sql = query.toString();
1441    
1442                            Session session = null;
1443    
1444                            try {
1445                                    session = openSession();
1446    
1447                                    Query q = session.createQuery(sql);
1448    
1449                                    QueryPos qPos = QueryPos.getInstance(q);
1450    
1451                                    qPos.add(groupId);
1452    
1453                                    if (articleId != null) {
1454                                            qPos.add(articleId);
1455                                    }
1456    
1457                                    List<JournalArticleResource> list = q.list();
1458    
1459                                    result = list;
1460    
1461                                    JournalArticleResource journalArticleResource = null;
1462    
1463                                    if (list.isEmpty()) {
1464                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_A,
1465                                                    finderArgs, list);
1466                                    }
1467                                    else {
1468                                            journalArticleResource = list.get(0);
1469    
1470                                            cacheResult(journalArticleResource);
1471    
1472                                            if ((journalArticleResource.getGroupId() != groupId) ||
1473                                                            (journalArticleResource.getArticleId() == null) ||
1474                                                            !journalArticleResource.getArticleId()
1475                                                                                                               .equals(articleId)) {
1476                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_A,
1477                                                            finderArgs, journalArticleResource);
1478                                            }
1479                                    }
1480    
1481                                    return journalArticleResource;
1482                            }
1483                            catch (Exception e) {
1484                                    throw processException(e);
1485                            }
1486                            finally {
1487                                    if (result == null) {
1488                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_A,
1489                                                    finderArgs);
1490                                    }
1491    
1492                                    closeSession(session);
1493                            }
1494                    }
1495                    else {
1496                            if (result instanceof List<?>) {
1497                                    return null;
1498                            }
1499                            else {
1500                                    return (JournalArticleResource)result;
1501                            }
1502                    }
1503            }
1504    
1505            /**
1506             * Finds all the journal article resources.
1507             *
1508             * @return the journal article resources
1509             * @throws SystemException if a system exception occurred
1510             */
1511            public List<JournalArticleResource> findAll() throws SystemException {
1512                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1513            }
1514    
1515            /**
1516             * Finds a range of all the journal article resources.
1517             *
1518             * <p>
1519             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1520             * </p>
1521             *
1522             * @param start the lower bound of the range of journal article resources to return
1523             * @param end the upper bound of the range of journal article resources to return (not inclusive)
1524             * @return the range of journal article resources
1525             * @throws SystemException if a system exception occurred
1526             */
1527            public List<JournalArticleResource> findAll(int start, int end)
1528                    throws SystemException {
1529                    return findAll(start, end, null);
1530            }
1531    
1532            /**
1533             * Finds an ordered range of all the journal article resources.
1534             *
1535             * <p>
1536             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1537             * </p>
1538             *
1539             * @param start the lower bound of the range of journal article resources to return
1540             * @param end the upper bound of the range of journal article resources to return (not inclusive)
1541             * @param orderByComparator the comparator to order the results by
1542             * @return the ordered range of journal article resources
1543             * @throws SystemException if a system exception occurred
1544             */
1545            public List<JournalArticleResource> findAll(int start, int end,
1546                    OrderByComparator orderByComparator) throws SystemException {
1547                    Object[] finderArgs = new Object[] {
1548                                    String.valueOf(start), String.valueOf(end),
1549                                    String.valueOf(orderByComparator)
1550                            };
1551    
1552                    List<JournalArticleResource> list = (List<JournalArticleResource>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1553                                    finderArgs, this);
1554    
1555                    if (list == null) {
1556                            StringBundler query = null;
1557                            String sql = null;
1558    
1559                            if (orderByComparator != null) {
1560                                    query = new StringBundler(2 +
1561                                                    (orderByComparator.getOrderByFields().length * 3));
1562    
1563                                    query.append(_SQL_SELECT_JOURNALARTICLERESOURCE);
1564    
1565                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1566                                            orderByComparator);
1567    
1568                                    sql = query.toString();
1569                            }
1570                            else {
1571                                    sql = _SQL_SELECT_JOURNALARTICLERESOURCE;
1572                            }
1573    
1574                            Session session = null;
1575    
1576                            try {
1577                                    session = openSession();
1578    
1579                                    Query q = session.createQuery(sql);
1580    
1581                                    if (orderByComparator == null) {
1582                                            list = (List<JournalArticleResource>)QueryUtil.list(q,
1583                                                            getDialect(), start, end, false);
1584    
1585                                            Collections.sort(list);
1586                                    }
1587                                    else {
1588                                            list = (List<JournalArticleResource>)QueryUtil.list(q,
1589                                                            getDialect(), start, end);
1590                                    }
1591                            }
1592                            catch (Exception e) {
1593                                    throw processException(e);
1594                            }
1595                            finally {
1596                                    if (list == null) {
1597                                            FinderCacheUtil.removeResult(FINDER_PATH_FIND_ALL,
1598                                                    finderArgs);
1599                                    }
1600                                    else {
1601                                            cacheResult(list);
1602    
1603                                            FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs,
1604                                                    list);
1605                                    }
1606    
1607                                    closeSession(session);
1608                            }
1609                    }
1610    
1611                    return list;
1612            }
1613    
1614            /**
1615             * Removes all the journal article resources where uuid = &#63; from the database.
1616             *
1617             * @param uuid the uuid to search with
1618             * @throws SystemException if a system exception occurred
1619             */
1620            public void removeByUuid(String uuid) throws SystemException {
1621                    for (JournalArticleResource journalArticleResource : findByUuid(uuid)) {
1622                            remove(journalArticleResource);
1623                    }
1624            }
1625    
1626            /**
1627             * Removes the journal article resource where uuid = &#63; and groupId = &#63; from the database.
1628             *
1629             * @param uuid the uuid to search with
1630             * @param groupId the group id to search with
1631             * @throws SystemException if a system exception occurred
1632             */
1633            public void removeByUUID_G(String uuid, long groupId)
1634                    throws NoSuchArticleResourceException, SystemException {
1635                    JournalArticleResource journalArticleResource = findByUUID_G(uuid,
1636                                    groupId);
1637    
1638                    remove(journalArticleResource);
1639            }
1640    
1641            /**
1642             * Removes all the journal article resources where groupId = &#63; from the database.
1643             *
1644             * @param groupId the group id to search with
1645             * @throws SystemException if a system exception occurred
1646             */
1647            public void removeByGroupId(long groupId) throws SystemException {
1648                    for (JournalArticleResource journalArticleResource : findByGroupId(
1649                                    groupId)) {
1650                            remove(journalArticleResource);
1651                    }
1652            }
1653    
1654            /**
1655             * Removes the journal article resource where groupId = &#63; and articleId = &#63; from the database.
1656             *
1657             * @param groupId the group id to search with
1658             * @param articleId the article id to search with
1659             * @throws SystemException if a system exception occurred
1660             */
1661            public void removeByG_A(long groupId, String articleId)
1662                    throws NoSuchArticleResourceException, SystemException {
1663                    JournalArticleResource journalArticleResource = findByG_A(groupId,
1664                                    articleId);
1665    
1666                    remove(journalArticleResource);
1667            }
1668    
1669            /**
1670             * Removes all the journal article resources from the database.
1671             *
1672             * @throws SystemException if a system exception occurred
1673             */
1674            public void removeAll() throws SystemException {
1675                    for (JournalArticleResource journalArticleResource : findAll()) {
1676                            remove(journalArticleResource);
1677                    }
1678            }
1679    
1680            /**
1681             * Counts all the journal article resources where uuid = &#63;.
1682             *
1683             * @param uuid the uuid to search with
1684             * @return the number of matching journal article resources
1685             * @throws SystemException if a system exception occurred
1686             */
1687            public int countByUuid(String uuid) throws SystemException {
1688                    Object[] finderArgs = new Object[] { uuid };
1689    
1690                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
1691                                    finderArgs, this);
1692    
1693                    if (count == null) {
1694                            StringBundler query = new StringBundler(2);
1695    
1696                            query.append(_SQL_COUNT_JOURNALARTICLERESOURCE_WHERE);
1697    
1698                            if (uuid == null) {
1699                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
1700                            }
1701                            else {
1702                                    if (uuid.equals(StringPool.BLANK)) {
1703                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
1704                                    }
1705                                    else {
1706                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
1707                                    }
1708                            }
1709    
1710                            String sql = query.toString();
1711    
1712                            Session session = null;
1713    
1714                            try {
1715                                    session = openSession();
1716    
1717                                    Query q = session.createQuery(sql);
1718    
1719                                    QueryPos qPos = QueryPos.getInstance(q);
1720    
1721                                    if (uuid != null) {
1722                                            qPos.add(uuid);
1723                                    }
1724    
1725                                    count = (Long)q.uniqueResult();
1726                            }
1727                            catch (Exception e) {
1728                                    throw processException(e);
1729                            }
1730                            finally {
1731                                    if (count == null) {
1732                                            count = Long.valueOf(0);
1733                                    }
1734    
1735                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
1736                                            finderArgs, count);
1737    
1738                                    closeSession(session);
1739                            }
1740                    }
1741    
1742                    return count.intValue();
1743            }
1744    
1745            /**
1746             * Counts all the journal article resources where uuid = &#63; and groupId = &#63;.
1747             *
1748             * @param uuid the uuid to search with
1749             * @param groupId the group id to search with
1750             * @return the number of matching journal article resources
1751             * @throws SystemException if a system exception occurred
1752             */
1753            public int countByUUID_G(String uuid, long groupId)
1754                    throws SystemException {
1755                    Object[] finderArgs = new Object[] { uuid, groupId };
1756    
1757                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
1758                                    finderArgs, this);
1759    
1760                    if (count == null) {
1761                            StringBundler query = new StringBundler(3);
1762    
1763                            query.append(_SQL_COUNT_JOURNALARTICLERESOURCE_WHERE);
1764    
1765                            if (uuid == null) {
1766                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
1767                            }
1768                            else {
1769                                    if (uuid.equals(StringPool.BLANK)) {
1770                                            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
1771                                    }
1772                                    else {
1773                                            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
1774                                    }
1775                            }
1776    
1777                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
1778    
1779                            String sql = query.toString();
1780    
1781                            Session session = null;
1782    
1783                            try {
1784                                    session = openSession();
1785    
1786                                    Query q = session.createQuery(sql);
1787    
1788                                    QueryPos qPos = QueryPos.getInstance(q);
1789    
1790                                    if (uuid != null) {
1791                                            qPos.add(uuid);
1792                                    }
1793    
1794                                    qPos.add(groupId);
1795    
1796                                    count = (Long)q.uniqueResult();
1797                            }
1798                            catch (Exception e) {
1799                                    throw processException(e);
1800                            }
1801                            finally {
1802                                    if (count == null) {
1803                                            count = Long.valueOf(0);
1804                                    }
1805    
1806                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
1807                                            finderArgs, count);
1808    
1809                                    closeSession(session);
1810                            }
1811                    }
1812    
1813                    return count.intValue();
1814            }
1815    
1816            /**
1817             * Counts all the journal article resources where groupId = &#63;.
1818             *
1819             * @param groupId the group id to search with
1820             * @return the number of matching journal article resources
1821             * @throws SystemException if a system exception occurred
1822             */
1823            public int countByGroupId(long groupId) throws SystemException {
1824                    Object[] finderArgs = new Object[] { groupId };
1825    
1826                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
1827                                    finderArgs, this);
1828    
1829                    if (count == null) {
1830                            StringBundler query = new StringBundler(2);
1831    
1832                            query.append(_SQL_COUNT_JOURNALARTICLERESOURCE_WHERE);
1833    
1834                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1835    
1836                            String sql = query.toString();
1837    
1838                            Session session = null;
1839    
1840                            try {
1841                                    session = openSession();
1842    
1843                                    Query q = session.createQuery(sql);
1844    
1845                                    QueryPos qPos = QueryPos.getInstance(q);
1846    
1847                                    qPos.add(groupId);
1848    
1849                                    count = (Long)q.uniqueResult();
1850                            }
1851                            catch (Exception e) {
1852                                    throw processException(e);
1853                            }
1854                            finally {
1855                                    if (count == null) {
1856                                            count = Long.valueOf(0);
1857                                    }
1858    
1859                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
1860                                            finderArgs, count);
1861    
1862                                    closeSession(session);
1863                            }
1864                    }
1865    
1866                    return count.intValue();
1867            }
1868    
1869            /**
1870             * Counts all the journal article resources where groupId = &#63; and articleId = &#63;.
1871             *
1872             * @param groupId the group id to search with
1873             * @param articleId the article id to search with
1874             * @return the number of matching journal article resources
1875             * @throws SystemException if a system exception occurred
1876             */
1877            public int countByG_A(long groupId, String articleId)
1878                    throws SystemException {
1879                    Object[] finderArgs = new Object[] { groupId, articleId };
1880    
1881                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_A,
1882                                    finderArgs, this);
1883    
1884                    if (count == null) {
1885                            StringBundler query = new StringBundler(3);
1886    
1887                            query.append(_SQL_COUNT_JOURNALARTICLERESOURCE_WHERE);
1888    
1889                            query.append(_FINDER_COLUMN_G_A_GROUPID_2);
1890    
1891                            if (articleId == null) {
1892                                    query.append(_FINDER_COLUMN_G_A_ARTICLEID_1);
1893                            }
1894                            else {
1895                                    if (articleId.equals(StringPool.BLANK)) {
1896                                            query.append(_FINDER_COLUMN_G_A_ARTICLEID_3);
1897                                    }
1898                                    else {
1899                                            query.append(_FINDER_COLUMN_G_A_ARTICLEID_2);
1900                                    }
1901                            }
1902    
1903                            String sql = query.toString();
1904    
1905                            Session session = null;
1906    
1907                            try {
1908                                    session = openSession();
1909    
1910                                    Query q = session.createQuery(sql);
1911    
1912                                    QueryPos qPos = QueryPos.getInstance(q);
1913    
1914                                    qPos.add(groupId);
1915    
1916                                    if (articleId != null) {
1917                                            qPos.add(articleId);
1918                                    }
1919    
1920                                    count = (Long)q.uniqueResult();
1921                            }
1922                            catch (Exception e) {
1923                                    throw processException(e);
1924                            }
1925                            finally {
1926                                    if (count == null) {
1927                                            count = Long.valueOf(0);
1928                                    }
1929    
1930                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_A, finderArgs,
1931                                            count);
1932    
1933                                    closeSession(session);
1934                            }
1935                    }
1936    
1937                    return count.intValue();
1938            }
1939    
1940            /**
1941             * Counts all the journal article resources.
1942             *
1943             * @return the number of journal article resources
1944             * @throws SystemException if a system exception occurred
1945             */
1946            public int countAll() throws SystemException {
1947                    Object[] finderArgs = new Object[0];
1948    
1949                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1950                                    finderArgs, this);
1951    
1952                    if (count == null) {
1953                            Session session = null;
1954    
1955                            try {
1956                                    session = openSession();
1957    
1958                                    Query q = session.createQuery(_SQL_COUNT_JOURNALARTICLERESOURCE);
1959    
1960                                    count = (Long)q.uniqueResult();
1961                            }
1962                            catch (Exception e) {
1963                                    throw processException(e);
1964                            }
1965                            finally {
1966                                    if (count == null) {
1967                                            count = Long.valueOf(0);
1968                                    }
1969    
1970                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1971                                            count);
1972    
1973                                    closeSession(session);
1974                            }
1975                    }
1976    
1977                    return count.intValue();
1978            }
1979    
1980            /**
1981             * Initializes the journal article resource persistence.
1982             */
1983            public void afterPropertiesSet() {
1984                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1985                                            com.liferay.portal.util.PropsUtil.get(
1986                                                    "value.object.listener.com.liferay.portlet.journal.model.JournalArticleResource")));
1987    
1988                    if (listenerClassNames.length > 0) {
1989                            try {
1990                                    List<ModelListener<JournalArticleResource>> listenersList = new ArrayList<ModelListener<JournalArticleResource>>();
1991    
1992                                    for (String listenerClassName : listenerClassNames) {
1993                                            listenersList.add((ModelListener<JournalArticleResource>)InstanceFactory.newInstance(
1994                                                            listenerClassName));
1995                                    }
1996    
1997                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1998                            }
1999                            catch (Exception e) {
2000                                    _log.error(e);
2001                            }
2002                    }
2003            }
2004    
2005            public void destroy() {
2006                    EntityCacheUtil.removeCache(JournalArticleResourceImpl.class.getName());
2007                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2008                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
2009            }
2010    
2011            @BeanReference(type = JournalArticlePersistence.class)
2012            protected JournalArticlePersistence journalArticlePersistence;
2013            @BeanReference(type = JournalArticleImagePersistence.class)
2014            protected JournalArticleImagePersistence journalArticleImagePersistence;
2015            @BeanReference(type = JournalArticleResourcePersistence.class)
2016            protected JournalArticleResourcePersistence journalArticleResourcePersistence;
2017            @BeanReference(type = JournalContentSearchPersistence.class)
2018            protected JournalContentSearchPersistence journalContentSearchPersistence;
2019            @BeanReference(type = JournalFeedPersistence.class)
2020            protected JournalFeedPersistence journalFeedPersistence;
2021            @BeanReference(type = JournalStructurePersistence.class)
2022            protected JournalStructurePersistence journalStructurePersistence;
2023            @BeanReference(type = JournalTemplatePersistence.class)
2024            protected JournalTemplatePersistence journalTemplatePersistence;
2025            @BeanReference(type = ResourcePersistence.class)
2026            protected ResourcePersistence resourcePersistence;
2027            @BeanReference(type = UserPersistence.class)
2028            protected UserPersistence userPersistence;
2029            private static final String _SQL_SELECT_JOURNALARTICLERESOURCE = "SELECT journalArticleResource FROM JournalArticleResource journalArticleResource";
2030            private static final String _SQL_SELECT_JOURNALARTICLERESOURCE_WHERE = "SELECT journalArticleResource FROM JournalArticleResource journalArticleResource WHERE ";
2031            private static final String _SQL_COUNT_JOURNALARTICLERESOURCE = "SELECT COUNT(journalArticleResource) FROM JournalArticleResource journalArticleResource";
2032            private static final String _SQL_COUNT_JOURNALARTICLERESOURCE_WHERE = "SELECT COUNT(journalArticleResource) FROM JournalArticleResource journalArticleResource WHERE ";
2033            private static final String _FINDER_COLUMN_UUID_UUID_1 = "journalArticleResource.uuid IS NULL";
2034            private static final String _FINDER_COLUMN_UUID_UUID_2 = "journalArticleResource.uuid = ?";
2035            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(journalArticleResource.uuid IS NULL OR journalArticleResource.uuid = ?)";
2036            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "journalArticleResource.uuid IS NULL AND ";
2037            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "journalArticleResource.uuid = ? AND ";
2038            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(journalArticleResource.uuid IS NULL OR journalArticleResource.uuid = ?) AND ";
2039            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "journalArticleResource.groupId = ?";
2040            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "journalArticleResource.groupId = ?";
2041            private static final String _FINDER_COLUMN_G_A_GROUPID_2 = "journalArticleResource.groupId = ? AND ";
2042            private static final String _FINDER_COLUMN_G_A_ARTICLEID_1 = "journalArticleResource.articleId IS NULL";
2043            private static final String _FINDER_COLUMN_G_A_ARTICLEID_2 = "journalArticleResource.articleId = ?";
2044            private static final String _FINDER_COLUMN_G_A_ARTICLEID_3 = "(journalArticleResource.articleId IS NULL OR journalArticleResource.articleId = ?)";
2045            private static final String _ORDER_BY_ENTITY_ALIAS = "journalArticleResource.";
2046            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No JournalArticleResource exists with the primary key ";
2047            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No JournalArticleResource exists with the key {";
2048            private static Log _log = LogFactoryUtil.getLog(JournalArticleResourcePersistenceImpl.class);
2049    }