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