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