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