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