001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.journal.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
019    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
020    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderPath;
022    import com.liferay.portal.kernel.dao.orm.Query;
023    import com.liferay.portal.kernel.dao.orm.QueryPos;
024    import com.liferay.portal.kernel.dao.orm.QueryUtil;
025    import com.liferay.portal.kernel.dao.orm.Session;
026    import com.liferay.portal.kernel.exception.SystemException;
027    import com.liferay.portal.kernel.log.Log;
028    import com.liferay.portal.kernel.log.LogFactoryUtil;
029    import com.liferay.portal.kernel.util.GetterUtil;
030    import com.liferay.portal.kernel.util.InstanceFactory;
031    import com.liferay.portal.kernel.util.OrderByComparator;
032    import com.liferay.portal.kernel.util.StringBundler;
033    import com.liferay.portal.kernel.util.StringPool;
034    import com.liferay.portal.kernel.util.StringUtil;
035    import com.liferay.portal.kernel.util.UnmodifiableList;
036    import com.liferay.portal.kernel.util.Validator;
037    import com.liferay.portal.model.CacheModel;
038    import com.liferay.portal.model.ModelListener;
039    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
040    
041    import com.liferay.portlet.journal.NoSuchArticleImageException;
042    import com.liferay.portlet.journal.model.JournalArticleImage;
043    import com.liferay.portlet.journal.model.impl.JournalArticleImageImpl;
044    import com.liferay.portlet.journal.model.impl.JournalArticleImageModelImpl;
045    
046    import java.io.Serializable;
047    
048    import java.util.ArrayList;
049    import java.util.Collections;
050    import java.util.List;
051    
052    /**
053     * The persistence implementation for the journal article image service.
054     *
055     * <p>
056     * Caching information and settings can be found in <code>portal.properties</code>
057     * </p>
058     *
059     * @author Brian Wing Shun Chan
060     * @see JournalArticleImagePersistence
061     * @see JournalArticleImageUtil
062     * @generated
063     */
064    public class JournalArticleImagePersistenceImpl extends BasePersistenceImpl<JournalArticleImage>
065            implements JournalArticleImagePersistence {
066            /*
067             * NOTE FOR DEVELOPERS:
068             *
069             * Never modify or reference this class directly. Always use {@link JournalArticleImageUtil} to access the journal article image persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
070             */
071            public static final String FINDER_CLASS_NAME_ENTITY = JournalArticleImageImpl.class.getName();
072            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
073                    ".List1";
074            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
075                    ".List2";
076            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(JournalArticleImageModelImpl.ENTITY_CACHE_ENABLED,
077                            JournalArticleImageModelImpl.FINDER_CACHE_ENABLED,
078                            JournalArticleImageImpl.class,
079                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
080            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(JournalArticleImageModelImpl.ENTITY_CACHE_ENABLED,
081                            JournalArticleImageModelImpl.FINDER_CACHE_ENABLED,
082                            JournalArticleImageImpl.class,
083                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
084            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(JournalArticleImageModelImpl.ENTITY_CACHE_ENABLED,
085                            JournalArticleImageModelImpl.FINDER_CACHE_ENABLED, Long.class,
086                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
087            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(JournalArticleImageModelImpl.ENTITY_CACHE_ENABLED,
088                            JournalArticleImageModelImpl.FINDER_CACHE_ENABLED,
089                            JournalArticleImageImpl.class,
090                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
091                            new String[] {
092                                    Long.class.getName(),
093                                    
094                            Integer.class.getName(), Integer.class.getName(),
095                                    OrderByComparator.class.getName()
096                            });
097            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
098                    new FinderPath(JournalArticleImageModelImpl.ENTITY_CACHE_ENABLED,
099                            JournalArticleImageModelImpl.FINDER_CACHE_ENABLED,
100                            JournalArticleImageImpl.class,
101                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
102                            new String[] { Long.class.getName() },
103                            JournalArticleImageModelImpl.GROUPID_COLUMN_BITMASK);
104            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(JournalArticleImageModelImpl.ENTITY_CACHE_ENABLED,
105                            JournalArticleImageModelImpl.FINDER_CACHE_ENABLED, Long.class,
106                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
107                            new String[] { Long.class.getName() });
108    
109            /**
110             * Returns all the journal article images where groupId = &#63;.
111             *
112             * @param groupId the group ID
113             * @return the matching journal article images
114             * @throws SystemException if a system exception occurred
115             */
116            public List<JournalArticleImage> findByGroupId(long groupId)
117                    throws SystemException {
118                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
119            }
120    
121            /**
122             * Returns a range of all the journal article images where groupId = &#63;.
123             *
124             * <p>
125             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleImageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
126             * </p>
127             *
128             * @param groupId the group ID
129             * @param start the lower bound of the range of journal article images
130             * @param end the upper bound of the range of journal article images (not inclusive)
131             * @return the range of matching journal article images
132             * @throws SystemException if a system exception occurred
133             */
134            public List<JournalArticleImage> findByGroupId(long groupId, int start,
135                    int end) throws SystemException {
136                    return findByGroupId(groupId, start, end, null);
137            }
138    
139            /**
140             * Returns an ordered range of all the journal article images where groupId = &#63;.
141             *
142             * <p>
143             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleImageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
144             * </p>
145             *
146             * @param groupId the group ID
147             * @param start the lower bound of the range of journal article images
148             * @param end the upper bound of the range of journal article images (not inclusive)
149             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
150             * @return the ordered range of matching journal article images
151             * @throws SystemException if a system exception occurred
152             */
153            public List<JournalArticleImage> findByGroupId(long groupId, int start,
154                    int end, OrderByComparator orderByComparator) throws SystemException {
155                    boolean pagination = true;
156                    FinderPath finderPath = null;
157                    Object[] finderArgs = null;
158    
159                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
160                                    (orderByComparator == null)) {
161                            pagination = false;
162                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
163                            finderArgs = new Object[] { groupId };
164                    }
165                    else {
166                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
167                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
168                    }
169    
170                    List<JournalArticleImage> list = (List<JournalArticleImage>)FinderCacheUtil.getResult(finderPath,
171                                    finderArgs, this);
172    
173                    if ((list != null) && !list.isEmpty()) {
174                            for (JournalArticleImage journalArticleImage : list) {
175                                    if ((groupId != journalArticleImage.getGroupId())) {
176                                            list = null;
177    
178                                            break;
179                                    }
180                            }
181                    }
182    
183                    if (list == null) {
184                            StringBundler query = null;
185    
186                            if (orderByComparator != null) {
187                                    query = new StringBundler(3 +
188                                                    (orderByComparator.getOrderByFields().length * 3));
189                            }
190                            else {
191                                    query = new StringBundler(3);
192                            }
193    
194                            query.append(_SQL_SELECT_JOURNALARTICLEIMAGE_WHERE);
195    
196                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
197    
198                            if (orderByComparator != null) {
199                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
200                                            orderByComparator);
201                            }
202                            else
203                             if (pagination) {
204                                    query.append(JournalArticleImageModelImpl.ORDER_BY_JPQL);
205                            }
206    
207                            String sql = query.toString();
208    
209                            Session session = null;
210    
211                            try {
212                                    session = openSession();
213    
214                                    Query q = session.createQuery(sql);
215    
216                                    QueryPos qPos = QueryPos.getInstance(q);
217    
218                                    qPos.add(groupId);
219    
220                                    if (!pagination) {
221                                            list = (List<JournalArticleImage>)QueryUtil.list(q,
222                                                            getDialect(), start, end, false);
223    
224                                            Collections.sort(list);
225    
226                                            list = new UnmodifiableList<JournalArticleImage>(list);
227                                    }
228                                    else {
229                                            list = (List<JournalArticleImage>)QueryUtil.list(q,
230                                                            getDialect(), start, end);
231                                    }
232    
233                                    cacheResult(list);
234    
235                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
236                            }
237                            catch (Exception e) {
238                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
239    
240                                    throw processException(e);
241                            }
242                            finally {
243                                    closeSession(session);
244                            }
245                    }
246    
247                    return list;
248            }
249    
250            /**
251             * Returns the first journal article image in the ordered set where groupId = &#63;.
252             *
253             * @param groupId the group ID
254             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
255             * @return the first matching journal article image
256             * @throws com.liferay.portlet.journal.NoSuchArticleImageException if a matching journal article image could not be found
257             * @throws SystemException if a system exception occurred
258             */
259            public JournalArticleImage findByGroupId_First(long groupId,
260                    OrderByComparator orderByComparator)
261                    throws NoSuchArticleImageException, SystemException {
262                    JournalArticleImage journalArticleImage = fetchByGroupId_First(groupId,
263                                    orderByComparator);
264    
265                    if (journalArticleImage != null) {
266                            return journalArticleImage;
267                    }
268    
269                    StringBundler msg = new StringBundler(4);
270    
271                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
272    
273                    msg.append("groupId=");
274                    msg.append(groupId);
275    
276                    msg.append(StringPool.CLOSE_CURLY_BRACE);
277    
278                    throw new NoSuchArticleImageException(msg.toString());
279            }
280    
281            /**
282             * Returns the first journal article image in the ordered set where groupId = &#63;.
283             *
284             * @param groupId the group ID
285             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
286             * @return the first matching journal article image, or <code>null</code> if a matching journal article image could not be found
287             * @throws SystemException if a system exception occurred
288             */
289            public JournalArticleImage fetchByGroupId_First(long groupId,
290                    OrderByComparator orderByComparator) throws SystemException {
291                    List<JournalArticleImage> list = findByGroupId(groupId, 0, 1,
292                                    orderByComparator);
293    
294                    if (!list.isEmpty()) {
295                            return list.get(0);
296                    }
297    
298                    return null;
299            }
300    
301            /**
302             * Returns the last journal article image in the ordered set where groupId = &#63;.
303             *
304             * @param groupId the group ID
305             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
306             * @return the last matching journal article image
307             * @throws com.liferay.portlet.journal.NoSuchArticleImageException if a matching journal article image could not be found
308             * @throws SystemException if a system exception occurred
309             */
310            public JournalArticleImage findByGroupId_Last(long groupId,
311                    OrderByComparator orderByComparator)
312                    throws NoSuchArticleImageException, SystemException {
313                    JournalArticleImage journalArticleImage = fetchByGroupId_Last(groupId,
314                                    orderByComparator);
315    
316                    if (journalArticleImage != null) {
317                            return journalArticleImage;
318                    }
319    
320                    StringBundler msg = new StringBundler(4);
321    
322                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
323    
324                    msg.append("groupId=");
325                    msg.append(groupId);
326    
327                    msg.append(StringPool.CLOSE_CURLY_BRACE);
328    
329                    throw new NoSuchArticleImageException(msg.toString());
330            }
331    
332            /**
333             * Returns the last journal article image in the ordered set where groupId = &#63;.
334             *
335             * @param groupId the group ID
336             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
337             * @return the last matching journal article image, or <code>null</code> if a matching journal article image could not be found
338             * @throws SystemException if a system exception occurred
339             */
340            public JournalArticleImage fetchByGroupId_Last(long groupId,
341                    OrderByComparator orderByComparator) throws SystemException {
342                    int count = countByGroupId(groupId);
343    
344                    List<JournalArticleImage> list = findByGroupId(groupId, count - 1,
345                                    count, orderByComparator);
346    
347                    if (!list.isEmpty()) {
348                            return list.get(0);
349                    }
350    
351                    return null;
352            }
353    
354            /**
355             * Returns the journal article images before and after the current journal article image in the ordered set where groupId = &#63;.
356             *
357             * @param articleImageId the primary key of the current journal article image
358             * @param groupId the group ID
359             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
360             * @return the previous, current, and next journal article image
361             * @throws com.liferay.portlet.journal.NoSuchArticleImageException if a journal article image with the primary key could not be found
362             * @throws SystemException if a system exception occurred
363             */
364            public JournalArticleImage[] findByGroupId_PrevAndNext(
365                    long articleImageId, long groupId, OrderByComparator orderByComparator)
366                    throws NoSuchArticleImageException, SystemException {
367                    JournalArticleImage journalArticleImage = findByPrimaryKey(articleImageId);
368    
369                    Session session = null;
370    
371                    try {
372                            session = openSession();
373    
374                            JournalArticleImage[] array = new JournalArticleImageImpl[3];
375    
376                            array[0] = getByGroupId_PrevAndNext(session, journalArticleImage,
377                                            groupId, orderByComparator, true);
378    
379                            array[1] = journalArticleImage;
380    
381                            array[2] = getByGroupId_PrevAndNext(session, journalArticleImage,
382                                            groupId, orderByComparator, false);
383    
384                            return array;
385                    }
386                    catch (Exception e) {
387                            throw processException(e);
388                    }
389                    finally {
390                            closeSession(session);
391                    }
392            }
393    
394            protected JournalArticleImage getByGroupId_PrevAndNext(Session session,
395                    JournalArticleImage journalArticleImage, long groupId,
396                    OrderByComparator orderByComparator, boolean previous) {
397                    StringBundler query = null;
398    
399                    if (orderByComparator != null) {
400                            query = new StringBundler(6 +
401                                            (orderByComparator.getOrderByFields().length * 6));
402                    }
403                    else {
404                            query = new StringBundler(3);
405                    }
406    
407                    query.append(_SQL_SELECT_JOURNALARTICLEIMAGE_WHERE);
408    
409                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
410    
411                    if (orderByComparator != null) {
412                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
413    
414                            if (orderByConditionFields.length > 0) {
415                                    query.append(WHERE_AND);
416                            }
417    
418                            for (int i = 0; i < orderByConditionFields.length; i++) {
419                                    query.append(_ORDER_BY_ENTITY_ALIAS);
420                                    query.append(orderByConditionFields[i]);
421    
422                                    if ((i + 1) < orderByConditionFields.length) {
423                                            if (orderByComparator.isAscending() ^ previous) {
424                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
425                                            }
426                                            else {
427                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
428                                            }
429                                    }
430                                    else {
431                                            if (orderByComparator.isAscending() ^ previous) {
432                                                    query.append(WHERE_GREATER_THAN);
433                                            }
434                                            else {
435                                                    query.append(WHERE_LESSER_THAN);
436                                            }
437                                    }
438                            }
439    
440                            query.append(ORDER_BY_CLAUSE);
441    
442                            String[] orderByFields = orderByComparator.getOrderByFields();
443    
444                            for (int i = 0; i < orderByFields.length; i++) {
445                                    query.append(_ORDER_BY_ENTITY_ALIAS);
446                                    query.append(orderByFields[i]);
447    
448                                    if ((i + 1) < orderByFields.length) {
449                                            if (orderByComparator.isAscending() ^ previous) {
450                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
451                                            }
452                                            else {
453                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
454                                            }
455                                    }
456                                    else {
457                                            if (orderByComparator.isAscending() ^ previous) {
458                                                    query.append(ORDER_BY_ASC);
459                                            }
460                                            else {
461                                                    query.append(ORDER_BY_DESC);
462                                            }
463                                    }
464                            }
465                    }
466                    else {
467                            query.append(JournalArticleImageModelImpl.ORDER_BY_JPQL);
468                    }
469    
470                    String sql = query.toString();
471    
472                    Query q = session.createQuery(sql);
473    
474                    q.setFirstResult(0);
475                    q.setMaxResults(2);
476    
477                    QueryPos qPos = QueryPos.getInstance(q);
478    
479                    qPos.add(groupId);
480    
481                    if (orderByComparator != null) {
482                            Object[] values = orderByComparator.getOrderByConditionValues(journalArticleImage);
483    
484                            for (Object value : values) {
485                                    qPos.add(value);
486                            }
487                    }
488    
489                    List<JournalArticleImage> list = q.list();
490    
491                    if (list.size() == 2) {
492                            return list.get(1);
493                    }
494                    else {
495                            return null;
496                    }
497            }
498    
499            /**
500             * Removes all the journal article images where groupId = &#63; from the database.
501             *
502             * @param groupId the group ID
503             * @throws SystemException if a system exception occurred
504             */
505            public void removeByGroupId(long groupId) throws SystemException {
506                    for (JournalArticleImage journalArticleImage : findByGroupId(groupId,
507                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
508                            remove(journalArticleImage);
509                    }
510            }
511    
512            /**
513             * Returns the number of journal article images where groupId = &#63;.
514             *
515             * @param groupId the group ID
516             * @return the number of matching journal article images
517             * @throws SystemException if a system exception occurred
518             */
519            public int countByGroupId(long groupId) throws SystemException {
520                    FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
521    
522                    Object[] finderArgs = new Object[] { groupId };
523    
524                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
525                                    this);
526    
527                    if (count == null) {
528                            StringBundler query = new StringBundler(2);
529    
530                            query.append(_SQL_COUNT_JOURNALARTICLEIMAGE_WHERE);
531    
532                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
533    
534                            String sql = query.toString();
535    
536                            Session session = null;
537    
538                            try {
539                                    session = openSession();
540    
541                                    Query q = session.createQuery(sql);
542    
543                                    QueryPos qPos = QueryPos.getInstance(q);
544    
545                                    qPos.add(groupId);
546    
547                                    count = (Long)q.uniqueResult();
548    
549                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
550                            }
551                            catch (Exception e) {
552                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
553    
554                                    throw processException(e);
555                            }
556                            finally {
557                                    closeSession(session);
558                            }
559                    }
560    
561                    return count.intValue();
562            }
563    
564            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "journalArticleImage.groupId = ?";
565            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_TEMPIMAGE =
566                    new FinderPath(JournalArticleImageModelImpl.ENTITY_CACHE_ENABLED,
567                            JournalArticleImageModelImpl.FINDER_CACHE_ENABLED,
568                            JournalArticleImageImpl.class,
569                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByTempImage",
570                            new String[] {
571                                    Boolean.class.getName(),
572                                    
573                            Integer.class.getName(), Integer.class.getName(),
574                                    OrderByComparator.class.getName()
575                            });
576            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TEMPIMAGE =
577                    new FinderPath(JournalArticleImageModelImpl.ENTITY_CACHE_ENABLED,
578                            JournalArticleImageModelImpl.FINDER_CACHE_ENABLED,
579                            JournalArticleImageImpl.class,
580                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByTempImage",
581                            new String[] { Boolean.class.getName() },
582                            JournalArticleImageModelImpl.TEMPIMAGE_COLUMN_BITMASK);
583            public static final FinderPath FINDER_PATH_COUNT_BY_TEMPIMAGE = new FinderPath(JournalArticleImageModelImpl.ENTITY_CACHE_ENABLED,
584                            JournalArticleImageModelImpl.FINDER_CACHE_ENABLED, Long.class,
585                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByTempImage",
586                            new String[] { Boolean.class.getName() });
587    
588            /**
589             * Returns all the journal article images where tempImage = &#63;.
590             *
591             * @param tempImage the temp image
592             * @return the matching journal article images
593             * @throws SystemException if a system exception occurred
594             */
595            public List<JournalArticleImage> findByTempImage(boolean tempImage)
596                    throws SystemException {
597                    return findByTempImage(tempImage, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
598                            null);
599            }
600    
601            /**
602             * Returns a range of all the journal article images where tempImage = &#63;.
603             *
604             * <p>
605             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleImageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
606             * </p>
607             *
608             * @param tempImage the temp image
609             * @param start the lower bound of the range of journal article images
610             * @param end the upper bound of the range of journal article images (not inclusive)
611             * @return the range of matching journal article images
612             * @throws SystemException if a system exception occurred
613             */
614            public List<JournalArticleImage> findByTempImage(boolean tempImage,
615                    int start, int end) throws SystemException {
616                    return findByTempImage(tempImage, start, end, null);
617            }
618    
619            /**
620             * Returns an ordered range of all the journal article images where tempImage = &#63;.
621             *
622             * <p>
623             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleImageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
624             * </p>
625             *
626             * @param tempImage the temp image
627             * @param start the lower bound of the range of journal article images
628             * @param end the upper bound of the range of journal article images (not inclusive)
629             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
630             * @return the ordered range of matching journal article images
631             * @throws SystemException if a system exception occurred
632             */
633            public List<JournalArticleImage> findByTempImage(boolean tempImage,
634                    int start, int end, OrderByComparator orderByComparator)
635                    throws SystemException {
636                    boolean pagination = true;
637                    FinderPath finderPath = null;
638                    Object[] finderArgs = null;
639    
640                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
641                                    (orderByComparator == null)) {
642                            pagination = false;
643                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TEMPIMAGE;
644                            finderArgs = new Object[] { tempImage };
645                    }
646                    else {
647                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_TEMPIMAGE;
648                            finderArgs = new Object[] { tempImage, start, end, orderByComparator };
649                    }
650    
651                    List<JournalArticleImage> list = (List<JournalArticleImage>)FinderCacheUtil.getResult(finderPath,
652                                    finderArgs, this);
653    
654                    if ((list != null) && !list.isEmpty()) {
655                            for (JournalArticleImage journalArticleImage : list) {
656                                    if ((tempImage != journalArticleImage.getTempImage())) {
657                                            list = null;
658    
659                                            break;
660                                    }
661                            }
662                    }
663    
664                    if (list == null) {
665                            StringBundler query = null;
666    
667                            if (orderByComparator != null) {
668                                    query = new StringBundler(3 +
669                                                    (orderByComparator.getOrderByFields().length * 3));
670                            }
671                            else {
672                                    query = new StringBundler(3);
673                            }
674    
675                            query.append(_SQL_SELECT_JOURNALARTICLEIMAGE_WHERE);
676    
677                            query.append(_FINDER_COLUMN_TEMPIMAGE_TEMPIMAGE_2);
678    
679                            if (orderByComparator != null) {
680                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
681                                            orderByComparator);
682                            }
683                            else
684                             if (pagination) {
685                                    query.append(JournalArticleImageModelImpl.ORDER_BY_JPQL);
686                            }
687    
688                            String sql = query.toString();
689    
690                            Session session = null;
691    
692                            try {
693                                    session = openSession();
694    
695                                    Query q = session.createQuery(sql);
696    
697                                    QueryPos qPos = QueryPos.getInstance(q);
698    
699                                    qPos.add(tempImage);
700    
701                                    if (!pagination) {
702                                            list = (List<JournalArticleImage>)QueryUtil.list(q,
703                                                            getDialect(), start, end, false);
704    
705                                            Collections.sort(list);
706    
707                                            list = new UnmodifiableList<JournalArticleImage>(list);
708                                    }
709                                    else {
710                                            list = (List<JournalArticleImage>)QueryUtil.list(q,
711                                                            getDialect(), start, end);
712                                    }
713    
714                                    cacheResult(list);
715    
716                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
717                            }
718                            catch (Exception e) {
719                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
720    
721                                    throw processException(e);
722                            }
723                            finally {
724                                    closeSession(session);
725                            }
726                    }
727    
728                    return list;
729            }
730    
731            /**
732             * Returns the first journal article image in the ordered set where tempImage = &#63;.
733             *
734             * @param tempImage the temp image
735             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
736             * @return the first matching journal article image
737             * @throws com.liferay.portlet.journal.NoSuchArticleImageException if a matching journal article image could not be found
738             * @throws SystemException if a system exception occurred
739             */
740            public JournalArticleImage findByTempImage_First(boolean tempImage,
741                    OrderByComparator orderByComparator)
742                    throws NoSuchArticleImageException, SystemException {
743                    JournalArticleImage journalArticleImage = fetchByTempImage_First(tempImage,
744                                    orderByComparator);
745    
746                    if (journalArticleImage != null) {
747                            return journalArticleImage;
748                    }
749    
750                    StringBundler msg = new StringBundler(4);
751    
752                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
753    
754                    msg.append("tempImage=");
755                    msg.append(tempImage);
756    
757                    msg.append(StringPool.CLOSE_CURLY_BRACE);
758    
759                    throw new NoSuchArticleImageException(msg.toString());
760            }
761    
762            /**
763             * Returns the first journal article image in the ordered set where tempImage = &#63;.
764             *
765             * @param tempImage the temp image
766             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
767             * @return the first matching journal article image, or <code>null</code> if a matching journal article image could not be found
768             * @throws SystemException if a system exception occurred
769             */
770            public JournalArticleImage fetchByTempImage_First(boolean tempImage,
771                    OrderByComparator orderByComparator) throws SystemException {
772                    List<JournalArticleImage> list = findByTempImage(tempImage, 0, 1,
773                                    orderByComparator);
774    
775                    if (!list.isEmpty()) {
776                            return list.get(0);
777                    }
778    
779                    return null;
780            }
781    
782            /**
783             * Returns the last journal article image in the ordered set where tempImage = &#63;.
784             *
785             * @param tempImage the temp image
786             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
787             * @return the last matching journal article image
788             * @throws com.liferay.portlet.journal.NoSuchArticleImageException if a matching journal article image could not be found
789             * @throws SystemException if a system exception occurred
790             */
791            public JournalArticleImage findByTempImage_Last(boolean tempImage,
792                    OrderByComparator orderByComparator)
793                    throws NoSuchArticleImageException, SystemException {
794                    JournalArticleImage journalArticleImage = fetchByTempImage_Last(tempImage,
795                                    orderByComparator);
796    
797                    if (journalArticleImage != null) {
798                            return journalArticleImage;
799                    }
800    
801                    StringBundler msg = new StringBundler(4);
802    
803                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
804    
805                    msg.append("tempImage=");
806                    msg.append(tempImage);
807    
808                    msg.append(StringPool.CLOSE_CURLY_BRACE);
809    
810                    throw new NoSuchArticleImageException(msg.toString());
811            }
812    
813            /**
814             * Returns the last journal article image in the ordered set where tempImage = &#63;.
815             *
816             * @param tempImage the temp image
817             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
818             * @return the last matching journal article image, or <code>null</code> if a matching journal article image could not be found
819             * @throws SystemException if a system exception occurred
820             */
821            public JournalArticleImage fetchByTempImage_Last(boolean tempImage,
822                    OrderByComparator orderByComparator) throws SystemException {
823                    int count = countByTempImage(tempImage);
824    
825                    List<JournalArticleImage> list = findByTempImage(tempImage, count - 1,
826                                    count, orderByComparator);
827    
828                    if (!list.isEmpty()) {
829                            return list.get(0);
830                    }
831    
832                    return null;
833            }
834    
835            /**
836             * Returns the journal article images before and after the current journal article image in the ordered set where tempImage = &#63;.
837             *
838             * @param articleImageId the primary key of the current journal article image
839             * @param tempImage the temp image
840             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
841             * @return the previous, current, and next journal article image
842             * @throws com.liferay.portlet.journal.NoSuchArticleImageException if a journal article image with the primary key could not be found
843             * @throws SystemException if a system exception occurred
844             */
845            public JournalArticleImage[] findByTempImage_PrevAndNext(
846                    long articleImageId, boolean tempImage,
847                    OrderByComparator orderByComparator)
848                    throws NoSuchArticleImageException, SystemException {
849                    JournalArticleImage journalArticleImage = findByPrimaryKey(articleImageId);
850    
851                    Session session = null;
852    
853                    try {
854                            session = openSession();
855    
856                            JournalArticleImage[] array = new JournalArticleImageImpl[3];
857    
858                            array[0] = getByTempImage_PrevAndNext(session, journalArticleImage,
859                                            tempImage, orderByComparator, true);
860    
861                            array[1] = journalArticleImage;
862    
863                            array[2] = getByTempImage_PrevAndNext(session, journalArticleImage,
864                                            tempImage, orderByComparator, false);
865    
866                            return array;
867                    }
868                    catch (Exception e) {
869                            throw processException(e);
870                    }
871                    finally {
872                            closeSession(session);
873                    }
874            }
875    
876            protected JournalArticleImage getByTempImage_PrevAndNext(Session session,
877                    JournalArticleImage journalArticleImage, boolean tempImage,
878                    OrderByComparator orderByComparator, boolean previous) {
879                    StringBundler query = null;
880    
881                    if (orderByComparator != null) {
882                            query = new StringBundler(6 +
883                                            (orderByComparator.getOrderByFields().length * 6));
884                    }
885                    else {
886                            query = new StringBundler(3);
887                    }
888    
889                    query.append(_SQL_SELECT_JOURNALARTICLEIMAGE_WHERE);
890    
891                    query.append(_FINDER_COLUMN_TEMPIMAGE_TEMPIMAGE_2);
892    
893                    if (orderByComparator != null) {
894                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
895    
896                            if (orderByConditionFields.length > 0) {
897                                    query.append(WHERE_AND);
898                            }
899    
900                            for (int i = 0; i < orderByConditionFields.length; i++) {
901                                    query.append(_ORDER_BY_ENTITY_ALIAS);
902                                    query.append(orderByConditionFields[i]);
903    
904                                    if ((i + 1) < orderByConditionFields.length) {
905                                            if (orderByComparator.isAscending() ^ previous) {
906                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
907                                            }
908                                            else {
909                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
910                                            }
911                                    }
912                                    else {
913                                            if (orderByComparator.isAscending() ^ previous) {
914                                                    query.append(WHERE_GREATER_THAN);
915                                            }
916                                            else {
917                                                    query.append(WHERE_LESSER_THAN);
918                                            }
919                                    }
920                            }
921    
922                            query.append(ORDER_BY_CLAUSE);
923    
924                            String[] orderByFields = orderByComparator.getOrderByFields();
925    
926                            for (int i = 0; i < orderByFields.length; i++) {
927                                    query.append(_ORDER_BY_ENTITY_ALIAS);
928                                    query.append(orderByFields[i]);
929    
930                                    if ((i + 1) < orderByFields.length) {
931                                            if (orderByComparator.isAscending() ^ previous) {
932                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
933                                            }
934                                            else {
935                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
936                                            }
937                                    }
938                                    else {
939                                            if (orderByComparator.isAscending() ^ previous) {
940                                                    query.append(ORDER_BY_ASC);
941                                            }
942                                            else {
943                                                    query.append(ORDER_BY_DESC);
944                                            }
945                                    }
946                            }
947                    }
948                    else {
949                            query.append(JournalArticleImageModelImpl.ORDER_BY_JPQL);
950                    }
951    
952                    String sql = query.toString();
953    
954                    Query q = session.createQuery(sql);
955    
956                    q.setFirstResult(0);
957                    q.setMaxResults(2);
958    
959                    QueryPos qPos = QueryPos.getInstance(q);
960    
961                    qPos.add(tempImage);
962    
963                    if (orderByComparator != null) {
964                            Object[] values = orderByComparator.getOrderByConditionValues(journalArticleImage);
965    
966                            for (Object value : values) {
967                                    qPos.add(value);
968                            }
969                    }
970    
971                    List<JournalArticleImage> list = q.list();
972    
973                    if (list.size() == 2) {
974                            return list.get(1);
975                    }
976                    else {
977                            return null;
978                    }
979            }
980    
981            /**
982             * Removes all the journal article images where tempImage = &#63; from the database.
983             *
984             * @param tempImage the temp image
985             * @throws SystemException if a system exception occurred
986             */
987            public void removeByTempImage(boolean tempImage) throws SystemException {
988                    for (JournalArticleImage journalArticleImage : findByTempImage(
989                                    tempImage, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
990                            remove(journalArticleImage);
991                    }
992            }
993    
994            /**
995             * Returns the number of journal article images where tempImage = &#63;.
996             *
997             * @param tempImage the temp image
998             * @return the number of matching journal article images
999             * @throws SystemException if a system exception occurred
1000             */
1001            public int countByTempImage(boolean tempImage) throws SystemException {
1002                    FinderPath finderPath = FINDER_PATH_COUNT_BY_TEMPIMAGE;
1003    
1004                    Object[] finderArgs = new Object[] { tempImage };
1005    
1006                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1007                                    this);
1008    
1009                    if (count == null) {
1010                            StringBundler query = new StringBundler(2);
1011    
1012                            query.append(_SQL_COUNT_JOURNALARTICLEIMAGE_WHERE);
1013    
1014                            query.append(_FINDER_COLUMN_TEMPIMAGE_TEMPIMAGE_2);
1015    
1016                            String sql = query.toString();
1017    
1018                            Session session = null;
1019    
1020                            try {
1021                                    session = openSession();
1022    
1023                                    Query q = session.createQuery(sql);
1024    
1025                                    QueryPos qPos = QueryPos.getInstance(q);
1026    
1027                                    qPos.add(tempImage);
1028    
1029                                    count = (Long)q.uniqueResult();
1030    
1031                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1032                            }
1033                            catch (Exception e) {
1034                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1035    
1036                                    throw processException(e);
1037                            }
1038                            finally {
1039                                    closeSession(session);
1040                            }
1041                    }
1042    
1043                    return count.intValue();
1044            }
1045    
1046            private static final String _FINDER_COLUMN_TEMPIMAGE_TEMPIMAGE_2 = "journalArticleImage.tempImage = ?";
1047            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_A_V = new FinderPath(JournalArticleImageModelImpl.ENTITY_CACHE_ENABLED,
1048                            JournalArticleImageModelImpl.FINDER_CACHE_ENABLED,
1049                            JournalArticleImageImpl.class,
1050                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_A_V",
1051                            new String[] {
1052                                    Long.class.getName(), String.class.getName(),
1053                                    Double.class.getName(),
1054                                    
1055                            Integer.class.getName(), Integer.class.getName(),
1056                                    OrderByComparator.class.getName()
1057                            });
1058            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_A_V = new FinderPath(JournalArticleImageModelImpl.ENTITY_CACHE_ENABLED,
1059                            JournalArticleImageModelImpl.FINDER_CACHE_ENABLED,
1060                            JournalArticleImageImpl.class,
1061                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_A_V",
1062                            new String[] {
1063                                    Long.class.getName(), String.class.getName(),
1064                                    Double.class.getName()
1065                            },
1066                            JournalArticleImageModelImpl.GROUPID_COLUMN_BITMASK |
1067                            JournalArticleImageModelImpl.ARTICLEID_COLUMN_BITMASK |
1068                            JournalArticleImageModelImpl.VERSION_COLUMN_BITMASK);
1069            public static final FinderPath FINDER_PATH_COUNT_BY_G_A_V = new FinderPath(JournalArticleImageModelImpl.ENTITY_CACHE_ENABLED,
1070                            JournalArticleImageModelImpl.FINDER_CACHE_ENABLED, Long.class,
1071                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_A_V",
1072                            new String[] {
1073                                    Long.class.getName(), String.class.getName(),
1074                                    Double.class.getName()
1075                            });
1076    
1077            /**
1078             * Returns all the journal article images where groupId = &#63; and articleId = &#63; and version = &#63;.
1079             *
1080             * @param groupId the group ID
1081             * @param articleId the article ID
1082             * @param version the version
1083             * @return the matching journal article images
1084             * @throws SystemException if a system exception occurred
1085             */
1086            public List<JournalArticleImage> findByG_A_V(long groupId,
1087                    String articleId, double version) throws SystemException {
1088                    return findByG_A_V(groupId, articleId, version, QueryUtil.ALL_POS,
1089                            QueryUtil.ALL_POS, null);
1090            }
1091    
1092            /**
1093             * Returns a range of all the journal article images where groupId = &#63; and articleId = &#63; and version = &#63;.
1094             *
1095             * <p>
1096             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleImageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1097             * </p>
1098             *
1099             * @param groupId the group ID
1100             * @param articleId the article ID
1101             * @param version the version
1102             * @param start the lower bound of the range of journal article images
1103             * @param end the upper bound of the range of journal article images (not inclusive)
1104             * @return the range of matching journal article images
1105             * @throws SystemException if a system exception occurred
1106             */
1107            public List<JournalArticleImage> findByG_A_V(long groupId,
1108                    String articleId, double version, int start, int end)
1109                    throws SystemException {
1110                    return findByG_A_V(groupId, articleId, version, start, end, null);
1111            }
1112    
1113            /**
1114             * Returns an ordered range of all the journal article images where groupId = &#63; and articleId = &#63; and version = &#63;.
1115             *
1116             * <p>
1117             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleImageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1118             * </p>
1119             *
1120             * @param groupId the group ID
1121             * @param articleId the article ID
1122             * @param version the version
1123             * @param start the lower bound of the range of journal article images
1124             * @param end the upper bound of the range of journal article images (not inclusive)
1125             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1126             * @return the ordered range of matching journal article images
1127             * @throws SystemException if a system exception occurred
1128             */
1129            public List<JournalArticleImage> findByG_A_V(long groupId,
1130                    String articleId, double version, int start, int end,
1131                    OrderByComparator orderByComparator) throws SystemException {
1132                    boolean pagination = true;
1133                    FinderPath finderPath = null;
1134                    Object[] finderArgs = null;
1135    
1136                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1137                                    (orderByComparator == null)) {
1138                            pagination = false;
1139                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_A_V;
1140                            finderArgs = new Object[] { groupId, articleId, version };
1141                    }
1142                    else {
1143                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_A_V;
1144                            finderArgs = new Object[] {
1145                                            groupId, articleId, version,
1146                                            
1147                                            start, end, orderByComparator
1148                                    };
1149                    }
1150    
1151                    List<JournalArticleImage> list = (List<JournalArticleImage>)FinderCacheUtil.getResult(finderPath,
1152                                    finderArgs, this);
1153    
1154                    if ((list != null) && !list.isEmpty()) {
1155                            for (JournalArticleImage journalArticleImage : list) {
1156                                    if ((groupId != journalArticleImage.getGroupId()) ||
1157                                                    !Validator.equals(articleId,
1158                                                            journalArticleImage.getArticleId()) ||
1159                                                    (version != journalArticleImage.getVersion())) {
1160                                            list = null;
1161    
1162                                            break;
1163                                    }
1164                            }
1165                    }
1166    
1167                    if (list == null) {
1168                            StringBundler query = null;
1169    
1170                            if (orderByComparator != null) {
1171                                    query = new StringBundler(5 +
1172                                                    (orderByComparator.getOrderByFields().length * 3));
1173                            }
1174                            else {
1175                                    query = new StringBundler(5);
1176                            }
1177    
1178                            query.append(_SQL_SELECT_JOURNALARTICLEIMAGE_WHERE);
1179    
1180                            query.append(_FINDER_COLUMN_G_A_V_GROUPID_2);
1181    
1182                            if (articleId == null) {
1183                                    query.append(_FINDER_COLUMN_G_A_V_ARTICLEID_1);
1184                            }
1185                            else {
1186                                    if (articleId.equals(StringPool.BLANK)) {
1187                                            query.append(_FINDER_COLUMN_G_A_V_ARTICLEID_3);
1188                                    }
1189                                    else {
1190                                            query.append(_FINDER_COLUMN_G_A_V_ARTICLEID_2);
1191                                    }
1192                            }
1193    
1194                            query.append(_FINDER_COLUMN_G_A_V_VERSION_2);
1195    
1196                            if (orderByComparator != null) {
1197                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1198                                            orderByComparator);
1199                            }
1200                            else
1201                             if (pagination) {
1202                                    query.append(JournalArticleImageModelImpl.ORDER_BY_JPQL);
1203                            }
1204    
1205                            String sql = query.toString();
1206    
1207                            Session session = null;
1208    
1209                            try {
1210                                    session = openSession();
1211    
1212                                    Query q = session.createQuery(sql);
1213    
1214                                    QueryPos qPos = QueryPos.getInstance(q);
1215    
1216                                    qPos.add(groupId);
1217    
1218                                    if (articleId != null) {
1219                                            qPos.add(articleId);
1220                                    }
1221    
1222                                    qPos.add(version);
1223    
1224                                    if (!pagination) {
1225                                            list = (List<JournalArticleImage>)QueryUtil.list(q,
1226                                                            getDialect(), start, end, false);
1227    
1228                                            Collections.sort(list);
1229    
1230                                            list = new UnmodifiableList<JournalArticleImage>(list);
1231                                    }
1232                                    else {
1233                                            list = (List<JournalArticleImage>)QueryUtil.list(q,
1234                                                            getDialect(), start, end);
1235                                    }
1236    
1237                                    cacheResult(list);
1238    
1239                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1240                            }
1241                            catch (Exception e) {
1242                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1243    
1244                                    throw processException(e);
1245                            }
1246                            finally {
1247                                    closeSession(session);
1248                            }
1249                    }
1250    
1251                    return list;
1252            }
1253    
1254            /**
1255             * Returns the first journal article image in the ordered set where groupId = &#63; and articleId = &#63; and version = &#63;.
1256             *
1257             * @param groupId the group ID
1258             * @param articleId the article ID
1259             * @param version the version
1260             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1261             * @return the first matching journal article image
1262             * @throws com.liferay.portlet.journal.NoSuchArticleImageException if a matching journal article image could not be found
1263             * @throws SystemException if a system exception occurred
1264             */
1265            public JournalArticleImage findByG_A_V_First(long groupId,
1266                    String articleId, double version, OrderByComparator orderByComparator)
1267                    throws NoSuchArticleImageException, SystemException {
1268                    JournalArticleImage journalArticleImage = fetchByG_A_V_First(groupId,
1269                                    articleId, version, orderByComparator);
1270    
1271                    if (journalArticleImage != null) {
1272                            return journalArticleImage;
1273                    }
1274    
1275                    StringBundler msg = new StringBundler(8);
1276    
1277                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1278    
1279                    msg.append("groupId=");
1280                    msg.append(groupId);
1281    
1282                    msg.append(", articleId=");
1283                    msg.append(articleId);
1284    
1285                    msg.append(", version=");
1286                    msg.append(version);
1287    
1288                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1289    
1290                    throw new NoSuchArticleImageException(msg.toString());
1291            }
1292    
1293            /**
1294             * Returns the first journal article image in the ordered set where groupId = &#63; and articleId = &#63; and version = &#63;.
1295             *
1296             * @param groupId the group ID
1297             * @param articleId the article ID
1298             * @param version the version
1299             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1300             * @return the first matching journal article image, or <code>null</code> if a matching journal article image could not be found
1301             * @throws SystemException if a system exception occurred
1302             */
1303            public JournalArticleImage fetchByG_A_V_First(long groupId,
1304                    String articleId, double version, OrderByComparator orderByComparator)
1305                    throws SystemException {
1306                    List<JournalArticleImage> list = findByG_A_V(groupId, articleId,
1307                                    version, 0, 1, orderByComparator);
1308    
1309                    if (!list.isEmpty()) {
1310                            return list.get(0);
1311                    }
1312    
1313                    return null;
1314            }
1315    
1316            /**
1317             * Returns the last journal article image in the ordered set where groupId = &#63; and articleId = &#63; and version = &#63;.
1318             *
1319             * @param groupId the group ID
1320             * @param articleId the article ID
1321             * @param version the version
1322             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1323             * @return the last matching journal article image
1324             * @throws com.liferay.portlet.journal.NoSuchArticleImageException if a matching journal article image could not be found
1325             * @throws SystemException if a system exception occurred
1326             */
1327            public JournalArticleImage findByG_A_V_Last(long groupId, String articleId,
1328                    double version, OrderByComparator orderByComparator)
1329                    throws NoSuchArticleImageException, SystemException {
1330                    JournalArticleImage journalArticleImage = fetchByG_A_V_Last(groupId,
1331                                    articleId, version, orderByComparator);
1332    
1333                    if (journalArticleImage != null) {
1334                            return journalArticleImage;
1335                    }
1336    
1337                    StringBundler msg = new StringBundler(8);
1338    
1339                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1340    
1341                    msg.append("groupId=");
1342                    msg.append(groupId);
1343    
1344                    msg.append(", articleId=");
1345                    msg.append(articleId);
1346    
1347                    msg.append(", version=");
1348                    msg.append(version);
1349    
1350                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1351    
1352                    throw new NoSuchArticleImageException(msg.toString());
1353            }
1354    
1355            /**
1356             * Returns the last journal article image in the ordered set where groupId = &#63; and articleId = &#63; and version = &#63;.
1357             *
1358             * @param groupId the group ID
1359             * @param articleId the article ID
1360             * @param version the version
1361             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1362             * @return the last matching journal article image, or <code>null</code> if a matching journal article image could not be found
1363             * @throws SystemException if a system exception occurred
1364             */
1365            public JournalArticleImage fetchByG_A_V_Last(long groupId,
1366                    String articleId, double version, OrderByComparator orderByComparator)
1367                    throws SystemException {
1368                    int count = countByG_A_V(groupId, articleId, version);
1369    
1370                    List<JournalArticleImage> list = findByG_A_V(groupId, articleId,
1371                                    version, count - 1, count, orderByComparator);
1372    
1373                    if (!list.isEmpty()) {
1374                            return list.get(0);
1375                    }
1376    
1377                    return null;
1378            }
1379    
1380            /**
1381             * Returns the journal article images before and after the current journal article image in the ordered set where groupId = &#63; and articleId = &#63; and version = &#63;.
1382             *
1383             * @param articleImageId the primary key of the current journal article image
1384             * @param groupId the group ID
1385             * @param articleId the article ID
1386             * @param version the version
1387             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1388             * @return the previous, current, and next journal article image
1389             * @throws com.liferay.portlet.journal.NoSuchArticleImageException if a journal article image with the primary key could not be found
1390             * @throws SystemException if a system exception occurred
1391             */
1392            public JournalArticleImage[] findByG_A_V_PrevAndNext(long articleImageId,
1393                    long groupId, String articleId, double version,
1394                    OrderByComparator orderByComparator)
1395                    throws NoSuchArticleImageException, SystemException {
1396                    JournalArticleImage journalArticleImage = findByPrimaryKey(articleImageId);
1397    
1398                    Session session = null;
1399    
1400                    try {
1401                            session = openSession();
1402    
1403                            JournalArticleImage[] array = new JournalArticleImageImpl[3];
1404    
1405                            array[0] = getByG_A_V_PrevAndNext(session, journalArticleImage,
1406                                            groupId, articleId, version, orderByComparator, true);
1407    
1408                            array[1] = journalArticleImage;
1409    
1410                            array[2] = getByG_A_V_PrevAndNext(session, journalArticleImage,
1411                                            groupId, articleId, version, orderByComparator, false);
1412    
1413                            return array;
1414                    }
1415                    catch (Exception e) {
1416                            throw processException(e);
1417                    }
1418                    finally {
1419                            closeSession(session);
1420                    }
1421            }
1422    
1423            protected JournalArticleImage getByG_A_V_PrevAndNext(Session session,
1424                    JournalArticleImage journalArticleImage, long groupId,
1425                    String articleId, double version, OrderByComparator orderByComparator,
1426                    boolean previous) {
1427                    StringBundler query = null;
1428    
1429                    if (orderByComparator != null) {
1430                            query = new StringBundler(6 +
1431                                            (orderByComparator.getOrderByFields().length * 6));
1432                    }
1433                    else {
1434                            query = new StringBundler(3);
1435                    }
1436    
1437                    query.append(_SQL_SELECT_JOURNALARTICLEIMAGE_WHERE);
1438    
1439                    query.append(_FINDER_COLUMN_G_A_V_GROUPID_2);
1440    
1441                    if (articleId == null) {
1442                            query.append(_FINDER_COLUMN_G_A_V_ARTICLEID_1);
1443                    }
1444                    else {
1445                            if (articleId.equals(StringPool.BLANK)) {
1446                                    query.append(_FINDER_COLUMN_G_A_V_ARTICLEID_3);
1447                            }
1448                            else {
1449                                    query.append(_FINDER_COLUMN_G_A_V_ARTICLEID_2);
1450                            }
1451                    }
1452    
1453                    query.append(_FINDER_COLUMN_G_A_V_VERSION_2);
1454    
1455                    if (orderByComparator != null) {
1456                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1457    
1458                            if (orderByConditionFields.length > 0) {
1459                                    query.append(WHERE_AND);
1460                            }
1461    
1462                            for (int i = 0; i < orderByConditionFields.length; i++) {
1463                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1464                                    query.append(orderByConditionFields[i]);
1465    
1466                                    if ((i + 1) < orderByConditionFields.length) {
1467                                            if (orderByComparator.isAscending() ^ previous) {
1468                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1469                                            }
1470                                            else {
1471                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1472                                            }
1473                                    }
1474                                    else {
1475                                            if (orderByComparator.isAscending() ^ previous) {
1476                                                    query.append(WHERE_GREATER_THAN);
1477                                            }
1478                                            else {
1479                                                    query.append(WHERE_LESSER_THAN);
1480                                            }
1481                                    }
1482                            }
1483    
1484                            query.append(ORDER_BY_CLAUSE);
1485    
1486                            String[] orderByFields = orderByComparator.getOrderByFields();
1487    
1488                            for (int i = 0; i < orderByFields.length; i++) {
1489                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1490                                    query.append(orderByFields[i]);
1491    
1492                                    if ((i + 1) < orderByFields.length) {
1493                                            if (orderByComparator.isAscending() ^ previous) {
1494                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1495                                            }
1496                                            else {
1497                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1498                                            }
1499                                    }
1500                                    else {
1501                                            if (orderByComparator.isAscending() ^ previous) {
1502                                                    query.append(ORDER_BY_ASC);
1503                                            }
1504                                            else {
1505                                                    query.append(ORDER_BY_DESC);
1506                                            }
1507                                    }
1508                            }
1509                    }
1510                    else {
1511                            query.append(JournalArticleImageModelImpl.ORDER_BY_JPQL);
1512                    }
1513    
1514                    String sql = query.toString();
1515    
1516                    Query q = session.createQuery(sql);
1517    
1518                    q.setFirstResult(0);
1519                    q.setMaxResults(2);
1520    
1521                    QueryPos qPos = QueryPos.getInstance(q);
1522    
1523                    qPos.add(groupId);
1524    
1525                    if (articleId != null) {
1526                            qPos.add(articleId);
1527                    }
1528    
1529                    qPos.add(version);
1530    
1531                    if (orderByComparator != null) {
1532                            Object[] values = orderByComparator.getOrderByConditionValues(journalArticleImage);
1533    
1534                            for (Object value : values) {
1535                                    qPos.add(value);
1536                            }
1537                    }
1538    
1539                    List<JournalArticleImage> list = q.list();
1540    
1541                    if (list.size() == 2) {
1542                            return list.get(1);
1543                    }
1544                    else {
1545                            return null;
1546                    }
1547            }
1548    
1549            /**
1550             * Removes all the journal article images where groupId = &#63; and articleId = &#63; and version = &#63; from the database.
1551             *
1552             * @param groupId the group ID
1553             * @param articleId the article ID
1554             * @param version the version
1555             * @throws SystemException if a system exception occurred
1556             */
1557            public void removeByG_A_V(long groupId, String articleId, double version)
1558                    throws SystemException {
1559                    for (JournalArticleImage journalArticleImage : findByG_A_V(groupId,
1560                                    articleId, version, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1561                            remove(journalArticleImage);
1562                    }
1563            }
1564    
1565            /**
1566             * Returns the number of journal article images where groupId = &#63; and articleId = &#63; and version = &#63;.
1567             *
1568             * @param groupId the group ID
1569             * @param articleId the article ID
1570             * @param version the version
1571             * @return the number of matching journal article images
1572             * @throws SystemException if a system exception occurred
1573             */
1574            public int countByG_A_V(long groupId, String articleId, double version)
1575                    throws SystemException {
1576                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_A_V;
1577    
1578                    Object[] finderArgs = new Object[] { groupId, articleId, version };
1579    
1580                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1581                                    this);
1582    
1583                    if (count == null) {
1584                            StringBundler query = new StringBundler(4);
1585    
1586                            query.append(_SQL_COUNT_JOURNALARTICLEIMAGE_WHERE);
1587    
1588                            query.append(_FINDER_COLUMN_G_A_V_GROUPID_2);
1589    
1590                            if (articleId == null) {
1591                                    query.append(_FINDER_COLUMN_G_A_V_ARTICLEID_1);
1592                            }
1593                            else {
1594                                    if (articleId.equals(StringPool.BLANK)) {
1595                                            query.append(_FINDER_COLUMN_G_A_V_ARTICLEID_3);
1596                                    }
1597                                    else {
1598                                            query.append(_FINDER_COLUMN_G_A_V_ARTICLEID_2);
1599                                    }
1600                            }
1601    
1602                            query.append(_FINDER_COLUMN_G_A_V_VERSION_2);
1603    
1604                            String sql = query.toString();
1605    
1606                            Session session = null;
1607    
1608                            try {
1609                                    session = openSession();
1610    
1611                                    Query q = session.createQuery(sql);
1612    
1613                                    QueryPos qPos = QueryPos.getInstance(q);
1614    
1615                                    qPos.add(groupId);
1616    
1617                                    if (articleId != null) {
1618                                            qPos.add(articleId);
1619                                    }
1620    
1621                                    qPos.add(version);
1622    
1623                                    count = (Long)q.uniqueResult();
1624    
1625                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1626                            }
1627                            catch (Exception e) {
1628                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1629    
1630                                    throw processException(e);
1631                            }
1632                            finally {
1633                                    closeSession(session);
1634                            }
1635                    }
1636    
1637                    return count.intValue();
1638            }
1639    
1640            private static final String _FINDER_COLUMN_G_A_V_GROUPID_2 = "journalArticleImage.groupId = ? AND ";
1641            private static final String _FINDER_COLUMN_G_A_V_ARTICLEID_1 = "journalArticleImage.articleId IS NULL AND ";
1642            private static final String _FINDER_COLUMN_G_A_V_ARTICLEID_2 = "journalArticleImage.articleId = ? AND ";
1643            private static final String _FINDER_COLUMN_G_A_V_ARTICLEID_3 = "(journalArticleImage.articleId IS NULL OR journalArticleImage.articleId = ?) AND ";
1644            private static final String _FINDER_COLUMN_G_A_V_VERSION_2 = "journalArticleImage.version = ?";
1645            public static final FinderPath FINDER_PATH_FETCH_BY_G_A_V_E_E_L = new FinderPath(JournalArticleImageModelImpl.ENTITY_CACHE_ENABLED,
1646                            JournalArticleImageModelImpl.FINDER_CACHE_ENABLED,
1647                            JournalArticleImageImpl.class, FINDER_CLASS_NAME_ENTITY,
1648                            "fetchByG_A_V_E_E_L",
1649                            new String[] {
1650                                    Long.class.getName(), String.class.getName(),
1651                                    Double.class.getName(), String.class.getName(),
1652                                    String.class.getName(), String.class.getName()
1653                            },
1654                            JournalArticleImageModelImpl.GROUPID_COLUMN_BITMASK |
1655                            JournalArticleImageModelImpl.ARTICLEID_COLUMN_BITMASK |
1656                            JournalArticleImageModelImpl.VERSION_COLUMN_BITMASK |
1657                            JournalArticleImageModelImpl.ELINSTANCEID_COLUMN_BITMASK |
1658                            JournalArticleImageModelImpl.ELNAME_COLUMN_BITMASK |
1659                            JournalArticleImageModelImpl.LANGUAGEID_COLUMN_BITMASK);
1660            public static final FinderPath FINDER_PATH_COUNT_BY_G_A_V_E_E_L = new FinderPath(JournalArticleImageModelImpl.ENTITY_CACHE_ENABLED,
1661                            JournalArticleImageModelImpl.FINDER_CACHE_ENABLED, Long.class,
1662                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_A_V_E_E_L",
1663                            new String[] {
1664                                    Long.class.getName(), String.class.getName(),
1665                                    Double.class.getName(), String.class.getName(),
1666                                    String.class.getName(), String.class.getName()
1667                            });
1668    
1669            /**
1670             * Returns the journal article image where groupId = &#63; and articleId = &#63; and version = &#63; and elInstanceId = &#63; and elName = &#63; and languageId = &#63; or throws a {@link com.liferay.portlet.journal.NoSuchArticleImageException} if it could not be found.
1671             *
1672             * @param groupId the group ID
1673             * @param articleId the article ID
1674             * @param version the version
1675             * @param elInstanceId the el instance ID
1676             * @param elName the el name
1677             * @param languageId the language ID
1678             * @return the matching journal article image
1679             * @throws com.liferay.portlet.journal.NoSuchArticleImageException if a matching journal article image could not be found
1680             * @throws SystemException if a system exception occurred
1681             */
1682            public JournalArticleImage findByG_A_V_E_E_L(long groupId,
1683                    String articleId, double version, String elInstanceId, String elName,
1684                    String languageId) throws NoSuchArticleImageException, SystemException {
1685                    JournalArticleImage journalArticleImage = fetchByG_A_V_E_E_L(groupId,
1686                                    articleId, version, elInstanceId, elName, languageId);
1687    
1688                    if (journalArticleImage == null) {
1689                            StringBundler msg = new StringBundler(14);
1690    
1691                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1692    
1693                            msg.append("groupId=");
1694                            msg.append(groupId);
1695    
1696                            msg.append(", articleId=");
1697                            msg.append(articleId);
1698    
1699                            msg.append(", version=");
1700                            msg.append(version);
1701    
1702                            msg.append(", elInstanceId=");
1703                            msg.append(elInstanceId);
1704    
1705                            msg.append(", elName=");
1706                            msg.append(elName);
1707    
1708                            msg.append(", languageId=");
1709                            msg.append(languageId);
1710    
1711                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1712    
1713                            if (_log.isWarnEnabled()) {
1714                                    _log.warn(msg.toString());
1715                            }
1716    
1717                            throw new NoSuchArticleImageException(msg.toString());
1718                    }
1719    
1720                    return journalArticleImage;
1721            }
1722    
1723            /**
1724             * Returns the journal article image where groupId = &#63; and articleId = &#63; and version = &#63; and elInstanceId = &#63; and elName = &#63; and languageId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
1725             *
1726             * @param groupId the group ID
1727             * @param articleId the article ID
1728             * @param version the version
1729             * @param elInstanceId the el instance ID
1730             * @param elName the el name
1731             * @param languageId the language ID
1732             * @return the matching journal article image, or <code>null</code> if a matching journal article image could not be found
1733             * @throws SystemException if a system exception occurred
1734             */
1735            public JournalArticleImage fetchByG_A_V_E_E_L(long groupId,
1736                    String articleId, double version, String elInstanceId, String elName,
1737                    String languageId) throws SystemException {
1738                    return fetchByG_A_V_E_E_L(groupId, articleId, version, elInstanceId,
1739                            elName, languageId, true);
1740            }
1741    
1742            /**
1743             * Returns the journal article image where groupId = &#63; and articleId = &#63; and version = &#63; and elInstanceId = &#63; and elName = &#63; and languageId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
1744             *
1745             * @param groupId the group ID
1746             * @param articleId the article ID
1747             * @param version the version
1748             * @param elInstanceId the el instance ID
1749             * @param elName the el name
1750             * @param languageId the language ID
1751             * @param retrieveFromCache whether to use the finder cache
1752             * @return the matching journal article image, or <code>null</code> if a matching journal article image could not be found
1753             * @throws SystemException if a system exception occurred
1754             */
1755            public JournalArticleImage fetchByG_A_V_E_E_L(long groupId,
1756                    String articleId, double version, String elInstanceId, String elName,
1757                    String languageId, boolean retrieveFromCache) throws SystemException {
1758                    Object[] finderArgs = new Object[] {
1759                                    groupId, articleId, version, elInstanceId, elName, languageId
1760                            };
1761    
1762                    Object result = null;
1763    
1764                    if (retrieveFromCache) {
1765                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_A_V_E_E_L,
1766                                            finderArgs, this);
1767                    }
1768    
1769                    if (result instanceof JournalArticleImage) {
1770                            JournalArticleImage journalArticleImage = (JournalArticleImage)result;
1771    
1772                            if ((groupId != journalArticleImage.getGroupId()) ||
1773                                            !Validator.equals(articleId,
1774                                                    journalArticleImage.getArticleId()) ||
1775                                            (version != journalArticleImage.getVersion()) ||
1776                                            !Validator.equals(elInstanceId,
1777                                                    journalArticleImage.getElInstanceId()) ||
1778                                            !Validator.equals(elName, journalArticleImage.getElName()) ||
1779                                            !Validator.equals(languageId,
1780                                                    journalArticleImage.getLanguageId())) {
1781                                    result = null;
1782                            }
1783                    }
1784    
1785                    if (result == null) {
1786                            StringBundler query = new StringBundler(8);
1787    
1788                            query.append(_SQL_SELECT_JOURNALARTICLEIMAGE_WHERE);
1789    
1790                            query.append(_FINDER_COLUMN_G_A_V_E_E_L_GROUPID_2);
1791    
1792                            if (articleId == null) {
1793                                    query.append(_FINDER_COLUMN_G_A_V_E_E_L_ARTICLEID_1);
1794                            }
1795                            else {
1796                                    if (articleId.equals(StringPool.BLANK)) {
1797                                            query.append(_FINDER_COLUMN_G_A_V_E_E_L_ARTICLEID_3);
1798                                    }
1799                                    else {
1800                                            query.append(_FINDER_COLUMN_G_A_V_E_E_L_ARTICLEID_2);
1801                                    }
1802                            }
1803    
1804                            query.append(_FINDER_COLUMN_G_A_V_E_E_L_VERSION_2);
1805    
1806                            if (elInstanceId == null) {
1807                                    query.append(_FINDER_COLUMN_G_A_V_E_E_L_ELINSTANCEID_1);
1808                            }
1809                            else {
1810                                    if (elInstanceId.equals(StringPool.BLANK)) {
1811                                            query.append(_FINDER_COLUMN_G_A_V_E_E_L_ELINSTANCEID_3);
1812                                    }
1813                                    else {
1814                                            query.append(_FINDER_COLUMN_G_A_V_E_E_L_ELINSTANCEID_2);
1815                                    }
1816                            }
1817    
1818                            if (elName == null) {
1819                                    query.append(_FINDER_COLUMN_G_A_V_E_E_L_ELNAME_1);
1820                            }
1821                            else {
1822                                    if (elName.equals(StringPool.BLANK)) {
1823                                            query.append(_FINDER_COLUMN_G_A_V_E_E_L_ELNAME_3);
1824                                    }
1825                                    else {
1826                                            query.append(_FINDER_COLUMN_G_A_V_E_E_L_ELNAME_2);
1827                                    }
1828                            }
1829    
1830                            if (languageId == null) {
1831                                    query.append(_FINDER_COLUMN_G_A_V_E_E_L_LANGUAGEID_1);
1832                            }
1833                            else {
1834                                    if (languageId.equals(StringPool.BLANK)) {
1835                                            query.append(_FINDER_COLUMN_G_A_V_E_E_L_LANGUAGEID_3);
1836                                    }
1837                                    else {
1838                                            query.append(_FINDER_COLUMN_G_A_V_E_E_L_LANGUAGEID_2);
1839                                    }
1840                            }
1841    
1842                            String sql = query.toString();
1843    
1844                            Session session = null;
1845    
1846                            try {
1847                                    session = openSession();
1848    
1849                                    Query q = session.createQuery(sql);
1850    
1851                                    QueryPos qPos = QueryPos.getInstance(q);
1852    
1853                                    qPos.add(groupId);
1854    
1855                                    if (articleId != null) {
1856                                            qPos.add(articleId);
1857                                    }
1858    
1859                                    qPos.add(version);
1860    
1861                                    if (elInstanceId != null) {
1862                                            qPos.add(elInstanceId);
1863                                    }
1864    
1865                                    if (elName != null) {
1866                                            qPos.add(elName);
1867                                    }
1868    
1869                                    if (languageId != null) {
1870                                            qPos.add(languageId);
1871                                    }
1872    
1873                                    List<JournalArticleImage> list = q.list();
1874    
1875                                    if (list.isEmpty()) {
1876                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_A_V_E_E_L,
1877                                                    finderArgs, list);
1878                                    }
1879                                    else {
1880                                            JournalArticleImage journalArticleImage = list.get(0);
1881    
1882                                            result = journalArticleImage;
1883    
1884                                            cacheResult(journalArticleImage);
1885    
1886                                            if ((journalArticleImage.getGroupId() != groupId) ||
1887                                                            (journalArticleImage.getArticleId() == null) ||
1888                                                            !journalArticleImage.getArticleId().equals(articleId) ||
1889                                                            (journalArticleImage.getVersion() != version) ||
1890                                                            (journalArticleImage.getElInstanceId() == null) ||
1891                                                            !journalArticleImage.getElInstanceId()
1892                                                                                                            .equals(elInstanceId) ||
1893                                                            (journalArticleImage.getElName() == null) ||
1894                                                            !journalArticleImage.getElName().equals(elName) ||
1895                                                            (journalArticleImage.getLanguageId() == null) ||
1896                                                            !journalArticleImage.getLanguageId()
1897                                                                                                            .equals(languageId)) {
1898                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_A_V_E_E_L,
1899                                                            finderArgs, journalArticleImage);
1900                                            }
1901                                    }
1902                            }
1903                            catch (Exception e) {
1904                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_A_V_E_E_L,
1905                                            finderArgs);
1906    
1907                                    throw processException(e);
1908                            }
1909                            finally {
1910                                    closeSession(session);
1911                            }
1912                    }
1913    
1914                    if (result instanceof List<?>) {
1915                            return null;
1916                    }
1917                    else {
1918                            return (JournalArticleImage)result;
1919                    }
1920            }
1921    
1922            /**
1923             * Removes the journal article image where groupId = &#63; and articleId = &#63; and version = &#63; and elInstanceId = &#63; and elName = &#63; and languageId = &#63; from the database.
1924             *
1925             * @param groupId the group ID
1926             * @param articleId the article ID
1927             * @param version the version
1928             * @param elInstanceId the el instance ID
1929             * @param elName the el name
1930             * @param languageId the language ID
1931             * @return the journal article image that was removed
1932             * @throws SystemException if a system exception occurred
1933             */
1934            public JournalArticleImage removeByG_A_V_E_E_L(long groupId,
1935                    String articleId, double version, String elInstanceId, String elName,
1936                    String languageId) throws NoSuchArticleImageException, SystemException {
1937                    JournalArticleImage journalArticleImage = findByG_A_V_E_E_L(groupId,
1938                                    articleId, version, elInstanceId, elName, languageId);
1939    
1940                    return remove(journalArticleImage);
1941            }
1942    
1943            /**
1944             * Returns the number of journal article images where groupId = &#63; and articleId = &#63; and version = &#63; and elInstanceId = &#63; and elName = &#63; and languageId = &#63;.
1945             *
1946             * @param groupId the group ID
1947             * @param articleId the article ID
1948             * @param version the version
1949             * @param elInstanceId the el instance ID
1950             * @param elName the el name
1951             * @param languageId the language ID
1952             * @return the number of matching journal article images
1953             * @throws SystemException if a system exception occurred
1954             */
1955            public int countByG_A_V_E_E_L(long groupId, String articleId,
1956                    double version, String elInstanceId, String elName, String languageId)
1957                    throws SystemException {
1958                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_A_V_E_E_L;
1959    
1960                    Object[] finderArgs = new Object[] {
1961                                    groupId, articleId, version, elInstanceId, elName, languageId
1962                            };
1963    
1964                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1965                                    this);
1966    
1967                    if (count == null) {
1968                            StringBundler query = new StringBundler(7);
1969    
1970                            query.append(_SQL_COUNT_JOURNALARTICLEIMAGE_WHERE);
1971    
1972                            query.append(_FINDER_COLUMN_G_A_V_E_E_L_GROUPID_2);
1973    
1974                            if (articleId == null) {
1975                                    query.append(_FINDER_COLUMN_G_A_V_E_E_L_ARTICLEID_1);
1976                            }
1977                            else {
1978                                    if (articleId.equals(StringPool.BLANK)) {
1979                                            query.append(_FINDER_COLUMN_G_A_V_E_E_L_ARTICLEID_3);
1980                                    }
1981                                    else {
1982                                            query.append(_FINDER_COLUMN_G_A_V_E_E_L_ARTICLEID_2);
1983                                    }
1984                            }
1985    
1986                            query.append(_FINDER_COLUMN_G_A_V_E_E_L_VERSION_2);
1987    
1988                            if (elInstanceId == null) {
1989                                    query.append(_FINDER_COLUMN_G_A_V_E_E_L_ELINSTANCEID_1);
1990                            }
1991                            else {
1992                                    if (elInstanceId.equals(StringPool.BLANK)) {
1993                                            query.append(_FINDER_COLUMN_G_A_V_E_E_L_ELINSTANCEID_3);
1994                                    }
1995                                    else {
1996                                            query.append(_FINDER_COLUMN_G_A_V_E_E_L_ELINSTANCEID_2);
1997                                    }
1998                            }
1999    
2000                            if (elName == null) {
2001                                    query.append(_FINDER_COLUMN_G_A_V_E_E_L_ELNAME_1);
2002                            }
2003                            else {
2004                                    if (elName.equals(StringPool.BLANK)) {
2005                                            query.append(_FINDER_COLUMN_G_A_V_E_E_L_ELNAME_3);
2006                                    }
2007                                    else {
2008                                            query.append(_FINDER_COLUMN_G_A_V_E_E_L_ELNAME_2);
2009                                    }
2010                            }
2011    
2012                            if (languageId == null) {
2013                                    query.append(_FINDER_COLUMN_G_A_V_E_E_L_LANGUAGEID_1);
2014                            }
2015                            else {
2016                                    if (languageId.equals(StringPool.BLANK)) {
2017                                            query.append(_FINDER_COLUMN_G_A_V_E_E_L_LANGUAGEID_3);
2018                                    }
2019                                    else {
2020                                            query.append(_FINDER_COLUMN_G_A_V_E_E_L_LANGUAGEID_2);
2021                                    }
2022                            }
2023    
2024                            String sql = query.toString();
2025    
2026                            Session session = null;
2027    
2028                            try {
2029                                    session = openSession();
2030    
2031                                    Query q = session.createQuery(sql);
2032    
2033                                    QueryPos qPos = QueryPos.getInstance(q);
2034    
2035                                    qPos.add(groupId);
2036    
2037                                    if (articleId != null) {
2038                                            qPos.add(articleId);
2039                                    }
2040    
2041                                    qPos.add(version);
2042    
2043                                    if (elInstanceId != null) {
2044                                            qPos.add(elInstanceId);
2045                                    }
2046    
2047                                    if (elName != null) {
2048                                            qPos.add(elName);
2049                                    }
2050    
2051                                    if (languageId != null) {
2052                                            qPos.add(languageId);
2053                                    }
2054    
2055                                    count = (Long)q.uniqueResult();
2056    
2057                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2058                            }
2059                            catch (Exception e) {
2060                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2061    
2062                                    throw processException(e);
2063                            }
2064                            finally {
2065                                    closeSession(session);
2066                            }
2067                    }
2068    
2069                    return count.intValue();
2070            }
2071    
2072            private static final String _FINDER_COLUMN_G_A_V_E_E_L_GROUPID_2 = "journalArticleImage.groupId = ? AND ";
2073            private static final String _FINDER_COLUMN_G_A_V_E_E_L_ARTICLEID_1 = "journalArticleImage.articleId IS NULL AND ";
2074            private static final String _FINDER_COLUMN_G_A_V_E_E_L_ARTICLEID_2 = "journalArticleImage.articleId = ? AND ";
2075            private static final String _FINDER_COLUMN_G_A_V_E_E_L_ARTICLEID_3 = "(journalArticleImage.articleId IS NULL OR journalArticleImage.articleId = ?) AND ";
2076            private static final String _FINDER_COLUMN_G_A_V_E_E_L_VERSION_2 = "journalArticleImage.version = ? AND ";
2077            private static final String _FINDER_COLUMN_G_A_V_E_E_L_ELINSTANCEID_1 = "journalArticleImage.elInstanceId IS NULL AND ";
2078            private static final String _FINDER_COLUMN_G_A_V_E_E_L_ELINSTANCEID_2 = "journalArticleImage.elInstanceId = ? AND ";
2079            private static final String _FINDER_COLUMN_G_A_V_E_E_L_ELINSTANCEID_3 = "(journalArticleImage.elInstanceId IS NULL OR journalArticleImage.elInstanceId = ?) AND ";
2080            private static final String _FINDER_COLUMN_G_A_V_E_E_L_ELNAME_1 = "journalArticleImage.elName IS NULL AND ";
2081            private static final String _FINDER_COLUMN_G_A_V_E_E_L_ELNAME_2 = "journalArticleImage.elName = ? AND ";
2082            private static final String _FINDER_COLUMN_G_A_V_E_E_L_ELNAME_3 = "(journalArticleImage.elName IS NULL OR journalArticleImage.elName = ?) AND ";
2083            private static final String _FINDER_COLUMN_G_A_V_E_E_L_LANGUAGEID_1 = "journalArticleImage.languageId IS NULL";
2084            private static final String _FINDER_COLUMN_G_A_V_E_E_L_LANGUAGEID_2 = "journalArticleImage.languageId = ?";
2085            private static final String _FINDER_COLUMN_G_A_V_E_E_L_LANGUAGEID_3 = "(journalArticleImage.languageId IS NULL OR journalArticleImage.languageId = ?)";
2086    
2087            /**
2088             * Caches the journal article image in the entity cache if it is enabled.
2089             *
2090             * @param journalArticleImage the journal article image
2091             */
2092            public void cacheResult(JournalArticleImage journalArticleImage) {
2093                    EntityCacheUtil.putResult(JournalArticleImageModelImpl.ENTITY_CACHE_ENABLED,
2094                            JournalArticleImageImpl.class, journalArticleImage.getPrimaryKey(),
2095                            journalArticleImage);
2096    
2097                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_A_V_E_E_L,
2098                            new Object[] {
2099                                    Long.valueOf(journalArticleImage.getGroupId()),
2100                                    
2101                            journalArticleImage.getArticleId(),
2102                                    Double.valueOf(journalArticleImage.getVersion()),
2103                                    
2104                            journalArticleImage.getElInstanceId(),
2105                                    
2106                            journalArticleImage.getElName(),
2107                                    
2108                            journalArticleImage.getLanguageId()
2109                            }, journalArticleImage);
2110    
2111                    journalArticleImage.resetOriginalValues();
2112            }
2113    
2114            /**
2115             * Caches the journal article images in the entity cache if it is enabled.
2116             *
2117             * @param journalArticleImages the journal article images
2118             */
2119            public void cacheResult(List<JournalArticleImage> journalArticleImages) {
2120                    for (JournalArticleImage journalArticleImage : journalArticleImages) {
2121                            if (EntityCacheUtil.getResult(
2122                                                    JournalArticleImageModelImpl.ENTITY_CACHE_ENABLED,
2123                                                    JournalArticleImageImpl.class,
2124                                                    journalArticleImage.getPrimaryKey()) == null) {
2125                                    cacheResult(journalArticleImage);
2126                            }
2127                            else {
2128                                    journalArticleImage.resetOriginalValues();
2129                            }
2130                    }
2131            }
2132    
2133            /**
2134             * Clears the cache for all journal article images.
2135             *
2136             * <p>
2137             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
2138             * </p>
2139             */
2140            @Override
2141            public void clearCache() {
2142                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
2143                            CacheRegistryUtil.clear(JournalArticleImageImpl.class.getName());
2144                    }
2145    
2146                    EntityCacheUtil.clearCache(JournalArticleImageImpl.class.getName());
2147    
2148                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
2149                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2150                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2151            }
2152    
2153            /**
2154             * Clears the cache for the journal article image.
2155             *
2156             * <p>
2157             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
2158             * </p>
2159             */
2160            @Override
2161            public void clearCache(JournalArticleImage journalArticleImage) {
2162                    EntityCacheUtil.removeResult(JournalArticleImageModelImpl.ENTITY_CACHE_ENABLED,
2163                            JournalArticleImageImpl.class, journalArticleImage.getPrimaryKey());
2164    
2165                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2166                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2167    
2168                    clearUniqueFindersCache(journalArticleImage);
2169            }
2170    
2171            @Override
2172            public void clearCache(List<JournalArticleImage> journalArticleImages) {
2173                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2174                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2175    
2176                    for (JournalArticleImage journalArticleImage : journalArticleImages) {
2177                            EntityCacheUtil.removeResult(JournalArticleImageModelImpl.ENTITY_CACHE_ENABLED,
2178                                    JournalArticleImageImpl.class,
2179                                    journalArticleImage.getPrimaryKey());
2180    
2181                            clearUniqueFindersCache(journalArticleImage);
2182                    }
2183            }
2184    
2185            protected void cacheUniqueFindersCache(
2186                    JournalArticleImage journalArticleImage) {
2187                    if (journalArticleImage.isNew()) {
2188                            Object[] args = new Object[] {
2189                                            Long.valueOf(journalArticleImage.getGroupId()),
2190                                            
2191                                            journalArticleImage.getArticleId(),
2192                                            Double.valueOf(journalArticleImage.getVersion()),
2193                                            
2194                                            journalArticleImage.getElInstanceId(),
2195                                            
2196                                            journalArticleImage.getElName(),
2197                                            
2198                                            journalArticleImage.getLanguageId()
2199                                    };
2200    
2201                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_A_V_E_E_L, args,
2202                                    Long.valueOf(1));
2203                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_A_V_E_E_L, args,
2204                                    journalArticleImage);
2205                    }
2206                    else {
2207                            JournalArticleImageModelImpl journalArticleImageModelImpl = (JournalArticleImageModelImpl)journalArticleImage;
2208    
2209                            if ((journalArticleImageModelImpl.getColumnBitmask() &
2210                                            FINDER_PATH_FETCH_BY_G_A_V_E_E_L.getColumnBitmask()) != 0) {
2211                                    Object[] args = new Object[] {
2212                                                    Long.valueOf(journalArticleImage.getGroupId()),
2213                                                    
2214                                                    journalArticleImage.getArticleId(),
2215                                                    Double.valueOf(journalArticleImage.getVersion()),
2216                                                    
2217                                                    journalArticleImage.getElInstanceId(),
2218                                                    
2219                                                    journalArticleImage.getElName(),
2220                                                    
2221                                                    journalArticleImage.getLanguageId()
2222                                            };
2223    
2224                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_A_V_E_E_L,
2225                                            args, Long.valueOf(1));
2226                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_A_V_E_E_L,
2227                                            args, journalArticleImage);
2228                            }
2229                    }
2230            }
2231    
2232            protected void clearUniqueFindersCache(
2233                    JournalArticleImage journalArticleImage) {
2234                    JournalArticleImageModelImpl journalArticleImageModelImpl = (JournalArticleImageModelImpl)journalArticleImage;
2235    
2236                    Object[] args = new Object[] {
2237                                    Long.valueOf(journalArticleImage.getGroupId()),
2238                                    
2239                                    journalArticleImage.getArticleId(),
2240                                    Double.valueOf(journalArticleImage.getVersion()),
2241                                    
2242                                    journalArticleImage.getElInstanceId(),
2243                                    
2244                                    journalArticleImage.getElName(),
2245                                    
2246                                    journalArticleImage.getLanguageId()
2247                            };
2248    
2249                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_A_V_E_E_L, args);
2250                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_A_V_E_E_L, args);
2251    
2252                    if ((journalArticleImageModelImpl.getColumnBitmask() &
2253                                    FINDER_PATH_FETCH_BY_G_A_V_E_E_L.getColumnBitmask()) != 0) {
2254                            args = new Object[] {
2255                                            Long.valueOf(journalArticleImageModelImpl.getOriginalGroupId()),
2256                                            
2257                                            journalArticleImageModelImpl.getOriginalArticleId(),
2258                                            Double.valueOf(journalArticleImageModelImpl.getOriginalVersion()),
2259                                            
2260                                            journalArticleImageModelImpl.getOriginalElInstanceId(),
2261                                            
2262                                            journalArticleImageModelImpl.getOriginalElName(),
2263                                            
2264                                            journalArticleImageModelImpl.getOriginalLanguageId()
2265                                    };
2266    
2267                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_A_V_E_E_L, args);
2268                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_A_V_E_E_L, args);
2269                    }
2270            }
2271    
2272            /**
2273             * Creates a new journal article image with the primary key. Does not add the journal article image to the database.
2274             *
2275             * @param articleImageId the primary key for the new journal article image
2276             * @return the new journal article image
2277             */
2278            public JournalArticleImage create(long articleImageId) {
2279                    JournalArticleImage journalArticleImage = new JournalArticleImageImpl();
2280    
2281                    journalArticleImage.setNew(true);
2282                    journalArticleImage.setPrimaryKey(articleImageId);
2283    
2284                    return journalArticleImage;
2285            }
2286    
2287            /**
2288             * Removes the journal article image with the primary key from the database. Also notifies the appropriate model listeners.
2289             *
2290             * @param articleImageId the primary key of the journal article image
2291             * @return the journal article image that was removed
2292             * @throws com.liferay.portlet.journal.NoSuchArticleImageException if a journal article image with the primary key could not be found
2293             * @throws SystemException if a system exception occurred
2294             */
2295            public JournalArticleImage remove(long articleImageId)
2296                    throws NoSuchArticleImageException, SystemException {
2297                    return remove(Long.valueOf(articleImageId));
2298            }
2299    
2300            /**
2301             * Removes the journal article image with the primary key from the database. Also notifies the appropriate model listeners.
2302             *
2303             * @param primaryKey the primary key of the journal article image
2304             * @return the journal article image that was removed
2305             * @throws com.liferay.portlet.journal.NoSuchArticleImageException if a journal article image with the primary key could not be found
2306             * @throws SystemException if a system exception occurred
2307             */
2308            @Override
2309            public JournalArticleImage remove(Serializable primaryKey)
2310                    throws NoSuchArticleImageException, SystemException {
2311                    Session session = null;
2312    
2313                    try {
2314                            session = openSession();
2315    
2316                            JournalArticleImage journalArticleImage = (JournalArticleImage)session.get(JournalArticleImageImpl.class,
2317                                            primaryKey);
2318    
2319                            if (journalArticleImage == null) {
2320                                    if (_log.isWarnEnabled()) {
2321                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2322                                    }
2323    
2324                                    throw new NoSuchArticleImageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2325                                            primaryKey);
2326                            }
2327    
2328                            return remove(journalArticleImage);
2329                    }
2330                    catch (NoSuchArticleImageException nsee) {
2331                            throw nsee;
2332                    }
2333                    catch (Exception e) {
2334                            throw processException(e);
2335                    }
2336                    finally {
2337                            closeSession(session);
2338                    }
2339            }
2340    
2341            @Override
2342            protected JournalArticleImage removeImpl(
2343                    JournalArticleImage journalArticleImage) throws SystemException {
2344                    journalArticleImage = toUnwrappedModel(journalArticleImage);
2345    
2346                    Session session = null;
2347    
2348                    try {
2349                            session = openSession();
2350    
2351                            if (!session.contains(journalArticleImage)) {
2352                                    journalArticleImage = (JournalArticleImage)session.get(JournalArticleImageImpl.class,
2353                                                    journalArticleImage.getPrimaryKeyObj());
2354                            }
2355    
2356                            if (journalArticleImage != null) {
2357                                    session.delete(journalArticleImage);
2358                            }
2359                    }
2360                    catch (Exception e) {
2361                            throw processException(e);
2362                    }
2363                    finally {
2364                            closeSession(session);
2365                    }
2366    
2367                    if (journalArticleImage != null) {
2368                            clearCache(journalArticleImage);
2369                    }
2370    
2371                    return journalArticleImage;
2372            }
2373    
2374            @Override
2375            public JournalArticleImage updateImpl(
2376                    com.liferay.portlet.journal.model.JournalArticleImage journalArticleImage)
2377                    throws SystemException {
2378                    journalArticleImage = toUnwrappedModel(journalArticleImage);
2379    
2380                    boolean isNew = journalArticleImage.isNew();
2381    
2382                    JournalArticleImageModelImpl journalArticleImageModelImpl = (JournalArticleImageModelImpl)journalArticleImage;
2383    
2384                    Session session = null;
2385    
2386                    try {
2387                            session = openSession();
2388    
2389                            if (journalArticleImage.isNew()) {
2390                                    session.save(journalArticleImage);
2391    
2392                                    journalArticleImage.setNew(false);
2393                            }
2394                            else {
2395                                    session.merge(journalArticleImage);
2396                            }
2397                    }
2398                    catch (Exception e) {
2399                            throw processException(e);
2400                    }
2401                    finally {
2402                            closeSession(session);
2403                    }
2404    
2405                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2406    
2407                    if (isNew || !JournalArticleImageModelImpl.COLUMN_BITMASK_ENABLED) {
2408                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2409                    }
2410    
2411                    else {
2412                            if ((journalArticleImageModelImpl.getColumnBitmask() &
2413                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
2414                                    Object[] args = new Object[] {
2415                                                    Long.valueOf(journalArticleImageModelImpl.getOriginalGroupId())
2416                                            };
2417    
2418                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
2419                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
2420                                            args);
2421    
2422                                    args = new Object[] {
2423                                                    Long.valueOf(journalArticleImageModelImpl.getGroupId())
2424                                            };
2425    
2426                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
2427                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
2428                                            args);
2429                            }
2430    
2431                            if ((journalArticleImageModelImpl.getColumnBitmask() &
2432                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TEMPIMAGE.getColumnBitmask()) != 0) {
2433                                    Object[] args = new Object[] {
2434                                                    Boolean.valueOf(journalArticleImageModelImpl.getOriginalTempImage())
2435                                            };
2436    
2437                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TEMPIMAGE,
2438                                            args);
2439                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TEMPIMAGE,
2440                                            args);
2441    
2442                                    args = new Object[] {
2443                                                    Boolean.valueOf(journalArticleImageModelImpl.getTempImage())
2444                                            };
2445    
2446                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TEMPIMAGE,
2447                                            args);
2448                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TEMPIMAGE,
2449                                            args);
2450                            }
2451    
2452                            if ((journalArticleImageModelImpl.getColumnBitmask() &
2453                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_A_V.getColumnBitmask()) != 0) {
2454                                    Object[] args = new Object[] {
2455                                                    Long.valueOf(journalArticleImageModelImpl.getOriginalGroupId()),
2456                                                    
2457                                                    journalArticleImageModelImpl.getOriginalArticleId(),
2458                                                    Double.valueOf(journalArticleImageModelImpl.getOriginalVersion())
2459                                            };
2460    
2461                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_A_V, args);
2462                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_A_V,
2463                                            args);
2464    
2465                                    args = new Object[] {
2466                                                    Long.valueOf(journalArticleImageModelImpl.getGroupId()),
2467                                                    
2468                                                    journalArticleImageModelImpl.getArticleId(),
2469                                                    Double.valueOf(journalArticleImageModelImpl.getVersion())
2470                                            };
2471    
2472                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_A_V, args);
2473                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_A_V,
2474                                            args);
2475                            }
2476                    }
2477    
2478                    EntityCacheUtil.putResult(JournalArticleImageModelImpl.ENTITY_CACHE_ENABLED,
2479                            JournalArticleImageImpl.class, journalArticleImage.getPrimaryKey(),
2480                            journalArticleImage);
2481    
2482                    clearUniqueFindersCache(journalArticleImage);
2483                    cacheUniqueFindersCache(journalArticleImage);
2484    
2485                    return journalArticleImage;
2486            }
2487    
2488            protected JournalArticleImage toUnwrappedModel(
2489                    JournalArticleImage journalArticleImage) {
2490                    if (journalArticleImage instanceof JournalArticleImageImpl) {
2491                            return journalArticleImage;
2492                    }
2493    
2494                    JournalArticleImageImpl journalArticleImageImpl = new JournalArticleImageImpl();
2495    
2496                    journalArticleImageImpl.setNew(journalArticleImage.isNew());
2497                    journalArticleImageImpl.setPrimaryKey(journalArticleImage.getPrimaryKey());
2498    
2499                    journalArticleImageImpl.setArticleImageId(journalArticleImage.getArticleImageId());
2500                    journalArticleImageImpl.setGroupId(journalArticleImage.getGroupId());
2501                    journalArticleImageImpl.setArticleId(journalArticleImage.getArticleId());
2502                    journalArticleImageImpl.setVersion(journalArticleImage.getVersion());
2503                    journalArticleImageImpl.setElInstanceId(journalArticleImage.getElInstanceId());
2504                    journalArticleImageImpl.setElName(journalArticleImage.getElName());
2505                    journalArticleImageImpl.setLanguageId(journalArticleImage.getLanguageId());
2506                    journalArticleImageImpl.setTempImage(journalArticleImage.isTempImage());
2507    
2508                    return journalArticleImageImpl;
2509            }
2510    
2511            /**
2512             * Returns the journal article image with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
2513             *
2514             * @param primaryKey the primary key of the journal article image
2515             * @return the journal article image
2516             * @throws com.liferay.portal.NoSuchModelException if a journal article image with the primary key could not be found
2517             * @throws SystemException if a system exception occurred
2518             */
2519            @Override
2520            public JournalArticleImage findByPrimaryKey(Serializable primaryKey)
2521                    throws NoSuchModelException, SystemException {
2522                    return findByPrimaryKey(((Long)primaryKey).longValue());
2523            }
2524    
2525            /**
2526             * Returns the journal article image with the primary key or throws a {@link com.liferay.portlet.journal.NoSuchArticleImageException} if it could not be found.
2527             *
2528             * @param articleImageId the primary key of the journal article image
2529             * @return the journal article image
2530             * @throws com.liferay.portlet.journal.NoSuchArticleImageException if a journal article image with the primary key could not be found
2531             * @throws SystemException if a system exception occurred
2532             */
2533            public JournalArticleImage findByPrimaryKey(long articleImageId)
2534                    throws NoSuchArticleImageException, SystemException {
2535                    JournalArticleImage journalArticleImage = fetchByPrimaryKey(articleImageId);
2536    
2537                    if (journalArticleImage == null) {
2538                            if (_log.isWarnEnabled()) {
2539                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + articleImageId);
2540                            }
2541    
2542                            throw new NoSuchArticleImageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2543                                    articleImageId);
2544                    }
2545    
2546                    return journalArticleImage;
2547            }
2548    
2549            /**
2550             * Returns the journal article image with the primary key or returns <code>null</code> if it could not be found.
2551             *
2552             * @param primaryKey the primary key of the journal article image
2553             * @return the journal article image, or <code>null</code> if a journal article image with the primary key could not be found
2554             * @throws SystemException if a system exception occurred
2555             */
2556            @Override
2557            public JournalArticleImage fetchByPrimaryKey(Serializable primaryKey)
2558                    throws SystemException {
2559                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
2560            }
2561    
2562            /**
2563             * Returns the journal article image with the primary key or returns <code>null</code> if it could not be found.
2564             *
2565             * @param articleImageId the primary key of the journal article image
2566             * @return the journal article image, or <code>null</code> if a journal article image with the primary key could not be found
2567             * @throws SystemException if a system exception occurred
2568             */
2569            public JournalArticleImage fetchByPrimaryKey(long articleImageId)
2570                    throws SystemException {
2571                    JournalArticleImage journalArticleImage = (JournalArticleImage)EntityCacheUtil.getResult(JournalArticleImageModelImpl.ENTITY_CACHE_ENABLED,
2572                                    JournalArticleImageImpl.class, articleImageId);
2573    
2574                    if (journalArticleImage == _nullJournalArticleImage) {
2575                            return null;
2576                    }
2577    
2578                    if (journalArticleImage == null) {
2579                            Session session = null;
2580    
2581                            try {
2582                                    session = openSession();
2583    
2584                                    journalArticleImage = (JournalArticleImage)session.get(JournalArticleImageImpl.class,
2585                                                    Long.valueOf(articleImageId));
2586    
2587                                    if (journalArticleImage != null) {
2588                                            cacheResult(journalArticleImage);
2589                                    }
2590                                    else {
2591                                            EntityCacheUtil.putResult(JournalArticleImageModelImpl.ENTITY_CACHE_ENABLED,
2592                                                    JournalArticleImageImpl.class, articleImageId,
2593                                                    _nullJournalArticleImage);
2594                                    }
2595                            }
2596                            catch (Exception e) {
2597                                    EntityCacheUtil.removeResult(JournalArticleImageModelImpl.ENTITY_CACHE_ENABLED,
2598                                            JournalArticleImageImpl.class, articleImageId);
2599    
2600                                    throw processException(e);
2601                            }
2602                            finally {
2603                                    closeSession(session);
2604                            }
2605                    }
2606    
2607                    return journalArticleImage;
2608            }
2609    
2610            /**
2611             * Returns all the journal article images.
2612             *
2613             * @return the journal article images
2614             * @throws SystemException if a system exception occurred
2615             */
2616            public List<JournalArticleImage> findAll() throws SystemException {
2617                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2618            }
2619    
2620            /**
2621             * Returns a range of all the journal article images.
2622             *
2623             * <p>
2624             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleImageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2625             * </p>
2626             *
2627             * @param start the lower bound of the range of journal article images
2628             * @param end the upper bound of the range of journal article images (not inclusive)
2629             * @return the range of journal article images
2630             * @throws SystemException if a system exception occurred
2631             */
2632            public List<JournalArticleImage> findAll(int start, int end)
2633                    throws SystemException {
2634                    return findAll(start, end, null);
2635            }
2636    
2637            /**
2638             * Returns an ordered range of all the journal article images.
2639             *
2640             * <p>
2641             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleImageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2642             * </p>
2643             *
2644             * @param start the lower bound of the range of journal article images
2645             * @param end the upper bound of the range of journal article images (not inclusive)
2646             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2647             * @return the ordered range of journal article images
2648             * @throws SystemException if a system exception occurred
2649             */
2650            public List<JournalArticleImage> findAll(int start, int end,
2651                    OrderByComparator orderByComparator) throws SystemException {
2652                    boolean pagination = true;
2653                    FinderPath finderPath = null;
2654                    Object[] finderArgs = null;
2655    
2656                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2657                                    (orderByComparator == null)) {
2658                            pagination = false;
2659                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2660                            finderArgs = FINDER_ARGS_EMPTY;
2661                    }
2662                    else {
2663                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2664                            finderArgs = new Object[] { start, end, orderByComparator };
2665                    }
2666    
2667                    List<JournalArticleImage> list = (List<JournalArticleImage>)FinderCacheUtil.getResult(finderPath,
2668                                    finderArgs, this);
2669    
2670                    if (list == null) {
2671                            StringBundler query = null;
2672                            String sql = null;
2673    
2674                            if (orderByComparator != null) {
2675                                    query = new StringBundler(2 +
2676                                                    (orderByComparator.getOrderByFields().length * 3));
2677    
2678                                    query.append(_SQL_SELECT_JOURNALARTICLEIMAGE);
2679    
2680                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2681                                            orderByComparator);
2682    
2683                                    sql = query.toString();
2684                            }
2685                            else {
2686                                    sql = _SQL_SELECT_JOURNALARTICLEIMAGE;
2687    
2688                                    if (pagination) {
2689                                            sql = sql.concat(JournalArticleImageModelImpl.ORDER_BY_JPQL);
2690                                    }
2691                            }
2692    
2693                            Session session = null;
2694    
2695                            try {
2696                                    session = openSession();
2697    
2698                                    Query q = session.createQuery(sql);
2699    
2700                                    if (!pagination) {
2701                                            list = (List<JournalArticleImage>)QueryUtil.list(q,
2702                                                            getDialect(), start, end, false);
2703    
2704                                            Collections.sort(list);
2705    
2706                                            list = new UnmodifiableList<JournalArticleImage>(list);
2707                                    }
2708                                    else {
2709                                            list = (List<JournalArticleImage>)QueryUtil.list(q,
2710                                                            getDialect(), start, end);
2711                                    }
2712    
2713                                    cacheResult(list);
2714    
2715                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2716                            }
2717                            catch (Exception e) {
2718                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2719    
2720                                    throw processException(e);
2721                            }
2722                            finally {
2723                                    closeSession(session);
2724                            }
2725                    }
2726    
2727                    return list;
2728            }
2729    
2730            /**
2731             * Removes all the journal article images from the database.
2732             *
2733             * @throws SystemException if a system exception occurred
2734             */
2735            public void removeAll() throws SystemException {
2736                    for (JournalArticleImage journalArticleImage : findAll()) {
2737                            remove(journalArticleImage);
2738                    }
2739            }
2740    
2741            /**
2742             * Returns the number of journal article images.
2743             *
2744             * @return the number of journal article images
2745             * @throws SystemException if a system exception occurred
2746             */
2747            public int countAll() throws SystemException {
2748                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2749                                    FINDER_ARGS_EMPTY, this);
2750    
2751                    if (count == null) {
2752                            Session session = null;
2753    
2754                            try {
2755                                    session = openSession();
2756    
2757                                    Query q = session.createQuery(_SQL_COUNT_JOURNALARTICLEIMAGE);
2758    
2759                                    count = (Long)q.uniqueResult();
2760    
2761                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2762                                            FINDER_ARGS_EMPTY, count);
2763                            }
2764                            catch (Exception e) {
2765                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
2766                                            FINDER_ARGS_EMPTY);
2767    
2768                                    throw processException(e);
2769                            }
2770                            finally {
2771                                    closeSession(session);
2772                            }
2773                    }
2774    
2775                    return count.intValue();
2776            }
2777    
2778            /**
2779             * Initializes the journal article image persistence.
2780             */
2781            public void afterPropertiesSet() {
2782                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2783                                            com.liferay.portal.util.PropsUtil.get(
2784                                                    "value.object.listener.com.liferay.portlet.journal.model.JournalArticleImage")));
2785    
2786                    if (listenerClassNames.length > 0) {
2787                            try {
2788                                    List<ModelListener<JournalArticleImage>> listenersList = new ArrayList<ModelListener<JournalArticleImage>>();
2789    
2790                                    for (String listenerClassName : listenerClassNames) {
2791                                            listenersList.add((ModelListener<JournalArticleImage>)InstanceFactory.newInstance(
2792                                                            listenerClassName));
2793                                    }
2794    
2795                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2796                            }
2797                            catch (Exception e) {
2798                                    _log.error(e);
2799                            }
2800                    }
2801            }
2802    
2803            public void destroy() {
2804                    EntityCacheUtil.removeCache(JournalArticleImageImpl.class.getName());
2805                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2806                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2807                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2808            }
2809    
2810            private static final String _SQL_SELECT_JOURNALARTICLEIMAGE = "SELECT journalArticleImage FROM JournalArticleImage journalArticleImage";
2811            private static final String _SQL_SELECT_JOURNALARTICLEIMAGE_WHERE = "SELECT journalArticleImage FROM JournalArticleImage journalArticleImage WHERE ";
2812            private static final String _SQL_COUNT_JOURNALARTICLEIMAGE = "SELECT COUNT(journalArticleImage) FROM JournalArticleImage journalArticleImage";
2813            private static final String _SQL_COUNT_JOURNALARTICLEIMAGE_WHERE = "SELECT COUNT(journalArticleImage) FROM JournalArticleImage journalArticleImage WHERE ";
2814            private static final String _ORDER_BY_ENTITY_ALIAS = "journalArticleImage.";
2815            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No JournalArticleImage exists with the primary key ";
2816            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No JournalArticleImage exists with the key {";
2817            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2818            private static Log _log = LogFactoryUtil.getLog(JournalArticleImagePersistenceImpl.class);
2819            private static JournalArticleImage _nullJournalArticleImage = new JournalArticleImageImpl() {
2820                            @Override
2821                            public Object clone() {
2822                                    return this;
2823                            }
2824    
2825                            @Override
2826                            public CacheModel<JournalArticleImage> toCacheModel() {
2827                                    return _nullJournalArticleImageCacheModel;
2828                            }
2829                    };
2830    
2831            private static CacheModel<JournalArticleImage> _nullJournalArticleImageCacheModel =
2832                    new CacheModel<JournalArticleImage>() {
2833                            public JournalArticleImage toEntityModel() {
2834                                    return _nullJournalArticleImage;
2835                            }
2836                    };
2837    }