001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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.getOriginalUuid(),
305                                    new Long(journalArticleResourceModelImpl.getOriginalGroupId())
306                            });
307    
308                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_A,
309                            new Object[] {
310                                    new Long(journalArticleResourceModelImpl.getOriginalGroupId()),
311                                    
312                            journalArticleResourceModelImpl.getOriginalArticleId()
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                            Session session = null;
570    
571                            try {
572                                    session = openSession();
573    
574                                    StringBundler query = null;
575    
576                                    if (orderByComparator != null) {
577                                            query = new StringBundler(3 +
578                                                            (orderByComparator.getOrderByFields().length * 3));
579                                    }
580                                    else {
581                                            query = new StringBundler(2);
582                                    }
583    
584                                    query.append(_SQL_SELECT_JOURNALARTICLERESOURCE_WHERE);
585    
586                                    if (uuid == null) {
587                                            query.append(_FINDER_COLUMN_UUID_UUID_1);
588                                    }
589                                    else {
590                                            if (uuid.equals(StringPool.BLANK)) {
591                                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
592                                            }
593                                            else {
594                                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
595                                            }
596                                    }
597    
598                                    if (orderByComparator != null) {
599                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
600                                                    orderByComparator);
601                                    }
602    
603                                    String sql = query.toString();
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                                            list = new ArrayList<JournalArticleResource>();
622                                    }
623    
624                                    cacheResult(list);
625    
626                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_UUID, finderArgs,
627                                            list);
628    
629                                    closeSession(session);
630                            }
631                    }
632    
633                    return list;
634            }
635    
636            /**
637             * Finds the first journal article resource in the ordered set where uuid = &#63;.
638             *
639             * <p>
640             * 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.
641             * </p>
642             *
643             * @param uuid the uuid to search with
644             * @param orderByComparator the comparator to order the set by
645             * @return the first matching journal article resource
646             * @throws com.liferay.portlet.journal.NoSuchArticleResourceException if a matching journal article resource could not be found
647             * @throws SystemException if a system exception occurred
648             */
649            public JournalArticleResource findByUuid_First(String uuid,
650                    OrderByComparator orderByComparator)
651                    throws NoSuchArticleResourceException, SystemException {
652                    List<JournalArticleResource> list = findByUuid(uuid, 0, 1,
653                                    orderByComparator);
654    
655                    if (list.isEmpty()) {
656                            StringBundler msg = new StringBundler(4);
657    
658                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
659    
660                            msg.append("uuid=");
661                            msg.append(uuid);
662    
663                            msg.append(StringPool.CLOSE_CURLY_BRACE);
664    
665                            throw new NoSuchArticleResourceException(msg.toString());
666                    }
667                    else {
668                            return list.get(0);
669                    }
670            }
671    
672            /**
673             * Finds the last journal article resource in the ordered set where uuid = &#63;.
674             *
675             * <p>
676             * 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.
677             * </p>
678             *
679             * @param uuid the uuid to search with
680             * @param orderByComparator the comparator to order the set by
681             * @return the last matching journal article resource
682             * @throws com.liferay.portlet.journal.NoSuchArticleResourceException if a matching journal article resource could not be found
683             * @throws SystemException if a system exception occurred
684             */
685            public JournalArticleResource findByUuid_Last(String uuid,
686                    OrderByComparator orderByComparator)
687                    throws NoSuchArticleResourceException, SystemException {
688                    int count = countByUuid(uuid);
689    
690                    List<JournalArticleResource> list = findByUuid(uuid, count - 1, count,
691                                    orderByComparator);
692    
693                    if (list.isEmpty()) {
694                            StringBundler msg = new StringBundler(4);
695    
696                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
697    
698                            msg.append("uuid=");
699                            msg.append(uuid);
700    
701                            msg.append(StringPool.CLOSE_CURLY_BRACE);
702    
703                            throw new NoSuchArticleResourceException(msg.toString());
704                    }
705                    else {
706                            return list.get(0);
707                    }
708            }
709    
710            /**
711             * Finds the journal article resources before and after the current journal article resource in the ordered set where uuid = &#63;.
712             *
713             * <p>
714             * 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.
715             * </p>
716             *
717             * @param resourcePrimKey the primary key of the current journal article resource
718             * @param uuid the uuid to search with
719             * @param orderByComparator the comparator to order the set by
720             * @return the previous, current, and next journal article resource
721             * @throws com.liferay.portlet.journal.NoSuchArticleResourceException if a journal article resource with the primary key could not be found
722             * @throws SystemException if a system exception occurred
723             */
724            public JournalArticleResource[] findByUuid_PrevAndNext(
725                    long resourcePrimKey, String uuid, OrderByComparator orderByComparator)
726                    throws NoSuchArticleResourceException, SystemException {
727                    JournalArticleResource journalArticleResource = findByPrimaryKey(resourcePrimKey);
728    
729                    Session session = null;
730    
731                    try {
732                            session = openSession();
733    
734                            JournalArticleResource[] array = new JournalArticleResourceImpl[3];
735    
736                            array[0] = getByUuid_PrevAndNext(session, journalArticleResource,
737                                            uuid, orderByComparator, true);
738    
739                            array[1] = journalArticleResource;
740    
741                            array[2] = getByUuid_PrevAndNext(session, journalArticleResource,
742                                            uuid, orderByComparator, false);
743    
744                            return array;
745                    }
746                    catch (Exception e) {
747                            throw processException(e);
748                    }
749                    finally {
750                            closeSession(session);
751                    }
752            }
753    
754            protected JournalArticleResource getByUuid_PrevAndNext(Session session,
755                    JournalArticleResource journalArticleResource, String uuid,
756                    OrderByComparator orderByComparator, boolean previous) {
757                    StringBundler query = null;
758    
759                    if (orderByComparator != null) {
760                            query = new StringBundler(6 +
761                                            (orderByComparator.getOrderByFields().length * 6));
762                    }
763                    else {
764                            query = new StringBundler(3);
765                    }
766    
767                    query.append(_SQL_SELECT_JOURNALARTICLERESOURCE_WHERE);
768    
769                    if (uuid == null) {
770                            query.append(_FINDER_COLUMN_UUID_UUID_1);
771                    }
772                    else {
773                            if (uuid.equals(StringPool.BLANK)) {
774                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
775                            }
776                            else {
777                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
778                            }
779                    }
780    
781                    if (orderByComparator != null) {
782                            String[] orderByFields = orderByComparator.getOrderByFields();
783    
784                            if (orderByFields.length > 0) {
785                                    query.append(WHERE_AND);
786                            }
787    
788                            for (int i = 0; i < orderByFields.length; i++) {
789                                    query.append(_ORDER_BY_ENTITY_ALIAS);
790                                    query.append(orderByFields[i]);
791    
792                                    if ((i + 1) < orderByFields.length) {
793                                            if (orderByComparator.isAscending() ^ previous) {
794                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
795                                            }
796                                            else {
797                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
798                                            }
799                                    }
800                                    else {
801                                            if (orderByComparator.isAscending() ^ previous) {
802                                                    query.append(WHERE_GREATER_THAN);
803                                            }
804                                            else {
805                                                    query.append(WHERE_LESSER_THAN);
806                                            }
807                                    }
808                            }
809    
810                            query.append(ORDER_BY_CLAUSE);
811    
812                            for (int i = 0; i < orderByFields.length; i++) {
813                                    query.append(_ORDER_BY_ENTITY_ALIAS);
814                                    query.append(orderByFields[i]);
815    
816                                    if ((i + 1) < orderByFields.length) {
817                                            if (orderByComparator.isAscending() ^ previous) {
818                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
819                                            }
820                                            else {
821                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
822                                            }
823                                    }
824                                    else {
825                                            if (orderByComparator.isAscending() ^ previous) {
826                                                    query.append(ORDER_BY_ASC);
827                                            }
828                                            else {
829                                                    query.append(ORDER_BY_DESC);
830                                            }
831                                    }
832                            }
833                    }
834    
835                    String sql = query.toString();
836    
837                    Query q = session.createQuery(sql);
838    
839                    q.setFirstResult(0);
840                    q.setMaxResults(2);
841    
842                    QueryPos qPos = QueryPos.getInstance(q);
843    
844                    if (uuid != null) {
845                            qPos.add(uuid);
846                    }
847    
848                    if (orderByComparator != null) {
849                            Object[] values = orderByComparator.getOrderByValues(journalArticleResource);
850    
851                            for (Object value : values) {
852                                    qPos.add(value);
853                            }
854                    }
855    
856                    List<JournalArticleResource> list = q.list();
857    
858                    if (list.size() == 2) {
859                            return list.get(1);
860                    }
861                    else {
862                            return null;
863                    }
864            }
865    
866            /**
867             * 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.
868             *
869             * @param uuid the uuid to search with
870             * @param groupId the group id to search with
871             * @return the matching journal article resource
872             * @throws com.liferay.portlet.journal.NoSuchArticleResourceException if a matching journal article resource could not be found
873             * @throws SystemException if a system exception occurred
874             */
875            public JournalArticleResource findByUUID_G(String uuid, long groupId)
876                    throws NoSuchArticleResourceException, SystemException {
877                    JournalArticleResource journalArticleResource = fetchByUUID_G(uuid,
878                                    groupId);
879    
880                    if (journalArticleResource == null) {
881                            StringBundler msg = new StringBundler(6);
882    
883                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
884    
885                            msg.append("uuid=");
886                            msg.append(uuid);
887    
888                            msg.append(", groupId=");
889                            msg.append(groupId);
890    
891                            msg.append(StringPool.CLOSE_CURLY_BRACE);
892    
893                            if (_log.isWarnEnabled()) {
894                                    _log.warn(msg.toString());
895                            }
896    
897                            throw new NoSuchArticleResourceException(msg.toString());
898                    }
899    
900                    return journalArticleResource;
901            }
902    
903            /**
904             * 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.
905             *
906             * @param uuid the uuid to search with
907             * @param groupId the group id to search with
908             * @return the matching journal article resource, or <code>null</code> if a matching journal article resource could not be found
909             * @throws SystemException if a system exception occurred
910             */
911            public JournalArticleResource fetchByUUID_G(String uuid, long groupId)
912                    throws SystemException {
913                    return fetchByUUID_G(uuid, groupId, true);
914            }
915    
916            /**
917             * 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.
918             *
919             * @param uuid the uuid to search with
920             * @param groupId the group id to search with
921             * @return the matching journal article resource, or <code>null</code> if a matching journal article resource could not be found
922             * @throws SystemException if a system exception occurred
923             */
924            public JournalArticleResource fetchByUUID_G(String uuid, long groupId,
925                    boolean retrieveFromCache) throws SystemException {
926                    Object[] finderArgs = new Object[] { uuid, groupId };
927    
928                    Object result = null;
929    
930                    if (retrieveFromCache) {
931                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
932                                            finderArgs, this);
933                    }
934    
935                    if (result == null) {
936                            Session session = null;
937    
938                            try {
939                                    session = openSession();
940    
941                                    StringBundler query = new StringBundler(3);
942    
943                                    query.append(_SQL_SELECT_JOURNALARTICLERESOURCE_WHERE);
944    
945                                    if (uuid == null) {
946                                            query.append(_FINDER_COLUMN_UUID_G_UUID_1);
947                                    }
948                                    else {
949                                            if (uuid.equals(StringPool.BLANK)) {
950                                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
951                                            }
952                                            else {
953                                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
954                                            }
955                                    }
956    
957                                    query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
958    
959                                    String sql = query.toString();
960    
961                                    Query q = session.createQuery(sql);
962    
963                                    QueryPos qPos = QueryPos.getInstance(q);
964    
965                                    if (uuid != null) {
966                                            qPos.add(uuid);
967                                    }
968    
969                                    qPos.add(groupId);
970    
971                                    List<JournalArticleResource> list = q.list();
972    
973                                    result = list;
974    
975                                    JournalArticleResource journalArticleResource = null;
976    
977                                    if (list.isEmpty()) {
978                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
979                                                    finderArgs, list);
980                                    }
981                                    else {
982                                            journalArticleResource = list.get(0);
983    
984                                            cacheResult(journalArticleResource);
985    
986                                            if ((journalArticleResource.getUuid() == null) ||
987                                                            !journalArticleResource.getUuid().equals(uuid) ||
988                                                            (journalArticleResource.getGroupId() != groupId)) {
989                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
990                                                            finderArgs, journalArticleResource);
991                                            }
992                                    }
993    
994                                    return journalArticleResource;
995                            }
996                            catch (Exception e) {
997                                    throw processException(e);
998                            }
999                            finally {
1000                                    if (result == null) {
1001                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1002                                                    finderArgs, new ArrayList<JournalArticleResource>());
1003                                    }
1004    
1005                                    closeSession(session);
1006                            }
1007                    }
1008                    else {
1009                            if (result instanceof List<?>) {
1010                                    return null;
1011                            }
1012                            else {
1013                                    return (JournalArticleResource)result;
1014                            }
1015                    }
1016            }
1017    
1018            /**
1019             * Finds all the journal article resources where groupId = &#63;.
1020             *
1021             * @param groupId the group id to search with
1022             * @return the matching journal article resources
1023             * @throws SystemException if a system exception occurred
1024             */
1025            public List<JournalArticleResource> findByGroupId(long groupId)
1026                    throws SystemException {
1027                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1028            }
1029    
1030            /**
1031             * Finds a range of all the journal article resources where groupId = &#63;.
1032             *
1033             * <p>
1034             * 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.
1035             * </p>
1036             *
1037             * @param groupId the group id to search with
1038             * @param start the lower bound of the range of journal article resources to return
1039             * @param end the upper bound of the range of journal article resources to return (not inclusive)
1040             * @return the range of matching journal article resources
1041             * @throws SystemException if a system exception occurred
1042             */
1043            public List<JournalArticleResource> findByGroupId(long groupId, int start,
1044                    int end) throws SystemException {
1045                    return findByGroupId(groupId, start, end, null);
1046            }
1047    
1048            /**
1049             * Finds an ordered range of all the journal article resources where groupId = &#63;.
1050             *
1051             * <p>
1052             * 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.
1053             * </p>
1054             *
1055             * @param groupId the group id to search with
1056             * @param start the lower bound of the range of journal article resources to return
1057             * @param end the upper bound of the range of journal article resources to return (not inclusive)
1058             * @param orderByComparator the comparator to order the results by
1059             * @return the ordered range of matching journal article resources
1060             * @throws SystemException if a system exception occurred
1061             */
1062            public List<JournalArticleResource> findByGroupId(long groupId, int start,
1063                    int end, OrderByComparator orderByComparator) throws SystemException {
1064                    Object[] finderArgs = new Object[] {
1065                                    groupId,
1066                                    
1067                                    String.valueOf(start), String.valueOf(end),
1068                                    String.valueOf(orderByComparator)
1069                            };
1070    
1071                    List<JournalArticleResource> list = (List<JournalArticleResource>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
1072                                    finderArgs, this);
1073    
1074                    if (list == null) {
1075                            Session session = null;
1076    
1077                            try {
1078                                    session = openSession();
1079    
1080                                    StringBundler query = null;
1081    
1082                                    if (orderByComparator != null) {
1083                                            query = new StringBundler(3 +
1084                                                            (orderByComparator.getOrderByFields().length * 3));
1085                                    }
1086                                    else {
1087                                            query = new StringBundler(2);
1088                                    }
1089    
1090                                    query.append(_SQL_SELECT_JOURNALARTICLERESOURCE_WHERE);
1091    
1092                                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1093    
1094                                    if (orderByComparator != null) {
1095                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1096                                                    orderByComparator);
1097                                    }
1098    
1099                                    String sql = query.toString();
1100    
1101                                    Query q = session.createQuery(sql);
1102    
1103                                    QueryPos qPos = QueryPos.getInstance(q);
1104    
1105                                    qPos.add(groupId);
1106    
1107                                    list = (List<JournalArticleResource>)QueryUtil.list(q,
1108                                                    getDialect(), start, end);
1109                            }
1110                            catch (Exception e) {
1111                                    throw processException(e);
1112                            }
1113                            finally {
1114                                    if (list == null) {
1115                                            list = new ArrayList<JournalArticleResource>();
1116                                    }
1117    
1118                                    cacheResult(list);
1119    
1120                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
1121                                            finderArgs, list);
1122    
1123                                    closeSession(session);
1124                            }
1125                    }
1126    
1127                    return list;
1128            }
1129    
1130            /**
1131             * Finds the first journal article resource in the ordered set where groupId = &#63;.
1132             *
1133             * <p>
1134             * 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.
1135             * </p>
1136             *
1137             * @param groupId the group id to search with
1138             * @param orderByComparator the comparator to order the set by
1139             * @return the first matching journal article resource
1140             * @throws com.liferay.portlet.journal.NoSuchArticleResourceException if a matching journal article resource could not be found
1141             * @throws SystemException if a system exception occurred
1142             */
1143            public JournalArticleResource findByGroupId_First(long groupId,
1144                    OrderByComparator orderByComparator)
1145                    throws NoSuchArticleResourceException, SystemException {
1146                    List<JournalArticleResource> list = findByGroupId(groupId, 0, 1,
1147                                    orderByComparator);
1148    
1149                    if (list.isEmpty()) {
1150                            StringBundler msg = new StringBundler(4);
1151    
1152                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1153    
1154                            msg.append("groupId=");
1155                            msg.append(groupId);
1156    
1157                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1158    
1159                            throw new NoSuchArticleResourceException(msg.toString());
1160                    }
1161                    else {
1162                            return list.get(0);
1163                    }
1164            }
1165    
1166            /**
1167             * Finds the last journal article resource in the ordered set where groupId = &#63;.
1168             *
1169             * <p>
1170             * 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.
1171             * </p>
1172             *
1173             * @param groupId the group id to search with
1174             * @param orderByComparator the comparator to order the set by
1175             * @return the last matching journal article resource
1176             * @throws com.liferay.portlet.journal.NoSuchArticleResourceException if a matching journal article resource could not be found
1177             * @throws SystemException if a system exception occurred
1178             */
1179            public JournalArticleResource findByGroupId_Last(long groupId,
1180                    OrderByComparator orderByComparator)
1181                    throws NoSuchArticleResourceException, SystemException {
1182                    int count = countByGroupId(groupId);
1183    
1184                    List<JournalArticleResource> list = findByGroupId(groupId, count - 1,
1185                                    count, orderByComparator);
1186    
1187                    if (list.isEmpty()) {
1188                            StringBundler msg = new StringBundler(4);
1189    
1190                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1191    
1192                            msg.append("groupId=");
1193                            msg.append(groupId);
1194    
1195                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1196    
1197                            throw new NoSuchArticleResourceException(msg.toString());
1198                    }
1199                    else {
1200                            return list.get(0);
1201                    }
1202            }
1203    
1204            /**
1205             * Finds the journal article resources before and after the current journal article resource in the ordered set where groupId = &#63;.
1206             *
1207             * <p>
1208             * 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.
1209             * </p>
1210             *
1211             * @param resourcePrimKey the primary key of the current journal article resource
1212             * @param groupId the group id to search with
1213             * @param orderByComparator the comparator to order the set by
1214             * @return the previous, current, and next journal article resource
1215             * @throws com.liferay.portlet.journal.NoSuchArticleResourceException if a journal article resource with the primary key could not be found
1216             * @throws SystemException if a system exception occurred
1217             */
1218            public JournalArticleResource[] findByGroupId_PrevAndNext(
1219                    long resourcePrimKey, long groupId, OrderByComparator orderByComparator)
1220                    throws NoSuchArticleResourceException, SystemException {
1221                    JournalArticleResource journalArticleResource = findByPrimaryKey(resourcePrimKey);
1222    
1223                    Session session = null;
1224    
1225                    try {
1226                            session = openSession();
1227    
1228                            JournalArticleResource[] array = new JournalArticleResourceImpl[3];
1229    
1230                            array[0] = getByGroupId_PrevAndNext(session,
1231                                            journalArticleResource, groupId, orderByComparator, true);
1232    
1233                            array[1] = journalArticleResource;
1234    
1235                            array[2] = getByGroupId_PrevAndNext(session,
1236                                            journalArticleResource, groupId, orderByComparator, false);
1237    
1238                            return array;
1239                    }
1240                    catch (Exception e) {
1241                            throw processException(e);
1242                    }
1243                    finally {
1244                            closeSession(session);
1245                    }
1246            }
1247    
1248            protected JournalArticleResource getByGroupId_PrevAndNext(Session session,
1249                    JournalArticleResource journalArticleResource, long groupId,
1250                    OrderByComparator orderByComparator, boolean previous) {
1251                    StringBundler query = null;
1252    
1253                    if (orderByComparator != null) {
1254                            query = new StringBundler(6 +
1255                                            (orderByComparator.getOrderByFields().length * 6));
1256                    }
1257                    else {
1258                            query = new StringBundler(3);
1259                    }
1260    
1261                    query.append(_SQL_SELECT_JOURNALARTICLERESOURCE_WHERE);
1262    
1263                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1264    
1265                    if (orderByComparator != null) {
1266                            String[] orderByFields = orderByComparator.getOrderByFields();
1267    
1268                            if (orderByFields.length > 0) {
1269                                    query.append(WHERE_AND);
1270                            }
1271    
1272                            for (int i = 0; i < orderByFields.length; i++) {
1273                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1274                                    query.append(orderByFields[i]);
1275    
1276                                    if ((i + 1) < orderByFields.length) {
1277                                            if (orderByComparator.isAscending() ^ previous) {
1278                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1279                                            }
1280                                            else {
1281                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1282                                            }
1283                                    }
1284                                    else {
1285                                            if (orderByComparator.isAscending() ^ previous) {
1286                                                    query.append(WHERE_GREATER_THAN);
1287                                            }
1288                                            else {
1289                                                    query.append(WHERE_LESSER_THAN);
1290                                            }
1291                                    }
1292                            }
1293    
1294                            query.append(ORDER_BY_CLAUSE);
1295    
1296                            for (int i = 0; i < orderByFields.length; i++) {
1297                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1298                                    query.append(orderByFields[i]);
1299    
1300                                    if ((i + 1) < orderByFields.length) {
1301                                            if (orderByComparator.isAscending() ^ previous) {
1302                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1303                                            }
1304                                            else {
1305                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1306                                            }
1307                                    }
1308                                    else {
1309                                            if (orderByComparator.isAscending() ^ previous) {
1310                                                    query.append(ORDER_BY_ASC);
1311                                            }
1312                                            else {
1313                                                    query.append(ORDER_BY_DESC);
1314                                            }
1315                                    }
1316                            }
1317                    }
1318    
1319                    String sql = query.toString();
1320    
1321                    Query q = session.createQuery(sql);
1322    
1323                    q.setFirstResult(0);
1324                    q.setMaxResults(2);
1325    
1326                    QueryPos qPos = QueryPos.getInstance(q);
1327    
1328                    qPos.add(groupId);
1329    
1330                    if (orderByComparator != null) {
1331                            Object[] values = orderByComparator.getOrderByValues(journalArticleResource);
1332    
1333                            for (Object value : values) {
1334                                    qPos.add(value);
1335                            }
1336                    }
1337    
1338                    List<JournalArticleResource> list = q.list();
1339    
1340                    if (list.size() == 2) {
1341                            return list.get(1);
1342                    }
1343                    else {
1344                            return null;
1345                    }
1346            }
1347    
1348            /**
1349             * 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.
1350             *
1351             * @param groupId the group id to search with
1352             * @param articleId the article id to search with
1353             * @return the matching journal article resource
1354             * @throws com.liferay.portlet.journal.NoSuchArticleResourceException if a matching journal article resource could not be found
1355             * @throws SystemException if a system exception occurred
1356             */
1357            public JournalArticleResource findByG_A(long groupId, String articleId)
1358                    throws NoSuchArticleResourceException, SystemException {
1359                    JournalArticleResource journalArticleResource = fetchByG_A(groupId,
1360                                    articleId);
1361    
1362                    if (journalArticleResource == null) {
1363                            StringBundler msg = new StringBundler(6);
1364    
1365                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1366    
1367                            msg.append("groupId=");
1368                            msg.append(groupId);
1369    
1370                            msg.append(", articleId=");
1371                            msg.append(articleId);
1372    
1373                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1374    
1375                            if (_log.isWarnEnabled()) {
1376                                    _log.warn(msg.toString());
1377                            }
1378    
1379                            throw new NoSuchArticleResourceException(msg.toString());
1380                    }
1381    
1382                    return journalArticleResource;
1383            }
1384    
1385            /**
1386             * 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.
1387             *
1388             * @param groupId the group id to search with
1389             * @param articleId the article id to search with
1390             * @return the matching journal article resource, or <code>null</code> if a matching journal article resource could not be found
1391             * @throws SystemException if a system exception occurred
1392             */
1393            public JournalArticleResource fetchByG_A(long groupId, String articleId)
1394                    throws SystemException {
1395                    return fetchByG_A(groupId, articleId, true);
1396            }
1397    
1398            /**
1399             * 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.
1400             *
1401             * @param groupId the group id to search with
1402             * @param articleId the article id to search with
1403             * @return the matching journal article resource, or <code>null</code> if a matching journal article resource could not be found
1404             * @throws SystemException if a system exception occurred
1405             */
1406            public JournalArticleResource fetchByG_A(long groupId, String articleId,
1407                    boolean retrieveFromCache) throws SystemException {
1408                    Object[] finderArgs = new Object[] { groupId, articleId };
1409    
1410                    Object result = null;
1411    
1412                    if (retrieveFromCache) {
1413                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_A,
1414                                            finderArgs, this);
1415                    }
1416    
1417                    if (result == null) {
1418                            Session session = null;
1419    
1420                            try {
1421                                    session = openSession();
1422    
1423                                    StringBundler query = new StringBundler(3);
1424    
1425                                    query.append(_SQL_SELECT_JOURNALARTICLERESOURCE_WHERE);
1426    
1427                                    query.append(_FINDER_COLUMN_G_A_GROUPID_2);
1428    
1429                                    if (articleId == null) {
1430                                            query.append(_FINDER_COLUMN_G_A_ARTICLEID_1);
1431                                    }
1432                                    else {
1433                                            if (articleId.equals(StringPool.BLANK)) {
1434                                                    query.append(_FINDER_COLUMN_G_A_ARTICLEID_3);
1435                                            }
1436                                            else {
1437                                                    query.append(_FINDER_COLUMN_G_A_ARTICLEID_2);
1438                                            }
1439                                    }
1440    
1441                                    String sql = query.toString();
1442    
1443                                    Query q = session.createQuery(sql);
1444    
1445                                    QueryPos qPos = QueryPos.getInstance(q);
1446    
1447                                    qPos.add(groupId);
1448    
1449                                    if (articleId != null) {
1450                                            qPos.add(articleId);
1451                                    }
1452    
1453                                    List<JournalArticleResource> list = q.list();
1454    
1455                                    result = list;
1456    
1457                                    JournalArticleResource journalArticleResource = null;
1458    
1459                                    if (list.isEmpty()) {
1460                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_A,
1461                                                    finderArgs, list);
1462                                    }
1463                                    else {
1464                                            journalArticleResource = list.get(0);
1465    
1466                                            cacheResult(journalArticleResource);
1467    
1468                                            if ((journalArticleResource.getGroupId() != groupId) ||
1469                                                            (journalArticleResource.getArticleId() == null) ||
1470                                                            !journalArticleResource.getArticleId()
1471                                                                                                               .equals(articleId)) {
1472                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_A,
1473                                                            finderArgs, journalArticleResource);
1474                                            }
1475                                    }
1476    
1477                                    return journalArticleResource;
1478                            }
1479                            catch (Exception e) {
1480                                    throw processException(e);
1481                            }
1482                            finally {
1483                                    if (result == null) {
1484                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_A,
1485                                                    finderArgs, new ArrayList<JournalArticleResource>());
1486                                    }
1487    
1488                                    closeSession(session);
1489                            }
1490                    }
1491                    else {
1492                            if (result instanceof List<?>) {
1493                                    return null;
1494                            }
1495                            else {
1496                                    return (JournalArticleResource)result;
1497                            }
1498                    }
1499            }
1500    
1501            /**
1502             * Finds all the journal article resources.
1503             *
1504             * @return the journal article resources
1505             * @throws SystemException if a system exception occurred
1506             */
1507            public List<JournalArticleResource> findAll() throws SystemException {
1508                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1509            }
1510    
1511            /**
1512             * Finds a range of all the journal article resources.
1513             *
1514             * <p>
1515             * 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.
1516             * </p>
1517             *
1518             * @param start the lower bound of the range of journal article resources to return
1519             * @param end the upper bound of the range of journal article resources to return (not inclusive)
1520             * @return the range of journal article resources
1521             * @throws SystemException if a system exception occurred
1522             */
1523            public List<JournalArticleResource> findAll(int start, int end)
1524                    throws SystemException {
1525                    return findAll(start, end, null);
1526            }
1527    
1528            /**
1529             * Finds an ordered range of all the journal article resources.
1530             *
1531             * <p>
1532             * 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.
1533             * </p>
1534             *
1535             * @param start the lower bound of the range of journal article resources to return
1536             * @param end the upper bound of the range of journal article resources to return (not inclusive)
1537             * @param orderByComparator the comparator to order the results by
1538             * @return the ordered range of journal article resources
1539             * @throws SystemException if a system exception occurred
1540             */
1541            public List<JournalArticleResource> findAll(int start, int end,
1542                    OrderByComparator orderByComparator) throws SystemException {
1543                    Object[] finderArgs = new Object[] {
1544                                    String.valueOf(start), String.valueOf(end),
1545                                    String.valueOf(orderByComparator)
1546                            };
1547    
1548                    List<JournalArticleResource> list = (List<JournalArticleResource>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1549                                    finderArgs, this);
1550    
1551                    if (list == null) {
1552                            Session session = null;
1553    
1554                            try {
1555                                    session = openSession();
1556    
1557                                    StringBundler query = null;
1558                                    String sql = null;
1559    
1560                                    if (orderByComparator != null) {
1561                                            query = new StringBundler(2 +
1562                                                            (orderByComparator.getOrderByFields().length * 3));
1563    
1564                                            query.append(_SQL_SELECT_JOURNALARTICLERESOURCE);
1565    
1566                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1567                                                    orderByComparator);
1568    
1569                                            sql = query.toString();
1570                                    }
1571                                    else {
1572                                            sql = _SQL_SELECT_JOURNALARTICLERESOURCE;
1573                                    }
1574    
1575                                    Query q = session.createQuery(sql);
1576    
1577                                    if (orderByComparator == null) {
1578                                            list = (List<JournalArticleResource>)QueryUtil.list(q,
1579                                                            getDialect(), start, end, false);
1580    
1581                                            Collections.sort(list);
1582                                    }
1583                                    else {
1584                                            list = (List<JournalArticleResource>)QueryUtil.list(q,
1585                                                            getDialect(), start, end);
1586                                    }
1587                            }
1588                            catch (Exception e) {
1589                                    throw processException(e);
1590                            }
1591                            finally {
1592                                    if (list == null) {
1593                                            list = new ArrayList<JournalArticleResource>();
1594                                    }
1595    
1596                                    cacheResult(list);
1597    
1598                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1599    
1600                                    closeSession(session);
1601                            }
1602                    }
1603    
1604                    return list;
1605            }
1606    
1607            /**
1608             * Removes all the journal article resources where uuid = &#63; from the database.
1609             *
1610             * @param uuid the uuid to search with
1611             * @throws SystemException if a system exception occurred
1612             */
1613            public void removeByUuid(String uuid) throws SystemException {
1614                    for (JournalArticleResource journalArticleResource : findByUuid(uuid)) {
1615                            remove(journalArticleResource);
1616                    }
1617            }
1618    
1619            /**
1620             * Removes the journal article resource where uuid = &#63; and groupId = &#63; from the database.
1621             *
1622             * @param uuid the uuid to search with
1623             * @param groupId the group id to search with
1624             * @throws SystemException if a system exception occurred
1625             */
1626            public void removeByUUID_G(String uuid, long groupId)
1627                    throws NoSuchArticleResourceException, SystemException {
1628                    JournalArticleResource journalArticleResource = findByUUID_G(uuid,
1629                                    groupId);
1630    
1631                    remove(journalArticleResource);
1632            }
1633    
1634            /**
1635             * Removes all the journal article resources where groupId = &#63; from the database.
1636             *
1637             * @param groupId the group id to search with
1638             * @throws SystemException if a system exception occurred
1639             */
1640            public void removeByGroupId(long groupId) throws SystemException {
1641                    for (JournalArticleResource journalArticleResource : findByGroupId(
1642                                    groupId)) {
1643                            remove(journalArticleResource);
1644                    }
1645            }
1646    
1647            /**
1648             * Removes the journal article resource where groupId = &#63; and articleId = &#63; from the database.
1649             *
1650             * @param groupId the group id to search with
1651             * @param articleId the article id to search with
1652             * @throws SystemException if a system exception occurred
1653             */
1654            public void removeByG_A(long groupId, String articleId)
1655                    throws NoSuchArticleResourceException, SystemException {
1656                    JournalArticleResource journalArticleResource = findByG_A(groupId,
1657                                    articleId);
1658    
1659                    remove(journalArticleResource);
1660            }
1661    
1662            /**
1663             * Removes all the journal article resources from the database.
1664             *
1665             * @throws SystemException if a system exception occurred
1666             */
1667            public void removeAll() throws SystemException {
1668                    for (JournalArticleResource journalArticleResource : findAll()) {
1669                            remove(journalArticleResource);
1670                    }
1671            }
1672    
1673            /**
1674             * Counts all the journal article resources where uuid = &#63;.
1675             *
1676             * @param uuid the uuid to search with
1677             * @return the number of matching journal article resources
1678             * @throws SystemException if a system exception occurred
1679             */
1680            public int countByUuid(String uuid) throws SystemException {
1681                    Object[] finderArgs = new Object[] { uuid };
1682    
1683                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
1684                                    finderArgs, this);
1685    
1686                    if (count == null) {
1687                            Session session = null;
1688    
1689                            try {
1690                                    session = openSession();
1691    
1692                                    StringBundler query = new StringBundler(2);
1693    
1694                                    query.append(_SQL_COUNT_JOURNALARTICLERESOURCE_WHERE);
1695    
1696                                    if (uuid == null) {
1697                                            query.append(_FINDER_COLUMN_UUID_UUID_1);
1698                                    }
1699                                    else {
1700                                            if (uuid.equals(StringPool.BLANK)) {
1701                                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
1702                                            }
1703                                            else {
1704                                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
1705                                            }
1706                                    }
1707    
1708                                    String sql = query.toString();
1709    
1710                                    Query q = session.createQuery(sql);
1711    
1712                                    QueryPos qPos = QueryPos.getInstance(q);
1713    
1714                                    if (uuid != null) {
1715                                            qPos.add(uuid);
1716                                    }
1717    
1718                                    count = (Long)q.uniqueResult();
1719                            }
1720                            catch (Exception e) {
1721                                    throw processException(e);
1722                            }
1723                            finally {
1724                                    if (count == null) {
1725                                            count = Long.valueOf(0);
1726                                    }
1727    
1728                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
1729                                            finderArgs, count);
1730    
1731                                    closeSession(session);
1732                            }
1733                    }
1734    
1735                    return count.intValue();
1736            }
1737    
1738            /**
1739             * Counts all the journal article resources where uuid = &#63; and groupId = &#63;.
1740             *
1741             * @param uuid the uuid to search with
1742             * @param groupId the group id to search with
1743             * @return the number of matching journal article resources
1744             * @throws SystemException if a system exception occurred
1745             */
1746            public int countByUUID_G(String uuid, long groupId)
1747                    throws SystemException {
1748                    Object[] finderArgs = new Object[] { uuid, groupId };
1749    
1750                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
1751                                    finderArgs, this);
1752    
1753                    if (count == null) {
1754                            Session session = null;
1755    
1756                            try {
1757                                    session = openSession();
1758    
1759                                    StringBundler query = new StringBundler(3);
1760    
1761                                    query.append(_SQL_COUNT_JOURNALARTICLERESOURCE_WHERE);
1762    
1763                                    if (uuid == null) {
1764                                            query.append(_FINDER_COLUMN_UUID_G_UUID_1);
1765                                    }
1766                                    else {
1767                                            if (uuid.equals(StringPool.BLANK)) {
1768                                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
1769                                            }
1770                                            else {
1771                                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
1772                                            }
1773                                    }
1774    
1775                                    query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
1776    
1777                                    String sql = query.toString();
1778    
1779                                    Query q = session.createQuery(sql);
1780    
1781                                    QueryPos qPos = QueryPos.getInstance(q);
1782    
1783                                    if (uuid != null) {
1784                                            qPos.add(uuid);
1785                                    }
1786    
1787                                    qPos.add(groupId);
1788    
1789                                    count = (Long)q.uniqueResult();
1790                            }
1791                            catch (Exception e) {
1792                                    throw processException(e);
1793                            }
1794                            finally {
1795                                    if (count == null) {
1796                                            count = Long.valueOf(0);
1797                                    }
1798    
1799                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
1800                                            finderArgs, count);
1801    
1802                                    closeSession(session);
1803                            }
1804                    }
1805    
1806                    return count.intValue();
1807            }
1808    
1809            /**
1810             * Counts all the journal article resources where groupId = &#63;.
1811             *
1812             * @param groupId the group id to search with
1813             * @return the number of matching journal article resources
1814             * @throws SystemException if a system exception occurred
1815             */
1816            public int countByGroupId(long groupId) throws SystemException {
1817                    Object[] finderArgs = new Object[] { groupId };
1818    
1819                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
1820                                    finderArgs, this);
1821    
1822                    if (count == null) {
1823                            Session session = null;
1824    
1825                            try {
1826                                    session = openSession();
1827    
1828                                    StringBundler query = new StringBundler(2);
1829    
1830                                    query.append(_SQL_COUNT_JOURNALARTICLERESOURCE_WHERE);
1831    
1832                                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1833    
1834                                    String sql = query.toString();
1835    
1836                                    Query q = session.createQuery(sql);
1837    
1838                                    QueryPos qPos = QueryPos.getInstance(q);
1839    
1840                                    qPos.add(groupId);
1841    
1842                                    count = (Long)q.uniqueResult();
1843                            }
1844                            catch (Exception e) {
1845                                    throw processException(e);
1846                            }
1847                            finally {
1848                                    if (count == null) {
1849                                            count = Long.valueOf(0);
1850                                    }
1851    
1852                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
1853                                            finderArgs, count);
1854    
1855                                    closeSession(session);
1856                            }
1857                    }
1858    
1859                    return count.intValue();
1860            }
1861    
1862            /**
1863             * Counts all the journal article resources where groupId = &#63; and articleId = &#63;.
1864             *
1865             * @param groupId the group id to search with
1866             * @param articleId the article id to search with
1867             * @return the number of matching journal article resources
1868             * @throws SystemException if a system exception occurred
1869             */
1870            public int countByG_A(long groupId, String articleId)
1871                    throws SystemException {
1872                    Object[] finderArgs = new Object[] { groupId, articleId };
1873    
1874                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_A,
1875                                    finderArgs, this);
1876    
1877                    if (count == null) {
1878                            Session session = null;
1879    
1880                            try {
1881                                    session = openSession();
1882    
1883                                    StringBundler query = new StringBundler(3);
1884    
1885                                    query.append(_SQL_COUNT_JOURNALARTICLERESOURCE_WHERE);
1886    
1887                                    query.append(_FINDER_COLUMN_G_A_GROUPID_2);
1888    
1889                                    if (articleId == null) {
1890                                            query.append(_FINDER_COLUMN_G_A_ARTICLEID_1);
1891                                    }
1892                                    else {
1893                                            if (articleId.equals(StringPool.BLANK)) {
1894                                                    query.append(_FINDER_COLUMN_G_A_ARTICLEID_3);
1895                                            }
1896                                            else {
1897                                                    query.append(_FINDER_COLUMN_G_A_ARTICLEID_2);
1898                                            }
1899                                    }
1900    
1901                                    String sql = query.toString();
1902    
1903                                    Query q = session.createQuery(sql);
1904    
1905                                    QueryPos qPos = QueryPos.getInstance(q);
1906    
1907                                    qPos.add(groupId);
1908    
1909                                    if (articleId != null) {
1910                                            qPos.add(articleId);
1911                                    }
1912    
1913                                    count = (Long)q.uniqueResult();
1914                            }
1915                            catch (Exception e) {
1916                                    throw processException(e);
1917                            }
1918                            finally {
1919                                    if (count == null) {
1920                                            count = Long.valueOf(0);
1921                                    }
1922    
1923                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_A, finderArgs,
1924                                            count);
1925    
1926                                    closeSession(session);
1927                            }
1928                    }
1929    
1930                    return count.intValue();
1931            }
1932    
1933            /**
1934             * Counts all the journal article resources.
1935             *
1936             * @return the number of journal article resources
1937             * @throws SystemException if a system exception occurred
1938             */
1939            public int countAll() throws SystemException {
1940                    Object[] finderArgs = new Object[0];
1941    
1942                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1943                                    finderArgs, this);
1944    
1945                    if (count == null) {
1946                            Session session = null;
1947    
1948                            try {
1949                                    session = openSession();
1950    
1951                                    Query q = session.createQuery(_SQL_COUNT_JOURNALARTICLERESOURCE);
1952    
1953                                    count = (Long)q.uniqueResult();
1954                            }
1955                            catch (Exception e) {
1956                                    throw processException(e);
1957                            }
1958                            finally {
1959                                    if (count == null) {
1960                                            count = Long.valueOf(0);
1961                                    }
1962    
1963                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1964                                            count);
1965    
1966                                    closeSession(session);
1967                            }
1968                    }
1969    
1970                    return count.intValue();
1971            }
1972    
1973            /**
1974             * Initializes the journal article resource persistence.
1975             */
1976            public void afterPropertiesSet() {
1977                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1978                                            com.liferay.portal.util.PropsUtil.get(
1979                                                    "value.object.listener.com.liferay.portlet.journal.model.JournalArticleResource")));
1980    
1981                    if (listenerClassNames.length > 0) {
1982                            try {
1983                                    List<ModelListener<JournalArticleResource>> listenersList = new ArrayList<ModelListener<JournalArticleResource>>();
1984    
1985                                    for (String listenerClassName : listenerClassNames) {
1986                                            listenersList.add((ModelListener<JournalArticleResource>)InstanceFactory.newInstance(
1987                                                            listenerClassName));
1988                                    }
1989    
1990                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1991                            }
1992                            catch (Exception e) {
1993                                    _log.error(e);
1994                            }
1995                    }
1996            }
1997    
1998            public void destroy() {
1999                    EntityCacheUtil.removeCache(JournalArticleResourceImpl.class.getName());
2000                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2001                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
2002            }
2003    
2004            @BeanReference(type = JournalArticlePersistence.class)
2005            protected JournalArticlePersistence journalArticlePersistence;
2006            @BeanReference(type = JournalArticleImagePersistence.class)
2007            protected JournalArticleImagePersistence journalArticleImagePersistence;
2008            @BeanReference(type = JournalArticleResourcePersistence.class)
2009            protected JournalArticleResourcePersistence journalArticleResourcePersistence;
2010            @BeanReference(type = JournalContentSearchPersistence.class)
2011            protected JournalContentSearchPersistence journalContentSearchPersistence;
2012            @BeanReference(type = JournalFeedPersistence.class)
2013            protected JournalFeedPersistence journalFeedPersistence;
2014            @BeanReference(type = JournalStructurePersistence.class)
2015            protected JournalStructurePersistence journalStructurePersistence;
2016            @BeanReference(type = JournalTemplatePersistence.class)
2017            protected JournalTemplatePersistence journalTemplatePersistence;
2018            @BeanReference(type = ResourcePersistence.class)
2019            protected ResourcePersistence resourcePersistence;
2020            @BeanReference(type = UserPersistence.class)
2021            protected UserPersistence userPersistence;
2022            private static final String _SQL_SELECT_JOURNALARTICLERESOURCE = "SELECT journalArticleResource FROM JournalArticleResource journalArticleResource";
2023            private static final String _SQL_SELECT_JOURNALARTICLERESOURCE_WHERE = "SELECT journalArticleResource FROM JournalArticleResource journalArticleResource WHERE ";
2024            private static final String _SQL_COUNT_JOURNALARTICLERESOURCE = "SELECT COUNT(journalArticleResource) FROM JournalArticleResource journalArticleResource";
2025            private static final String _SQL_COUNT_JOURNALARTICLERESOURCE_WHERE = "SELECT COUNT(journalArticleResource) FROM JournalArticleResource journalArticleResource WHERE ";
2026            private static final String _FINDER_COLUMN_UUID_UUID_1 = "journalArticleResource.uuid IS NULL";
2027            private static final String _FINDER_COLUMN_UUID_UUID_2 = "journalArticleResource.uuid = ?";
2028            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(journalArticleResource.uuid IS NULL OR journalArticleResource.uuid = ?)";
2029            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "journalArticleResource.uuid IS NULL AND ";
2030            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "journalArticleResource.uuid = ? AND ";
2031            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(journalArticleResource.uuid IS NULL OR journalArticleResource.uuid = ?) AND ";
2032            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "journalArticleResource.groupId = ?";
2033            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "journalArticleResource.groupId = ?";
2034            private static final String _FINDER_COLUMN_G_A_GROUPID_2 = "journalArticleResource.groupId = ? AND ";
2035            private static final String _FINDER_COLUMN_G_A_ARTICLEID_1 = "journalArticleResource.articleId IS NULL";
2036            private static final String _FINDER_COLUMN_G_A_ARTICLEID_2 = "journalArticleResource.articleId = ?";
2037            private static final String _FINDER_COLUMN_G_A_ARTICLEID_3 = "(journalArticleResource.articleId IS NULL OR journalArticleResource.articleId = ?)";
2038            private static final String _ORDER_BY_ENTITY_ALIAS = "journalArticleResource.";
2039            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No JournalArticleResource exists with the primary key ";
2040            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No JournalArticleResource exists with the key {";
2041            private static Log _log = LogFactoryUtil.getLog(JournalArticleResourcePersistenceImpl.class);
2042    }