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            public JournalArticleImagePersistenceImpl() {
2156                    setModelClass(JournalArticleImage.class);
2157            }
2158    
2159            /**
2160             * Caches the journal article image in the entity cache if it is enabled.
2161             *
2162             * @param journalArticleImage the journal article image
2163             */
2164            @Override
2165            public void cacheResult(JournalArticleImage journalArticleImage) {
2166                    EntityCacheUtil.putResult(JournalArticleImageModelImpl.ENTITY_CACHE_ENABLED,
2167                            JournalArticleImageImpl.class, journalArticleImage.getPrimaryKey(),
2168                            journalArticleImage);
2169    
2170                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_A_V_E_E_L,
2171                            new Object[] {
2172                                    journalArticleImage.getGroupId(),
2173                                    journalArticleImage.getArticleId(),
2174                                    journalArticleImage.getVersion(),
2175                                    journalArticleImage.getElInstanceId(),
2176                                    journalArticleImage.getElName(),
2177                                    journalArticleImage.getLanguageId()
2178                            }, journalArticleImage);
2179    
2180                    journalArticleImage.resetOriginalValues();
2181            }
2182    
2183            /**
2184             * Caches the journal article images in the entity cache if it is enabled.
2185             *
2186             * @param journalArticleImages the journal article images
2187             */
2188            @Override
2189            public void cacheResult(List<JournalArticleImage> journalArticleImages) {
2190                    for (JournalArticleImage journalArticleImage : journalArticleImages) {
2191                            if (EntityCacheUtil.getResult(
2192                                                    JournalArticleImageModelImpl.ENTITY_CACHE_ENABLED,
2193                                                    JournalArticleImageImpl.class,
2194                                                    journalArticleImage.getPrimaryKey()) == null) {
2195                                    cacheResult(journalArticleImage);
2196                            }
2197                            else {
2198                                    journalArticleImage.resetOriginalValues();
2199                            }
2200                    }
2201            }
2202    
2203            /**
2204             * Clears the cache for all journal article images.
2205             *
2206             * <p>
2207             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
2208             * </p>
2209             */
2210            @Override
2211            public void clearCache() {
2212                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
2213                            CacheRegistryUtil.clear(JournalArticleImageImpl.class.getName());
2214                    }
2215    
2216                    EntityCacheUtil.clearCache(JournalArticleImageImpl.class.getName());
2217    
2218                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
2219                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2220                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2221            }
2222    
2223            /**
2224             * Clears the cache for the journal article image.
2225             *
2226             * <p>
2227             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
2228             * </p>
2229             */
2230            @Override
2231            public void clearCache(JournalArticleImage journalArticleImage) {
2232                    EntityCacheUtil.removeResult(JournalArticleImageModelImpl.ENTITY_CACHE_ENABLED,
2233                            JournalArticleImageImpl.class, journalArticleImage.getPrimaryKey());
2234    
2235                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2236                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2237    
2238                    clearUniqueFindersCache(journalArticleImage);
2239            }
2240    
2241            @Override
2242            public void clearCache(List<JournalArticleImage> journalArticleImages) {
2243                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2244                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2245    
2246                    for (JournalArticleImage journalArticleImage : journalArticleImages) {
2247                            EntityCacheUtil.removeResult(JournalArticleImageModelImpl.ENTITY_CACHE_ENABLED,
2248                                    JournalArticleImageImpl.class,
2249                                    journalArticleImage.getPrimaryKey());
2250    
2251                            clearUniqueFindersCache(journalArticleImage);
2252                    }
2253            }
2254    
2255            protected void cacheUniqueFindersCache(
2256                    JournalArticleImage journalArticleImage) {
2257                    if (journalArticleImage.isNew()) {
2258                            Object[] args = new Object[] {
2259                                            journalArticleImage.getGroupId(),
2260                                            journalArticleImage.getArticleId(),
2261                                            journalArticleImage.getVersion(),
2262                                            journalArticleImage.getElInstanceId(),
2263                                            journalArticleImage.getElName(),
2264                                            journalArticleImage.getLanguageId()
2265                                    };
2266    
2267                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_A_V_E_E_L, args,
2268                                    Long.valueOf(1));
2269                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_A_V_E_E_L, args,
2270                                    journalArticleImage);
2271                    }
2272                    else {
2273                            JournalArticleImageModelImpl journalArticleImageModelImpl = (JournalArticleImageModelImpl)journalArticleImage;
2274    
2275                            if ((journalArticleImageModelImpl.getColumnBitmask() &
2276                                            FINDER_PATH_FETCH_BY_G_A_V_E_E_L.getColumnBitmask()) != 0) {
2277                                    Object[] args = new Object[] {
2278                                                    journalArticleImage.getGroupId(),
2279                                                    journalArticleImage.getArticleId(),
2280                                                    journalArticleImage.getVersion(),
2281                                                    journalArticleImage.getElInstanceId(),
2282                                                    journalArticleImage.getElName(),
2283                                                    journalArticleImage.getLanguageId()
2284                                            };
2285    
2286                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_A_V_E_E_L,
2287                                            args, Long.valueOf(1));
2288                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_A_V_E_E_L,
2289                                            args, journalArticleImage);
2290                            }
2291                    }
2292            }
2293    
2294            protected void clearUniqueFindersCache(
2295                    JournalArticleImage journalArticleImage) {
2296                    JournalArticleImageModelImpl journalArticleImageModelImpl = (JournalArticleImageModelImpl)journalArticleImage;
2297    
2298                    Object[] args = new Object[] {
2299                                    journalArticleImage.getGroupId(),
2300                                    journalArticleImage.getArticleId(),
2301                                    journalArticleImage.getVersion(),
2302                                    journalArticleImage.getElInstanceId(),
2303                                    journalArticleImage.getElName(),
2304                                    journalArticleImage.getLanguageId()
2305                            };
2306    
2307                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_A_V_E_E_L, args);
2308                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_A_V_E_E_L, args);
2309    
2310                    if ((journalArticleImageModelImpl.getColumnBitmask() &
2311                                    FINDER_PATH_FETCH_BY_G_A_V_E_E_L.getColumnBitmask()) != 0) {
2312                            args = new Object[] {
2313                                            journalArticleImageModelImpl.getOriginalGroupId(),
2314                                            journalArticleImageModelImpl.getOriginalArticleId(),
2315                                            journalArticleImageModelImpl.getOriginalVersion(),
2316                                            journalArticleImageModelImpl.getOriginalElInstanceId(),
2317                                            journalArticleImageModelImpl.getOriginalElName(),
2318                                            journalArticleImageModelImpl.getOriginalLanguageId()
2319                                    };
2320    
2321                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_A_V_E_E_L, args);
2322                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_A_V_E_E_L, args);
2323                    }
2324            }
2325    
2326            /**
2327             * Creates a new journal article image with the primary key. Does not add the journal article image to the database.
2328             *
2329             * @param articleImageId the primary key for the new journal article image
2330             * @return the new journal article image
2331             */
2332            @Override
2333            public JournalArticleImage create(long articleImageId) {
2334                    JournalArticleImage journalArticleImage = new JournalArticleImageImpl();
2335    
2336                    journalArticleImage.setNew(true);
2337                    journalArticleImage.setPrimaryKey(articleImageId);
2338    
2339                    return journalArticleImage;
2340            }
2341    
2342            /**
2343             * Removes the journal article image with the primary key from the database. Also notifies the appropriate model listeners.
2344             *
2345             * @param articleImageId the primary key of the journal article image
2346             * @return the journal article image that was removed
2347             * @throws com.liferay.portlet.journal.NoSuchArticleImageException if a journal article image with the primary key could not be found
2348             * @throws SystemException if a system exception occurred
2349             */
2350            @Override
2351            public JournalArticleImage remove(long articleImageId)
2352                    throws NoSuchArticleImageException, SystemException {
2353                    return remove((Serializable)articleImageId);
2354            }
2355    
2356            /**
2357             * Removes the journal article image with the primary key from the database. Also notifies the appropriate model listeners.
2358             *
2359             * @param primaryKey the primary key of the journal article image
2360             * @return the journal article image that was removed
2361             * @throws com.liferay.portlet.journal.NoSuchArticleImageException if a journal article image with the primary key could not be found
2362             * @throws SystemException if a system exception occurred
2363             */
2364            @Override
2365            public JournalArticleImage remove(Serializable primaryKey)
2366                    throws NoSuchArticleImageException, SystemException {
2367                    Session session = null;
2368    
2369                    try {
2370                            session = openSession();
2371    
2372                            JournalArticleImage journalArticleImage = (JournalArticleImage)session.get(JournalArticleImageImpl.class,
2373                                            primaryKey);
2374    
2375                            if (journalArticleImage == null) {
2376                                    if (_log.isWarnEnabled()) {
2377                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2378                                    }
2379    
2380                                    throw new NoSuchArticleImageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2381                                            primaryKey);
2382                            }
2383    
2384                            return remove(journalArticleImage);
2385                    }
2386                    catch (NoSuchArticleImageException nsee) {
2387                            throw nsee;
2388                    }
2389                    catch (Exception e) {
2390                            throw processException(e);
2391                    }
2392                    finally {
2393                            closeSession(session);
2394                    }
2395            }
2396    
2397            @Override
2398            protected JournalArticleImage removeImpl(
2399                    JournalArticleImage journalArticleImage) throws SystemException {
2400                    journalArticleImage = toUnwrappedModel(journalArticleImage);
2401    
2402                    Session session = null;
2403    
2404                    try {
2405                            session = openSession();
2406    
2407                            if (!session.contains(journalArticleImage)) {
2408                                    journalArticleImage = (JournalArticleImage)session.get(JournalArticleImageImpl.class,
2409                                                    journalArticleImage.getPrimaryKeyObj());
2410                            }
2411    
2412                            if (journalArticleImage != null) {
2413                                    session.delete(journalArticleImage);
2414                            }
2415                    }
2416                    catch (Exception e) {
2417                            throw processException(e);
2418                    }
2419                    finally {
2420                            closeSession(session);
2421                    }
2422    
2423                    if (journalArticleImage != null) {
2424                            clearCache(journalArticleImage);
2425                    }
2426    
2427                    return journalArticleImage;
2428            }
2429    
2430            @Override
2431            public JournalArticleImage updateImpl(
2432                    com.liferay.portlet.journal.model.JournalArticleImage journalArticleImage)
2433                    throws SystemException {
2434                    journalArticleImage = toUnwrappedModel(journalArticleImage);
2435    
2436                    boolean isNew = journalArticleImage.isNew();
2437    
2438                    JournalArticleImageModelImpl journalArticleImageModelImpl = (JournalArticleImageModelImpl)journalArticleImage;
2439    
2440                    Session session = null;
2441    
2442                    try {
2443                            session = openSession();
2444    
2445                            if (journalArticleImage.isNew()) {
2446                                    session.save(journalArticleImage);
2447    
2448                                    journalArticleImage.setNew(false);
2449                            }
2450                            else {
2451                                    session.merge(journalArticleImage);
2452                            }
2453                    }
2454                    catch (Exception e) {
2455                            throw processException(e);
2456                    }
2457                    finally {
2458                            closeSession(session);
2459                    }
2460    
2461                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2462    
2463                    if (isNew || !JournalArticleImageModelImpl.COLUMN_BITMASK_ENABLED) {
2464                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2465                    }
2466    
2467                    else {
2468                            if ((journalArticleImageModelImpl.getColumnBitmask() &
2469                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
2470                                    Object[] args = new Object[] {
2471                                                    journalArticleImageModelImpl.getOriginalGroupId()
2472                                            };
2473    
2474                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
2475                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
2476                                            args);
2477    
2478                                    args = new Object[] { journalArticleImageModelImpl.getGroupId() };
2479    
2480                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
2481                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
2482                                            args);
2483                            }
2484    
2485                            if ((journalArticleImageModelImpl.getColumnBitmask() &
2486                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TEMPIMAGE.getColumnBitmask()) != 0) {
2487                                    Object[] args = new Object[] {
2488                                                    journalArticleImageModelImpl.getOriginalTempImage()
2489                                            };
2490    
2491                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TEMPIMAGE,
2492                                            args);
2493                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TEMPIMAGE,
2494                                            args);
2495    
2496                                    args = new Object[] { journalArticleImageModelImpl.getTempImage() };
2497    
2498                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TEMPIMAGE,
2499                                            args);
2500                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TEMPIMAGE,
2501                                            args);
2502                            }
2503    
2504                            if ((journalArticleImageModelImpl.getColumnBitmask() &
2505                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_A_V.getColumnBitmask()) != 0) {
2506                                    Object[] args = new Object[] {
2507                                                    journalArticleImageModelImpl.getOriginalGroupId(),
2508                                                    journalArticleImageModelImpl.getOriginalArticleId(),
2509                                                    journalArticleImageModelImpl.getOriginalVersion()
2510                                            };
2511    
2512                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_A_V, args);
2513                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_A_V,
2514                                            args);
2515    
2516                                    args = new Object[] {
2517                                                    journalArticleImageModelImpl.getGroupId(),
2518                                                    journalArticleImageModelImpl.getArticleId(),
2519                                                    journalArticleImageModelImpl.getVersion()
2520                                            };
2521    
2522                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_A_V, args);
2523                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_A_V,
2524                                            args);
2525                            }
2526                    }
2527    
2528                    EntityCacheUtil.putResult(JournalArticleImageModelImpl.ENTITY_CACHE_ENABLED,
2529                            JournalArticleImageImpl.class, journalArticleImage.getPrimaryKey(),
2530                            journalArticleImage);
2531    
2532                    clearUniqueFindersCache(journalArticleImage);
2533                    cacheUniqueFindersCache(journalArticleImage);
2534    
2535                    return journalArticleImage;
2536            }
2537    
2538            protected JournalArticleImage toUnwrappedModel(
2539                    JournalArticleImage journalArticleImage) {
2540                    if (journalArticleImage instanceof JournalArticleImageImpl) {
2541                            return journalArticleImage;
2542                    }
2543    
2544                    JournalArticleImageImpl journalArticleImageImpl = new JournalArticleImageImpl();
2545    
2546                    journalArticleImageImpl.setNew(journalArticleImage.isNew());
2547                    journalArticleImageImpl.setPrimaryKey(journalArticleImage.getPrimaryKey());
2548    
2549                    journalArticleImageImpl.setArticleImageId(journalArticleImage.getArticleImageId());
2550                    journalArticleImageImpl.setGroupId(journalArticleImage.getGroupId());
2551                    journalArticleImageImpl.setArticleId(journalArticleImage.getArticleId());
2552                    journalArticleImageImpl.setVersion(journalArticleImage.getVersion());
2553                    journalArticleImageImpl.setElInstanceId(journalArticleImage.getElInstanceId());
2554                    journalArticleImageImpl.setElName(journalArticleImage.getElName());
2555                    journalArticleImageImpl.setLanguageId(journalArticleImage.getLanguageId());
2556                    journalArticleImageImpl.setTempImage(journalArticleImage.isTempImage());
2557    
2558                    return journalArticleImageImpl;
2559            }
2560    
2561            /**
2562             * Returns the journal article image with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
2563             *
2564             * @param primaryKey the primary key of the journal article image
2565             * @return the journal article image
2566             * @throws com.liferay.portlet.journal.NoSuchArticleImageException if a journal article image with the primary key could not be found
2567             * @throws SystemException if a system exception occurred
2568             */
2569            @Override
2570            public JournalArticleImage findByPrimaryKey(Serializable primaryKey)
2571                    throws NoSuchArticleImageException, SystemException {
2572                    JournalArticleImage journalArticleImage = fetchByPrimaryKey(primaryKey);
2573    
2574                    if (journalArticleImage == null) {
2575                            if (_log.isWarnEnabled()) {
2576                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2577                            }
2578    
2579                            throw new NoSuchArticleImageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2580                                    primaryKey);
2581                    }
2582    
2583                    return journalArticleImage;
2584            }
2585    
2586            /**
2587             * Returns the journal article image with the primary key or throws a {@link com.liferay.portlet.journal.NoSuchArticleImageException} if it could not be found.
2588             *
2589             * @param articleImageId the primary key of the journal article image
2590             * @return the journal article image
2591             * @throws com.liferay.portlet.journal.NoSuchArticleImageException if a journal article image with the primary key could not be found
2592             * @throws SystemException if a system exception occurred
2593             */
2594            @Override
2595            public JournalArticleImage findByPrimaryKey(long articleImageId)
2596                    throws NoSuchArticleImageException, SystemException {
2597                    return findByPrimaryKey((Serializable)articleImageId);
2598            }
2599    
2600            /**
2601             * Returns the journal article image with the primary key or returns <code>null</code> if it could not be found.
2602             *
2603             * @param primaryKey the primary key of the journal article image
2604             * @return the journal article image, or <code>null</code> if a journal article image with the primary key could not be found
2605             * @throws SystemException if a system exception occurred
2606             */
2607            @Override
2608            public JournalArticleImage fetchByPrimaryKey(Serializable primaryKey)
2609                    throws SystemException {
2610                    JournalArticleImage journalArticleImage = (JournalArticleImage)EntityCacheUtil.getResult(JournalArticleImageModelImpl.ENTITY_CACHE_ENABLED,
2611                                    JournalArticleImageImpl.class, primaryKey);
2612    
2613                    if (journalArticleImage == _nullJournalArticleImage) {
2614                            return null;
2615                    }
2616    
2617                    if (journalArticleImage == null) {
2618                            Session session = null;
2619    
2620                            try {
2621                                    session = openSession();
2622    
2623                                    journalArticleImage = (JournalArticleImage)session.get(JournalArticleImageImpl.class,
2624                                                    primaryKey);
2625    
2626                                    if (journalArticleImage != null) {
2627                                            cacheResult(journalArticleImage);
2628                                    }
2629                                    else {
2630                                            EntityCacheUtil.putResult(JournalArticleImageModelImpl.ENTITY_CACHE_ENABLED,
2631                                                    JournalArticleImageImpl.class, primaryKey,
2632                                                    _nullJournalArticleImage);
2633                                    }
2634                            }
2635                            catch (Exception e) {
2636                                    EntityCacheUtil.removeResult(JournalArticleImageModelImpl.ENTITY_CACHE_ENABLED,
2637                                            JournalArticleImageImpl.class, primaryKey);
2638    
2639                                    throw processException(e);
2640                            }
2641                            finally {
2642                                    closeSession(session);
2643                            }
2644                    }
2645    
2646                    return journalArticleImage;
2647            }
2648    
2649            /**
2650             * Returns the journal article image with the primary key or returns <code>null</code> if it could not be found.
2651             *
2652             * @param articleImageId the primary key of the journal article image
2653             * @return the journal article image, or <code>null</code> if a journal article image with the primary key could not be found
2654             * @throws SystemException if a system exception occurred
2655             */
2656            @Override
2657            public JournalArticleImage fetchByPrimaryKey(long articleImageId)
2658                    throws SystemException {
2659                    return fetchByPrimaryKey((Serializable)articleImageId);
2660            }
2661    
2662            /**
2663             * Returns all the journal article images.
2664             *
2665             * @return the journal article images
2666             * @throws SystemException if a system exception occurred
2667             */
2668            @Override
2669            public List<JournalArticleImage> findAll() throws SystemException {
2670                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2671            }
2672    
2673            /**
2674             * Returns a range of all the journal article images.
2675             *
2676             * <p>
2677             * 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.
2678             * </p>
2679             *
2680             * @param start the lower bound of the range of journal article images
2681             * @param end the upper bound of the range of journal article images (not inclusive)
2682             * @return the range of journal article images
2683             * @throws SystemException if a system exception occurred
2684             */
2685            @Override
2686            public List<JournalArticleImage> findAll(int start, int end)
2687                    throws SystemException {
2688                    return findAll(start, end, null);
2689            }
2690    
2691            /**
2692             * Returns an ordered range of all the journal article images.
2693             *
2694             * <p>
2695             * 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.
2696             * </p>
2697             *
2698             * @param start the lower bound of the range of journal article images
2699             * @param end the upper bound of the range of journal article images (not inclusive)
2700             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2701             * @return the ordered range of journal article images
2702             * @throws SystemException if a system exception occurred
2703             */
2704            @Override
2705            public List<JournalArticleImage> findAll(int start, int end,
2706                    OrderByComparator orderByComparator) throws SystemException {
2707                    boolean pagination = true;
2708                    FinderPath finderPath = null;
2709                    Object[] finderArgs = null;
2710    
2711                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2712                                    (orderByComparator == null)) {
2713                            pagination = false;
2714                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2715                            finderArgs = FINDER_ARGS_EMPTY;
2716                    }
2717                    else {
2718                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2719                            finderArgs = new Object[] { start, end, orderByComparator };
2720                    }
2721    
2722                    List<JournalArticleImage> list = (List<JournalArticleImage>)FinderCacheUtil.getResult(finderPath,
2723                                    finderArgs, this);
2724    
2725                    if (list == null) {
2726                            StringBundler query = null;
2727                            String sql = null;
2728    
2729                            if (orderByComparator != null) {
2730                                    query = new StringBundler(2 +
2731                                                    (orderByComparator.getOrderByFields().length * 3));
2732    
2733                                    query.append(_SQL_SELECT_JOURNALARTICLEIMAGE);
2734    
2735                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2736                                            orderByComparator);
2737    
2738                                    sql = query.toString();
2739                            }
2740                            else {
2741                                    sql = _SQL_SELECT_JOURNALARTICLEIMAGE;
2742    
2743                                    if (pagination) {
2744                                            sql = sql.concat(JournalArticleImageModelImpl.ORDER_BY_JPQL);
2745                                    }
2746                            }
2747    
2748                            Session session = null;
2749    
2750                            try {
2751                                    session = openSession();
2752    
2753                                    Query q = session.createQuery(sql);
2754    
2755                                    if (!pagination) {
2756                                            list = (List<JournalArticleImage>)QueryUtil.list(q,
2757                                                            getDialect(), start, end, false);
2758    
2759                                            Collections.sort(list);
2760    
2761                                            list = new UnmodifiableList<JournalArticleImage>(list);
2762                                    }
2763                                    else {
2764                                            list = (List<JournalArticleImage>)QueryUtil.list(q,
2765                                                            getDialect(), start, end);
2766                                    }
2767    
2768                                    cacheResult(list);
2769    
2770                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2771                            }
2772                            catch (Exception e) {
2773                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2774    
2775                                    throw processException(e);
2776                            }
2777                            finally {
2778                                    closeSession(session);
2779                            }
2780                    }
2781    
2782                    return list;
2783            }
2784    
2785            /**
2786             * Removes all the journal article images from the database.
2787             *
2788             * @throws SystemException if a system exception occurred
2789             */
2790            @Override
2791            public void removeAll() throws SystemException {
2792                    for (JournalArticleImage journalArticleImage : findAll()) {
2793                            remove(journalArticleImage);
2794                    }
2795            }
2796    
2797            /**
2798             * Returns the number of journal article images.
2799             *
2800             * @return the number of journal article images
2801             * @throws SystemException if a system exception occurred
2802             */
2803            @Override
2804            public int countAll() throws SystemException {
2805                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2806                                    FINDER_ARGS_EMPTY, this);
2807    
2808                    if (count == null) {
2809                            Session session = null;
2810    
2811                            try {
2812                                    session = openSession();
2813    
2814                                    Query q = session.createQuery(_SQL_COUNT_JOURNALARTICLEIMAGE);
2815    
2816                                    count = (Long)q.uniqueResult();
2817    
2818                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2819                                            FINDER_ARGS_EMPTY, count);
2820                            }
2821                            catch (Exception e) {
2822                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
2823                                            FINDER_ARGS_EMPTY);
2824    
2825                                    throw processException(e);
2826                            }
2827                            finally {
2828                                    closeSession(session);
2829                            }
2830                    }
2831    
2832                    return count.intValue();
2833            }
2834    
2835            /**
2836             * Initializes the journal article image persistence.
2837             */
2838            public void afterPropertiesSet() {
2839                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2840                                            com.liferay.portal.util.PropsUtil.get(
2841                                                    "value.object.listener.com.liferay.portlet.journal.model.JournalArticleImage")));
2842    
2843                    if (listenerClassNames.length > 0) {
2844                            try {
2845                                    List<ModelListener<JournalArticleImage>> listenersList = new ArrayList<ModelListener<JournalArticleImage>>();
2846    
2847                                    for (String listenerClassName : listenerClassNames) {
2848                                            listenersList.add((ModelListener<JournalArticleImage>)InstanceFactory.newInstance(
2849                                                            getClassLoader(), listenerClassName));
2850                                    }
2851    
2852                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2853                            }
2854                            catch (Exception e) {
2855                                    _log.error(e);
2856                            }
2857                    }
2858            }
2859    
2860            public void destroy() {
2861                    EntityCacheUtil.removeCache(JournalArticleImageImpl.class.getName());
2862                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2863                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2864                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2865            }
2866    
2867            private static final String _SQL_SELECT_JOURNALARTICLEIMAGE = "SELECT journalArticleImage FROM JournalArticleImage journalArticleImage";
2868            private static final String _SQL_SELECT_JOURNALARTICLEIMAGE_WHERE = "SELECT journalArticleImage FROM JournalArticleImage journalArticleImage WHERE ";
2869            private static final String _SQL_COUNT_JOURNALARTICLEIMAGE = "SELECT COUNT(journalArticleImage) FROM JournalArticleImage journalArticleImage";
2870            private static final String _SQL_COUNT_JOURNALARTICLEIMAGE_WHERE = "SELECT COUNT(journalArticleImage) FROM JournalArticleImage journalArticleImage WHERE ";
2871            private static final String _ORDER_BY_ENTITY_ALIAS = "journalArticleImage.";
2872            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No JournalArticleImage exists with the primary key ";
2873            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No JournalArticleImage exists with the key {";
2874            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2875            private static Log _log = LogFactoryUtil.getLog(JournalArticleImagePersistenceImpl.class);
2876            private static JournalArticleImage _nullJournalArticleImage = new JournalArticleImageImpl() {
2877                            @Override
2878                            public Object clone() {
2879                                    return this;
2880                            }
2881    
2882                            @Override
2883                            public CacheModel<JournalArticleImage> toCacheModel() {
2884                                    return _nullJournalArticleImageCacheModel;
2885                            }
2886                    };
2887    
2888            private static CacheModel<JournalArticleImage> _nullJournalArticleImageCacheModel =
2889                    new CacheModel<JournalArticleImage>() {
2890                            @Override
2891                            public JournalArticleImage toEntityModel() {
2892                                    return _nullJournalArticleImage;
2893                            }
2894                    };
2895    }