001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.journal.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.bean.BeanReference;
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.SQLQuery;
027    import com.liferay.portal.kernel.dao.orm.Session;
028    import com.liferay.portal.kernel.exception.SystemException;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.util.GetterUtil;
032    import com.liferay.portal.kernel.util.InstanceFactory;
033    import com.liferay.portal.kernel.util.OrderByComparator;
034    import com.liferay.portal.kernel.util.StringBundler;
035    import com.liferay.portal.kernel.util.StringPool;
036    import com.liferay.portal.kernel.util.StringUtil;
037    import com.liferay.portal.kernel.util.Validator;
038    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
039    import com.liferay.portal.model.CacheModel;
040    import com.liferay.portal.model.ModelListener;
041    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
042    import com.liferay.portal.service.persistence.BatchSessionUtil;
043    import com.liferay.portal.service.persistence.ImagePersistence;
044    import com.liferay.portal.service.persistence.ResourcePersistence;
045    import com.liferay.portal.service.persistence.UserPersistence;
046    import com.liferay.portal.service.persistence.WebDAVPropsPersistence;
047    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
048    
049    import com.liferay.portlet.expando.service.persistence.ExpandoValuePersistence;
050    import com.liferay.portlet.journal.NoSuchTemplateException;
051    import com.liferay.portlet.journal.model.JournalTemplate;
052    import com.liferay.portlet.journal.model.impl.JournalTemplateImpl;
053    import com.liferay.portlet.journal.model.impl.JournalTemplateModelImpl;
054    
055    import java.io.Serializable;
056    
057    import java.util.ArrayList;
058    import java.util.Collections;
059    import java.util.List;
060    
061    /**
062     * The persistence implementation for the journal template service.
063     *
064     * <p>
065     * Caching information and settings can be found in <code>portal.properties</code>
066     * </p>
067     *
068     * @author Brian Wing Shun Chan
069     * @see JournalTemplatePersistence
070     * @see JournalTemplateUtil
071     * @generated
072     */
073    public class JournalTemplatePersistenceImpl extends BasePersistenceImpl<JournalTemplate>
074            implements JournalTemplatePersistence {
075            /*
076             * NOTE FOR DEVELOPERS:
077             *
078             * Never modify or reference this class directly. Always use {@link JournalTemplateUtil} to access the journal template persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
079             */
080            public static final String FINDER_CLASS_NAME_ENTITY = JournalTemplateImpl.class.getName();
081            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
082                    ".List1";
083            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
084                    ".List2";
085            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
086                            JournalTemplateModelImpl.FINDER_CACHE_ENABLED,
087                            JournalTemplateImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
088                            "findByUuid",
089                            new String[] {
090                                    String.class.getName(),
091                                    
092                            "java.lang.Integer", "java.lang.Integer",
093                                    "com.liferay.portal.kernel.util.OrderByComparator"
094                            });
095            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
096                            JournalTemplateModelImpl.FINDER_CACHE_ENABLED,
097                            JournalTemplateImpl.class,
098                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
099                            new String[] { String.class.getName() },
100                            JournalTemplateModelImpl.UUID_COLUMN_BITMASK);
101            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
102                            JournalTemplateModelImpl.FINDER_CACHE_ENABLED, Long.class,
103                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
104                            new String[] { String.class.getName() });
105            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
106                            JournalTemplateModelImpl.FINDER_CACHE_ENABLED,
107                            JournalTemplateImpl.class, FINDER_CLASS_NAME_ENTITY,
108                            "fetchByUUID_G",
109                            new String[] { String.class.getName(), Long.class.getName() },
110                            JournalTemplateModelImpl.UUID_COLUMN_BITMASK |
111                            JournalTemplateModelImpl.GROUPID_COLUMN_BITMASK);
112            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
113                            JournalTemplateModelImpl.FINDER_CACHE_ENABLED, Long.class,
114                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
115                            new String[] { String.class.getName(), Long.class.getName() });
116            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
117                            JournalTemplateModelImpl.FINDER_CACHE_ENABLED,
118                            JournalTemplateImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
119                            "findByGroupId",
120                            new String[] {
121                                    Long.class.getName(),
122                                    
123                            "java.lang.Integer", "java.lang.Integer",
124                                    "com.liferay.portal.kernel.util.OrderByComparator"
125                            });
126            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
127                    new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
128                            JournalTemplateModelImpl.FINDER_CACHE_ENABLED,
129                            JournalTemplateImpl.class,
130                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
131                            new String[] { Long.class.getName() },
132                            JournalTemplateModelImpl.GROUPID_COLUMN_BITMASK);
133            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
134                            JournalTemplateModelImpl.FINDER_CACHE_ENABLED, Long.class,
135                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
136                            new String[] { Long.class.getName() });
137            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_TEMPLATEID =
138                    new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
139                            JournalTemplateModelImpl.FINDER_CACHE_ENABLED,
140                            JournalTemplateImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
141                            "findByTemplateId",
142                            new String[] {
143                                    String.class.getName(),
144                                    
145                            "java.lang.Integer", "java.lang.Integer",
146                                    "com.liferay.portal.kernel.util.OrderByComparator"
147                            });
148            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TEMPLATEID =
149                    new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
150                            JournalTemplateModelImpl.FINDER_CACHE_ENABLED,
151                            JournalTemplateImpl.class,
152                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByTemplateId",
153                            new String[] { String.class.getName() },
154                            JournalTemplateModelImpl.TEMPLATEID_COLUMN_BITMASK);
155            public static final FinderPath FINDER_PATH_COUNT_BY_TEMPLATEID = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
156                            JournalTemplateModelImpl.FINDER_CACHE_ENABLED, Long.class,
157                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByTemplateId",
158                            new String[] { String.class.getName() });
159            public static final FinderPath FINDER_PATH_FETCH_BY_SMALLIMAGEID = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
160                            JournalTemplateModelImpl.FINDER_CACHE_ENABLED,
161                            JournalTemplateImpl.class, FINDER_CLASS_NAME_ENTITY,
162                            "fetchBySmallImageId", new String[] { Long.class.getName() },
163                            JournalTemplateModelImpl.SMALLIMAGEID_COLUMN_BITMASK);
164            public static final FinderPath FINDER_PATH_COUNT_BY_SMALLIMAGEID = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
165                            JournalTemplateModelImpl.FINDER_CACHE_ENABLED, Long.class,
166                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countBySmallImageId",
167                            new String[] { Long.class.getName() });
168            public static final FinderPath FINDER_PATH_FETCH_BY_G_T = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
169                            JournalTemplateModelImpl.FINDER_CACHE_ENABLED,
170                            JournalTemplateImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByG_T",
171                            new String[] { Long.class.getName(), String.class.getName() },
172                            JournalTemplateModelImpl.GROUPID_COLUMN_BITMASK |
173                            JournalTemplateModelImpl.TEMPLATEID_COLUMN_BITMASK);
174            public static final FinderPath FINDER_PATH_COUNT_BY_G_T = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
175                            JournalTemplateModelImpl.FINDER_CACHE_ENABLED, Long.class,
176                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_T",
177                            new String[] { Long.class.getName(), String.class.getName() });
178            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
179                            JournalTemplateModelImpl.FINDER_CACHE_ENABLED,
180                            JournalTemplateImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
181                            "findByG_S",
182                            new String[] {
183                                    Long.class.getName(), String.class.getName(),
184                                    
185                            "java.lang.Integer", "java.lang.Integer",
186                                    "com.liferay.portal.kernel.util.OrderByComparator"
187                            });
188            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
189                            JournalTemplateModelImpl.FINDER_CACHE_ENABLED,
190                            JournalTemplateImpl.class,
191                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_S",
192                            new String[] { Long.class.getName(), String.class.getName() },
193                            JournalTemplateModelImpl.GROUPID_COLUMN_BITMASK |
194                            JournalTemplateModelImpl.STRUCTUREID_COLUMN_BITMASK);
195            public static final FinderPath FINDER_PATH_COUNT_BY_G_S = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
196                            JournalTemplateModelImpl.FINDER_CACHE_ENABLED, Long.class,
197                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_S",
198                            new String[] { Long.class.getName(), String.class.getName() });
199            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
200                            JournalTemplateModelImpl.FINDER_CACHE_ENABLED,
201                            JournalTemplateImpl.class,
202                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
203            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
204                            JournalTemplateModelImpl.FINDER_CACHE_ENABLED,
205                            JournalTemplateImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
206                            "findAll", new String[0]);
207            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
208                            JournalTemplateModelImpl.FINDER_CACHE_ENABLED, Long.class,
209                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
210    
211            /**
212             * Caches the journal template in the entity cache if it is enabled.
213             *
214             * @param journalTemplate the journal template
215             */
216            public void cacheResult(JournalTemplate journalTemplate) {
217                    EntityCacheUtil.putResult(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
218                            JournalTemplateImpl.class, journalTemplate.getPrimaryKey(),
219                            journalTemplate);
220    
221                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
222                            new Object[] {
223                                    journalTemplate.getUuid(),
224                                    Long.valueOf(journalTemplate.getGroupId())
225                            }, journalTemplate);
226    
227                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
228                            new Object[] { Long.valueOf(journalTemplate.getSmallImageId()) },
229                            journalTemplate);
230    
231                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_T,
232                            new Object[] {
233                                    Long.valueOf(journalTemplate.getGroupId()),
234                                    
235                            journalTemplate.getTemplateId()
236                            }, journalTemplate);
237    
238                    journalTemplate.resetOriginalValues();
239            }
240    
241            /**
242             * Caches the journal templates in the entity cache if it is enabled.
243             *
244             * @param journalTemplates the journal templates
245             */
246            public void cacheResult(List<JournalTemplate> journalTemplates) {
247                    for (JournalTemplate journalTemplate : journalTemplates) {
248                            if (EntityCacheUtil.getResult(
249                                                    JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
250                                                    JournalTemplateImpl.class,
251                                                    journalTemplate.getPrimaryKey()) == null) {
252                                    cacheResult(journalTemplate);
253                            }
254                            else {
255                                    journalTemplate.resetOriginalValues();
256                            }
257                    }
258            }
259    
260            /**
261             * Clears the cache for all journal templates.
262             *
263             * <p>
264             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
265             * </p>
266             */
267            @Override
268            public void clearCache() {
269                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
270                            CacheRegistryUtil.clear(JournalTemplateImpl.class.getName());
271                    }
272    
273                    EntityCacheUtil.clearCache(JournalTemplateImpl.class.getName());
274    
275                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
276                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
277                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
278            }
279    
280            /**
281             * Clears the cache for the journal template.
282             *
283             * <p>
284             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
285             * </p>
286             */
287            @Override
288            public void clearCache(JournalTemplate journalTemplate) {
289                    EntityCacheUtil.removeResult(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
290                            JournalTemplateImpl.class, journalTemplate.getPrimaryKey());
291    
292                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
293                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
294    
295                    clearUniqueFindersCache(journalTemplate);
296            }
297    
298            @Override
299            public void clearCache(List<JournalTemplate> journalTemplates) {
300                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
301                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
302    
303                    for (JournalTemplate journalTemplate : journalTemplates) {
304                            EntityCacheUtil.removeResult(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
305                                    JournalTemplateImpl.class, journalTemplate.getPrimaryKey());
306    
307                            clearUniqueFindersCache(journalTemplate);
308                    }
309            }
310    
311            protected void clearUniqueFindersCache(JournalTemplate journalTemplate) {
312                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
313                            new Object[] {
314                                    journalTemplate.getUuid(),
315                                    Long.valueOf(journalTemplate.getGroupId())
316                            });
317    
318                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
319                            new Object[] { Long.valueOf(journalTemplate.getSmallImageId()) });
320    
321                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_T,
322                            new Object[] {
323                                    Long.valueOf(journalTemplate.getGroupId()),
324                                    
325                            journalTemplate.getTemplateId()
326                            });
327            }
328    
329            /**
330             * Creates a new journal template with the primary key. Does not add the journal template to the database.
331             *
332             * @param id the primary key for the new journal template
333             * @return the new journal template
334             */
335            public JournalTemplate create(long id) {
336                    JournalTemplate journalTemplate = new JournalTemplateImpl();
337    
338                    journalTemplate.setNew(true);
339                    journalTemplate.setPrimaryKey(id);
340    
341                    String uuid = PortalUUIDUtil.generate();
342    
343                    journalTemplate.setUuid(uuid);
344    
345                    return journalTemplate;
346            }
347    
348            /**
349             * Removes the journal template with the primary key from the database. Also notifies the appropriate model listeners.
350             *
351             * @param id the primary key of the journal template
352             * @return the journal template that was removed
353             * @throws com.liferay.portlet.journal.NoSuchTemplateException if a journal template with the primary key could not be found
354             * @throws SystemException if a system exception occurred
355             */
356            public JournalTemplate remove(long id)
357                    throws NoSuchTemplateException, SystemException {
358                    return remove(Long.valueOf(id));
359            }
360    
361            /**
362             * Removes the journal template with the primary key from the database. Also notifies the appropriate model listeners.
363             *
364             * @param primaryKey the primary key of the journal template
365             * @return the journal template that was removed
366             * @throws com.liferay.portlet.journal.NoSuchTemplateException if a journal template with the primary key could not be found
367             * @throws SystemException if a system exception occurred
368             */
369            @Override
370            public JournalTemplate remove(Serializable primaryKey)
371                    throws NoSuchTemplateException, SystemException {
372                    Session session = null;
373    
374                    try {
375                            session = openSession();
376    
377                            JournalTemplate journalTemplate = (JournalTemplate)session.get(JournalTemplateImpl.class,
378                                            primaryKey);
379    
380                            if (journalTemplate == null) {
381                                    if (_log.isWarnEnabled()) {
382                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
383                                    }
384    
385                                    throw new NoSuchTemplateException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
386                                            primaryKey);
387                            }
388    
389                            return remove(journalTemplate);
390                    }
391                    catch (NoSuchTemplateException nsee) {
392                            throw nsee;
393                    }
394                    catch (Exception e) {
395                            throw processException(e);
396                    }
397                    finally {
398                            closeSession(session);
399                    }
400            }
401    
402            @Override
403            protected JournalTemplate removeImpl(JournalTemplate journalTemplate)
404                    throws SystemException {
405                    journalTemplate = toUnwrappedModel(journalTemplate);
406    
407                    Session session = null;
408    
409                    try {
410                            session = openSession();
411    
412                            BatchSessionUtil.delete(session, journalTemplate);
413                    }
414                    catch (Exception e) {
415                            throw processException(e);
416                    }
417                    finally {
418                            closeSession(session);
419                    }
420    
421                    clearCache(journalTemplate);
422    
423                    return journalTemplate;
424            }
425    
426            @Override
427            public JournalTemplate updateImpl(
428                    com.liferay.portlet.journal.model.JournalTemplate journalTemplate,
429                    boolean merge) throws SystemException {
430                    journalTemplate = toUnwrappedModel(journalTemplate);
431    
432                    boolean isNew = journalTemplate.isNew();
433    
434                    JournalTemplateModelImpl journalTemplateModelImpl = (JournalTemplateModelImpl)journalTemplate;
435    
436                    if (Validator.isNull(journalTemplate.getUuid())) {
437                            String uuid = PortalUUIDUtil.generate();
438    
439                            journalTemplate.setUuid(uuid);
440                    }
441    
442                    Session session = null;
443    
444                    try {
445                            session = openSession();
446    
447                            BatchSessionUtil.update(session, journalTemplate, merge);
448    
449                            journalTemplate.setNew(false);
450                    }
451                    catch (Exception e) {
452                            throw processException(e);
453                    }
454                    finally {
455                            closeSession(session);
456                    }
457    
458                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
459    
460                    if (isNew || !JournalTemplateModelImpl.COLUMN_BITMASK_ENABLED) {
461                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
462                    }
463    
464                    else {
465                            if ((journalTemplateModelImpl.getColumnBitmask() &
466                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
467                                    Object[] args = new Object[] {
468                                                    journalTemplateModelImpl.getOriginalUuid()
469                                            };
470    
471                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
472                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
473                                            args);
474    
475                                    args = new Object[] { journalTemplateModelImpl.getUuid() };
476    
477                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
478                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
479                                            args);
480                            }
481    
482                            if ((journalTemplateModelImpl.getColumnBitmask() &
483                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
484                                    Object[] args = new Object[] {
485                                                    Long.valueOf(journalTemplateModelImpl.getOriginalGroupId())
486                                            };
487    
488                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
489                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
490                                            args);
491    
492                                    args = new Object[] {
493                                                    Long.valueOf(journalTemplateModelImpl.getGroupId())
494                                            };
495    
496                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
497                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
498                                            args);
499                            }
500    
501                            if ((journalTemplateModelImpl.getColumnBitmask() &
502                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TEMPLATEID.getColumnBitmask()) != 0) {
503                                    Object[] args = new Object[] {
504                                                    journalTemplateModelImpl.getOriginalTemplateId()
505                                            };
506    
507                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TEMPLATEID,
508                                            args);
509                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TEMPLATEID,
510                                            args);
511    
512                                    args = new Object[] { journalTemplateModelImpl.getTemplateId() };
513    
514                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TEMPLATEID,
515                                            args);
516                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TEMPLATEID,
517                                            args);
518                            }
519    
520                            if ((journalTemplateModelImpl.getColumnBitmask() &
521                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S.getColumnBitmask()) != 0) {
522                                    Object[] args = new Object[] {
523                                                    Long.valueOf(journalTemplateModelImpl.getOriginalGroupId()),
524                                                    
525                                                    journalTemplateModelImpl.getOriginalStructureId()
526                                            };
527    
528                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
529                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
530                                            args);
531    
532                                    args = new Object[] {
533                                                    Long.valueOf(journalTemplateModelImpl.getGroupId()),
534                                                    
535                                                    journalTemplateModelImpl.getStructureId()
536                                            };
537    
538                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
539                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
540                                            args);
541                            }
542                    }
543    
544                    EntityCacheUtil.putResult(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
545                            JournalTemplateImpl.class, journalTemplate.getPrimaryKey(),
546                            journalTemplate);
547    
548                    if (isNew) {
549                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
550                                    new Object[] {
551                                            journalTemplate.getUuid(),
552                                            Long.valueOf(journalTemplate.getGroupId())
553                                    }, journalTemplate);
554    
555                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
556                                    new Object[] { Long.valueOf(journalTemplate.getSmallImageId()) },
557                                    journalTemplate);
558    
559                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_T,
560                                    new Object[] {
561                                            Long.valueOf(journalTemplate.getGroupId()),
562                                            
563                                    journalTemplate.getTemplateId()
564                                    }, journalTemplate);
565                    }
566                    else {
567                            if ((journalTemplateModelImpl.getColumnBitmask() &
568                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
569                                    Object[] args = new Object[] {
570                                                    journalTemplateModelImpl.getOriginalUuid(),
571                                                    Long.valueOf(journalTemplateModelImpl.getOriginalGroupId())
572                                            };
573    
574                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
575                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
576    
577                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
578                                            new Object[] {
579                                                    journalTemplate.getUuid(),
580                                                    Long.valueOf(journalTemplate.getGroupId())
581                                            }, journalTemplate);
582                            }
583    
584                            if ((journalTemplateModelImpl.getColumnBitmask() &
585                                            FINDER_PATH_FETCH_BY_SMALLIMAGEID.getColumnBitmask()) != 0) {
586                                    Object[] args = new Object[] {
587                                                    Long.valueOf(journalTemplateModelImpl.getOriginalSmallImageId())
588                                            };
589    
590                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_SMALLIMAGEID,
591                                            args);
592                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
593                                            args);
594    
595                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
596                                            new Object[] { Long.valueOf(
597                                                            journalTemplate.getSmallImageId()) },
598                                            journalTemplate);
599                            }
600    
601                            if ((journalTemplateModelImpl.getColumnBitmask() &
602                                            FINDER_PATH_FETCH_BY_G_T.getColumnBitmask()) != 0) {
603                                    Object[] args = new Object[] {
604                                                    Long.valueOf(journalTemplateModelImpl.getOriginalGroupId()),
605                                                    
606                                                    journalTemplateModelImpl.getOriginalTemplateId()
607                                            };
608    
609                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_T, args);
610                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_T, args);
611    
612                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_T,
613                                            new Object[] {
614                                                    Long.valueOf(journalTemplate.getGroupId()),
615                                                    
616                                            journalTemplate.getTemplateId()
617                                            }, journalTemplate);
618                            }
619                    }
620    
621                    return journalTemplate;
622            }
623    
624            protected JournalTemplate toUnwrappedModel(JournalTemplate journalTemplate) {
625                    if (journalTemplate instanceof JournalTemplateImpl) {
626                            return journalTemplate;
627                    }
628    
629                    JournalTemplateImpl journalTemplateImpl = new JournalTemplateImpl();
630    
631                    journalTemplateImpl.setNew(journalTemplate.isNew());
632                    journalTemplateImpl.setPrimaryKey(journalTemplate.getPrimaryKey());
633    
634                    journalTemplateImpl.setUuid(journalTemplate.getUuid());
635                    journalTemplateImpl.setId(journalTemplate.getId());
636                    journalTemplateImpl.setGroupId(journalTemplate.getGroupId());
637                    journalTemplateImpl.setCompanyId(journalTemplate.getCompanyId());
638                    journalTemplateImpl.setUserId(journalTemplate.getUserId());
639                    journalTemplateImpl.setUserName(journalTemplate.getUserName());
640                    journalTemplateImpl.setCreateDate(journalTemplate.getCreateDate());
641                    journalTemplateImpl.setModifiedDate(journalTemplate.getModifiedDate());
642                    journalTemplateImpl.setTemplateId(journalTemplate.getTemplateId());
643                    journalTemplateImpl.setStructureId(journalTemplate.getStructureId());
644                    journalTemplateImpl.setName(journalTemplate.getName());
645                    journalTemplateImpl.setDescription(journalTemplate.getDescription());
646                    journalTemplateImpl.setXsl(journalTemplate.getXsl());
647                    journalTemplateImpl.setLangType(journalTemplate.getLangType());
648                    journalTemplateImpl.setCacheable(journalTemplate.isCacheable());
649                    journalTemplateImpl.setSmallImage(journalTemplate.isSmallImage());
650                    journalTemplateImpl.setSmallImageId(journalTemplate.getSmallImageId());
651                    journalTemplateImpl.setSmallImageURL(journalTemplate.getSmallImageURL());
652    
653                    return journalTemplateImpl;
654            }
655    
656            /**
657             * Returns the journal template with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
658             *
659             * @param primaryKey the primary key of the journal template
660             * @return the journal template
661             * @throws com.liferay.portal.NoSuchModelException if a journal template with the primary key could not be found
662             * @throws SystemException if a system exception occurred
663             */
664            @Override
665            public JournalTemplate findByPrimaryKey(Serializable primaryKey)
666                    throws NoSuchModelException, SystemException {
667                    return findByPrimaryKey(((Long)primaryKey).longValue());
668            }
669    
670            /**
671             * Returns the journal template with the primary key or throws a {@link com.liferay.portlet.journal.NoSuchTemplateException} if it could not be found.
672             *
673             * @param id the primary key of the journal template
674             * @return the journal template
675             * @throws com.liferay.portlet.journal.NoSuchTemplateException if a journal template with the primary key could not be found
676             * @throws SystemException if a system exception occurred
677             */
678            public JournalTemplate findByPrimaryKey(long id)
679                    throws NoSuchTemplateException, SystemException {
680                    JournalTemplate journalTemplate = fetchByPrimaryKey(id);
681    
682                    if (journalTemplate == null) {
683                            if (_log.isWarnEnabled()) {
684                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + id);
685                            }
686    
687                            throw new NoSuchTemplateException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
688                                    id);
689                    }
690    
691                    return journalTemplate;
692            }
693    
694            /**
695             * Returns the journal template with the primary key or returns <code>null</code> if it could not be found.
696             *
697             * @param primaryKey the primary key of the journal template
698             * @return the journal template, or <code>null</code> if a journal template with the primary key could not be found
699             * @throws SystemException if a system exception occurred
700             */
701            @Override
702            public JournalTemplate fetchByPrimaryKey(Serializable primaryKey)
703                    throws SystemException {
704                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
705            }
706    
707            /**
708             * Returns the journal template with the primary key or returns <code>null</code> if it could not be found.
709             *
710             * @param id the primary key of the journal template
711             * @return the journal template, or <code>null</code> if a journal template with the primary key could not be found
712             * @throws SystemException if a system exception occurred
713             */
714            public JournalTemplate fetchByPrimaryKey(long id) throws SystemException {
715                    JournalTemplate journalTemplate = (JournalTemplate)EntityCacheUtil.getResult(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
716                                    JournalTemplateImpl.class, id);
717    
718                    if (journalTemplate == _nullJournalTemplate) {
719                            return null;
720                    }
721    
722                    if (journalTemplate == null) {
723                            Session session = null;
724    
725                            boolean hasException = false;
726    
727                            try {
728                                    session = openSession();
729    
730                                    journalTemplate = (JournalTemplate)session.get(JournalTemplateImpl.class,
731                                                    Long.valueOf(id));
732                            }
733                            catch (Exception e) {
734                                    hasException = true;
735    
736                                    throw processException(e);
737                            }
738                            finally {
739                                    if (journalTemplate != null) {
740                                            cacheResult(journalTemplate);
741                                    }
742                                    else if (!hasException) {
743                                            EntityCacheUtil.putResult(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
744                                                    JournalTemplateImpl.class, id, _nullJournalTemplate);
745                                    }
746    
747                                    closeSession(session);
748                            }
749                    }
750    
751                    return journalTemplate;
752            }
753    
754            /**
755             * Returns all the journal templates where uuid = &#63;.
756             *
757             * @param uuid the uuid
758             * @return the matching journal templates
759             * @throws SystemException if a system exception occurred
760             */
761            public List<JournalTemplate> findByUuid(String uuid)
762                    throws SystemException {
763                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
764            }
765    
766            /**
767             * Returns a range of all the journal templates where uuid = &#63;.
768             *
769             * <p>
770             * 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.
771             * </p>
772             *
773             * @param uuid the uuid
774             * @param start the lower bound of the range of journal templates
775             * @param end the upper bound of the range of journal templates (not inclusive)
776             * @return the range of matching journal templates
777             * @throws SystemException if a system exception occurred
778             */
779            public List<JournalTemplate> findByUuid(String uuid, int start, int end)
780                    throws SystemException {
781                    return findByUuid(uuid, start, end, null);
782            }
783    
784            /**
785             * Returns an ordered range of all the journal templates where uuid = &#63;.
786             *
787             * <p>
788             * 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.
789             * </p>
790             *
791             * @param uuid the uuid
792             * @param start the lower bound of the range of journal templates
793             * @param end the upper bound of the range of journal templates (not inclusive)
794             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
795             * @return the ordered range of matching journal templates
796             * @throws SystemException if a system exception occurred
797             */
798            public List<JournalTemplate> findByUuid(String uuid, int start, int end,
799                    OrderByComparator orderByComparator) throws SystemException {
800                    FinderPath finderPath = null;
801                    Object[] finderArgs = null;
802    
803                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
804                                    (orderByComparator == null)) {
805                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
806                            finderArgs = new Object[] { uuid };
807                    }
808                    else {
809                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
810                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
811                    }
812    
813                    List<JournalTemplate> list = (List<JournalTemplate>)FinderCacheUtil.getResult(finderPath,
814                                    finderArgs, this);
815    
816                    if (list == null) {
817                            StringBundler query = null;
818    
819                            if (orderByComparator != null) {
820                                    query = new StringBundler(3 +
821                                                    (orderByComparator.getOrderByFields().length * 3));
822                            }
823                            else {
824                                    query = new StringBundler(3);
825                            }
826    
827                            query.append(_SQL_SELECT_JOURNALTEMPLATE_WHERE);
828    
829                            if (uuid == null) {
830                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
831                            }
832                            else {
833                                    if (uuid.equals(StringPool.BLANK)) {
834                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
835                                    }
836                                    else {
837                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
838                                    }
839                            }
840    
841                            if (orderByComparator != null) {
842                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
843                                            orderByComparator);
844                            }
845    
846                            else {
847                                    query.append(JournalTemplateModelImpl.ORDER_BY_JPQL);
848                            }
849    
850                            String sql = query.toString();
851    
852                            Session session = null;
853    
854                            try {
855                                    session = openSession();
856    
857                                    Query q = session.createQuery(sql);
858    
859                                    QueryPos qPos = QueryPos.getInstance(q);
860    
861                                    if (uuid != null) {
862                                            qPos.add(uuid);
863                                    }
864    
865                                    list = (List<JournalTemplate>)QueryUtil.list(q, getDialect(),
866                                                    start, end);
867                            }
868                            catch (Exception e) {
869                                    throw processException(e);
870                            }
871                            finally {
872                                    if (list == null) {
873                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
874                                    }
875                                    else {
876                                            cacheResult(list);
877    
878                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
879                                    }
880    
881                                    closeSession(session);
882                            }
883                    }
884    
885                    return list;
886            }
887    
888            /**
889             * Returns the first journal template in the ordered set where uuid = &#63;.
890             *
891             * <p>
892             * 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.
893             * </p>
894             *
895             * @param uuid the uuid
896             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
897             * @return the first matching journal template
898             * @throws com.liferay.portlet.journal.NoSuchTemplateException if a matching journal template could not be found
899             * @throws SystemException if a system exception occurred
900             */
901            public JournalTemplate findByUuid_First(String uuid,
902                    OrderByComparator orderByComparator)
903                    throws NoSuchTemplateException, SystemException {
904                    List<JournalTemplate> list = findByUuid(uuid, 0, 1, orderByComparator);
905    
906                    if (list.isEmpty()) {
907                            StringBundler msg = new StringBundler(4);
908    
909                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
910    
911                            msg.append("uuid=");
912                            msg.append(uuid);
913    
914                            msg.append(StringPool.CLOSE_CURLY_BRACE);
915    
916                            throw new NoSuchTemplateException(msg.toString());
917                    }
918                    else {
919                            return list.get(0);
920                    }
921            }
922    
923            /**
924             * Returns the last journal template in the ordered set where uuid = &#63;.
925             *
926             * <p>
927             * 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.
928             * </p>
929             *
930             * @param uuid the uuid
931             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
932             * @return the last matching journal template
933             * @throws com.liferay.portlet.journal.NoSuchTemplateException if a matching journal template could not be found
934             * @throws SystemException if a system exception occurred
935             */
936            public JournalTemplate findByUuid_Last(String uuid,
937                    OrderByComparator orderByComparator)
938                    throws NoSuchTemplateException, SystemException {
939                    int count = countByUuid(uuid);
940    
941                    List<JournalTemplate> list = findByUuid(uuid, count - 1, count,
942                                    orderByComparator);
943    
944                    if (list.isEmpty()) {
945                            StringBundler msg = new StringBundler(4);
946    
947                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
948    
949                            msg.append("uuid=");
950                            msg.append(uuid);
951    
952                            msg.append(StringPool.CLOSE_CURLY_BRACE);
953    
954                            throw new NoSuchTemplateException(msg.toString());
955                    }
956                    else {
957                            return list.get(0);
958                    }
959            }
960    
961            /**
962             * Returns the journal templates before and after the current journal template in the ordered set where uuid = &#63;.
963             *
964             * <p>
965             * 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.
966             * </p>
967             *
968             * @param id the primary key of the current journal template
969             * @param uuid the uuid
970             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
971             * @return the previous, current, and next journal template
972             * @throws com.liferay.portlet.journal.NoSuchTemplateException if a journal template with the primary key could not be found
973             * @throws SystemException if a system exception occurred
974             */
975            public JournalTemplate[] findByUuid_PrevAndNext(long id, String uuid,
976                    OrderByComparator orderByComparator)
977                    throws NoSuchTemplateException, SystemException {
978                    JournalTemplate journalTemplate = findByPrimaryKey(id);
979    
980                    Session session = null;
981    
982                    try {
983                            session = openSession();
984    
985                            JournalTemplate[] array = new JournalTemplateImpl[3];
986    
987                            array[0] = getByUuid_PrevAndNext(session, journalTemplate, uuid,
988                                            orderByComparator, true);
989    
990                            array[1] = journalTemplate;
991    
992                            array[2] = getByUuid_PrevAndNext(session, journalTemplate, uuid,
993                                            orderByComparator, false);
994    
995                            return array;
996                    }
997                    catch (Exception e) {
998                            throw processException(e);
999                    }
1000                    finally {
1001                            closeSession(session);
1002                    }
1003            }
1004    
1005            protected JournalTemplate getByUuid_PrevAndNext(Session session,
1006                    JournalTemplate journalTemplate, String uuid,
1007                    OrderByComparator orderByComparator, boolean previous) {
1008                    StringBundler query = null;
1009    
1010                    if (orderByComparator != null) {
1011                            query = new StringBundler(6 +
1012                                            (orderByComparator.getOrderByFields().length * 6));
1013                    }
1014                    else {
1015                            query = new StringBundler(3);
1016                    }
1017    
1018                    query.append(_SQL_SELECT_JOURNALTEMPLATE_WHERE);
1019    
1020                    if (uuid == null) {
1021                            query.append(_FINDER_COLUMN_UUID_UUID_1);
1022                    }
1023                    else {
1024                            if (uuid.equals(StringPool.BLANK)) {
1025                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
1026                            }
1027                            else {
1028                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
1029                            }
1030                    }
1031    
1032                    if (orderByComparator != null) {
1033                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1034    
1035                            if (orderByConditionFields.length > 0) {
1036                                    query.append(WHERE_AND);
1037                            }
1038    
1039                            for (int i = 0; i < orderByConditionFields.length; i++) {
1040                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1041                                    query.append(orderByConditionFields[i]);
1042    
1043                                    if ((i + 1) < orderByConditionFields.length) {
1044                                            if (orderByComparator.isAscending() ^ previous) {
1045                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1046                                            }
1047                                            else {
1048                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1049                                            }
1050                                    }
1051                                    else {
1052                                            if (orderByComparator.isAscending() ^ previous) {
1053                                                    query.append(WHERE_GREATER_THAN);
1054                                            }
1055                                            else {
1056                                                    query.append(WHERE_LESSER_THAN);
1057                                            }
1058                                    }
1059                            }
1060    
1061                            query.append(ORDER_BY_CLAUSE);
1062    
1063                            String[] orderByFields = orderByComparator.getOrderByFields();
1064    
1065                            for (int i = 0; i < orderByFields.length; i++) {
1066                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1067                                    query.append(orderByFields[i]);
1068    
1069                                    if ((i + 1) < orderByFields.length) {
1070                                            if (orderByComparator.isAscending() ^ previous) {
1071                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1072                                            }
1073                                            else {
1074                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1075                                            }
1076                                    }
1077                                    else {
1078                                            if (orderByComparator.isAscending() ^ previous) {
1079                                                    query.append(ORDER_BY_ASC);
1080                                            }
1081                                            else {
1082                                                    query.append(ORDER_BY_DESC);
1083                                            }
1084                                    }
1085                            }
1086                    }
1087    
1088                    else {
1089                            query.append(JournalTemplateModelImpl.ORDER_BY_JPQL);
1090                    }
1091    
1092                    String sql = query.toString();
1093    
1094                    Query q = session.createQuery(sql);
1095    
1096                    q.setFirstResult(0);
1097                    q.setMaxResults(2);
1098    
1099                    QueryPos qPos = QueryPos.getInstance(q);
1100    
1101                    if (uuid != null) {
1102                            qPos.add(uuid);
1103                    }
1104    
1105                    if (orderByComparator != null) {
1106                            Object[] values = orderByComparator.getOrderByConditionValues(journalTemplate);
1107    
1108                            for (Object value : values) {
1109                                    qPos.add(value);
1110                            }
1111                    }
1112    
1113                    List<JournalTemplate> list = q.list();
1114    
1115                    if (list.size() == 2) {
1116                            return list.get(1);
1117                    }
1118                    else {
1119                            return null;
1120                    }
1121            }
1122    
1123            /**
1124             * Returns the journal template where uuid = &#63; and groupId = &#63; or throws a {@link com.liferay.portlet.journal.NoSuchTemplateException} if it could not be found.
1125             *
1126             * @param uuid the uuid
1127             * @param groupId the group ID
1128             * @return the matching journal template
1129             * @throws com.liferay.portlet.journal.NoSuchTemplateException if a matching journal template could not be found
1130             * @throws SystemException if a system exception occurred
1131             */
1132            public JournalTemplate findByUUID_G(String uuid, long groupId)
1133                    throws NoSuchTemplateException, SystemException {
1134                    JournalTemplate journalTemplate = fetchByUUID_G(uuid, groupId);
1135    
1136                    if (journalTemplate == null) {
1137                            StringBundler msg = new StringBundler(6);
1138    
1139                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1140    
1141                            msg.append("uuid=");
1142                            msg.append(uuid);
1143    
1144                            msg.append(", groupId=");
1145                            msg.append(groupId);
1146    
1147                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1148    
1149                            if (_log.isWarnEnabled()) {
1150                                    _log.warn(msg.toString());
1151                            }
1152    
1153                            throw new NoSuchTemplateException(msg.toString());
1154                    }
1155    
1156                    return journalTemplate;
1157            }
1158    
1159            /**
1160             * Returns the journal template where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
1161             *
1162             * @param uuid the uuid
1163             * @param groupId the group ID
1164             * @return the matching journal template, or <code>null</code> if a matching journal template could not be found
1165             * @throws SystemException if a system exception occurred
1166             */
1167            public JournalTemplate fetchByUUID_G(String uuid, long groupId)
1168                    throws SystemException {
1169                    return fetchByUUID_G(uuid, groupId, true);
1170            }
1171    
1172            /**
1173             * Returns the journal template where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
1174             *
1175             * @param uuid the uuid
1176             * @param groupId the group ID
1177             * @param retrieveFromCache whether to use the finder cache
1178             * @return the matching journal template, or <code>null</code> if a matching journal template could not be found
1179             * @throws SystemException if a system exception occurred
1180             */
1181            public JournalTemplate fetchByUUID_G(String uuid, long groupId,
1182                    boolean retrieveFromCache) throws SystemException {
1183                    Object[] finderArgs = new Object[] { uuid, groupId };
1184    
1185                    Object result = null;
1186    
1187                    if (retrieveFromCache) {
1188                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
1189                                            finderArgs, this);
1190                    }
1191    
1192                    if (result == null) {
1193                            StringBundler query = new StringBundler(4);
1194    
1195                            query.append(_SQL_SELECT_JOURNALTEMPLATE_WHERE);
1196    
1197                            if (uuid == null) {
1198                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
1199                            }
1200                            else {
1201                                    if (uuid.equals(StringPool.BLANK)) {
1202                                            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
1203                                    }
1204                                    else {
1205                                            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
1206                                    }
1207                            }
1208    
1209                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
1210    
1211                            query.append(JournalTemplateModelImpl.ORDER_BY_JPQL);
1212    
1213                            String sql = query.toString();
1214    
1215                            Session session = null;
1216    
1217                            try {
1218                                    session = openSession();
1219    
1220                                    Query q = session.createQuery(sql);
1221    
1222                                    QueryPos qPos = QueryPos.getInstance(q);
1223    
1224                                    if (uuid != null) {
1225                                            qPos.add(uuid);
1226                                    }
1227    
1228                                    qPos.add(groupId);
1229    
1230                                    List<JournalTemplate> list = q.list();
1231    
1232                                    result = list;
1233    
1234                                    JournalTemplate journalTemplate = null;
1235    
1236                                    if (list.isEmpty()) {
1237                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1238                                                    finderArgs, list);
1239                                    }
1240                                    else {
1241                                            journalTemplate = list.get(0);
1242    
1243                                            cacheResult(journalTemplate);
1244    
1245                                            if ((journalTemplate.getUuid() == null) ||
1246                                                            !journalTemplate.getUuid().equals(uuid) ||
1247                                                            (journalTemplate.getGroupId() != groupId)) {
1248                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1249                                                            finderArgs, journalTemplate);
1250                                            }
1251                                    }
1252    
1253                                    return journalTemplate;
1254                            }
1255                            catch (Exception e) {
1256                                    throw processException(e);
1257                            }
1258                            finally {
1259                                    if (result == null) {
1260                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
1261                                                    finderArgs);
1262                                    }
1263    
1264                                    closeSession(session);
1265                            }
1266                    }
1267                    else {
1268                            if (result instanceof List<?>) {
1269                                    return null;
1270                            }
1271                            else {
1272                                    return (JournalTemplate)result;
1273                            }
1274                    }
1275            }
1276    
1277            /**
1278             * Returns all the journal templates where groupId = &#63;.
1279             *
1280             * @param groupId the group ID
1281             * @return the matching journal templates
1282             * @throws SystemException if a system exception occurred
1283             */
1284            public List<JournalTemplate> findByGroupId(long groupId)
1285                    throws SystemException {
1286                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1287            }
1288    
1289            /**
1290             * Returns a range of all the journal templates where groupId = &#63;.
1291             *
1292             * <p>
1293             * 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.
1294             * </p>
1295             *
1296             * @param groupId the group ID
1297             * @param start the lower bound of the range of journal templates
1298             * @param end the upper bound of the range of journal templates (not inclusive)
1299             * @return the range of matching journal templates
1300             * @throws SystemException if a system exception occurred
1301             */
1302            public List<JournalTemplate> findByGroupId(long groupId, int start, int end)
1303                    throws SystemException {
1304                    return findByGroupId(groupId, start, end, null);
1305            }
1306    
1307            /**
1308             * Returns an ordered range of all the journal templates where groupId = &#63;.
1309             *
1310             * <p>
1311             * 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.
1312             * </p>
1313             *
1314             * @param groupId the group ID
1315             * @param start the lower bound of the range of journal templates
1316             * @param end the upper bound of the range of journal templates (not inclusive)
1317             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1318             * @return the ordered range of matching journal templates
1319             * @throws SystemException if a system exception occurred
1320             */
1321            public List<JournalTemplate> findByGroupId(long groupId, int start,
1322                    int end, OrderByComparator orderByComparator) throws SystemException {
1323                    FinderPath finderPath = null;
1324                    Object[] finderArgs = null;
1325    
1326                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1327                                    (orderByComparator == null)) {
1328                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1329                            finderArgs = new Object[] { groupId };
1330                    }
1331                    else {
1332                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1333                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
1334                    }
1335    
1336                    List<JournalTemplate> list = (List<JournalTemplate>)FinderCacheUtil.getResult(finderPath,
1337                                    finderArgs, this);
1338    
1339                    if (list == null) {
1340                            StringBundler query = null;
1341    
1342                            if (orderByComparator != null) {
1343                                    query = new StringBundler(3 +
1344                                                    (orderByComparator.getOrderByFields().length * 3));
1345                            }
1346                            else {
1347                                    query = new StringBundler(3);
1348                            }
1349    
1350                            query.append(_SQL_SELECT_JOURNALTEMPLATE_WHERE);
1351    
1352                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1353    
1354                            if (orderByComparator != null) {
1355                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1356                                            orderByComparator);
1357                            }
1358    
1359                            else {
1360                                    query.append(JournalTemplateModelImpl.ORDER_BY_JPQL);
1361                            }
1362    
1363                            String sql = query.toString();
1364    
1365                            Session session = null;
1366    
1367                            try {
1368                                    session = openSession();
1369    
1370                                    Query q = session.createQuery(sql);
1371    
1372                                    QueryPos qPos = QueryPos.getInstance(q);
1373    
1374                                    qPos.add(groupId);
1375    
1376                                    list = (List<JournalTemplate>)QueryUtil.list(q, getDialect(),
1377                                                    start, end);
1378                            }
1379                            catch (Exception e) {
1380                                    throw processException(e);
1381                            }
1382                            finally {
1383                                    if (list == null) {
1384                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1385                                    }
1386                                    else {
1387                                            cacheResult(list);
1388    
1389                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1390                                    }
1391    
1392                                    closeSession(session);
1393                            }
1394                    }
1395    
1396                    return list;
1397            }
1398    
1399            /**
1400             * Returns the first journal template in the ordered set where groupId = &#63;.
1401             *
1402             * <p>
1403             * 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.
1404             * </p>
1405             *
1406             * @param groupId the group ID
1407             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1408             * @return the first matching journal template
1409             * @throws com.liferay.portlet.journal.NoSuchTemplateException if a matching journal template could not be found
1410             * @throws SystemException if a system exception occurred
1411             */
1412            public JournalTemplate findByGroupId_First(long groupId,
1413                    OrderByComparator orderByComparator)
1414                    throws NoSuchTemplateException, SystemException {
1415                    List<JournalTemplate> list = findByGroupId(groupId, 0, 1,
1416                                    orderByComparator);
1417    
1418                    if (list.isEmpty()) {
1419                            StringBundler msg = new StringBundler(4);
1420    
1421                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1422    
1423                            msg.append("groupId=");
1424                            msg.append(groupId);
1425    
1426                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1427    
1428                            throw new NoSuchTemplateException(msg.toString());
1429                    }
1430                    else {
1431                            return list.get(0);
1432                    }
1433            }
1434    
1435            /**
1436             * Returns the last journal template in the ordered set where groupId = &#63;.
1437             *
1438             * <p>
1439             * 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.
1440             * </p>
1441             *
1442             * @param groupId the group ID
1443             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1444             * @return the last matching journal template
1445             * @throws com.liferay.portlet.journal.NoSuchTemplateException if a matching journal template could not be found
1446             * @throws SystemException if a system exception occurred
1447             */
1448            public JournalTemplate findByGroupId_Last(long groupId,
1449                    OrderByComparator orderByComparator)
1450                    throws NoSuchTemplateException, SystemException {
1451                    int count = countByGroupId(groupId);
1452    
1453                    List<JournalTemplate> list = findByGroupId(groupId, count - 1, count,
1454                                    orderByComparator);
1455    
1456                    if (list.isEmpty()) {
1457                            StringBundler msg = new StringBundler(4);
1458    
1459                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1460    
1461                            msg.append("groupId=");
1462                            msg.append(groupId);
1463    
1464                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1465    
1466                            throw new NoSuchTemplateException(msg.toString());
1467                    }
1468                    else {
1469                            return list.get(0);
1470                    }
1471            }
1472    
1473            /**
1474             * Returns the journal templates before and after the current journal template in the ordered set where groupId = &#63;.
1475             *
1476             * <p>
1477             * 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.
1478             * </p>
1479             *
1480             * @param id the primary key of the current journal template
1481             * @param groupId the group ID
1482             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1483             * @return the previous, current, and next journal template
1484             * @throws com.liferay.portlet.journal.NoSuchTemplateException if a journal template with the primary key could not be found
1485             * @throws SystemException if a system exception occurred
1486             */
1487            public JournalTemplate[] findByGroupId_PrevAndNext(long id, long groupId,
1488                    OrderByComparator orderByComparator)
1489                    throws NoSuchTemplateException, SystemException {
1490                    JournalTemplate journalTemplate = findByPrimaryKey(id);
1491    
1492                    Session session = null;
1493    
1494                    try {
1495                            session = openSession();
1496    
1497                            JournalTemplate[] array = new JournalTemplateImpl[3];
1498    
1499                            array[0] = getByGroupId_PrevAndNext(session, journalTemplate,
1500                                            groupId, orderByComparator, true);
1501    
1502                            array[1] = journalTemplate;
1503    
1504                            array[2] = getByGroupId_PrevAndNext(session, journalTemplate,
1505                                            groupId, orderByComparator, false);
1506    
1507                            return array;
1508                    }
1509                    catch (Exception e) {
1510                            throw processException(e);
1511                    }
1512                    finally {
1513                            closeSession(session);
1514                    }
1515            }
1516    
1517            protected JournalTemplate getByGroupId_PrevAndNext(Session session,
1518                    JournalTemplate journalTemplate, long groupId,
1519                    OrderByComparator orderByComparator, boolean previous) {
1520                    StringBundler query = null;
1521    
1522                    if (orderByComparator != null) {
1523                            query = new StringBundler(6 +
1524                                            (orderByComparator.getOrderByFields().length * 6));
1525                    }
1526                    else {
1527                            query = new StringBundler(3);
1528                    }
1529    
1530                    query.append(_SQL_SELECT_JOURNALTEMPLATE_WHERE);
1531    
1532                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1533    
1534                    if (orderByComparator != null) {
1535                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1536    
1537                            if (orderByConditionFields.length > 0) {
1538                                    query.append(WHERE_AND);
1539                            }
1540    
1541                            for (int i = 0; i < orderByConditionFields.length; i++) {
1542                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1543                                    query.append(orderByConditionFields[i]);
1544    
1545                                    if ((i + 1) < orderByConditionFields.length) {
1546                                            if (orderByComparator.isAscending() ^ previous) {
1547                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1548                                            }
1549                                            else {
1550                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1551                                            }
1552                                    }
1553                                    else {
1554                                            if (orderByComparator.isAscending() ^ previous) {
1555                                                    query.append(WHERE_GREATER_THAN);
1556                                            }
1557                                            else {
1558                                                    query.append(WHERE_LESSER_THAN);
1559                                            }
1560                                    }
1561                            }
1562    
1563                            query.append(ORDER_BY_CLAUSE);
1564    
1565                            String[] orderByFields = orderByComparator.getOrderByFields();
1566    
1567                            for (int i = 0; i < orderByFields.length; i++) {
1568                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1569                                    query.append(orderByFields[i]);
1570    
1571                                    if ((i + 1) < orderByFields.length) {
1572                                            if (orderByComparator.isAscending() ^ previous) {
1573                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1574                                            }
1575                                            else {
1576                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1577                                            }
1578                                    }
1579                                    else {
1580                                            if (orderByComparator.isAscending() ^ previous) {
1581                                                    query.append(ORDER_BY_ASC);
1582                                            }
1583                                            else {
1584                                                    query.append(ORDER_BY_DESC);
1585                                            }
1586                                    }
1587                            }
1588                    }
1589    
1590                    else {
1591                            query.append(JournalTemplateModelImpl.ORDER_BY_JPQL);
1592                    }
1593    
1594                    String sql = query.toString();
1595    
1596                    Query q = session.createQuery(sql);
1597    
1598                    q.setFirstResult(0);
1599                    q.setMaxResults(2);
1600    
1601                    QueryPos qPos = QueryPos.getInstance(q);
1602    
1603                    qPos.add(groupId);
1604    
1605                    if (orderByComparator != null) {
1606                            Object[] values = orderByComparator.getOrderByConditionValues(journalTemplate);
1607    
1608                            for (Object value : values) {
1609                                    qPos.add(value);
1610                            }
1611                    }
1612    
1613                    List<JournalTemplate> list = q.list();
1614    
1615                    if (list.size() == 2) {
1616                            return list.get(1);
1617                    }
1618                    else {
1619                            return null;
1620                    }
1621            }
1622    
1623            /**
1624             * Returns all the journal templates that the user has permission to view where groupId = &#63;.
1625             *
1626             * @param groupId the group ID
1627             * @return the matching journal templates that the user has permission to view
1628             * @throws SystemException if a system exception occurred
1629             */
1630            public List<JournalTemplate> filterFindByGroupId(long groupId)
1631                    throws SystemException {
1632                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1633                            QueryUtil.ALL_POS, null);
1634            }
1635    
1636            /**
1637             * Returns a range of all the journal templates that the user has permission to view where groupId = &#63;.
1638             *
1639             * <p>
1640             * 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.
1641             * </p>
1642             *
1643             * @param groupId the group ID
1644             * @param start the lower bound of the range of journal templates
1645             * @param end the upper bound of the range of journal templates (not inclusive)
1646             * @return the range of matching journal templates that the user has permission to view
1647             * @throws SystemException if a system exception occurred
1648             */
1649            public List<JournalTemplate> filterFindByGroupId(long groupId, int start,
1650                    int end) throws SystemException {
1651                    return filterFindByGroupId(groupId, start, end, null);
1652            }
1653    
1654            /**
1655             * Returns an ordered range of all the journal templates that the user has permissions to view where groupId = &#63;.
1656             *
1657             * <p>
1658             * 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.
1659             * </p>
1660             *
1661             * @param groupId the group ID
1662             * @param start the lower bound of the range of journal templates
1663             * @param end the upper bound of the range of journal templates (not inclusive)
1664             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1665             * @return the ordered range of matching journal templates that the user has permission to view
1666             * @throws SystemException if a system exception occurred
1667             */
1668            public List<JournalTemplate> filterFindByGroupId(long groupId, int start,
1669                    int end, OrderByComparator orderByComparator) throws SystemException {
1670                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1671                            return findByGroupId(groupId, start, end, orderByComparator);
1672                    }
1673    
1674                    StringBundler query = null;
1675    
1676                    if (orderByComparator != null) {
1677                            query = new StringBundler(3 +
1678                                            (orderByComparator.getOrderByFields().length * 3));
1679                    }
1680                    else {
1681                            query = new StringBundler(3);
1682                    }
1683    
1684                    if (getDB().isSupportsInlineDistinct()) {
1685                            query.append(_FILTER_SQL_SELECT_JOURNALTEMPLATE_WHERE);
1686                    }
1687                    else {
1688                            query.append(_FILTER_SQL_SELECT_JOURNALTEMPLATE_NO_INLINE_DISTINCT_WHERE_1);
1689                    }
1690    
1691                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1692    
1693                    if (!getDB().isSupportsInlineDistinct()) {
1694                            query.append(_FILTER_SQL_SELECT_JOURNALTEMPLATE_NO_INLINE_DISTINCT_WHERE_2);
1695                    }
1696    
1697                    if (orderByComparator != null) {
1698                            if (getDB().isSupportsInlineDistinct()) {
1699                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1700                                            orderByComparator);
1701                            }
1702                            else {
1703                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1704                                            orderByComparator);
1705                            }
1706                    }
1707    
1708                    else {
1709                            if (getDB().isSupportsInlineDistinct()) {
1710                                    query.append(JournalTemplateModelImpl.ORDER_BY_JPQL);
1711                            }
1712                            else {
1713                                    query.append(JournalTemplateModelImpl.ORDER_BY_SQL);
1714                            }
1715                    }
1716    
1717                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1718                                    JournalTemplate.class.getName(),
1719                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1720    
1721                    Session session = null;
1722    
1723                    try {
1724                            session = openSession();
1725    
1726                            SQLQuery q = session.createSQLQuery(sql);
1727    
1728                            if (getDB().isSupportsInlineDistinct()) {
1729                                    q.addEntity(_FILTER_ENTITY_ALIAS, JournalTemplateImpl.class);
1730                            }
1731                            else {
1732                                    q.addEntity(_FILTER_ENTITY_TABLE, JournalTemplateImpl.class);
1733                            }
1734    
1735                            QueryPos qPos = QueryPos.getInstance(q);
1736    
1737                            qPos.add(groupId);
1738    
1739                            return (List<JournalTemplate>)QueryUtil.list(q, getDialect(),
1740                                    start, end);
1741                    }
1742                    catch (Exception e) {
1743                            throw processException(e);
1744                    }
1745                    finally {
1746                            closeSession(session);
1747                    }
1748            }
1749    
1750            /**
1751             * Returns the journal templates before and after the current journal template in the ordered set of journal templates that the user has permission to view where groupId = &#63;.
1752             *
1753             * @param id the primary key of the current journal template
1754             * @param groupId the group ID
1755             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1756             * @return the previous, current, and next journal template
1757             * @throws com.liferay.portlet.journal.NoSuchTemplateException if a journal template with the primary key could not be found
1758             * @throws SystemException if a system exception occurred
1759             */
1760            public JournalTemplate[] filterFindByGroupId_PrevAndNext(long id,
1761                    long groupId, OrderByComparator orderByComparator)
1762                    throws NoSuchTemplateException, SystemException {
1763                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1764                            return findByGroupId_PrevAndNext(id, groupId, orderByComparator);
1765                    }
1766    
1767                    JournalTemplate journalTemplate = findByPrimaryKey(id);
1768    
1769                    Session session = null;
1770    
1771                    try {
1772                            session = openSession();
1773    
1774                            JournalTemplate[] array = new JournalTemplateImpl[3];
1775    
1776                            array[0] = filterGetByGroupId_PrevAndNext(session, journalTemplate,
1777                                            groupId, orderByComparator, true);
1778    
1779                            array[1] = journalTemplate;
1780    
1781                            array[2] = filterGetByGroupId_PrevAndNext(session, journalTemplate,
1782                                            groupId, orderByComparator, false);
1783    
1784                            return array;
1785                    }
1786                    catch (Exception e) {
1787                            throw processException(e);
1788                    }
1789                    finally {
1790                            closeSession(session);
1791                    }
1792            }
1793    
1794            protected JournalTemplate filterGetByGroupId_PrevAndNext(Session session,
1795                    JournalTemplate journalTemplate, long groupId,
1796                    OrderByComparator orderByComparator, boolean previous) {
1797                    StringBundler query = null;
1798    
1799                    if (orderByComparator != null) {
1800                            query = new StringBundler(6 +
1801                                            (orderByComparator.getOrderByFields().length * 6));
1802                    }
1803                    else {
1804                            query = new StringBundler(3);
1805                    }
1806    
1807                    if (getDB().isSupportsInlineDistinct()) {
1808                            query.append(_FILTER_SQL_SELECT_JOURNALTEMPLATE_WHERE);
1809                    }
1810                    else {
1811                            query.append(_FILTER_SQL_SELECT_JOURNALTEMPLATE_NO_INLINE_DISTINCT_WHERE_1);
1812                    }
1813    
1814                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1815    
1816                    if (!getDB().isSupportsInlineDistinct()) {
1817                            query.append(_FILTER_SQL_SELECT_JOURNALTEMPLATE_NO_INLINE_DISTINCT_WHERE_2);
1818                    }
1819    
1820                    if (orderByComparator != null) {
1821                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1822    
1823                            if (orderByConditionFields.length > 0) {
1824                                    query.append(WHERE_AND);
1825                            }
1826    
1827                            for (int i = 0; i < orderByConditionFields.length; i++) {
1828                                    if (getDB().isSupportsInlineDistinct()) {
1829                                            query.append(_ORDER_BY_ENTITY_ALIAS);
1830                                    }
1831                                    else {
1832                                            query.append(_ORDER_BY_ENTITY_TABLE);
1833                                    }
1834    
1835                                    query.append(orderByConditionFields[i]);
1836    
1837                                    if ((i + 1) < orderByConditionFields.length) {
1838                                            if (orderByComparator.isAscending() ^ previous) {
1839                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1840                                            }
1841                                            else {
1842                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1843                                            }
1844                                    }
1845                                    else {
1846                                            if (orderByComparator.isAscending() ^ previous) {
1847                                                    query.append(WHERE_GREATER_THAN);
1848                                            }
1849                                            else {
1850                                                    query.append(WHERE_LESSER_THAN);
1851                                            }
1852                                    }
1853                            }
1854    
1855                            query.append(ORDER_BY_CLAUSE);
1856    
1857                            String[] orderByFields = orderByComparator.getOrderByFields();
1858    
1859                            for (int i = 0; i < orderByFields.length; i++) {
1860                                    if (getDB().isSupportsInlineDistinct()) {
1861                                            query.append(_ORDER_BY_ENTITY_ALIAS);
1862                                    }
1863                                    else {
1864                                            query.append(_ORDER_BY_ENTITY_TABLE);
1865                                    }
1866    
1867                                    query.append(orderByFields[i]);
1868    
1869                                    if ((i + 1) < orderByFields.length) {
1870                                            if (orderByComparator.isAscending() ^ previous) {
1871                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1872                                            }
1873                                            else {
1874                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1875                                            }
1876                                    }
1877                                    else {
1878                                            if (orderByComparator.isAscending() ^ previous) {
1879                                                    query.append(ORDER_BY_ASC);
1880                                            }
1881                                            else {
1882                                                    query.append(ORDER_BY_DESC);
1883                                            }
1884                                    }
1885                            }
1886                    }
1887    
1888                    else {
1889                            if (getDB().isSupportsInlineDistinct()) {
1890                                    query.append(JournalTemplateModelImpl.ORDER_BY_JPQL);
1891                            }
1892                            else {
1893                                    query.append(JournalTemplateModelImpl.ORDER_BY_SQL);
1894                            }
1895                    }
1896    
1897                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1898                                    JournalTemplate.class.getName(),
1899                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1900    
1901                    SQLQuery q = session.createSQLQuery(sql);
1902    
1903                    q.setFirstResult(0);
1904                    q.setMaxResults(2);
1905    
1906                    if (getDB().isSupportsInlineDistinct()) {
1907                            q.addEntity(_FILTER_ENTITY_ALIAS, JournalTemplateImpl.class);
1908                    }
1909                    else {
1910                            q.addEntity(_FILTER_ENTITY_TABLE, JournalTemplateImpl.class);
1911                    }
1912    
1913                    QueryPos qPos = QueryPos.getInstance(q);
1914    
1915                    qPos.add(groupId);
1916    
1917                    if (orderByComparator != null) {
1918                            Object[] values = orderByComparator.getOrderByConditionValues(journalTemplate);
1919    
1920                            for (Object value : values) {
1921                                    qPos.add(value);
1922                            }
1923                    }
1924    
1925                    List<JournalTemplate> list = q.list();
1926    
1927                    if (list.size() == 2) {
1928                            return list.get(1);
1929                    }
1930                    else {
1931                            return null;
1932                    }
1933            }
1934    
1935            /**
1936             * Returns all the journal templates where templateId = &#63;.
1937             *
1938             * @param templateId the template ID
1939             * @return the matching journal templates
1940             * @throws SystemException if a system exception occurred
1941             */
1942            public List<JournalTemplate> findByTemplateId(String templateId)
1943                    throws SystemException {
1944                    return findByTemplateId(templateId, QueryUtil.ALL_POS,
1945                            QueryUtil.ALL_POS, null);
1946            }
1947    
1948            /**
1949             * Returns a range of all the journal templates where templateId = &#63;.
1950             *
1951             * <p>
1952             * 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.
1953             * </p>
1954             *
1955             * @param templateId the template ID
1956             * @param start the lower bound of the range of journal templates
1957             * @param end the upper bound of the range of journal templates (not inclusive)
1958             * @return the range of matching journal templates
1959             * @throws SystemException if a system exception occurred
1960             */
1961            public List<JournalTemplate> findByTemplateId(String templateId, int start,
1962                    int end) throws SystemException {
1963                    return findByTemplateId(templateId, start, end, null);
1964            }
1965    
1966            /**
1967             * Returns an ordered range of all the journal templates where templateId = &#63;.
1968             *
1969             * <p>
1970             * 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.
1971             * </p>
1972             *
1973             * @param templateId the template ID
1974             * @param start the lower bound of the range of journal templates
1975             * @param end the upper bound of the range of journal templates (not inclusive)
1976             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1977             * @return the ordered range of matching journal templates
1978             * @throws SystemException if a system exception occurred
1979             */
1980            public List<JournalTemplate> findByTemplateId(String templateId, int start,
1981                    int end, OrderByComparator orderByComparator) throws SystemException {
1982                    FinderPath finderPath = null;
1983                    Object[] finderArgs = null;
1984    
1985                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1986                                    (orderByComparator == null)) {
1987                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TEMPLATEID;
1988                            finderArgs = new Object[] { templateId };
1989                    }
1990                    else {
1991                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_TEMPLATEID;
1992                            finderArgs = new Object[] { templateId, start, end, orderByComparator };
1993                    }
1994    
1995                    List<JournalTemplate> list = (List<JournalTemplate>)FinderCacheUtil.getResult(finderPath,
1996                                    finderArgs, this);
1997    
1998                    if (list == null) {
1999                            StringBundler query = null;
2000    
2001                            if (orderByComparator != null) {
2002                                    query = new StringBundler(3 +
2003                                                    (orderByComparator.getOrderByFields().length * 3));
2004                            }
2005                            else {
2006                                    query = new StringBundler(3);
2007                            }
2008    
2009                            query.append(_SQL_SELECT_JOURNALTEMPLATE_WHERE);
2010    
2011                            if (templateId == null) {
2012                                    query.append(_FINDER_COLUMN_TEMPLATEID_TEMPLATEID_1);
2013                            }
2014                            else {
2015                                    if (templateId.equals(StringPool.BLANK)) {
2016                                            query.append(_FINDER_COLUMN_TEMPLATEID_TEMPLATEID_3);
2017                                    }
2018                                    else {
2019                                            query.append(_FINDER_COLUMN_TEMPLATEID_TEMPLATEID_2);
2020                                    }
2021                            }
2022    
2023                            if (orderByComparator != null) {
2024                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2025                                            orderByComparator);
2026                            }
2027    
2028                            else {
2029                                    query.append(JournalTemplateModelImpl.ORDER_BY_JPQL);
2030                            }
2031    
2032                            String sql = query.toString();
2033    
2034                            Session session = null;
2035    
2036                            try {
2037                                    session = openSession();
2038    
2039                                    Query q = session.createQuery(sql);
2040    
2041                                    QueryPos qPos = QueryPos.getInstance(q);
2042    
2043                                    if (templateId != null) {
2044                                            qPos.add(templateId);
2045                                    }
2046    
2047                                    list = (List<JournalTemplate>)QueryUtil.list(q, getDialect(),
2048                                                    start, end);
2049                            }
2050                            catch (Exception e) {
2051                                    throw processException(e);
2052                            }
2053                            finally {
2054                                    if (list == null) {
2055                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
2056                                    }
2057                                    else {
2058                                            cacheResult(list);
2059    
2060                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
2061                                    }
2062    
2063                                    closeSession(session);
2064                            }
2065                    }
2066    
2067                    return list;
2068            }
2069    
2070            /**
2071             * Returns the first journal template in the ordered set where templateId = &#63;.
2072             *
2073             * <p>
2074             * 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.
2075             * </p>
2076             *
2077             * @param templateId the template ID
2078             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2079             * @return the first matching journal template
2080             * @throws com.liferay.portlet.journal.NoSuchTemplateException if a matching journal template could not be found
2081             * @throws SystemException if a system exception occurred
2082             */
2083            public JournalTemplate findByTemplateId_First(String templateId,
2084                    OrderByComparator orderByComparator)
2085                    throws NoSuchTemplateException, SystemException {
2086                    List<JournalTemplate> list = findByTemplateId(templateId, 0, 1,
2087                                    orderByComparator);
2088    
2089                    if (list.isEmpty()) {
2090                            StringBundler msg = new StringBundler(4);
2091    
2092                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2093    
2094                            msg.append("templateId=");
2095                            msg.append(templateId);
2096    
2097                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2098    
2099                            throw new NoSuchTemplateException(msg.toString());
2100                    }
2101                    else {
2102                            return list.get(0);
2103                    }
2104            }
2105    
2106            /**
2107             * Returns the last journal template in the ordered set where templateId = &#63;.
2108             *
2109             * <p>
2110             * 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.
2111             * </p>
2112             *
2113             * @param templateId the template ID
2114             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2115             * @return the last matching journal template
2116             * @throws com.liferay.portlet.journal.NoSuchTemplateException if a matching journal template could not be found
2117             * @throws SystemException if a system exception occurred
2118             */
2119            public JournalTemplate findByTemplateId_Last(String templateId,
2120                    OrderByComparator orderByComparator)
2121                    throws NoSuchTemplateException, SystemException {
2122                    int count = countByTemplateId(templateId);
2123    
2124                    List<JournalTemplate> list = findByTemplateId(templateId, count - 1,
2125                                    count, orderByComparator);
2126    
2127                    if (list.isEmpty()) {
2128                            StringBundler msg = new StringBundler(4);
2129    
2130                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2131    
2132                            msg.append("templateId=");
2133                            msg.append(templateId);
2134    
2135                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2136    
2137                            throw new NoSuchTemplateException(msg.toString());
2138                    }
2139                    else {
2140                            return list.get(0);
2141                    }
2142            }
2143    
2144            /**
2145             * Returns the journal templates before and after the current journal template in the ordered set where templateId = &#63;.
2146             *
2147             * <p>
2148             * 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.
2149             * </p>
2150             *
2151             * @param id the primary key of the current journal template
2152             * @param templateId the template ID
2153             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2154             * @return the previous, current, and next journal template
2155             * @throws com.liferay.portlet.journal.NoSuchTemplateException if a journal template with the primary key could not be found
2156             * @throws SystemException if a system exception occurred
2157             */
2158            public JournalTemplate[] findByTemplateId_PrevAndNext(long id,
2159                    String templateId, OrderByComparator orderByComparator)
2160                    throws NoSuchTemplateException, SystemException {
2161                    JournalTemplate journalTemplate = findByPrimaryKey(id);
2162    
2163                    Session session = null;
2164    
2165                    try {
2166                            session = openSession();
2167    
2168                            JournalTemplate[] array = new JournalTemplateImpl[3];
2169    
2170                            array[0] = getByTemplateId_PrevAndNext(session, journalTemplate,
2171                                            templateId, orderByComparator, true);
2172    
2173                            array[1] = journalTemplate;
2174    
2175                            array[2] = getByTemplateId_PrevAndNext(session, journalTemplate,
2176                                            templateId, orderByComparator, false);
2177    
2178                            return array;
2179                    }
2180                    catch (Exception e) {
2181                            throw processException(e);
2182                    }
2183                    finally {
2184                            closeSession(session);
2185                    }
2186            }
2187    
2188            protected JournalTemplate getByTemplateId_PrevAndNext(Session session,
2189                    JournalTemplate journalTemplate, String templateId,
2190                    OrderByComparator orderByComparator, boolean previous) {
2191                    StringBundler query = null;
2192    
2193                    if (orderByComparator != null) {
2194                            query = new StringBundler(6 +
2195                                            (orderByComparator.getOrderByFields().length * 6));
2196                    }
2197                    else {
2198                            query = new StringBundler(3);
2199                    }
2200    
2201                    query.append(_SQL_SELECT_JOURNALTEMPLATE_WHERE);
2202    
2203                    if (templateId == null) {
2204                            query.append(_FINDER_COLUMN_TEMPLATEID_TEMPLATEID_1);
2205                    }
2206                    else {
2207                            if (templateId.equals(StringPool.BLANK)) {
2208                                    query.append(_FINDER_COLUMN_TEMPLATEID_TEMPLATEID_3);
2209                            }
2210                            else {
2211                                    query.append(_FINDER_COLUMN_TEMPLATEID_TEMPLATEID_2);
2212                            }
2213                    }
2214    
2215                    if (orderByComparator != null) {
2216                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2217    
2218                            if (orderByConditionFields.length > 0) {
2219                                    query.append(WHERE_AND);
2220                            }
2221    
2222                            for (int i = 0; i < orderByConditionFields.length; i++) {
2223                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2224                                    query.append(orderByConditionFields[i]);
2225    
2226                                    if ((i + 1) < orderByConditionFields.length) {
2227                                            if (orderByComparator.isAscending() ^ previous) {
2228                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2229                                            }
2230                                            else {
2231                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2232                                            }
2233                                    }
2234                                    else {
2235                                            if (orderByComparator.isAscending() ^ previous) {
2236                                                    query.append(WHERE_GREATER_THAN);
2237                                            }
2238                                            else {
2239                                                    query.append(WHERE_LESSER_THAN);
2240                                            }
2241                                    }
2242                            }
2243    
2244                            query.append(ORDER_BY_CLAUSE);
2245    
2246                            String[] orderByFields = orderByComparator.getOrderByFields();
2247    
2248                            for (int i = 0; i < orderByFields.length; i++) {
2249                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2250                                    query.append(orderByFields[i]);
2251    
2252                                    if ((i + 1) < orderByFields.length) {
2253                                            if (orderByComparator.isAscending() ^ previous) {
2254                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2255                                            }
2256                                            else {
2257                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2258                                            }
2259                                    }
2260                                    else {
2261                                            if (orderByComparator.isAscending() ^ previous) {
2262                                                    query.append(ORDER_BY_ASC);
2263                                            }
2264                                            else {
2265                                                    query.append(ORDER_BY_DESC);
2266                                            }
2267                                    }
2268                            }
2269                    }
2270    
2271                    else {
2272                            query.append(JournalTemplateModelImpl.ORDER_BY_JPQL);
2273                    }
2274    
2275                    String sql = query.toString();
2276    
2277                    Query q = session.createQuery(sql);
2278    
2279                    q.setFirstResult(0);
2280                    q.setMaxResults(2);
2281    
2282                    QueryPos qPos = QueryPos.getInstance(q);
2283    
2284                    if (templateId != null) {
2285                            qPos.add(templateId);
2286                    }
2287    
2288                    if (orderByComparator != null) {
2289                            Object[] values = orderByComparator.getOrderByConditionValues(journalTemplate);
2290    
2291                            for (Object value : values) {
2292                                    qPos.add(value);
2293                            }
2294                    }
2295    
2296                    List<JournalTemplate> list = q.list();
2297    
2298                    if (list.size() == 2) {
2299                            return list.get(1);
2300                    }
2301                    else {
2302                            return null;
2303                    }
2304            }
2305    
2306            /**
2307             * Returns the journal template where smallImageId = &#63; or throws a {@link com.liferay.portlet.journal.NoSuchTemplateException} if it could not be found.
2308             *
2309             * @param smallImageId the small image ID
2310             * @return the matching journal template
2311             * @throws com.liferay.portlet.journal.NoSuchTemplateException if a matching journal template could not be found
2312             * @throws SystemException if a system exception occurred
2313             */
2314            public JournalTemplate findBySmallImageId(long smallImageId)
2315                    throws NoSuchTemplateException, SystemException {
2316                    JournalTemplate journalTemplate = fetchBySmallImageId(smallImageId);
2317    
2318                    if (journalTemplate == null) {
2319                            StringBundler msg = new StringBundler(4);
2320    
2321                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2322    
2323                            msg.append("smallImageId=");
2324                            msg.append(smallImageId);
2325    
2326                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2327    
2328                            if (_log.isWarnEnabled()) {
2329                                    _log.warn(msg.toString());
2330                            }
2331    
2332                            throw new NoSuchTemplateException(msg.toString());
2333                    }
2334    
2335                    return journalTemplate;
2336            }
2337    
2338            /**
2339             * Returns the journal template where smallImageId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
2340             *
2341             * @param smallImageId the small image ID
2342             * @return the matching journal template, or <code>null</code> if a matching journal template could not be found
2343             * @throws SystemException if a system exception occurred
2344             */
2345            public JournalTemplate fetchBySmallImageId(long smallImageId)
2346                    throws SystemException {
2347                    return fetchBySmallImageId(smallImageId, true);
2348            }
2349    
2350            /**
2351             * Returns the journal template where smallImageId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
2352             *
2353             * @param smallImageId the small image ID
2354             * @param retrieveFromCache whether to use the finder cache
2355             * @return the matching journal template, or <code>null</code> if a matching journal template could not be found
2356             * @throws SystemException if a system exception occurred
2357             */
2358            public JournalTemplate fetchBySmallImageId(long smallImageId,
2359                    boolean retrieveFromCache) throws SystemException {
2360                    Object[] finderArgs = new Object[] { smallImageId };
2361    
2362                    Object result = null;
2363    
2364                    if (retrieveFromCache) {
2365                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
2366                                            finderArgs, this);
2367                    }
2368    
2369                    if (result == null) {
2370                            StringBundler query = new StringBundler(3);
2371    
2372                            query.append(_SQL_SELECT_JOURNALTEMPLATE_WHERE);
2373    
2374                            query.append(_FINDER_COLUMN_SMALLIMAGEID_SMALLIMAGEID_2);
2375    
2376                            query.append(JournalTemplateModelImpl.ORDER_BY_JPQL);
2377    
2378                            String sql = query.toString();
2379    
2380                            Session session = null;
2381    
2382                            try {
2383                                    session = openSession();
2384    
2385                                    Query q = session.createQuery(sql);
2386    
2387                                    QueryPos qPos = QueryPos.getInstance(q);
2388    
2389                                    qPos.add(smallImageId);
2390    
2391                                    List<JournalTemplate> list = q.list();
2392    
2393                                    result = list;
2394    
2395                                    JournalTemplate journalTemplate = null;
2396    
2397                                    if (list.isEmpty()) {
2398                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
2399                                                    finderArgs, list);
2400                                    }
2401                                    else {
2402                                            journalTemplate = list.get(0);
2403    
2404                                            cacheResult(journalTemplate);
2405    
2406                                            if ((journalTemplate.getSmallImageId() != smallImageId)) {
2407                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
2408                                                            finderArgs, journalTemplate);
2409                                            }
2410                                    }
2411    
2412                                    return journalTemplate;
2413                            }
2414                            catch (Exception e) {
2415                                    throw processException(e);
2416                            }
2417                            finally {
2418                                    if (result == null) {
2419                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
2420                                                    finderArgs);
2421                                    }
2422    
2423                                    closeSession(session);
2424                            }
2425                    }
2426                    else {
2427                            if (result instanceof List<?>) {
2428                                    return null;
2429                            }
2430                            else {
2431                                    return (JournalTemplate)result;
2432                            }
2433                    }
2434            }
2435    
2436            /**
2437             * Returns the journal template where groupId = &#63; and templateId = &#63; or throws a {@link com.liferay.portlet.journal.NoSuchTemplateException} if it could not be found.
2438             *
2439             * @param groupId the group ID
2440             * @param templateId the template ID
2441             * @return the matching journal template
2442             * @throws com.liferay.portlet.journal.NoSuchTemplateException if a matching journal template could not be found
2443             * @throws SystemException if a system exception occurred
2444             */
2445            public JournalTemplate findByG_T(long groupId, String templateId)
2446                    throws NoSuchTemplateException, SystemException {
2447                    JournalTemplate journalTemplate = fetchByG_T(groupId, templateId);
2448    
2449                    if (journalTemplate == null) {
2450                            StringBundler msg = new StringBundler(6);
2451    
2452                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2453    
2454                            msg.append("groupId=");
2455                            msg.append(groupId);
2456    
2457                            msg.append(", templateId=");
2458                            msg.append(templateId);
2459    
2460                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2461    
2462                            if (_log.isWarnEnabled()) {
2463                                    _log.warn(msg.toString());
2464                            }
2465    
2466                            throw new NoSuchTemplateException(msg.toString());
2467                    }
2468    
2469                    return journalTemplate;
2470            }
2471    
2472            /**
2473             * Returns the journal template where groupId = &#63; and templateId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
2474             *
2475             * @param groupId the group ID
2476             * @param templateId the template ID
2477             * @return the matching journal template, or <code>null</code> if a matching journal template could not be found
2478             * @throws SystemException if a system exception occurred
2479             */
2480            public JournalTemplate fetchByG_T(long groupId, String templateId)
2481                    throws SystemException {
2482                    return fetchByG_T(groupId, templateId, true);
2483            }
2484    
2485            /**
2486             * Returns the journal template where groupId = &#63; and templateId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
2487             *
2488             * @param groupId the group ID
2489             * @param templateId the template ID
2490             * @param retrieveFromCache whether to use the finder cache
2491             * @return the matching journal template, or <code>null</code> if a matching journal template could not be found
2492             * @throws SystemException if a system exception occurred
2493             */
2494            public JournalTemplate fetchByG_T(long groupId, String templateId,
2495                    boolean retrieveFromCache) throws SystemException {
2496                    Object[] finderArgs = new Object[] { groupId, templateId };
2497    
2498                    Object result = null;
2499    
2500                    if (retrieveFromCache) {
2501                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_T,
2502                                            finderArgs, this);
2503                    }
2504    
2505                    if (result == null) {
2506                            StringBundler query = new StringBundler(4);
2507    
2508                            query.append(_SQL_SELECT_JOURNALTEMPLATE_WHERE);
2509    
2510                            query.append(_FINDER_COLUMN_G_T_GROUPID_2);
2511    
2512                            if (templateId == null) {
2513                                    query.append(_FINDER_COLUMN_G_T_TEMPLATEID_1);
2514                            }
2515                            else {
2516                                    if (templateId.equals(StringPool.BLANK)) {
2517                                            query.append(_FINDER_COLUMN_G_T_TEMPLATEID_3);
2518                                    }
2519                                    else {
2520                                            query.append(_FINDER_COLUMN_G_T_TEMPLATEID_2);
2521                                    }
2522                            }
2523    
2524                            query.append(JournalTemplateModelImpl.ORDER_BY_JPQL);
2525    
2526                            String sql = query.toString();
2527    
2528                            Session session = null;
2529    
2530                            try {
2531                                    session = openSession();
2532    
2533                                    Query q = session.createQuery(sql);
2534    
2535                                    QueryPos qPos = QueryPos.getInstance(q);
2536    
2537                                    qPos.add(groupId);
2538    
2539                                    if (templateId != null) {
2540                                            qPos.add(templateId);
2541                                    }
2542    
2543                                    List<JournalTemplate> list = q.list();
2544    
2545                                    result = list;
2546    
2547                                    JournalTemplate journalTemplate = null;
2548    
2549                                    if (list.isEmpty()) {
2550                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_T,
2551                                                    finderArgs, list);
2552                                    }
2553                                    else {
2554                                            journalTemplate = list.get(0);
2555    
2556                                            cacheResult(journalTemplate);
2557    
2558                                            if ((journalTemplate.getGroupId() != groupId) ||
2559                                                            (journalTemplate.getTemplateId() == null) ||
2560                                                            !journalTemplate.getTemplateId().equals(templateId)) {
2561                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_T,
2562                                                            finderArgs, journalTemplate);
2563                                            }
2564                                    }
2565    
2566                                    return journalTemplate;
2567                            }
2568                            catch (Exception e) {
2569                                    throw processException(e);
2570                            }
2571                            finally {
2572                                    if (result == null) {
2573                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_T,
2574                                                    finderArgs);
2575                                    }
2576    
2577                                    closeSession(session);
2578                            }
2579                    }
2580                    else {
2581                            if (result instanceof List<?>) {
2582                                    return null;
2583                            }
2584                            else {
2585                                    return (JournalTemplate)result;
2586                            }
2587                    }
2588            }
2589    
2590            /**
2591             * Returns all the journal templates where groupId = &#63; and structureId = &#63;.
2592             *
2593             * @param groupId the group ID
2594             * @param structureId the structure ID
2595             * @return the matching journal templates
2596             * @throws SystemException if a system exception occurred
2597             */
2598            public List<JournalTemplate> findByG_S(long groupId, String structureId)
2599                    throws SystemException {
2600                    return findByG_S(groupId, structureId, QueryUtil.ALL_POS,
2601                            QueryUtil.ALL_POS, null);
2602            }
2603    
2604            /**
2605             * Returns a range of all the journal templates where groupId = &#63; and structureId = &#63;.
2606             *
2607             * <p>
2608             * 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.
2609             * </p>
2610             *
2611             * @param groupId the group ID
2612             * @param structureId the structure ID
2613             * @param start the lower bound of the range of journal templates
2614             * @param end the upper bound of the range of journal templates (not inclusive)
2615             * @return the range of matching journal templates
2616             * @throws SystemException if a system exception occurred
2617             */
2618            public List<JournalTemplate> findByG_S(long groupId, String structureId,
2619                    int start, int end) throws SystemException {
2620                    return findByG_S(groupId, structureId, start, end, null);
2621            }
2622    
2623            /**
2624             * Returns an ordered range of all the journal templates where groupId = &#63; and structureId = &#63;.
2625             *
2626             * <p>
2627             * 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.
2628             * </p>
2629             *
2630             * @param groupId the group ID
2631             * @param structureId the structure ID
2632             * @param start the lower bound of the range of journal templates
2633             * @param end the upper bound of the range of journal templates (not inclusive)
2634             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2635             * @return the ordered range of matching journal templates
2636             * @throws SystemException if a system exception occurred
2637             */
2638            public List<JournalTemplate> findByG_S(long groupId, String structureId,
2639                    int start, int end, OrderByComparator orderByComparator)
2640                    throws SystemException {
2641                    FinderPath finderPath = null;
2642                    Object[] finderArgs = null;
2643    
2644                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2645                                    (orderByComparator == null)) {
2646                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S;
2647                            finderArgs = new Object[] { groupId, structureId };
2648                    }
2649                    else {
2650                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S;
2651                            finderArgs = new Object[] {
2652                                            groupId, structureId,
2653                                            
2654                                            start, end, orderByComparator
2655                                    };
2656                    }
2657    
2658                    List<JournalTemplate> list = (List<JournalTemplate>)FinderCacheUtil.getResult(finderPath,
2659                                    finderArgs, this);
2660    
2661                    if (list == null) {
2662                            StringBundler query = null;
2663    
2664                            if (orderByComparator != null) {
2665                                    query = new StringBundler(4 +
2666                                                    (orderByComparator.getOrderByFields().length * 3));
2667                            }
2668                            else {
2669                                    query = new StringBundler(4);
2670                            }
2671    
2672                            query.append(_SQL_SELECT_JOURNALTEMPLATE_WHERE);
2673    
2674                            query.append(_FINDER_COLUMN_G_S_GROUPID_2);
2675    
2676                            if (structureId == null) {
2677                                    query.append(_FINDER_COLUMN_G_S_STRUCTUREID_1);
2678                            }
2679                            else {
2680                                    if (structureId.equals(StringPool.BLANK)) {
2681                                            query.append(_FINDER_COLUMN_G_S_STRUCTUREID_3);
2682                                    }
2683                                    else {
2684                                            query.append(_FINDER_COLUMN_G_S_STRUCTUREID_2);
2685                                    }
2686                            }
2687    
2688                            if (orderByComparator != null) {
2689                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2690                                            orderByComparator);
2691                            }
2692    
2693                            else {
2694                                    query.append(JournalTemplateModelImpl.ORDER_BY_JPQL);
2695                            }
2696    
2697                            String sql = query.toString();
2698    
2699                            Session session = null;
2700    
2701                            try {
2702                                    session = openSession();
2703    
2704                                    Query q = session.createQuery(sql);
2705    
2706                                    QueryPos qPos = QueryPos.getInstance(q);
2707    
2708                                    qPos.add(groupId);
2709    
2710                                    if (structureId != null) {
2711                                            qPos.add(structureId);
2712                                    }
2713    
2714                                    list = (List<JournalTemplate>)QueryUtil.list(q, getDialect(),
2715                                                    start, end);
2716                            }
2717                            catch (Exception e) {
2718                                    throw processException(e);
2719                            }
2720                            finally {
2721                                    if (list == null) {
2722                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
2723                                    }
2724                                    else {
2725                                            cacheResult(list);
2726    
2727                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
2728                                    }
2729    
2730                                    closeSession(session);
2731                            }
2732                    }
2733    
2734                    return list;
2735            }
2736    
2737            /**
2738             * Returns the first journal template in the ordered set where groupId = &#63; and structureId = &#63;.
2739             *
2740             * <p>
2741             * 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.
2742             * </p>
2743             *
2744             * @param groupId the group ID
2745             * @param structureId the structure ID
2746             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2747             * @return the first matching journal template
2748             * @throws com.liferay.portlet.journal.NoSuchTemplateException if a matching journal template could not be found
2749             * @throws SystemException if a system exception occurred
2750             */
2751            public JournalTemplate findByG_S_First(long groupId, String structureId,
2752                    OrderByComparator orderByComparator)
2753                    throws NoSuchTemplateException, SystemException {
2754                    List<JournalTemplate> list = findByG_S(groupId, structureId, 0, 1,
2755                                    orderByComparator);
2756    
2757                    if (list.isEmpty()) {
2758                            StringBundler msg = new StringBundler(6);
2759    
2760                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2761    
2762                            msg.append("groupId=");
2763                            msg.append(groupId);
2764    
2765                            msg.append(", structureId=");
2766                            msg.append(structureId);
2767    
2768                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2769    
2770                            throw new NoSuchTemplateException(msg.toString());
2771                    }
2772                    else {
2773                            return list.get(0);
2774                    }
2775            }
2776    
2777            /**
2778             * Returns the last journal template in the ordered set where groupId = &#63; and structureId = &#63;.
2779             *
2780             * <p>
2781             * 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.
2782             * </p>
2783             *
2784             * @param groupId the group ID
2785             * @param structureId the structure ID
2786             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2787             * @return the last matching journal template
2788             * @throws com.liferay.portlet.journal.NoSuchTemplateException if a matching journal template could not be found
2789             * @throws SystemException if a system exception occurred
2790             */
2791            public JournalTemplate findByG_S_Last(long groupId, String structureId,
2792                    OrderByComparator orderByComparator)
2793                    throws NoSuchTemplateException, SystemException {
2794                    int count = countByG_S(groupId, structureId);
2795    
2796                    List<JournalTemplate> list = findByG_S(groupId, structureId, count - 1,
2797                                    count, orderByComparator);
2798    
2799                    if (list.isEmpty()) {
2800                            StringBundler msg = new StringBundler(6);
2801    
2802                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2803    
2804                            msg.append("groupId=");
2805                            msg.append(groupId);
2806    
2807                            msg.append(", structureId=");
2808                            msg.append(structureId);
2809    
2810                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2811    
2812                            throw new NoSuchTemplateException(msg.toString());
2813                    }
2814                    else {
2815                            return list.get(0);
2816                    }
2817            }
2818    
2819            /**
2820             * Returns the journal templates before and after the current journal template in the ordered set where groupId = &#63; and structureId = &#63;.
2821             *
2822             * <p>
2823             * 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.
2824             * </p>
2825             *
2826             * @param id the primary key of the current journal template
2827             * @param groupId the group ID
2828             * @param structureId the structure ID
2829             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2830             * @return the previous, current, and next journal template
2831             * @throws com.liferay.portlet.journal.NoSuchTemplateException if a journal template with the primary key could not be found
2832             * @throws SystemException if a system exception occurred
2833             */
2834            public JournalTemplate[] findByG_S_PrevAndNext(long id, long groupId,
2835                    String structureId, OrderByComparator orderByComparator)
2836                    throws NoSuchTemplateException, SystemException {
2837                    JournalTemplate journalTemplate = findByPrimaryKey(id);
2838    
2839                    Session session = null;
2840    
2841                    try {
2842                            session = openSession();
2843    
2844                            JournalTemplate[] array = new JournalTemplateImpl[3];
2845    
2846                            array[0] = getByG_S_PrevAndNext(session, journalTemplate, groupId,
2847                                            structureId, orderByComparator, true);
2848    
2849                            array[1] = journalTemplate;
2850    
2851                            array[2] = getByG_S_PrevAndNext(session, journalTemplate, groupId,
2852                                            structureId, orderByComparator, false);
2853    
2854                            return array;
2855                    }
2856                    catch (Exception e) {
2857                            throw processException(e);
2858                    }
2859                    finally {
2860                            closeSession(session);
2861                    }
2862            }
2863    
2864            protected JournalTemplate getByG_S_PrevAndNext(Session session,
2865                    JournalTemplate journalTemplate, long groupId, String structureId,
2866                    OrderByComparator orderByComparator, boolean previous) {
2867                    StringBundler query = null;
2868    
2869                    if (orderByComparator != null) {
2870                            query = new StringBundler(6 +
2871                                            (orderByComparator.getOrderByFields().length * 6));
2872                    }
2873                    else {
2874                            query = new StringBundler(3);
2875                    }
2876    
2877                    query.append(_SQL_SELECT_JOURNALTEMPLATE_WHERE);
2878    
2879                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
2880    
2881                    if (structureId == null) {
2882                            query.append(_FINDER_COLUMN_G_S_STRUCTUREID_1);
2883                    }
2884                    else {
2885                            if (structureId.equals(StringPool.BLANK)) {
2886                                    query.append(_FINDER_COLUMN_G_S_STRUCTUREID_3);
2887                            }
2888                            else {
2889                                    query.append(_FINDER_COLUMN_G_S_STRUCTUREID_2);
2890                            }
2891                    }
2892    
2893                    if (orderByComparator != null) {
2894                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2895    
2896                            if (orderByConditionFields.length > 0) {
2897                                    query.append(WHERE_AND);
2898                            }
2899    
2900                            for (int i = 0; i < orderByConditionFields.length; i++) {
2901                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2902                                    query.append(orderByConditionFields[i]);
2903    
2904                                    if ((i + 1) < orderByConditionFields.length) {
2905                                            if (orderByComparator.isAscending() ^ previous) {
2906                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2907                                            }
2908                                            else {
2909                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2910                                            }
2911                                    }
2912                                    else {
2913                                            if (orderByComparator.isAscending() ^ previous) {
2914                                                    query.append(WHERE_GREATER_THAN);
2915                                            }
2916                                            else {
2917                                                    query.append(WHERE_LESSER_THAN);
2918                                            }
2919                                    }
2920                            }
2921    
2922                            query.append(ORDER_BY_CLAUSE);
2923    
2924                            String[] orderByFields = orderByComparator.getOrderByFields();
2925    
2926                            for (int i = 0; i < orderByFields.length; i++) {
2927                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2928                                    query.append(orderByFields[i]);
2929    
2930                                    if ((i + 1) < orderByFields.length) {
2931                                            if (orderByComparator.isAscending() ^ previous) {
2932                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2933                                            }
2934                                            else {
2935                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2936                                            }
2937                                    }
2938                                    else {
2939                                            if (orderByComparator.isAscending() ^ previous) {
2940                                                    query.append(ORDER_BY_ASC);
2941                                            }
2942                                            else {
2943                                                    query.append(ORDER_BY_DESC);
2944                                            }
2945                                    }
2946                            }
2947                    }
2948    
2949                    else {
2950                            query.append(JournalTemplateModelImpl.ORDER_BY_JPQL);
2951                    }
2952    
2953                    String sql = query.toString();
2954    
2955                    Query q = session.createQuery(sql);
2956    
2957                    q.setFirstResult(0);
2958                    q.setMaxResults(2);
2959    
2960                    QueryPos qPos = QueryPos.getInstance(q);
2961    
2962                    qPos.add(groupId);
2963    
2964                    if (structureId != null) {
2965                            qPos.add(structureId);
2966                    }
2967    
2968                    if (orderByComparator != null) {
2969                            Object[] values = orderByComparator.getOrderByConditionValues(journalTemplate);
2970    
2971                            for (Object value : values) {
2972                                    qPos.add(value);
2973                            }
2974                    }
2975    
2976                    List<JournalTemplate> list = q.list();
2977    
2978                    if (list.size() == 2) {
2979                            return list.get(1);
2980                    }
2981                    else {
2982                            return null;
2983                    }
2984            }
2985    
2986            /**
2987             * Returns all the journal templates that the user has permission to view where groupId = &#63; and structureId = &#63;.
2988             *
2989             * @param groupId the group ID
2990             * @param structureId the structure ID
2991             * @return the matching journal templates that the user has permission to view
2992             * @throws SystemException if a system exception occurred
2993             */
2994            public List<JournalTemplate> filterFindByG_S(long groupId,
2995                    String structureId) throws SystemException {
2996                    return filterFindByG_S(groupId, structureId, QueryUtil.ALL_POS,
2997                            QueryUtil.ALL_POS, null);
2998            }
2999    
3000            /**
3001             * Returns a range of all the journal templates that the user has permission to view where groupId = &#63; and structureId = &#63;.
3002             *
3003             * <p>
3004             * 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.
3005             * </p>
3006             *
3007             * @param groupId the group ID
3008             * @param structureId the structure ID
3009             * @param start the lower bound of the range of journal templates
3010             * @param end the upper bound of the range of journal templates (not inclusive)
3011             * @return the range of matching journal templates that the user has permission to view
3012             * @throws SystemException if a system exception occurred
3013             */
3014            public List<JournalTemplate> filterFindByG_S(long groupId,
3015                    String structureId, int start, int end) throws SystemException {
3016                    return filterFindByG_S(groupId, structureId, start, end, null);
3017            }
3018    
3019            /**
3020             * Returns an ordered range of all the journal templates that the user has permissions to view where groupId = &#63; and structureId = &#63;.
3021             *
3022             * <p>
3023             * 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.
3024             * </p>
3025             *
3026             * @param groupId the group ID
3027             * @param structureId the structure ID
3028             * @param start the lower bound of the range of journal templates
3029             * @param end the upper bound of the range of journal templates (not inclusive)
3030             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3031             * @return the ordered range of matching journal templates that the user has permission to view
3032             * @throws SystemException if a system exception occurred
3033             */
3034            public List<JournalTemplate> filterFindByG_S(long groupId,
3035                    String structureId, int start, int end,
3036                    OrderByComparator orderByComparator) throws SystemException {
3037                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3038                            return findByG_S(groupId, structureId, start, end, orderByComparator);
3039                    }
3040    
3041                    StringBundler query = null;
3042    
3043                    if (orderByComparator != null) {
3044                            query = new StringBundler(4 +
3045                                            (orderByComparator.getOrderByFields().length * 3));
3046                    }
3047                    else {
3048                            query = new StringBundler(4);
3049                    }
3050    
3051                    if (getDB().isSupportsInlineDistinct()) {
3052                            query.append(_FILTER_SQL_SELECT_JOURNALTEMPLATE_WHERE);
3053                    }
3054                    else {
3055                            query.append(_FILTER_SQL_SELECT_JOURNALTEMPLATE_NO_INLINE_DISTINCT_WHERE_1);
3056                    }
3057    
3058                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
3059    
3060                    if (structureId == null) {
3061                            query.append(_FINDER_COLUMN_G_S_STRUCTUREID_1);
3062                    }
3063                    else {
3064                            if (structureId.equals(StringPool.BLANK)) {
3065                                    query.append(_FINDER_COLUMN_G_S_STRUCTUREID_3);
3066                            }
3067                            else {
3068                                    query.append(_FINDER_COLUMN_G_S_STRUCTUREID_2);
3069                            }
3070                    }
3071    
3072                    if (!getDB().isSupportsInlineDistinct()) {
3073                            query.append(_FILTER_SQL_SELECT_JOURNALTEMPLATE_NO_INLINE_DISTINCT_WHERE_2);
3074                    }
3075    
3076                    if (orderByComparator != null) {
3077                            if (getDB().isSupportsInlineDistinct()) {
3078                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3079                                            orderByComparator);
3080                            }
3081                            else {
3082                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3083                                            orderByComparator);
3084                            }
3085                    }
3086    
3087                    else {
3088                            if (getDB().isSupportsInlineDistinct()) {
3089                                    query.append(JournalTemplateModelImpl.ORDER_BY_JPQL);
3090                            }
3091                            else {
3092                                    query.append(JournalTemplateModelImpl.ORDER_BY_SQL);
3093                            }
3094                    }
3095    
3096                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3097                                    JournalTemplate.class.getName(),
3098                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3099    
3100                    Session session = null;
3101    
3102                    try {
3103                            session = openSession();
3104    
3105                            SQLQuery q = session.createSQLQuery(sql);
3106    
3107                            if (getDB().isSupportsInlineDistinct()) {
3108                                    q.addEntity(_FILTER_ENTITY_ALIAS, JournalTemplateImpl.class);
3109                            }
3110                            else {
3111                                    q.addEntity(_FILTER_ENTITY_TABLE, JournalTemplateImpl.class);
3112                            }
3113    
3114                            QueryPos qPos = QueryPos.getInstance(q);
3115    
3116                            qPos.add(groupId);
3117    
3118                            if (structureId != null) {
3119                                    qPos.add(structureId);
3120                            }
3121    
3122                            return (List<JournalTemplate>)QueryUtil.list(q, getDialect(),
3123                                    start, end);
3124                    }
3125                    catch (Exception e) {
3126                            throw processException(e);
3127                    }
3128                    finally {
3129                            closeSession(session);
3130                    }
3131            }
3132    
3133            /**
3134             * Returns the journal templates before and after the current journal template in the ordered set of journal templates that the user has permission to view where groupId = &#63; and structureId = &#63;.
3135             *
3136             * @param id the primary key of the current journal template
3137             * @param groupId the group ID
3138             * @param structureId the structure ID
3139             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3140             * @return the previous, current, and next journal template
3141             * @throws com.liferay.portlet.journal.NoSuchTemplateException if a journal template with the primary key could not be found
3142             * @throws SystemException if a system exception occurred
3143             */
3144            public JournalTemplate[] filterFindByG_S_PrevAndNext(long id, long groupId,
3145                    String structureId, OrderByComparator orderByComparator)
3146                    throws NoSuchTemplateException, SystemException {
3147                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3148                            return findByG_S_PrevAndNext(id, groupId, structureId,
3149                                    orderByComparator);
3150                    }
3151    
3152                    JournalTemplate journalTemplate = findByPrimaryKey(id);
3153    
3154                    Session session = null;
3155    
3156                    try {
3157                            session = openSession();
3158    
3159                            JournalTemplate[] array = new JournalTemplateImpl[3];
3160    
3161                            array[0] = filterGetByG_S_PrevAndNext(session, journalTemplate,
3162                                            groupId, structureId, orderByComparator, true);
3163    
3164                            array[1] = journalTemplate;
3165    
3166                            array[2] = filterGetByG_S_PrevAndNext(session, journalTemplate,
3167                                            groupId, structureId, orderByComparator, false);
3168    
3169                            return array;
3170                    }
3171                    catch (Exception e) {
3172                            throw processException(e);
3173                    }
3174                    finally {
3175                            closeSession(session);
3176                    }
3177            }
3178    
3179            protected JournalTemplate filterGetByG_S_PrevAndNext(Session session,
3180                    JournalTemplate journalTemplate, long groupId, String structureId,
3181                    OrderByComparator orderByComparator, boolean previous) {
3182                    StringBundler query = null;
3183    
3184                    if (orderByComparator != null) {
3185                            query = new StringBundler(6 +
3186                                            (orderByComparator.getOrderByFields().length * 6));
3187                    }
3188                    else {
3189                            query = new StringBundler(3);
3190                    }
3191    
3192                    if (getDB().isSupportsInlineDistinct()) {
3193                            query.append(_FILTER_SQL_SELECT_JOURNALTEMPLATE_WHERE);
3194                    }
3195                    else {
3196                            query.append(_FILTER_SQL_SELECT_JOURNALTEMPLATE_NO_INLINE_DISTINCT_WHERE_1);
3197                    }
3198    
3199                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
3200    
3201                    if (structureId == null) {
3202                            query.append(_FINDER_COLUMN_G_S_STRUCTUREID_1);
3203                    }
3204                    else {
3205                            if (structureId.equals(StringPool.BLANK)) {
3206                                    query.append(_FINDER_COLUMN_G_S_STRUCTUREID_3);
3207                            }
3208                            else {
3209                                    query.append(_FINDER_COLUMN_G_S_STRUCTUREID_2);
3210                            }
3211                    }
3212    
3213                    if (!getDB().isSupportsInlineDistinct()) {
3214                            query.append(_FILTER_SQL_SELECT_JOURNALTEMPLATE_NO_INLINE_DISTINCT_WHERE_2);
3215                    }
3216    
3217                    if (orderByComparator != null) {
3218                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3219    
3220                            if (orderByConditionFields.length > 0) {
3221                                    query.append(WHERE_AND);
3222                            }
3223    
3224                            for (int i = 0; i < orderByConditionFields.length; i++) {
3225                                    if (getDB().isSupportsInlineDistinct()) {
3226                                            query.append(_ORDER_BY_ENTITY_ALIAS);
3227                                    }
3228                                    else {
3229                                            query.append(_ORDER_BY_ENTITY_TABLE);
3230                                    }
3231    
3232                                    query.append(orderByConditionFields[i]);
3233    
3234                                    if ((i + 1) < orderByConditionFields.length) {
3235                                            if (orderByComparator.isAscending() ^ previous) {
3236                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3237                                            }
3238                                            else {
3239                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3240                                            }
3241                                    }
3242                                    else {
3243                                            if (orderByComparator.isAscending() ^ previous) {
3244                                                    query.append(WHERE_GREATER_THAN);
3245                                            }
3246                                            else {
3247                                                    query.append(WHERE_LESSER_THAN);
3248                                            }
3249                                    }
3250                            }
3251    
3252                            query.append(ORDER_BY_CLAUSE);
3253    
3254                            String[] orderByFields = orderByComparator.getOrderByFields();
3255    
3256                            for (int i = 0; i < orderByFields.length; i++) {
3257                                    if (getDB().isSupportsInlineDistinct()) {
3258                                            query.append(_ORDER_BY_ENTITY_ALIAS);
3259                                    }
3260                                    else {
3261                                            query.append(_ORDER_BY_ENTITY_TABLE);
3262                                    }
3263    
3264                                    query.append(orderByFields[i]);
3265    
3266                                    if ((i + 1) < orderByFields.length) {
3267                                            if (orderByComparator.isAscending() ^ previous) {
3268                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3269                                            }
3270                                            else {
3271                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3272                                            }
3273                                    }
3274                                    else {
3275                                            if (orderByComparator.isAscending() ^ previous) {
3276                                                    query.append(ORDER_BY_ASC);
3277                                            }
3278                                            else {
3279                                                    query.append(ORDER_BY_DESC);
3280                                            }
3281                                    }
3282                            }
3283                    }
3284    
3285                    else {
3286                            if (getDB().isSupportsInlineDistinct()) {
3287                                    query.append(JournalTemplateModelImpl.ORDER_BY_JPQL);
3288                            }
3289                            else {
3290                                    query.append(JournalTemplateModelImpl.ORDER_BY_SQL);
3291                            }
3292                    }
3293    
3294                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3295                                    JournalTemplate.class.getName(),
3296                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3297    
3298                    SQLQuery q = session.createSQLQuery(sql);
3299    
3300                    q.setFirstResult(0);
3301                    q.setMaxResults(2);
3302    
3303                    if (getDB().isSupportsInlineDistinct()) {
3304                            q.addEntity(_FILTER_ENTITY_ALIAS, JournalTemplateImpl.class);
3305                    }
3306                    else {
3307                            q.addEntity(_FILTER_ENTITY_TABLE, JournalTemplateImpl.class);
3308                    }
3309    
3310                    QueryPos qPos = QueryPos.getInstance(q);
3311    
3312                    qPos.add(groupId);
3313    
3314                    if (structureId != null) {
3315                            qPos.add(structureId);
3316                    }
3317    
3318                    if (orderByComparator != null) {
3319                            Object[] values = orderByComparator.getOrderByConditionValues(journalTemplate);
3320    
3321                            for (Object value : values) {
3322                                    qPos.add(value);
3323                            }
3324                    }
3325    
3326                    List<JournalTemplate> list = q.list();
3327    
3328                    if (list.size() == 2) {
3329                            return list.get(1);
3330                    }
3331                    else {
3332                            return null;
3333                    }
3334            }
3335    
3336            /**
3337             * Returns all the journal templates.
3338             *
3339             * @return the journal templates
3340             * @throws SystemException if a system exception occurred
3341             */
3342            public List<JournalTemplate> findAll() throws SystemException {
3343                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3344            }
3345    
3346            /**
3347             * Returns a range of all the journal templates.
3348             *
3349             * <p>
3350             * 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.
3351             * </p>
3352             *
3353             * @param start the lower bound of the range of journal templates
3354             * @param end the upper bound of the range of journal templates (not inclusive)
3355             * @return the range of journal templates
3356             * @throws SystemException if a system exception occurred
3357             */
3358            public List<JournalTemplate> findAll(int start, int end)
3359                    throws SystemException {
3360                    return findAll(start, end, null);
3361            }
3362    
3363            /**
3364             * Returns an ordered range of all the journal templates.
3365             *
3366             * <p>
3367             * 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.
3368             * </p>
3369             *
3370             * @param start the lower bound of the range of journal templates
3371             * @param end the upper bound of the range of journal templates (not inclusive)
3372             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3373             * @return the ordered range of journal templates
3374             * @throws SystemException if a system exception occurred
3375             */
3376            public List<JournalTemplate> findAll(int start, int end,
3377                    OrderByComparator orderByComparator) throws SystemException {
3378                    FinderPath finderPath = null;
3379                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
3380    
3381                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3382                                    (orderByComparator == null)) {
3383                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
3384                            finderArgs = FINDER_ARGS_EMPTY;
3385                    }
3386                    else {
3387                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
3388                            finderArgs = new Object[] { start, end, orderByComparator };
3389                    }
3390    
3391                    List<JournalTemplate> list = (List<JournalTemplate>)FinderCacheUtil.getResult(finderPath,
3392                                    finderArgs, this);
3393    
3394                    if (list == null) {
3395                            StringBundler query = null;
3396                            String sql = null;
3397    
3398                            if (orderByComparator != null) {
3399                                    query = new StringBundler(2 +
3400                                                    (orderByComparator.getOrderByFields().length * 3));
3401    
3402                                    query.append(_SQL_SELECT_JOURNALTEMPLATE);
3403    
3404                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3405                                            orderByComparator);
3406    
3407                                    sql = query.toString();
3408                            }
3409                            else {
3410                                    sql = _SQL_SELECT_JOURNALTEMPLATE.concat(JournalTemplateModelImpl.ORDER_BY_JPQL);
3411                            }
3412    
3413                            Session session = null;
3414    
3415                            try {
3416                                    session = openSession();
3417    
3418                                    Query q = session.createQuery(sql);
3419    
3420                                    if (orderByComparator == null) {
3421                                            list = (List<JournalTemplate>)QueryUtil.list(q,
3422                                                            getDialect(), start, end, false);
3423    
3424                                            Collections.sort(list);
3425                                    }
3426                                    else {
3427                                            list = (List<JournalTemplate>)QueryUtil.list(q,
3428                                                            getDialect(), start, end);
3429                                    }
3430                            }
3431                            catch (Exception e) {
3432                                    throw processException(e);
3433                            }
3434                            finally {
3435                                    if (list == null) {
3436                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
3437                                    }
3438                                    else {
3439                                            cacheResult(list);
3440    
3441                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
3442                                    }
3443    
3444                                    closeSession(session);
3445                            }
3446                    }
3447    
3448                    return list;
3449            }
3450    
3451            /**
3452             * Removes all the journal templates where uuid = &#63; from the database.
3453             *
3454             * @param uuid the uuid
3455             * @throws SystemException if a system exception occurred
3456             */
3457            public void removeByUuid(String uuid) throws SystemException {
3458                    for (JournalTemplate journalTemplate : findByUuid(uuid)) {
3459                            remove(journalTemplate);
3460                    }
3461            }
3462    
3463            /**
3464             * Removes the journal template where uuid = &#63; and groupId = &#63; from the database.
3465             *
3466             * @param uuid the uuid
3467             * @param groupId the group ID
3468             * @throws SystemException if a system exception occurred
3469             */
3470            public void removeByUUID_G(String uuid, long groupId)
3471                    throws NoSuchTemplateException, SystemException {
3472                    JournalTemplate journalTemplate = findByUUID_G(uuid, groupId);
3473    
3474                    remove(journalTemplate);
3475            }
3476    
3477            /**
3478             * Removes all the journal templates where groupId = &#63; from the database.
3479             *
3480             * @param groupId the group ID
3481             * @throws SystemException if a system exception occurred
3482             */
3483            public void removeByGroupId(long groupId) throws SystemException {
3484                    for (JournalTemplate journalTemplate : findByGroupId(groupId)) {
3485                            remove(journalTemplate);
3486                    }
3487            }
3488    
3489            /**
3490             * Removes all the journal templates where templateId = &#63; from the database.
3491             *
3492             * @param templateId the template ID
3493             * @throws SystemException if a system exception occurred
3494             */
3495            public void removeByTemplateId(String templateId) throws SystemException {
3496                    for (JournalTemplate journalTemplate : findByTemplateId(templateId)) {
3497                            remove(journalTemplate);
3498                    }
3499            }
3500    
3501            /**
3502             * Removes the journal template where smallImageId = &#63; from the database.
3503             *
3504             * @param smallImageId the small image ID
3505             * @throws SystemException if a system exception occurred
3506             */
3507            public void removeBySmallImageId(long smallImageId)
3508                    throws NoSuchTemplateException, SystemException {
3509                    JournalTemplate journalTemplate = findBySmallImageId(smallImageId);
3510    
3511                    remove(journalTemplate);
3512            }
3513    
3514            /**
3515             * Removes the journal template where groupId = &#63; and templateId = &#63; from the database.
3516             *
3517             * @param groupId the group ID
3518             * @param templateId the template ID
3519             * @throws SystemException if a system exception occurred
3520             */
3521            public void removeByG_T(long groupId, String templateId)
3522                    throws NoSuchTemplateException, SystemException {
3523                    JournalTemplate journalTemplate = findByG_T(groupId, templateId);
3524    
3525                    remove(journalTemplate);
3526            }
3527    
3528            /**
3529             * Removes all the journal templates where groupId = &#63; and structureId = &#63; from the database.
3530             *
3531             * @param groupId the group ID
3532             * @param structureId the structure ID
3533             * @throws SystemException if a system exception occurred
3534             */
3535            public void removeByG_S(long groupId, String structureId)
3536                    throws SystemException {
3537                    for (JournalTemplate journalTemplate : findByG_S(groupId, structureId)) {
3538                            remove(journalTemplate);
3539                    }
3540            }
3541    
3542            /**
3543             * Removes all the journal templates from the database.
3544             *
3545             * @throws SystemException if a system exception occurred
3546             */
3547            public void removeAll() throws SystemException {
3548                    for (JournalTemplate journalTemplate : findAll()) {
3549                            remove(journalTemplate);
3550                    }
3551            }
3552    
3553            /**
3554             * Returns the number of journal templates where uuid = &#63;.
3555             *
3556             * @param uuid the uuid
3557             * @return the number of matching journal templates
3558             * @throws SystemException if a system exception occurred
3559             */
3560            public int countByUuid(String uuid) throws SystemException {
3561                    Object[] finderArgs = new Object[] { uuid };
3562    
3563                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
3564                                    finderArgs, this);
3565    
3566                    if (count == null) {
3567                            StringBundler query = new StringBundler(2);
3568    
3569                            query.append(_SQL_COUNT_JOURNALTEMPLATE_WHERE);
3570    
3571                            if (uuid == null) {
3572                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
3573                            }
3574                            else {
3575                                    if (uuid.equals(StringPool.BLANK)) {
3576                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
3577                                    }
3578                                    else {
3579                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
3580                                    }
3581                            }
3582    
3583                            String sql = query.toString();
3584    
3585                            Session session = null;
3586    
3587                            try {
3588                                    session = openSession();
3589    
3590                                    Query q = session.createQuery(sql);
3591    
3592                                    QueryPos qPos = QueryPos.getInstance(q);
3593    
3594                                    if (uuid != null) {
3595                                            qPos.add(uuid);
3596                                    }
3597    
3598                                    count = (Long)q.uniqueResult();
3599                            }
3600                            catch (Exception e) {
3601                                    throw processException(e);
3602                            }
3603                            finally {
3604                                    if (count == null) {
3605                                            count = Long.valueOf(0);
3606                                    }
3607    
3608                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
3609                                            finderArgs, count);
3610    
3611                                    closeSession(session);
3612                            }
3613                    }
3614    
3615                    return count.intValue();
3616            }
3617    
3618            /**
3619             * Returns the number of journal templates where uuid = &#63; and groupId = &#63;.
3620             *
3621             * @param uuid the uuid
3622             * @param groupId the group ID
3623             * @return the number of matching journal templates
3624             * @throws SystemException if a system exception occurred
3625             */
3626            public int countByUUID_G(String uuid, long groupId)
3627                    throws SystemException {
3628                    Object[] finderArgs = new Object[] { uuid, groupId };
3629    
3630                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
3631                                    finderArgs, this);
3632    
3633                    if (count == null) {
3634                            StringBundler query = new StringBundler(3);
3635    
3636                            query.append(_SQL_COUNT_JOURNALTEMPLATE_WHERE);
3637    
3638                            if (uuid == null) {
3639                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
3640                            }
3641                            else {
3642                                    if (uuid.equals(StringPool.BLANK)) {
3643                                            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
3644                                    }
3645                                    else {
3646                                            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
3647                                    }
3648                            }
3649    
3650                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
3651    
3652                            String sql = query.toString();
3653    
3654                            Session session = null;
3655    
3656                            try {
3657                                    session = openSession();
3658    
3659                                    Query q = session.createQuery(sql);
3660    
3661                                    QueryPos qPos = QueryPos.getInstance(q);
3662    
3663                                    if (uuid != null) {
3664                                            qPos.add(uuid);
3665                                    }
3666    
3667                                    qPos.add(groupId);
3668    
3669                                    count = (Long)q.uniqueResult();
3670                            }
3671                            catch (Exception e) {
3672                                    throw processException(e);
3673                            }
3674                            finally {
3675                                    if (count == null) {
3676                                            count = Long.valueOf(0);
3677                                    }
3678    
3679                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
3680                                            finderArgs, count);
3681    
3682                                    closeSession(session);
3683                            }
3684                    }
3685    
3686                    return count.intValue();
3687            }
3688    
3689            /**
3690             * Returns the number of journal templates where groupId = &#63;.
3691             *
3692             * @param groupId the group ID
3693             * @return the number of matching journal templates
3694             * @throws SystemException if a system exception occurred
3695             */
3696            public int countByGroupId(long groupId) throws SystemException {
3697                    Object[] finderArgs = new Object[] { groupId };
3698    
3699                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
3700                                    finderArgs, this);
3701    
3702                    if (count == null) {
3703                            StringBundler query = new StringBundler(2);
3704    
3705                            query.append(_SQL_COUNT_JOURNALTEMPLATE_WHERE);
3706    
3707                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
3708    
3709                            String sql = query.toString();
3710    
3711                            Session session = null;
3712    
3713                            try {
3714                                    session = openSession();
3715    
3716                                    Query q = session.createQuery(sql);
3717    
3718                                    QueryPos qPos = QueryPos.getInstance(q);
3719    
3720                                    qPos.add(groupId);
3721    
3722                                    count = (Long)q.uniqueResult();
3723                            }
3724                            catch (Exception e) {
3725                                    throw processException(e);
3726                            }
3727                            finally {
3728                                    if (count == null) {
3729                                            count = Long.valueOf(0);
3730                                    }
3731    
3732                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
3733                                            finderArgs, count);
3734    
3735                                    closeSession(session);
3736                            }
3737                    }
3738    
3739                    return count.intValue();
3740            }
3741    
3742            /**
3743             * Returns the number of journal templates that the user has permission to view where groupId = &#63;.
3744             *
3745             * @param groupId the group ID
3746             * @return the number of matching journal templates that the user has permission to view
3747             * @throws SystemException if a system exception occurred
3748             */
3749            public int filterCountByGroupId(long groupId) throws SystemException {
3750                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3751                            return countByGroupId(groupId);
3752                    }
3753    
3754                    StringBundler query = new StringBundler(2);
3755    
3756                    query.append(_FILTER_SQL_COUNT_JOURNALTEMPLATE_WHERE);
3757    
3758                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
3759    
3760                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3761                                    JournalTemplate.class.getName(),
3762                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3763    
3764                    Session session = null;
3765    
3766                    try {
3767                            session = openSession();
3768    
3769                            SQLQuery q = session.createSQLQuery(sql);
3770    
3771                            q.addScalar(COUNT_COLUMN_NAME,
3772                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
3773    
3774                            QueryPos qPos = QueryPos.getInstance(q);
3775    
3776                            qPos.add(groupId);
3777    
3778                            Long count = (Long)q.uniqueResult();
3779    
3780                            return count.intValue();
3781                    }
3782                    catch (Exception e) {
3783                            throw processException(e);
3784                    }
3785                    finally {
3786                            closeSession(session);
3787                    }
3788            }
3789    
3790            /**
3791             * Returns the number of journal templates where templateId = &#63;.
3792             *
3793             * @param templateId the template ID
3794             * @return the number of matching journal templates
3795             * @throws SystemException if a system exception occurred
3796             */
3797            public int countByTemplateId(String templateId) throws SystemException {
3798                    Object[] finderArgs = new Object[] { templateId };
3799    
3800                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_TEMPLATEID,
3801                                    finderArgs, this);
3802    
3803                    if (count == null) {
3804                            StringBundler query = new StringBundler(2);
3805    
3806                            query.append(_SQL_COUNT_JOURNALTEMPLATE_WHERE);
3807    
3808                            if (templateId == null) {
3809                                    query.append(_FINDER_COLUMN_TEMPLATEID_TEMPLATEID_1);
3810                            }
3811                            else {
3812                                    if (templateId.equals(StringPool.BLANK)) {
3813                                            query.append(_FINDER_COLUMN_TEMPLATEID_TEMPLATEID_3);
3814                                    }
3815                                    else {
3816                                            query.append(_FINDER_COLUMN_TEMPLATEID_TEMPLATEID_2);
3817                                    }
3818                            }
3819    
3820                            String sql = query.toString();
3821    
3822                            Session session = null;
3823    
3824                            try {
3825                                    session = openSession();
3826    
3827                                    Query q = session.createQuery(sql);
3828    
3829                                    QueryPos qPos = QueryPos.getInstance(q);
3830    
3831                                    if (templateId != null) {
3832                                            qPos.add(templateId);
3833                                    }
3834    
3835                                    count = (Long)q.uniqueResult();
3836                            }
3837                            catch (Exception e) {
3838                                    throw processException(e);
3839                            }
3840                            finally {
3841                                    if (count == null) {
3842                                            count = Long.valueOf(0);
3843                                    }
3844    
3845                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_TEMPLATEID,
3846                                            finderArgs, count);
3847    
3848                                    closeSession(session);
3849                            }
3850                    }
3851    
3852                    return count.intValue();
3853            }
3854    
3855            /**
3856             * Returns the number of journal templates where smallImageId = &#63;.
3857             *
3858             * @param smallImageId the small image ID
3859             * @return the number of matching journal templates
3860             * @throws SystemException if a system exception occurred
3861             */
3862            public int countBySmallImageId(long smallImageId) throws SystemException {
3863                    Object[] finderArgs = new Object[] { smallImageId };
3864    
3865                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_SMALLIMAGEID,
3866                                    finderArgs, this);
3867    
3868                    if (count == null) {
3869                            StringBundler query = new StringBundler(2);
3870    
3871                            query.append(_SQL_COUNT_JOURNALTEMPLATE_WHERE);
3872    
3873                            query.append(_FINDER_COLUMN_SMALLIMAGEID_SMALLIMAGEID_2);
3874    
3875                            String sql = query.toString();
3876    
3877                            Session session = null;
3878    
3879                            try {
3880                                    session = openSession();
3881    
3882                                    Query q = session.createQuery(sql);
3883    
3884                                    QueryPos qPos = QueryPos.getInstance(q);
3885    
3886                                    qPos.add(smallImageId);
3887    
3888                                    count = (Long)q.uniqueResult();
3889                            }
3890                            catch (Exception e) {
3891                                    throw processException(e);
3892                            }
3893                            finally {
3894                                    if (count == null) {
3895                                            count = Long.valueOf(0);
3896                                    }
3897    
3898                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_SMALLIMAGEID,
3899                                            finderArgs, count);
3900    
3901                                    closeSession(session);
3902                            }
3903                    }
3904    
3905                    return count.intValue();
3906            }
3907    
3908            /**
3909             * Returns the number of journal templates where groupId = &#63; and templateId = &#63;.
3910             *
3911             * @param groupId the group ID
3912             * @param templateId the template ID
3913             * @return the number of matching journal templates
3914             * @throws SystemException if a system exception occurred
3915             */
3916            public int countByG_T(long groupId, String templateId)
3917                    throws SystemException {
3918                    Object[] finderArgs = new Object[] { groupId, templateId };
3919    
3920                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_T,
3921                                    finderArgs, this);
3922    
3923                    if (count == null) {
3924                            StringBundler query = new StringBundler(3);
3925    
3926                            query.append(_SQL_COUNT_JOURNALTEMPLATE_WHERE);
3927    
3928                            query.append(_FINDER_COLUMN_G_T_GROUPID_2);
3929    
3930                            if (templateId == null) {
3931                                    query.append(_FINDER_COLUMN_G_T_TEMPLATEID_1);
3932                            }
3933                            else {
3934                                    if (templateId.equals(StringPool.BLANK)) {
3935                                            query.append(_FINDER_COLUMN_G_T_TEMPLATEID_3);
3936                                    }
3937                                    else {
3938                                            query.append(_FINDER_COLUMN_G_T_TEMPLATEID_2);
3939                                    }
3940                            }
3941    
3942                            String sql = query.toString();
3943    
3944                            Session session = null;
3945    
3946                            try {
3947                                    session = openSession();
3948    
3949                                    Query q = session.createQuery(sql);
3950    
3951                                    QueryPos qPos = QueryPos.getInstance(q);
3952    
3953                                    qPos.add(groupId);
3954    
3955                                    if (templateId != null) {
3956                                            qPos.add(templateId);
3957                                    }
3958    
3959                                    count = (Long)q.uniqueResult();
3960                            }
3961                            catch (Exception e) {
3962                                    throw processException(e);
3963                            }
3964                            finally {
3965                                    if (count == null) {
3966                                            count = Long.valueOf(0);
3967                                    }
3968    
3969                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_T, finderArgs,
3970                                            count);
3971    
3972                                    closeSession(session);
3973                            }
3974                    }
3975    
3976                    return count.intValue();
3977            }
3978    
3979            /**
3980             * Returns the number of journal templates where groupId = &#63; and structureId = &#63;.
3981             *
3982             * @param groupId the group ID
3983             * @param structureId the structure ID
3984             * @return the number of matching journal templates
3985             * @throws SystemException if a system exception occurred
3986             */
3987            public int countByG_S(long groupId, String structureId)
3988                    throws SystemException {
3989                    Object[] finderArgs = new Object[] { groupId, structureId };
3990    
3991                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_S,
3992                                    finderArgs, this);
3993    
3994                    if (count == null) {
3995                            StringBundler query = new StringBundler(3);
3996    
3997                            query.append(_SQL_COUNT_JOURNALTEMPLATE_WHERE);
3998    
3999                            query.append(_FINDER_COLUMN_G_S_GROUPID_2);
4000    
4001                            if (structureId == null) {
4002                                    query.append(_FINDER_COLUMN_G_S_STRUCTUREID_1);
4003                            }
4004                            else {
4005                                    if (structureId.equals(StringPool.BLANK)) {
4006                                            query.append(_FINDER_COLUMN_G_S_STRUCTUREID_3);
4007                                    }
4008                                    else {
4009                                            query.append(_FINDER_COLUMN_G_S_STRUCTUREID_2);
4010                                    }
4011                            }
4012    
4013                            String sql = query.toString();
4014    
4015                            Session session = null;
4016    
4017                            try {
4018                                    session = openSession();
4019    
4020                                    Query q = session.createQuery(sql);
4021    
4022                                    QueryPos qPos = QueryPos.getInstance(q);
4023    
4024                                    qPos.add(groupId);
4025    
4026                                    if (structureId != null) {
4027                                            qPos.add(structureId);
4028                                    }
4029    
4030                                    count = (Long)q.uniqueResult();
4031                            }
4032                            catch (Exception e) {
4033                                    throw processException(e);
4034                            }
4035                            finally {
4036                                    if (count == null) {
4037                                            count = Long.valueOf(0);
4038                                    }
4039    
4040                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_S, finderArgs,
4041                                            count);
4042    
4043                                    closeSession(session);
4044                            }
4045                    }
4046    
4047                    return count.intValue();
4048            }
4049    
4050            /**
4051             * Returns the number of journal templates that the user has permission to view where groupId = &#63; and structureId = &#63;.
4052             *
4053             * @param groupId the group ID
4054             * @param structureId the structure ID
4055             * @return the number of matching journal templates that the user has permission to view
4056             * @throws SystemException if a system exception occurred
4057             */
4058            public int filterCountByG_S(long groupId, String structureId)
4059                    throws SystemException {
4060                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4061                            return countByG_S(groupId, structureId);
4062                    }
4063    
4064                    StringBundler query = new StringBundler(3);
4065    
4066                    query.append(_FILTER_SQL_COUNT_JOURNALTEMPLATE_WHERE);
4067    
4068                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
4069    
4070                    if (structureId == null) {
4071                            query.append(_FINDER_COLUMN_G_S_STRUCTUREID_1);
4072                    }
4073                    else {
4074                            if (structureId.equals(StringPool.BLANK)) {
4075                                    query.append(_FINDER_COLUMN_G_S_STRUCTUREID_3);
4076                            }
4077                            else {
4078                                    query.append(_FINDER_COLUMN_G_S_STRUCTUREID_2);
4079                            }
4080                    }
4081    
4082                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4083                                    JournalTemplate.class.getName(),
4084                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4085    
4086                    Session session = null;
4087    
4088                    try {
4089                            session = openSession();
4090    
4091                            SQLQuery q = session.createSQLQuery(sql);
4092    
4093                            q.addScalar(COUNT_COLUMN_NAME,
4094                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
4095    
4096                            QueryPos qPos = QueryPos.getInstance(q);
4097    
4098                            qPos.add(groupId);
4099    
4100                            if (structureId != null) {
4101                                    qPos.add(structureId);
4102                            }
4103    
4104                            Long count = (Long)q.uniqueResult();
4105    
4106                            return count.intValue();
4107                    }
4108                    catch (Exception e) {
4109                            throw processException(e);
4110                    }
4111                    finally {
4112                            closeSession(session);
4113                    }
4114            }
4115    
4116            /**
4117             * Returns the number of journal templates.
4118             *
4119             * @return the number of journal templates
4120             * @throws SystemException if a system exception occurred
4121             */
4122            public int countAll() throws SystemException {
4123                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
4124                                    FINDER_ARGS_EMPTY, this);
4125    
4126                    if (count == null) {
4127                            Session session = null;
4128    
4129                            try {
4130                                    session = openSession();
4131    
4132                                    Query q = session.createQuery(_SQL_COUNT_JOURNALTEMPLATE);
4133    
4134                                    count = (Long)q.uniqueResult();
4135                            }
4136                            catch (Exception e) {
4137                                    throw processException(e);
4138                            }
4139                            finally {
4140                                    if (count == null) {
4141                                            count = Long.valueOf(0);
4142                                    }
4143    
4144                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
4145                                            FINDER_ARGS_EMPTY, count);
4146    
4147                                    closeSession(session);
4148                            }
4149                    }
4150    
4151                    return count.intValue();
4152            }
4153    
4154            /**
4155             * Initializes the journal template persistence.
4156             */
4157            public void afterPropertiesSet() {
4158                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
4159                                            com.liferay.portal.util.PropsUtil.get(
4160                                                    "value.object.listener.com.liferay.portlet.journal.model.JournalTemplate")));
4161    
4162                    if (listenerClassNames.length > 0) {
4163                            try {
4164                                    List<ModelListener<JournalTemplate>> listenersList = new ArrayList<ModelListener<JournalTemplate>>();
4165    
4166                                    for (String listenerClassName : listenerClassNames) {
4167                                            listenersList.add((ModelListener<JournalTemplate>)InstanceFactory.newInstance(
4168                                                            listenerClassName));
4169                                    }
4170    
4171                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
4172                            }
4173                            catch (Exception e) {
4174                                    _log.error(e);
4175                            }
4176                    }
4177            }
4178    
4179            public void destroy() {
4180                    EntityCacheUtil.removeCache(JournalTemplateImpl.class.getName());
4181                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
4182                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4183            }
4184    
4185            @BeanReference(type = JournalArticlePersistence.class)
4186            protected JournalArticlePersistence journalArticlePersistence;
4187            @BeanReference(type = JournalArticleImagePersistence.class)
4188            protected JournalArticleImagePersistence journalArticleImagePersistence;
4189            @BeanReference(type = JournalArticleResourcePersistence.class)
4190            protected JournalArticleResourcePersistence journalArticleResourcePersistence;
4191            @BeanReference(type = JournalContentSearchPersistence.class)
4192            protected JournalContentSearchPersistence journalContentSearchPersistence;
4193            @BeanReference(type = JournalFeedPersistence.class)
4194            protected JournalFeedPersistence journalFeedPersistence;
4195            @BeanReference(type = JournalStructurePersistence.class)
4196            protected JournalStructurePersistence journalStructurePersistence;
4197            @BeanReference(type = JournalTemplatePersistence.class)
4198            protected JournalTemplatePersistence journalTemplatePersistence;
4199            @BeanReference(type = ImagePersistence.class)
4200            protected ImagePersistence imagePersistence;
4201            @BeanReference(type = ResourcePersistence.class)
4202            protected ResourcePersistence resourcePersistence;
4203            @BeanReference(type = UserPersistence.class)
4204            protected UserPersistence userPersistence;
4205            @BeanReference(type = WebDAVPropsPersistence.class)
4206            protected WebDAVPropsPersistence webDAVPropsPersistence;
4207            @BeanReference(type = ExpandoValuePersistence.class)
4208            protected ExpandoValuePersistence expandoValuePersistence;
4209            private static final String _SQL_SELECT_JOURNALTEMPLATE = "SELECT journalTemplate FROM JournalTemplate journalTemplate";
4210            private static final String _SQL_SELECT_JOURNALTEMPLATE_WHERE = "SELECT journalTemplate FROM JournalTemplate journalTemplate WHERE ";
4211            private static final String _SQL_COUNT_JOURNALTEMPLATE = "SELECT COUNT(journalTemplate) FROM JournalTemplate journalTemplate";
4212            private static final String _SQL_COUNT_JOURNALTEMPLATE_WHERE = "SELECT COUNT(journalTemplate) FROM JournalTemplate journalTemplate WHERE ";
4213            private static final String _FINDER_COLUMN_UUID_UUID_1 = "journalTemplate.uuid IS NULL";
4214            private static final String _FINDER_COLUMN_UUID_UUID_2 = "journalTemplate.uuid = ?";
4215            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(journalTemplate.uuid IS NULL OR journalTemplate.uuid = ?)";
4216            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "journalTemplate.uuid IS NULL AND ";
4217            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "journalTemplate.uuid = ? AND ";
4218            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(journalTemplate.uuid IS NULL OR journalTemplate.uuid = ?) AND ";
4219            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "journalTemplate.groupId = ?";
4220            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "journalTemplate.groupId = ?";
4221            private static final String _FINDER_COLUMN_TEMPLATEID_TEMPLATEID_1 = "journalTemplate.templateId IS NULL";
4222            private static final String _FINDER_COLUMN_TEMPLATEID_TEMPLATEID_2 = "journalTemplate.templateId = ?";
4223            private static final String _FINDER_COLUMN_TEMPLATEID_TEMPLATEID_3 = "(journalTemplate.templateId IS NULL OR journalTemplate.templateId = ?)";
4224            private static final String _FINDER_COLUMN_SMALLIMAGEID_SMALLIMAGEID_2 = "journalTemplate.smallImageId = ?";
4225            private static final String _FINDER_COLUMN_G_T_GROUPID_2 = "journalTemplate.groupId = ? AND ";
4226            private static final String _FINDER_COLUMN_G_T_TEMPLATEID_1 = "journalTemplate.templateId IS NULL";
4227            private static final String _FINDER_COLUMN_G_T_TEMPLATEID_2 = "journalTemplate.templateId = ?";
4228            private static final String _FINDER_COLUMN_G_T_TEMPLATEID_3 = "(journalTemplate.templateId IS NULL OR journalTemplate.templateId = ?)";
4229            private static final String _FINDER_COLUMN_G_S_GROUPID_2 = "journalTemplate.groupId = ? AND ";
4230            private static final String _FINDER_COLUMN_G_S_STRUCTUREID_1 = "journalTemplate.structureId IS NULL";
4231            private static final String _FINDER_COLUMN_G_S_STRUCTUREID_2 = "journalTemplate.structureId = ?";
4232            private static final String _FINDER_COLUMN_G_S_STRUCTUREID_3 = "(journalTemplate.structureId IS NULL OR journalTemplate.structureId = ?)";
4233            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "journalTemplate.id_";
4234            private static final String _FILTER_SQL_SELECT_JOURNALTEMPLATE_WHERE = "SELECT DISTINCT {journalTemplate.*} FROM JournalTemplate journalTemplate WHERE ";
4235            private static final String _FILTER_SQL_SELECT_JOURNALTEMPLATE_NO_INLINE_DISTINCT_WHERE_1 =
4236                    "SELECT {JournalTemplate.*} FROM (SELECT DISTINCT journalTemplate.id_ FROM JournalTemplate journalTemplate WHERE ";
4237            private static final String _FILTER_SQL_SELECT_JOURNALTEMPLATE_NO_INLINE_DISTINCT_WHERE_2 =
4238                    ") TEMP_TABLE INNER JOIN JournalTemplate ON TEMP_TABLE.id_ = JournalTemplate.id_";
4239            private static final String _FILTER_SQL_COUNT_JOURNALTEMPLATE_WHERE = "SELECT COUNT(DISTINCT journalTemplate.id_) AS COUNT_VALUE FROM JournalTemplate journalTemplate WHERE ";
4240            private static final String _FILTER_ENTITY_ALIAS = "journalTemplate";
4241            private static final String _FILTER_ENTITY_TABLE = "JournalTemplate";
4242            private static final String _ORDER_BY_ENTITY_ALIAS = "journalTemplate.";
4243            private static final String _ORDER_BY_ENTITY_TABLE = "JournalTemplate.";
4244            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No JournalTemplate exists with the primary key ";
4245            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No JournalTemplate exists with the key {";
4246            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
4247            private static Log _log = LogFactoryUtil.getLog(JournalTemplatePersistenceImpl.class);
4248            private static JournalTemplate _nullJournalTemplate = new JournalTemplateImpl() {
4249                            @Override
4250                            public Object clone() {
4251                                    return this;
4252                            }
4253    
4254                            @Override
4255                            public CacheModel<JournalTemplate> toCacheModel() {
4256                                    return _nullJournalTemplateCacheModel;
4257                            }
4258                    };
4259    
4260            private static CacheModel<JournalTemplate> _nullJournalTemplateCacheModel = new CacheModel<JournalTemplate>() {
4261                            public JournalTemplate toEntityModel() {
4262                                    return _nullJournalTemplate;
4263                            }
4264                    };
4265    }