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