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