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