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