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