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