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