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