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.GroupPersistence;
043    import com.liferay.portal.service.persistence.ImagePersistence;
044    import com.liferay.portal.service.persistence.UserPersistence;
045    import com.liferay.portal.service.persistence.WebDAVPropsPersistence;
046    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
047    
048    import com.liferay.portlet.expando.service.persistence.ExpandoValuePersistence;
049    import com.liferay.portlet.journal.NoSuchTemplateException;
050    import com.liferay.portlet.journal.model.JournalTemplate;
051    import com.liferay.portlet.journal.model.impl.JournalTemplateImpl;
052    import com.liferay.portlet.journal.model.impl.JournalTemplateModelImpl;
053    
054    import java.io.Serializable;
055    
056    import java.util.ArrayList;
057    import java.util.Collections;
058    import java.util.List;
059    
060    /**
061     * The persistence implementation for the journal template service.
062     *
063     * <p>
064     * Caching information and settings can be found in <code>portal.properties</code>
065     * </p>
066     *
067     * @author Brian Wing Shun Chan
068     * @see JournalTemplatePersistence
069     * @see JournalTemplateUtil
070     * @generated
071     */
072    public class JournalTemplatePersistenceImpl extends BasePersistenceImpl<JournalTemplate>
073            implements JournalTemplatePersistence {
074            /*
075             * NOTE FOR DEVELOPERS:
076             *
077             * 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.
078             */
079            public static final String FINDER_CLASS_NAME_ENTITY = JournalTemplateImpl.class.getName();
080            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
081                    ".List1";
082            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
083                    ".List2";
084            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
085                            JournalTemplateModelImpl.FINDER_CACHE_ENABLED,
086                            JournalTemplateImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
087                            "findByUuid",
088                            new String[] {
089                                    String.class.getName(),
090                                    
091                            "java.lang.Integer", "java.lang.Integer",
092                                    "com.liferay.portal.kernel.util.OrderByComparator"
093                            });
094            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
095                            JournalTemplateModelImpl.FINDER_CACHE_ENABLED,
096                            JournalTemplateImpl.class,
097                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
098                            new String[] { String.class.getName() },
099                            JournalTemplateModelImpl.UUID_COLUMN_BITMASK);
100            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
101                            JournalTemplateModelImpl.FINDER_CACHE_ENABLED, Long.class,
102                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
103                            new String[] { String.class.getName() });
104            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
105                            JournalTemplateModelImpl.FINDER_CACHE_ENABLED,
106                            JournalTemplateImpl.class, FINDER_CLASS_NAME_ENTITY,
107                            "fetchByUUID_G",
108                            new String[] { String.class.getName(), Long.class.getName() },
109                            JournalTemplateModelImpl.UUID_COLUMN_BITMASK |
110                            JournalTemplateModelImpl.GROUPID_COLUMN_BITMASK);
111            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
112                            JournalTemplateModelImpl.FINDER_CACHE_ENABLED, Long.class,
113                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
114                            new String[] { String.class.getName(), Long.class.getName() });
115            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
116                            JournalTemplateModelImpl.FINDER_CACHE_ENABLED,
117                            JournalTemplateImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
118                            "findByUuid_C",
119                            new String[] {
120                                    String.class.getName(), Long.class.getName(),
121                                    
122                            "java.lang.Integer", "java.lang.Integer",
123                                    "com.liferay.portal.kernel.util.OrderByComparator"
124                            });
125            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
126                    new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
127                            JournalTemplateModelImpl.FINDER_CACHE_ENABLED,
128                            JournalTemplateImpl.class,
129                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
130                            new String[] { String.class.getName(), Long.class.getName() },
131                            JournalTemplateModelImpl.UUID_COLUMN_BITMASK |
132                            JournalTemplateModelImpl.COMPANYID_COLUMN_BITMASK);
133            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
134                            JournalTemplateModelImpl.FINDER_CACHE_ENABLED, Long.class,
135                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
136                            new String[] { String.class.getName(), Long.class.getName() });
137            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
138                            JournalTemplateModelImpl.FINDER_CACHE_ENABLED,
139                            JournalTemplateImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
140                            "findByGroupId",
141                            new String[] {
142                                    Long.class.getName(),
143                                    
144                            "java.lang.Integer", "java.lang.Integer",
145                                    "com.liferay.portal.kernel.util.OrderByComparator"
146                            });
147            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
148                    new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
149                            JournalTemplateModelImpl.FINDER_CACHE_ENABLED,
150                            JournalTemplateImpl.class,
151                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
152                            new String[] { Long.class.getName() },
153                            JournalTemplateModelImpl.GROUPID_COLUMN_BITMASK);
154            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
155                            JournalTemplateModelImpl.FINDER_CACHE_ENABLED, Long.class,
156                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
157                            new String[] { Long.class.getName() });
158            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_TEMPLATEID =
159                    new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
160                            JournalTemplateModelImpl.FINDER_CACHE_ENABLED,
161                            JournalTemplateImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
162                            "findByTemplateId",
163                            new String[] {
164                                    String.class.getName(),
165                                    
166                            "java.lang.Integer", "java.lang.Integer",
167                                    "com.liferay.portal.kernel.util.OrderByComparator"
168                            });
169            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TEMPLATEID =
170                    new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
171                            JournalTemplateModelImpl.FINDER_CACHE_ENABLED,
172                            JournalTemplateImpl.class,
173                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByTemplateId",
174                            new String[] { String.class.getName() },
175                            JournalTemplateModelImpl.TEMPLATEID_COLUMN_BITMASK);
176            public static final FinderPath FINDER_PATH_COUNT_BY_TEMPLATEID = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
177                            JournalTemplateModelImpl.FINDER_CACHE_ENABLED, Long.class,
178                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByTemplateId",
179                            new String[] { String.class.getName() });
180            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_STRUCTUREID =
181                    new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
182                            JournalTemplateModelImpl.FINDER_CACHE_ENABLED,
183                            JournalTemplateImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
184                            "findByStructureId",
185                            new String[] {
186                                    String.class.getName(),
187                                    
188                            "java.lang.Integer", "java.lang.Integer",
189                                    "com.liferay.portal.kernel.util.OrderByComparator"
190                            });
191            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_STRUCTUREID =
192                    new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
193                            JournalTemplateModelImpl.FINDER_CACHE_ENABLED,
194                            JournalTemplateImpl.class,
195                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByStructureId",
196                            new String[] { String.class.getName() },
197                            JournalTemplateModelImpl.STRUCTUREID_COLUMN_BITMASK);
198            public static final FinderPath FINDER_PATH_COUNT_BY_STRUCTUREID = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
199                            JournalTemplateModelImpl.FINDER_CACHE_ENABLED, Long.class,
200                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByStructureId",
201                            new String[] { String.class.getName() });
202            public static final FinderPath FINDER_PATH_FETCH_BY_SMALLIMAGEID = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
203                            JournalTemplateModelImpl.FINDER_CACHE_ENABLED,
204                            JournalTemplateImpl.class, FINDER_CLASS_NAME_ENTITY,
205                            "fetchBySmallImageId", new String[] { Long.class.getName() },
206                            JournalTemplateModelImpl.SMALLIMAGEID_COLUMN_BITMASK);
207            public static final FinderPath FINDER_PATH_COUNT_BY_SMALLIMAGEID = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
208                            JournalTemplateModelImpl.FINDER_CACHE_ENABLED, Long.class,
209                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countBySmallImageId",
210                            new String[] { Long.class.getName() });
211            public static final FinderPath FINDER_PATH_FETCH_BY_G_T = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
212                            JournalTemplateModelImpl.FINDER_CACHE_ENABLED,
213                            JournalTemplateImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByG_T",
214                            new String[] { Long.class.getName(), String.class.getName() },
215                            JournalTemplateModelImpl.GROUPID_COLUMN_BITMASK |
216                            JournalTemplateModelImpl.TEMPLATEID_COLUMN_BITMASK);
217            public static final FinderPath FINDER_PATH_COUNT_BY_G_T = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
218                            JournalTemplateModelImpl.FINDER_CACHE_ENABLED, Long.class,
219                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_T",
220                            new String[] { Long.class.getName(), String.class.getName() });
221            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
222                            JournalTemplateModelImpl.FINDER_CACHE_ENABLED,
223                            JournalTemplateImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
224                            "findByG_S",
225                            new String[] {
226                                    Long.class.getName(), String.class.getName(),
227                                    
228                            "java.lang.Integer", "java.lang.Integer",
229                                    "com.liferay.portal.kernel.util.OrderByComparator"
230                            });
231            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
232                            JournalTemplateModelImpl.FINDER_CACHE_ENABLED,
233                            JournalTemplateImpl.class,
234                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_S",
235                            new String[] { Long.class.getName(), String.class.getName() },
236                            JournalTemplateModelImpl.GROUPID_COLUMN_BITMASK |
237                            JournalTemplateModelImpl.STRUCTUREID_COLUMN_BITMASK);
238            public static final FinderPath FINDER_PATH_COUNT_BY_G_S = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
239                            JournalTemplateModelImpl.FINDER_CACHE_ENABLED, Long.class,
240                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_S",
241                            new String[] { Long.class.getName(), String.class.getName() });
242            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
243                            JournalTemplateModelImpl.FINDER_CACHE_ENABLED,
244                            JournalTemplateImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
245                            "findAll", new String[0]);
246            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
247                            JournalTemplateModelImpl.FINDER_CACHE_ENABLED,
248                            JournalTemplateImpl.class,
249                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
250            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
251                            JournalTemplateModelImpl.FINDER_CACHE_ENABLED, Long.class,
252                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
253    
254            /**
255             * Caches the journal template in the entity cache if it is enabled.
256             *
257             * @param journalTemplate the journal template
258             */
259            public void cacheResult(JournalTemplate journalTemplate) {
260                    EntityCacheUtil.putResult(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
261                            JournalTemplateImpl.class, journalTemplate.getPrimaryKey(),
262                            journalTemplate);
263    
264                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
265                            new Object[] {
266                                    journalTemplate.getUuid(),
267                                    Long.valueOf(journalTemplate.getGroupId())
268                            }, journalTemplate);
269    
270                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
271                            new Object[] { Long.valueOf(journalTemplate.getSmallImageId()) },
272                            journalTemplate);
273    
274                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_T,
275                            new Object[] {
276                                    Long.valueOf(journalTemplate.getGroupId()),
277                                    
278                            journalTemplate.getTemplateId()
279                            }, journalTemplate);
280    
281                    journalTemplate.resetOriginalValues();
282            }
283    
284            /**
285             * Caches the journal templates in the entity cache if it is enabled.
286             *
287             * @param journalTemplates the journal templates
288             */
289            public void cacheResult(List<JournalTemplate> journalTemplates) {
290                    for (JournalTemplate journalTemplate : journalTemplates) {
291                            if (EntityCacheUtil.getResult(
292                                                    JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
293                                                    JournalTemplateImpl.class,
294                                                    journalTemplate.getPrimaryKey()) == null) {
295                                    cacheResult(journalTemplate);
296                            }
297                            else {
298                                    journalTemplate.resetOriginalValues();
299                            }
300                    }
301            }
302    
303            /**
304             * Clears the cache for all journal templates.
305             *
306             * <p>
307             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
308             * </p>
309             */
310            @Override
311            public void clearCache() {
312                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
313                            CacheRegistryUtil.clear(JournalTemplateImpl.class.getName());
314                    }
315    
316                    EntityCacheUtil.clearCache(JournalTemplateImpl.class.getName());
317    
318                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
319                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
320                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
321            }
322    
323            /**
324             * Clears the cache for the journal template.
325             *
326             * <p>
327             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
328             * </p>
329             */
330            @Override
331            public void clearCache(JournalTemplate journalTemplate) {
332                    EntityCacheUtil.removeResult(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
333                            JournalTemplateImpl.class, journalTemplate.getPrimaryKey());
334    
335                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
336                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
337    
338                    clearUniqueFindersCache(journalTemplate);
339            }
340    
341            @Override
342            public void clearCache(List<JournalTemplate> journalTemplates) {
343                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
344                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
345    
346                    for (JournalTemplate journalTemplate : journalTemplates) {
347                            EntityCacheUtil.removeResult(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
348                                    JournalTemplateImpl.class, journalTemplate.getPrimaryKey());
349    
350                            clearUniqueFindersCache(journalTemplate);
351                    }
352            }
353    
354            protected void clearUniqueFindersCache(JournalTemplate journalTemplate) {
355                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
356                            new Object[] {
357                                    journalTemplate.getUuid(),
358                                    Long.valueOf(journalTemplate.getGroupId())
359                            });
360    
361                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
362                            new Object[] { Long.valueOf(journalTemplate.getSmallImageId()) });
363    
364                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_T,
365                            new Object[] {
366                                    Long.valueOf(journalTemplate.getGroupId()),
367                                    
368                            journalTemplate.getTemplateId()
369                            });
370            }
371    
372            /**
373             * Creates a new journal template with the primary key. Does not add the journal template to the database.
374             *
375             * @param id the primary key for the new journal template
376             * @return the new journal template
377             */
378            public JournalTemplate create(long id) {
379                    JournalTemplate journalTemplate = new JournalTemplateImpl();
380    
381                    journalTemplate.setNew(true);
382                    journalTemplate.setPrimaryKey(id);
383    
384                    String uuid = PortalUUIDUtil.generate();
385    
386                    journalTemplate.setUuid(uuid);
387    
388                    return journalTemplate;
389            }
390    
391            /**
392             * Removes the journal template with the primary key from the database. Also notifies the appropriate model listeners.
393             *
394             * @param id the primary key of the journal template
395             * @return the journal template that was removed
396             * @throws com.liferay.portlet.journal.NoSuchTemplateException if a journal template with the primary key could not be found
397             * @throws SystemException if a system exception occurred
398             */
399            public JournalTemplate remove(long id)
400                    throws NoSuchTemplateException, SystemException {
401                    return remove(Long.valueOf(id));
402            }
403    
404            /**
405             * Removes the journal template with the primary key from the database. Also notifies the appropriate model listeners.
406             *
407             * @param primaryKey the primary key of the journal template
408             * @return the journal template that was removed
409             * @throws com.liferay.portlet.journal.NoSuchTemplateException if a journal template with the primary key could not be found
410             * @throws SystemException if a system exception occurred
411             */
412            @Override
413            public JournalTemplate remove(Serializable primaryKey)
414                    throws NoSuchTemplateException, SystemException {
415                    Session session = null;
416    
417                    try {
418                            session = openSession();
419    
420                            JournalTemplate journalTemplate = (JournalTemplate)session.get(JournalTemplateImpl.class,
421                                            primaryKey);
422    
423                            if (journalTemplate == null) {
424                                    if (_log.isWarnEnabled()) {
425                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
426                                    }
427    
428                                    throw new NoSuchTemplateException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
429                                            primaryKey);
430                            }
431    
432                            return remove(journalTemplate);
433                    }
434                    catch (NoSuchTemplateException nsee) {
435                            throw nsee;
436                    }
437                    catch (Exception e) {
438                            throw processException(e);
439                    }
440                    finally {
441                            closeSession(session);
442                    }
443            }
444    
445            @Override
446            protected JournalTemplate removeImpl(JournalTemplate journalTemplate)
447                    throws SystemException {
448                    journalTemplate = toUnwrappedModel(journalTemplate);
449    
450                    Session session = null;
451    
452                    try {
453                            session = openSession();
454    
455                            if (journalTemplate.isCachedModel()) {
456                                    journalTemplate = (JournalTemplate)session.get(JournalTemplateImpl.class,
457                                                    journalTemplate.getPrimaryKeyObj());
458                            }
459    
460                            session.delete(journalTemplate);
461                    }
462                    catch (Exception e) {
463                            throw processException(e);
464                    }
465                    finally {
466                            closeSession(session);
467                    }
468    
469                    clearCache(journalTemplate);
470    
471                    return journalTemplate;
472            }
473    
474            @Override
475            public JournalTemplate updateImpl(
476                    com.liferay.portlet.journal.model.JournalTemplate journalTemplate)
477                    throws SystemException {
478                    journalTemplate = toUnwrappedModel(journalTemplate);
479    
480                    boolean isNew = journalTemplate.isNew();
481    
482                    JournalTemplateModelImpl journalTemplateModelImpl = (JournalTemplateModelImpl)journalTemplate;
483    
484                    if (Validator.isNull(journalTemplate.getUuid())) {
485                            String uuid = PortalUUIDUtil.generate();
486    
487                            journalTemplate.setUuid(uuid);
488                    }
489    
490                    Session session = null;
491    
492                    try {
493                            session = openSession();
494    
495                            if (journalTemplate.isNew()) {
496                                    session.save(journalTemplate);
497    
498                                    journalTemplate.setNew(false);
499                            }
500                            else {
501                                    session.merge(journalTemplate);
502                            }
503                    }
504                    catch (Exception e) {
505                            throw processException(e);
506                    }
507                    finally {
508                            closeSession(session);
509                    }
510    
511                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
512    
513                    if (isNew || !JournalTemplateModelImpl.COLUMN_BITMASK_ENABLED) {
514                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
515                    }
516    
517                    else {
518                            if ((journalTemplateModelImpl.getColumnBitmask() &
519                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
520                                    Object[] args = new Object[] {
521                                                    journalTemplateModelImpl.getOriginalUuid()
522                                            };
523    
524                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
525                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
526                                            args);
527    
528                                    args = new Object[] { journalTemplateModelImpl.getUuid() };
529    
530                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
531                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
532                                            args);
533                            }
534    
535                            if ((journalTemplateModelImpl.getColumnBitmask() &
536                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
537                                    Object[] args = new Object[] {
538                                                    journalTemplateModelImpl.getOriginalUuid(),
539                                                    Long.valueOf(journalTemplateModelImpl.getOriginalCompanyId())
540                                            };
541    
542                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
543                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
544                                            args);
545    
546                                    args = new Object[] {
547                                                    journalTemplateModelImpl.getUuid(),
548                                                    Long.valueOf(journalTemplateModelImpl.getCompanyId())
549                                            };
550    
551                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
552                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
553                                            args);
554                            }
555    
556                            if ((journalTemplateModelImpl.getColumnBitmask() &
557                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
558                                    Object[] args = new Object[] {
559                                                    Long.valueOf(journalTemplateModelImpl.getOriginalGroupId())
560                                            };
561    
562                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
563                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
564                                            args);
565    
566                                    args = new Object[] {
567                                                    Long.valueOf(journalTemplateModelImpl.getGroupId())
568                                            };
569    
570                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
571                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
572                                            args);
573                            }
574    
575                            if ((journalTemplateModelImpl.getColumnBitmask() &
576                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TEMPLATEID.getColumnBitmask()) != 0) {
577                                    Object[] args = new Object[] {
578                                                    journalTemplateModelImpl.getOriginalTemplateId()
579                                            };
580    
581                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TEMPLATEID,
582                                            args);
583                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TEMPLATEID,
584                                            args);
585    
586                                    args = new Object[] { journalTemplateModelImpl.getTemplateId() };
587    
588                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TEMPLATEID,
589                                            args);
590                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TEMPLATEID,
591                                            args);
592                            }
593    
594                            if ((journalTemplateModelImpl.getColumnBitmask() &
595                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_STRUCTUREID.getColumnBitmask()) != 0) {
596                                    Object[] args = new Object[] {
597                                                    journalTemplateModelImpl.getOriginalStructureId()
598                                            };
599    
600                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_STRUCTUREID,
601                                            args);
602                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_STRUCTUREID,
603                                            args);
604    
605                                    args = new Object[] { journalTemplateModelImpl.getStructureId() };
606    
607                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_STRUCTUREID,
608                                            args);
609                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_STRUCTUREID,
610                                            args);
611                            }
612    
613                            if ((journalTemplateModelImpl.getColumnBitmask() &
614                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S.getColumnBitmask()) != 0) {
615                                    Object[] args = new Object[] {
616                                                    Long.valueOf(journalTemplateModelImpl.getOriginalGroupId()),
617                                                    
618                                                    journalTemplateModelImpl.getOriginalStructureId()
619                                            };
620    
621                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
622                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
623                                            args);
624    
625                                    args = new Object[] {
626                                                    Long.valueOf(journalTemplateModelImpl.getGroupId()),
627                                                    
628                                                    journalTemplateModelImpl.getStructureId()
629                                            };
630    
631                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
632                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
633                                            args);
634                            }
635                    }
636    
637                    EntityCacheUtil.putResult(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
638                            JournalTemplateImpl.class, journalTemplate.getPrimaryKey(),
639                            journalTemplate);
640    
641                    if (isNew) {
642                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
643                                    new Object[] {
644                                            journalTemplate.getUuid(),
645                                            Long.valueOf(journalTemplate.getGroupId())
646                                    }, journalTemplate);
647    
648                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
649                                    new Object[] { Long.valueOf(journalTemplate.getSmallImageId()) },
650                                    journalTemplate);
651    
652                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_T,
653                                    new Object[] {
654                                            Long.valueOf(journalTemplate.getGroupId()),
655                                            
656                                    journalTemplate.getTemplateId()
657                                    }, journalTemplate);
658                    }
659                    else {
660                            if ((journalTemplateModelImpl.getColumnBitmask() &
661                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
662                                    Object[] args = new Object[] {
663                                                    journalTemplateModelImpl.getOriginalUuid(),
664                                                    Long.valueOf(journalTemplateModelImpl.getOriginalGroupId())
665                                            };
666    
667                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
668    
669                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
670    
671                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
672                                            new Object[] {
673                                                    journalTemplate.getUuid(),
674                                                    Long.valueOf(journalTemplate.getGroupId())
675                                            }, journalTemplate);
676                            }
677    
678                            if ((journalTemplateModelImpl.getColumnBitmask() &
679                                            FINDER_PATH_FETCH_BY_SMALLIMAGEID.getColumnBitmask()) != 0) {
680                                    Object[] args = new Object[] {
681                                                    Long.valueOf(journalTemplateModelImpl.getOriginalSmallImageId())
682                                            };
683    
684                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_SMALLIMAGEID,
685                                            args);
686    
687                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
688                                            args);
689    
690                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
691                                            new Object[] { Long.valueOf(
692                                                            journalTemplate.getSmallImageId()) },
693                                            journalTemplate);
694                            }
695    
696                            if ((journalTemplateModelImpl.getColumnBitmask() &
697                                            FINDER_PATH_FETCH_BY_G_T.getColumnBitmask()) != 0) {
698                                    Object[] args = new Object[] {
699                                                    Long.valueOf(journalTemplateModelImpl.getOriginalGroupId()),
700                                                    
701                                                    journalTemplateModelImpl.getOriginalTemplateId()
702                                            };
703    
704                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_T, args);
705    
706                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_T, args);
707    
708                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_T,
709                                            new Object[] {
710                                                    Long.valueOf(journalTemplate.getGroupId()),
711                                                    
712                                            journalTemplate.getTemplateId()
713                                            }, journalTemplate);
714                            }
715                    }
716    
717                    return journalTemplate;
718            }
719    
720            protected JournalTemplate toUnwrappedModel(JournalTemplate journalTemplate) {
721                    if (journalTemplate instanceof JournalTemplateImpl) {
722                            return journalTemplate;
723                    }
724    
725                    JournalTemplateImpl journalTemplateImpl = new JournalTemplateImpl();
726    
727                    journalTemplateImpl.setNew(journalTemplate.isNew());
728                    journalTemplateImpl.setPrimaryKey(journalTemplate.getPrimaryKey());
729    
730                    journalTemplateImpl.setUuid(journalTemplate.getUuid());
731                    journalTemplateImpl.setId(journalTemplate.getId());
732                    journalTemplateImpl.setGroupId(journalTemplate.getGroupId());
733                    journalTemplateImpl.setCompanyId(journalTemplate.getCompanyId());
734                    journalTemplateImpl.setUserId(journalTemplate.getUserId());
735                    journalTemplateImpl.setUserName(journalTemplate.getUserName());
736                    journalTemplateImpl.setCreateDate(journalTemplate.getCreateDate());
737                    journalTemplateImpl.setModifiedDate(journalTemplate.getModifiedDate());
738                    journalTemplateImpl.setTemplateId(journalTemplate.getTemplateId());
739                    journalTemplateImpl.setStructureId(journalTemplate.getStructureId());
740                    journalTemplateImpl.setName(journalTemplate.getName());
741                    journalTemplateImpl.setDescription(journalTemplate.getDescription());
742                    journalTemplateImpl.setXsl(journalTemplate.getXsl());
743                    journalTemplateImpl.setLangType(journalTemplate.getLangType());
744                    journalTemplateImpl.setCacheable(journalTemplate.isCacheable());
745                    journalTemplateImpl.setSmallImage(journalTemplate.isSmallImage());
746                    journalTemplateImpl.setSmallImageId(journalTemplate.getSmallImageId());
747                    journalTemplateImpl.setSmallImageURL(journalTemplate.getSmallImageURL());
748    
749                    return journalTemplateImpl;
750            }
751    
752            /**
753             * Returns the journal template with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
754             *
755             * @param primaryKey the primary key of the journal template
756             * @return the journal template
757             * @throws com.liferay.portal.NoSuchModelException if a journal template with the primary key could not be found
758             * @throws SystemException if a system exception occurred
759             */
760            @Override
761            public JournalTemplate findByPrimaryKey(Serializable primaryKey)
762                    throws NoSuchModelException, SystemException {
763                    return findByPrimaryKey(((Long)primaryKey).longValue());
764            }
765    
766            /**
767             * Returns the journal template with the primary key or throws a {@link com.liferay.portlet.journal.NoSuchTemplateException} if it could not be found.
768             *
769             * @param id the primary key of the journal template
770             * @return the journal template
771             * @throws com.liferay.portlet.journal.NoSuchTemplateException if a journal template with the primary key could not be found
772             * @throws SystemException if a system exception occurred
773             */
774            public JournalTemplate findByPrimaryKey(long id)
775                    throws NoSuchTemplateException, SystemException {
776                    JournalTemplate journalTemplate = fetchByPrimaryKey(id);
777    
778                    if (journalTemplate == null) {
779                            if (_log.isWarnEnabled()) {
780                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + id);
781                            }
782    
783                            throw new NoSuchTemplateException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
784                                    id);
785                    }
786    
787                    return journalTemplate;
788            }
789    
790            /**
791             * Returns the journal template with the primary key or returns <code>null</code> if it could not be found.
792             *
793             * @param primaryKey the primary key of the journal template
794             * @return the journal template, or <code>null</code> if a journal template with the primary key could not be found
795             * @throws SystemException if a system exception occurred
796             */
797            @Override
798            public JournalTemplate fetchByPrimaryKey(Serializable primaryKey)
799                    throws SystemException {
800                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
801            }
802    
803            /**
804             * Returns the journal template with the primary key or returns <code>null</code> if it could not be found.
805             *
806             * @param id the primary key of the journal template
807             * @return the journal template, or <code>null</code> if a journal template with the primary key could not be found
808             * @throws SystemException if a system exception occurred
809             */
810            public JournalTemplate fetchByPrimaryKey(long id) throws SystemException {
811                    JournalTemplate journalTemplate = (JournalTemplate)EntityCacheUtil.getResult(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
812                                    JournalTemplateImpl.class, id);
813    
814                    if (journalTemplate == _nullJournalTemplate) {
815                            return null;
816                    }
817    
818                    if (journalTemplate == null) {
819                            Session session = null;
820    
821                            boolean hasException = false;
822    
823                            try {
824                                    session = openSession();
825    
826                                    journalTemplate = (JournalTemplate)session.get(JournalTemplateImpl.class,
827                                                    Long.valueOf(id));
828                            }
829                            catch (Exception e) {
830                                    hasException = true;
831    
832                                    throw processException(e);
833                            }
834                            finally {
835                                    if (journalTemplate != null) {
836                                            cacheResult(journalTemplate);
837                                    }
838                                    else if (!hasException) {
839                                            EntityCacheUtil.putResult(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
840                                                    JournalTemplateImpl.class, id, _nullJournalTemplate);
841                                    }
842    
843                                    closeSession(session);
844                            }
845                    }
846    
847                    return journalTemplate;
848            }
849    
850            /**
851             * Returns all the journal templates where uuid = &#63;.
852             *
853             * @param uuid the uuid
854             * @return the matching journal templates
855             * @throws SystemException if a system exception occurred
856             */
857            public List<JournalTemplate> findByUuid(String uuid)
858                    throws SystemException {
859                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
860            }
861    
862            /**
863             * Returns a range of all the journal templates where uuid = &#63;.
864             *
865             * <p>
866             * 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.
867             * </p>
868             *
869             * @param uuid the uuid
870             * @param start the lower bound of the range of journal templates
871             * @param end the upper bound of the range of journal templates (not inclusive)
872             * @return the range of matching journal templates
873             * @throws SystemException if a system exception occurred
874             */
875            public List<JournalTemplate> findByUuid(String uuid, int start, int end)
876                    throws SystemException {
877                    return findByUuid(uuid, start, end, null);
878            }
879    
880            /**
881             * Returns an ordered range of all the journal templates where uuid = &#63;.
882             *
883             * <p>
884             * 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.
885             * </p>
886             *
887             * @param uuid the uuid
888             * @param start the lower bound of the range of journal templates
889             * @param end the upper bound of the range of journal templates (not inclusive)
890             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
891             * @return the ordered range of matching journal templates
892             * @throws SystemException if a system exception occurred
893             */
894            public List<JournalTemplate> findByUuid(String uuid, int start, int end,
895                    OrderByComparator orderByComparator) throws SystemException {
896                    FinderPath finderPath = null;
897                    Object[] finderArgs = null;
898    
899                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
900                                    (orderByComparator == null)) {
901                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
902                            finderArgs = new Object[] { uuid };
903                    }
904                    else {
905                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
906                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
907                    }
908    
909                    List<JournalTemplate> list = (List<JournalTemplate>)FinderCacheUtil.getResult(finderPath,
910                                    finderArgs, this);
911    
912                    if ((list != null) && !list.isEmpty()) {
913                            for (JournalTemplate journalTemplate : list) {
914                                    if (!Validator.equals(uuid, journalTemplate.getUuid())) {
915                                            list = null;
916    
917                                            break;
918                                    }
919                            }
920                    }
921    
922                    if (list == null) {
923                            StringBundler query = null;
924    
925                            if (orderByComparator != null) {
926                                    query = new StringBundler(3 +
927                                                    (orderByComparator.getOrderByFields().length * 3));
928                            }
929                            else {
930                                    query = new StringBundler(3);
931                            }
932    
933                            query.append(_SQL_SELECT_JOURNALTEMPLATE_WHERE);
934    
935                            if (uuid == null) {
936                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
937                            }
938                            else {
939                                    if (uuid.equals(StringPool.BLANK)) {
940                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
941                                    }
942                                    else {
943                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
944                                    }
945                            }
946    
947                            if (orderByComparator != null) {
948                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
949                                            orderByComparator);
950                            }
951    
952                            else {
953                                    query.append(JournalTemplateModelImpl.ORDER_BY_JPQL);
954                            }
955    
956                            String sql = query.toString();
957    
958                            Session session = null;
959    
960                            try {
961                                    session = openSession();
962    
963                                    Query q = session.createQuery(sql);
964    
965                                    QueryPos qPos = QueryPos.getInstance(q);
966    
967                                    if (uuid != null) {
968                                            qPos.add(uuid);
969                                    }
970    
971                                    list = (List<JournalTemplate>)QueryUtil.list(q, getDialect(),
972                                                    start, end);
973                            }
974                            catch (Exception e) {
975                                    throw processException(e);
976                            }
977                            finally {
978                                    if (list == null) {
979                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
980                                    }
981                                    else {
982                                            cacheResult(list);
983    
984                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
985                                    }
986    
987                                    closeSession(session);
988                            }
989                    }
990    
991                    return list;
992            }
993    
994            /**
995             * Returns the first journal template in the ordered set where uuid = &#63;.
996             *
997             * @param uuid the uuid
998             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
999             * @return the first matching journal template
1000             * @throws com.liferay.portlet.journal.NoSuchTemplateException if a matching journal template could not be found
1001             * @throws SystemException if a system exception occurred
1002             */
1003            public JournalTemplate findByUuid_First(String uuid,
1004                    OrderByComparator orderByComparator)
1005                    throws NoSuchTemplateException, SystemException {
1006                    JournalTemplate journalTemplate = fetchByUuid_First(uuid,
1007                                    orderByComparator);
1008    
1009                    if (journalTemplate != null) {
1010                            return journalTemplate;
1011                    }
1012    
1013                    StringBundler msg = new StringBundler(4);
1014    
1015                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1016    
1017                    msg.append("uuid=");
1018                    msg.append(uuid);
1019    
1020                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1021    
1022                    throw new NoSuchTemplateException(msg.toString());
1023            }
1024    
1025            /**
1026             * Returns the first journal template in the ordered set where uuid = &#63;.
1027             *
1028             * @param uuid the uuid
1029             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1030             * @return the first matching journal template, or <code>null</code> if a matching journal template could not be found
1031             * @throws SystemException if a system exception occurred
1032             */
1033            public JournalTemplate fetchByUuid_First(String uuid,
1034                    OrderByComparator orderByComparator) throws SystemException {
1035                    List<JournalTemplate> list = findByUuid(uuid, 0, 1, orderByComparator);
1036    
1037                    if (!list.isEmpty()) {
1038                            return list.get(0);
1039                    }
1040    
1041                    return null;
1042            }
1043    
1044            /**
1045             * Returns the last journal template in the ordered set where uuid = &#63;.
1046             *
1047             * @param uuid the uuid
1048             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1049             * @return the last matching journal template
1050             * @throws com.liferay.portlet.journal.NoSuchTemplateException if a matching journal template could not be found
1051             * @throws SystemException if a system exception occurred
1052             */
1053            public JournalTemplate findByUuid_Last(String uuid,
1054                    OrderByComparator orderByComparator)
1055                    throws NoSuchTemplateException, SystemException {
1056                    JournalTemplate journalTemplate = fetchByUuid_Last(uuid,
1057                                    orderByComparator);
1058    
1059                    if (journalTemplate != null) {
1060                            return journalTemplate;
1061                    }
1062    
1063                    StringBundler msg = new StringBundler(4);
1064    
1065                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1066    
1067                    msg.append("uuid=");
1068                    msg.append(uuid);
1069    
1070                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1071    
1072                    throw new NoSuchTemplateException(msg.toString());
1073            }
1074    
1075            /**
1076             * Returns the last journal template in the ordered set where uuid = &#63;.
1077             *
1078             * @param uuid the uuid
1079             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1080             * @return the last matching journal template, or <code>null</code> if a matching journal template could not be found
1081             * @throws SystemException if a system exception occurred
1082             */
1083            public JournalTemplate fetchByUuid_Last(String uuid,
1084                    OrderByComparator orderByComparator) throws SystemException {
1085                    int count = countByUuid(uuid);
1086    
1087                    List<JournalTemplate> list = findByUuid(uuid, count - 1, count,
1088                                    orderByComparator);
1089    
1090                    if (!list.isEmpty()) {
1091                            return list.get(0);
1092                    }
1093    
1094                    return null;
1095            }
1096    
1097            /**
1098             * Returns the journal templates before and after the current journal template in the ordered set where uuid = &#63;.
1099             *
1100             * @param id the primary key of the current journal template
1101             * @param uuid the uuid
1102             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1103             * @return the previous, current, and next journal template
1104             * @throws com.liferay.portlet.journal.NoSuchTemplateException if a journal template with the primary key could not be found
1105             * @throws SystemException if a system exception occurred
1106             */
1107            public JournalTemplate[] findByUuid_PrevAndNext(long id, String uuid,
1108                    OrderByComparator orderByComparator)
1109                    throws NoSuchTemplateException, SystemException {
1110                    JournalTemplate journalTemplate = findByPrimaryKey(id);
1111    
1112                    Session session = null;
1113    
1114                    try {
1115                            session = openSession();
1116    
1117                            JournalTemplate[] array = new JournalTemplateImpl[3];
1118    
1119                            array[0] = getByUuid_PrevAndNext(session, journalTemplate, uuid,
1120                                            orderByComparator, true);
1121    
1122                            array[1] = journalTemplate;
1123    
1124                            array[2] = getByUuid_PrevAndNext(session, journalTemplate, uuid,
1125                                            orderByComparator, false);
1126    
1127                            return array;
1128                    }
1129                    catch (Exception e) {
1130                            throw processException(e);
1131                    }
1132                    finally {
1133                            closeSession(session);
1134                    }
1135            }
1136    
1137            protected JournalTemplate getByUuid_PrevAndNext(Session session,
1138                    JournalTemplate journalTemplate, String uuid,
1139                    OrderByComparator orderByComparator, boolean previous) {
1140                    StringBundler query = null;
1141    
1142                    if (orderByComparator != null) {
1143                            query = new StringBundler(6 +
1144                                            (orderByComparator.getOrderByFields().length * 6));
1145                    }
1146                    else {
1147                            query = new StringBundler(3);
1148                    }
1149    
1150                    query.append(_SQL_SELECT_JOURNALTEMPLATE_WHERE);
1151    
1152                    if (uuid == null) {
1153                            query.append(_FINDER_COLUMN_UUID_UUID_1);
1154                    }
1155                    else {
1156                            if (uuid.equals(StringPool.BLANK)) {
1157                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
1158                            }
1159                            else {
1160                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
1161                            }
1162                    }
1163    
1164                    if (orderByComparator != null) {
1165                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1166    
1167                            if (orderByConditionFields.length > 0) {
1168                                    query.append(WHERE_AND);
1169                            }
1170    
1171                            for (int i = 0; i < orderByConditionFields.length; i++) {
1172                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1173                                    query.append(orderByConditionFields[i]);
1174    
1175                                    if ((i + 1) < orderByConditionFields.length) {
1176                                            if (orderByComparator.isAscending() ^ previous) {
1177                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1178                                            }
1179                                            else {
1180                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1181                                            }
1182                                    }
1183                                    else {
1184                                            if (orderByComparator.isAscending() ^ previous) {
1185                                                    query.append(WHERE_GREATER_THAN);
1186                                            }
1187                                            else {
1188                                                    query.append(WHERE_LESSER_THAN);
1189                                            }
1190                                    }
1191                            }
1192    
1193                            query.append(ORDER_BY_CLAUSE);
1194    
1195                            String[] orderByFields = orderByComparator.getOrderByFields();
1196    
1197                            for (int i = 0; i < orderByFields.length; i++) {
1198                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1199                                    query.append(orderByFields[i]);
1200    
1201                                    if ((i + 1) < orderByFields.length) {
1202                                            if (orderByComparator.isAscending() ^ previous) {
1203                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1204                                            }
1205                                            else {
1206                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1207                                            }
1208                                    }
1209                                    else {
1210                                            if (orderByComparator.isAscending() ^ previous) {
1211                                                    query.append(ORDER_BY_ASC);
1212                                            }
1213                                            else {
1214                                                    query.append(ORDER_BY_DESC);
1215                                            }
1216                                    }
1217                            }
1218                    }
1219    
1220                    else {
1221                            query.append(JournalTemplateModelImpl.ORDER_BY_JPQL);
1222                    }
1223    
1224                    String sql = query.toString();
1225    
1226                    Query q = session.createQuery(sql);
1227    
1228                    q.setFirstResult(0);
1229                    q.setMaxResults(2);
1230    
1231                    QueryPos qPos = QueryPos.getInstance(q);
1232    
1233                    if (uuid != null) {
1234                            qPos.add(uuid);
1235                    }
1236    
1237                    if (orderByComparator != null) {
1238                            Object[] values = orderByComparator.getOrderByConditionValues(journalTemplate);
1239    
1240                            for (Object value : values) {
1241                                    qPos.add(value);
1242                            }
1243                    }
1244    
1245                    List<JournalTemplate> list = q.list();
1246    
1247                    if (list.size() == 2) {
1248                            return list.get(1);
1249                    }
1250                    else {
1251                            return null;
1252                    }
1253            }
1254    
1255            /**
1256             * 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.
1257             *
1258             * @param uuid the uuid
1259             * @param groupId the group ID
1260             * @return the matching journal template
1261             * @throws com.liferay.portlet.journal.NoSuchTemplateException if a matching journal template could not be found
1262             * @throws SystemException if a system exception occurred
1263             */
1264            public JournalTemplate findByUUID_G(String uuid, long groupId)
1265                    throws NoSuchTemplateException, SystemException {
1266                    JournalTemplate journalTemplate = fetchByUUID_G(uuid, groupId);
1267    
1268                    if (journalTemplate == null) {
1269                            StringBundler msg = new StringBundler(6);
1270    
1271                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1272    
1273                            msg.append("uuid=");
1274                            msg.append(uuid);
1275    
1276                            msg.append(", groupId=");
1277                            msg.append(groupId);
1278    
1279                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1280    
1281                            if (_log.isWarnEnabled()) {
1282                                    _log.warn(msg.toString());
1283                            }
1284    
1285                            throw new NoSuchTemplateException(msg.toString());
1286                    }
1287    
1288                    return journalTemplate;
1289            }
1290    
1291            /**
1292             * 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.
1293             *
1294             * @param uuid the uuid
1295             * @param groupId the group ID
1296             * @return the matching journal template, or <code>null</code> if a matching journal template could not be found
1297             * @throws SystemException if a system exception occurred
1298             */
1299            public JournalTemplate fetchByUUID_G(String uuid, long groupId)
1300                    throws SystemException {
1301                    return fetchByUUID_G(uuid, groupId, true);
1302            }
1303    
1304            /**
1305             * 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.
1306             *
1307             * @param uuid the uuid
1308             * @param groupId the group ID
1309             * @param retrieveFromCache whether to use the finder cache
1310             * @return the matching journal template, or <code>null</code> if a matching journal template could not be found
1311             * @throws SystemException if a system exception occurred
1312             */
1313            public JournalTemplate fetchByUUID_G(String uuid, long groupId,
1314                    boolean retrieveFromCache) throws SystemException {
1315                    Object[] finderArgs = new Object[] { uuid, groupId };
1316    
1317                    Object result = null;
1318    
1319                    if (retrieveFromCache) {
1320                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
1321                                            finderArgs, this);
1322                    }
1323    
1324                    if (result instanceof JournalTemplate) {
1325                            JournalTemplate journalTemplate = (JournalTemplate)result;
1326    
1327                            if (!Validator.equals(uuid, journalTemplate.getUuid()) ||
1328                                            (groupId != journalTemplate.getGroupId())) {
1329                                    result = null;
1330                            }
1331                    }
1332    
1333                    if (result == null) {
1334                            StringBundler query = new StringBundler(4);
1335    
1336                            query.append(_SQL_SELECT_JOURNALTEMPLATE_WHERE);
1337    
1338                            if (uuid == null) {
1339                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
1340                            }
1341                            else {
1342                                    if (uuid.equals(StringPool.BLANK)) {
1343                                            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
1344                                    }
1345                                    else {
1346                                            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
1347                                    }
1348                            }
1349    
1350                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
1351    
1352                            query.append(JournalTemplateModelImpl.ORDER_BY_JPQL);
1353    
1354                            String sql = query.toString();
1355    
1356                            Session session = null;
1357    
1358                            try {
1359                                    session = openSession();
1360    
1361                                    Query q = session.createQuery(sql);
1362    
1363                                    QueryPos qPos = QueryPos.getInstance(q);
1364    
1365                                    if (uuid != null) {
1366                                            qPos.add(uuid);
1367                                    }
1368    
1369                                    qPos.add(groupId);
1370    
1371                                    List<JournalTemplate> list = q.list();
1372    
1373                                    result = list;
1374    
1375                                    JournalTemplate journalTemplate = null;
1376    
1377                                    if (list.isEmpty()) {
1378                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1379                                                    finderArgs, list);
1380                                    }
1381                                    else {
1382                                            journalTemplate = list.get(0);
1383    
1384                                            cacheResult(journalTemplate);
1385    
1386                                            if ((journalTemplate.getUuid() == null) ||
1387                                                            !journalTemplate.getUuid().equals(uuid) ||
1388                                                            (journalTemplate.getGroupId() != groupId)) {
1389                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1390                                                            finderArgs, journalTemplate);
1391                                            }
1392                                    }
1393    
1394                                    return journalTemplate;
1395                            }
1396                            catch (Exception e) {
1397                                    throw processException(e);
1398                            }
1399                            finally {
1400                                    if (result == null) {
1401                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
1402                                                    finderArgs);
1403                                    }
1404    
1405                                    closeSession(session);
1406                            }
1407                    }
1408                    else {
1409                            if (result instanceof List<?>) {
1410                                    return null;
1411                            }
1412                            else {
1413                                    return (JournalTemplate)result;
1414                            }
1415                    }
1416            }
1417    
1418            /**
1419             * Returns all the journal templates where uuid = &#63; and companyId = &#63;.
1420             *
1421             * @param uuid the uuid
1422             * @param companyId the company ID
1423             * @return the matching journal templates
1424             * @throws SystemException if a system exception occurred
1425             */
1426            public List<JournalTemplate> findByUuid_C(String uuid, long companyId)
1427                    throws SystemException {
1428                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
1429                            QueryUtil.ALL_POS, null);
1430            }
1431    
1432            /**
1433             * Returns a range of all the journal templates where uuid = &#63; and companyId = &#63;.
1434             *
1435             * <p>
1436             * 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.
1437             * </p>
1438             *
1439             * @param uuid the uuid
1440             * @param companyId the company ID
1441             * @param start the lower bound of the range of journal templates
1442             * @param end the upper bound of the range of journal templates (not inclusive)
1443             * @return the range of matching journal templates
1444             * @throws SystemException if a system exception occurred
1445             */
1446            public List<JournalTemplate> findByUuid_C(String uuid, long companyId,
1447                    int start, int end) throws SystemException {
1448                    return findByUuid_C(uuid, companyId, start, end, null);
1449            }
1450    
1451            /**
1452             * Returns an ordered range of all the journal templates where uuid = &#63; and companyId = &#63;.
1453             *
1454             * <p>
1455             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1456             * </p>
1457             *
1458             * @param uuid the uuid
1459             * @param companyId the company ID
1460             * @param start the lower bound of the range of journal templates
1461             * @param end the upper bound of the range of journal templates (not inclusive)
1462             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1463             * @return the ordered range of matching journal templates
1464             * @throws SystemException if a system exception occurred
1465             */
1466            public List<JournalTemplate> findByUuid_C(String uuid, long companyId,
1467                    int start, int end, OrderByComparator orderByComparator)
1468                    throws SystemException {
1469                    FinderPath finderPath = null;
1470                    Object[] finderArgs = null;
1471    
1472                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1473                                    (orderByComparator == null)) {
1474                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
1475                            finderArgs = new Object[] { uuid, companyId };
1476                    }
1477                    else {
1478                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
1479                            finderArgs = new Object[] {
1480                                            uuid, companyId,
1481                                            
1482                                            start, end, orderByComparator
1483                                    };
1484                    }
1485    
1486                    List<JournalTemplate> list = (List<JournalTemplate>)FinderCacheUtil.getResult(finderPath,
1487                                    finderArgs, this);
1488    
1489                    if ((list != null) && !list.isEmpty()) {
1490                            for (JournalTemplate journalTemplate : list) {
1491                                    if (!Validator.equals(uuid, journalTemplate.getUuid()) ||
1492                                                    (companyId != journalTemplate.getCompanyId())) {
1493                                            list = null;
1494    
1495                                            break;
1496                                    }
1497                            }
1498                    }
1499    
1500                    if (list == null) {
1501                            StringBundler query = null;
1502    
1503                            if (orderByComparator != null) {
1504                                    query = new StringBundler(4 +
1505                                                    (orderByComparator.getOrderByFields().length * 3));
1506                            }
1507                            else {
1508                                    query = new StringBundler(4);
1509                            }
1510    
1511                            query.append(_SQL_SELECT_JOURNALTEMPLATE_WHERE);
1512    
1513                            if (uuid == null) {
1514                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1515                            }
1516                            else {
1517                                    if (uuid.equals(StringPool.BLANK)) {
1518                                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1519                                    }
1520                                    else {
1521                                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1522                                    }
1523                            }
1524    
1525                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1526    
1527                            if (orderByComparator != null) {
1528                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1529                                            orderByComparator);
1530                            }
1531    
1532                            else {
1533                                    query.append(JournalTemplateModelImpl.ORDER_BY_JPQL);
1534                            }
1535    
1536                            String sql = query.toString();
1537    
1538                            Session session = null;
1539    
1540                            try {
1541                                    session = openSession();
1542    
1543                                    Query q = session.createQuery(sql);
1544    
1545                                    QueryPos qPos = QueryPos.getInstance(q);
1546    
1547                                    if (uuid != null) {
1548                                            qPos.add(uuid);
1549                                    }
1550    
1551                                    qPos.add(companyId);
1552    
1553                                    list = (List<JournalTemplate>)QueryUtil.list(q, getDialect(),
1554                                                    start, end);
1555                            }
1556                            catch (Exception e) {
1557                                    throw processException(e);
1558                            }
1559                            finally {
1560                                    if (list == null) {
1561                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1562                                    }
1563                                    else {
1564                                            cacheResult(list);
1565    
1566                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1567                                    }
1568    
1569                                    closeSession(session);
1570                            }
1571                    }
1572    
1573                    return list;
1574            }
1575    
1576            /**
1577             * Returns the first journal template in the ordered set where uuid = &#63; and companyId = &#63;.
1578             *
1579             * @param uuid the uuid
1580             * @param companyId the company ID
1581             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1582             * @return the first matching journal template
1583             * @throws com.liferay.portlet.journal.NoSuchTemplateException if a matching journal template could not be found
1584             * @throws SystemException if a system exception occurred
1585             */
1586            public JournalTemplate findByUuid_C_First(String uuid, long companyId,
1587                    OrderByComparator orderByComparator)
1588                    throws NoSuchTemplateException, SystemException {
1589                    JournalTemplate journalTemplate = fetchByUuid_C_First(uuid, companyId,
1590                                    orderByComparator);
1591    
1592                    if (journalTemplate != null) {
1593                            return journalTemplate;
1594                    }
1595    
1596                    StringBundler msg = new StringBundler(6);
1597    
1598                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1599    
1600                    msg.append("uuid=");
1601                    msg.append(uuid);
1602    
1603                    msg.append(", companyId=");
1604                    msg.append(companyId);
1605    
1606                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1607    
1608                    throw new NoSuchTemplateException(msg.toString());
1609            }
1610    
1611            /**
1612             * Returns the first journal template in the ordered set where uuid = &#63; and companyId = &#63;.
1613             *
1614             * @param uuid the uuid
1615             * @param companyId the company ID
1616             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1617             * @return the first matching journal template, or <code>null</code> if a matching journal template could not be found
1618             * @throws SystemException if a system exception occurred
1619             */
1620            public JournalTemplate fetchByUuid_C_First(String uuid, long companyId,
1621                    OrderByComparator orderByComparator) throws SystemException {
1622                    List<JournalTemplate> list = findByUuid_C(uuid, companyId, 0, 1,
1623                                    orderByComparator);
1624    
1625                    if (!list.isEmpty()) {
1626                            return list.get(0);
1627                    }
1628    
1629                    return null;
1630            }
1631    
1632            /**
1633             * Returns the last journal template in the ordered set where uuid = &#63; and companyId = &#63;.
1634             *
1635             * @param uuid the uuid
1636             * @param companyId the company ID
1637             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1638             * @return the last matching journal template
1639             * @throws com.liferay.portlet.journal.NoSuchTemplateException if a matching journal template could not be found
1640             * @throws SystemException if a system exception occurred
1641             */
1642            public JournalTemplate findByUuid_C_Last(String uuid, long companyId,
1643                    OrderByComparator orderByComparator)
1644                    throws NoSuchTemplateException, SystemException {
1645                    JournalTemplate journalTemplate = fetchByUuid_C_Last(uuid, companyId,
1646                                    orderByComparator);
1647    
1648                    if (journalTemplate != null) {
1649                            return journalTemplate;
1650                    }
1651    
1652                    StringBundler msg = new StringBundler(6);
1653    
1654                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1655    
1656                    msg.append("uuid=");
1657                    msg.append(uuid);
1658    
1659                    msg.append(", companyId=");
1660                    msg.append(companyId);
1661    
1662                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1663    
1664                    throw new NoSuchTemplateException(msg.toString());
1665            }
1666    
1667            /**
1668             * Returns the last journal template in the ordered set where uuid = &#63; and companyId = &#63;.
1669             *
1670             * @param uuid the uuid
1671             * @param companyId the company ID
1672             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1673             * @return the last matching journal template, or <code>null</code> if a matching journal template could not be found
1674             * @throws SystemException if a system exception occurred
1675             */
1676            public JournalTemplate fetchByUuid_C_Last(String uuid, long companyId,
1677                    OrderByComparator orderByComparator) throws SystemException {
1678                    int count = countByUuid_C(uuid, companyId);
1679    
1680                    List<JournalTemplate> list = findByUuid_C(uuid, companyId, count - 1,
1681                                    count, orderByComparator);
1682    
1683                    if (!list.isEmpty()) {
1684                            return list.get(0);
1685                    }
1686    
1687                    return null;
1688            }
1689    
1690            /**
1691             * Returns the journal templates before and after the current journal template in the ordered set where uuid = &#63; and companyId = &#63;.
1692             *
1693             * @param id the primary key of the current journal template
1694             * @param uuid the uuid
1695             * @param companyId the company ID
1696             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1697             * @return the previous, current, and next journal template
1698             * @throws com.liferay.portlet.journal.NoSuchTemplateException if a journal template with the primary key could not be found
1699             * @throws SystemException if a system exception occurred
1700             */
1701            public JournalTemplate[] findByUuid_C_PrevAndNext(long id, String uuid,
1702                    long companyId, OrderByComparator orderByComparator)
1703                    throws NoSuchTemplateException, SystemException {
1704                    JournalTemplate journalTemplate = findByPrimaryKey(id);
1705    
1706                    Session session = null;
1707    
1708                    try {
1709                            session = openSession();
1710    
1711                            JournalTemplate[] array = new JournalTemplateImpl[3];
1712    
1713                            array[0] = getByUuid_C_PrevAndNext(session, journalTemplate, uuid,
1714                                            companyId, orderByComparator, true);
1715    
1716                            array[1] = journalTemplate;
1717    
1718                            array[2] = getByUuid_C_PrevAndNext(session, journalTemplate, uuid,
1719                                            companyId, orderByComparator, false);
1720    
1721                            return array;
1722                    }
1723                    catch (Exception e) {
1724                            throw processException(e);
1725                    }
1726                    finally {
1727                            closeSession(session);
1728                    }
1729            }
1730    
1731            protected JournalTemplate getByUuid_C_PrevAndNext(Session session,
1732                    JournalTemplate journalTemplate, String uuid, long companyId,
1733                    OrderByComparator orderByComparator, boolean previous) {
1734                    StringBundler query = null;
1735    
1736                    if (orderByComparator != null) {
1737                            query = new StringBundler(6 +
1738                                            (orderByComparator.getOrderByFields().length * 6));
1739                    }
1740                    else {
1741                            query = new StringBundler(3);
1742                    }
1743    
1744                    query.append(_SQL_SELECT_JOURNALTEMPLATE_WHERE);
1745    
1746                    if (uuid == null) {
1747                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1748                    }
1749                    else {
1750                            if (uuid.equals(StringPool.BLANK)) {
1751                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1752                            }
1753                            else {
1754                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1755                            }
1756                    }
1757    
1758                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1759    
1760                    if (orderByComparator != null) {
1761                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1762    
1763                            if (orderByConditionFields.length > 0) {
1764                                    query.append(WHERE_AND);
1765                            }
1766    
1767                            for (int i = 0; i < orderByConditionFields.length; i++) {
1768                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1769                                    query.append(orderByConditionFields[i]);
1770    
1771                                    if ((i + 1) < orderByConditionFields.length) {
1772                                            if (orderByComparator.isAscending() ^ previous) {
1773                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1774                                            }
1775                                            else {
1776                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1777                                            }
1778                                    }
1779                                    else {
1780                                            if (orderByComparator.isAscending() ^ previous) {
1781                                                    query.append(WHERE_GREATER_THAN);
1782                                            }
1783                                            else {
1784                                                    query.append(WHERE_LESSER_THAN);
1785                                            }
1786                                    }
1787                            }
1788    
1789                            query.append(ORDER_BY_CLAUSE);
1790    
1791                            String[] orderByFields = orderByComparator.getOrderByFields();
1792    
1793                            for (int i = 0; i < orderByFields.length; i++) {
1794                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1795                                    query.append(orderByFields[i]);
1796    
1797                                    if ((i + 1) < orderByFields.length) {
1798                                            if (orderByComparator.isAscending() ^ previous) {
1799                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1800                                            }
1801                                            else {
1802                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1803                                            }
1804                                    }
1805                                    else {
1806                                            if (orderByComparator.isAscending() ^ previous) {
1807                                                    query.append(ORDER_BY_ASC);
1808                                            }
1809                                            else {
1810                                                    query.append(ORDER_BY_DESC);
1811                                            }
1812                                    }
1813                            }
1814                    }
1815    
1816                    else {
1817                            query.append(JournalTemplateModelImpl.ORDER_BY_JPQL);
1818                    }
1819    
1820                    String sql = query.toString();
1821    
1822                    Query q = session.createQuery(sql);
1823    
1824                    q.setFirstResult(0);
1825                    q.setMaxResults(2);
1826    
1827                    QueryPos qPos = QueryPos.getInstance(q);
1828    
1829                    if (uuid != null) {
1830                            qPos.add(uuid);
1831                    }
1832    
1833                    qPos.add(companyId);
1834    
1835                    if (orderByComparator != null) {
1836                            Object[] values = orderByComparator.getOrderByConditionValues(journalTemplate);
1837    
1838                            for (Object value : values) {
1839                                    qPos.add(value);
1840                            }
1841                    }
1842    
1843                    List<JournalTemplate> list = q.list();
1844    
1845                    if (list.size() == 2) {
1846                            return list.get(1);
1847                    }
1848                    else {
1849                            return null;
1850                    }
1851            }
1852    
1853            /**
1854             * Returns all the journal templates where groupId = &#63;.
1855             *
1856             * @param groupId the group ID
1857             * @return the matching journal templates
1858             * @throws SystemException if a system exception occurred
1859             */
1860            public List<JournalTemplate> findByGroupId(long groupId)
1861                    throws SystemException {
1862                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1863            }
1864    
1865            /**
1866             * Returns a range of all the journal templates where groupId = &#63;.
1867             *
1868             * <p>
1869             * 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.
1870             * </p>
1871             *
1872             * @param groupId the group ID
1873             * @param start the lower bound of the range of journal templates
1874             * @param end the upper bound of the range of journal templates (not inclusive)
1875             * @return the range of matching journal templates
1876             * @throws SystemException if a system exception occurred
1877             */
1878            public List<JournalTemplate> findByGroupId(long groupId, int start, int end)
1879                    throws SystemException {
1880                    return findByGroupId(groupId, start, end, null);
1881            }
1882    
1883            /**
1884             * Returns an ordered range of all the journal templates where groupId = &#63;.
1885             *
1886             * <p>
1887             * 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.
1888             * </p>
1889             *
1890             * @param groupId the group ID
1891             * @param start the lower bound of the range of journal templates
1892             * @param end the upper bound of the range of journal templates (not inclusive)
1893             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1894             * @return the ordered range of matching journal templates
1895             * @throws SystemException if a system exception occurred
1896             */
1897            public List<JournalTemplate> findByGroupId(long groupId, int start,
1898                    int end, OrderByComparator orderByComparator) throws SystemException {
1899                    FinderPath finderPath = null;
1900                    Object[] finderArgs = null;
1901    
1902                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1903                                    (orderByComparator == null)) {
1904                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1905                            finderArgs = new Object[] { groupId };
1906                    }
1907                    else {
1908                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1909                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
1910                    }
1911    
1912                    List<JournalTemplate> list = (List<JournalTemplate>)FinderCacheUtil.getResult(finderPath,
1913                                    finderArgs, this);
1914    
1915                    if ((list != null) && !list.isEmpty()) {
1916                            for (JournalTemplate journalTemplate : list) {
1917                                    if ((groupId != journalTemplate.getGroupId())) {
1918                                            list = null;
1919    
1920                                            break;
1921                                    }
1922                            }
1923                    }
1924    
1925                    if (list == null) {
1926                            StringBundler query = null;
1927    
1928                            if (orderByComparator != null) {
1929                                    query = new StringBundler(3 +
1930                                                    (orderByComparator.getOrderByFields().length * 3));
1931                            }
1932                            else {
1933                                    query = new StringBundler(3);
1934                            }
1935    
1936                            query.append(_SQL_SELECT_JOURNALTEMPLATE_WHERE);
1937    
1938                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1939    
1940                            if (orderByComparator != null) {
1941                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1942                                            orderByComparator);
1943                            }
1944    
1945                            else {
1946                                    query.append(JournalTemplateModelImpl.ORDER_BY_JPQL);
1947                            }
1948    
1949                            String sql = query.toString();
1950    
1951                            Session session = null;
1952    
1953                            try {
1954                                    session = openSession();
1955    
1956                                    Query q = session.createQuery(sql);
1957    
1958                                    QueryPos qPos = QueryPos.getInstance(q);
1959    
1960                                    qPos.add(groupId);
1961    
1962                                    list = (List<JournalTemplate>)QueryUtil.list(q, getDialect(),
1963                                                    start, end);
1964                            }
1965                            catch (Exception e) {
1966                                    throw processException(e);
1967                            }
1968                            finally {
1969                                    if (list == null) {
1970                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1971                                    }
1972                                    else {
1973                                            cacheResult(list);
1974    
1975                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1976                                    }
1977    
1978                                    closeSession(session);
1979                            }
1980                    }
1981    
1982                    return list;
1983            }
1984    
1985            /**
1986             * Returns the first journal template in the ordered set where groupId = &#63;.
1987             *
1988             * @param groupId the group ID
1989             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1990             * @return the first matching journal template
1991             * @throws com.liferay.portlet.journal.NoSuchTemplateException if a matching journal template could not be found
1992             * @throws SystemException if a system exception occurred
1993             */
1994            public JournalTemplate findByGroupId_First(long groupId,
1995                    OrderByComparator orderByComparator)
1996                    throws NoSuchTemplateException, SystemException {
1997                    JournalTemplate journalTemplate = fetchByGroupId_First(groupId,
1998                                    orderByComparator);
1999    
2000                    if (journalTemplate != null) {
2001                            return journalTemplate;
2002                    }
2003    
2004                    StringBundler msg = new StringBundler(4);
2005    
2006                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2007    
2008                    msg.append("groupId=");
2009                    msg.append(groupId);
2010    
2011                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2012    
2013                    throw new NoSuchTemplateException(msg.toString());
2014            }
2015    
2016            /**
2017             * Returns the first journal template in the ordered set where groupId = &#63;.
2018             *
2019             * @param groupId the group ID
2020             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2021             * @return the first matching journal template, or <code>null</code> if a matching journal template could not be found
2022             * @throws SystemException if a system exception occurred
2023             */
2024            public JournalTemplate fetchByGroupId_First(long groupId,
2025                    OrderByComparator orderByComparator) throws SystemException {
2026                    List<JournalTemplate> list = findByGroupId(groupId, 0, 1,
2027                                    orderByComparator);
2028    
2029                    if (!list.isEmpty()) {
2030                            return list.get(0);
2031                    }
2032    
2033                    return null;
2034            }
2035    
2036            /**
2037             * Returns the last journal template in the ordered set where groupId = &#63;.
2038             *
2039             * @param groupId the group ID
2040             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2041             * @return the last matching journal template
2042             * @throws com.liferay.portlet.journal.NoSuchTemplateException if a matching journal template could not be found
2043             * @throws SystemException if a system exception occurred
2044             */
2045            public JournalTemplate findByGroupId_Last(long groupId,
2046                    OrderByComparator orderByComparator)
2047                    throws NoSuchTemplateException, SystemException {
2048                    JournalTemplate journalTemplate = fetchByGroupId_Last(groupId,
2049                                    orderByComparator);
2050    
2051                    if (journalTemplate != null) {
2052                            return journalTemplate;
2053                    }
2054    
2055                    StringBundler msg = new StringBundler(4);
2056    
2057                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2058    
2059                    msg.append("groupId=");
2060                    msg.append(groupId);
2061    
2062                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2063    
2064                    throw new NoSuchTemplateException(msg.toString());
2065            }
2066    
2067            /**
2068             * Returns the last journal template in the ordered set where groupId = &#63;.
2069             *
2070             * @param groupId the group ID
2071             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2072             * @return the last matching journal template, or <code>null</code> if a matching journal template could not be found
2073             * @throws SystemException if a system exception occurred
2074             */
2075            public JournalTemplate fetchByGroupId_Last(long groupId,
2076                    OrderByComparator orderByComparator) throws SystemException {
2077                    int count = countByGroupId(groupId);
2078    
2079                    List<JournalTemplate> list = findByGroupId(groupId, count - 1, count,
2080                                    orderByComparator);
2081    
2082                    if (!list.isEmpty()) {
2083                            return list.get(0);
2084                    }
2085    
2086                    return null;
2087            }
2088    
2089            /**
2090             * Returns the journal templates before and after the current journal template in the ordered set where groupId = &#63;.
2091             *
2092             * @param id the primary key of the current journal template
2093             * @param groupId the group ID
2094             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2095             * @return the previous, current, and next journal template
2096             * @throws com.liferay.portlet.journal.NoSuchTemplateException if a journal template with the primary key could not be found
2097             * @throws SystemException if a system exception occurred
2098             */
2099            public JournalTemplate[] findByGroupId_PrevAndNext(long id, long groupId,
2100                    OrderByComparator orderByComparator)
2101                    throws NoSuchTemplateException, SystemException {
2102                    JournalTemplate journalTemplate = findByPrimaryKey(id);
2103    
2104                    Session session = null;
2105    
2106                    try {
2107                            session = openSession();
2108    
2109                            JournalTemplate[] array = new JournalTemplateImpl[3];
2110    
2111                            array[0] = getByGroupId_PrevAndNext(session, journalTemplate,
2112                                            groupId, orderByComparator, true);
2113    
2114                            array[1] = journalTemplate;
2115    
2116                            array[2] = getByGroupId_PrevAndNext(session, journalTemplate,
2117                                            groupId, orderByComparator, false);
2118    
2119                            return array;
2120                    }
2121                    catch (Exception e) {
2122                            throw processException(e);
2123                    }
2124                    finally {
2125                            closeSession(session);
2126                    }
2127            }
2128    
2129            protected JournalTemplate getByGroupId_PrevAndNext(Session session,
2130                    JournalTemplate journalTemplate, long groupId,
2131                    OrderByComparator orderByComparator, boolean previous) {
2132                    StringBundler query = null;
2133    
2134                    if (orderByComparator != null) {
2135                            query = new StringBundler(6 +
2136                                            (orderByComparator.getOrderByFields().length * 6));
2137                    }
2138                    else {
2139                            query = new StringBundler(3);
2140                    }
2141    
2142                    query.append(_SQL_SELECT_JOURNALTEMPLATE_WHERE);
2143    
2144                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2145    
2146                    if (orderByComparator != null) {
2147                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2148    
2149                            if (orderByConditionFields.length > 0) {
2150                                    query.append(WHERE_AND);
2151                            }
2152    
2153                            for (int i = 0; i < orderByConditionFields.length; i++) {
2154                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2155                                    query.append(orderByConditionFields[i]);
2156    
2157                                    if ((i + 1) < orderByConditionFields.length) {
2158                                            if (orderByComparator.isAscending() ^ previous) {
2159                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2160                                            }
2161                                            else {
2162                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2163                                            }
2164                                    }
2165                                    else {
2166                                            if (orderByComparator.isAscending() ^ previous) {
2167                                                    query.append(WHERE_GREATER_THAN);
2168                                            }
2169                                            else {
2170                                                    query.append(WHERE_LESSER_THAN);
2171                                            }
2172                                    }
2173                            }
2174    
2175                            query.append(ORDER_BY_CLAUSE);
2176    
2177                            String[] orderByFields = orderByComparator.getOrderByFields();
2178    
2179                            for (int i = 0; i < orderByFields.length; i++) {
2180                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2181                                    query.append(orderByFields[i]);
2182    
2183                                    if ((i + 1) < orderByFields.length) {
2184                                            if (orderByComparator.isAscending() ^ previous) {
2185                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2186                                            }
2187                                            else {
2188                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2189                                            }
2190                                    }
2191                                    else {
2192                                            if (orderByComparator.isAscending() ^ previous) {
2193                                                    query.append(ORDER_BY_ASC);
2194                                            }
2195                                            else {
2196                                                    query.append(ORDER_BY_DESC);
2197                                            }
2198                                    }
2199                            }
2200                    }
2201    
2202                    else {
2203                            query.append(JournalTemplateModelImpl.ORDER_BY_JPQL);
2204                    }
2205    
2206                    String sql = query.toString();
2207    
2208                    Query q = session.createQuery(sql);
2209    
2210                    q.setFirstResult(0);
2211                    q.setMaxResults(2);
2212    
2213                    QueryPos qPos = QueryPos.getInstance(q);
2214    
2215                    qPos.add(groupId);
2216    
2217                    if (orderByComparator != null) {
2218                            Object[] values = orderByComparator.getOrderByConditionValues(journalTemplate);
2219    
2220                            for (Object value : values) {
2221                                    qPos.add(value);
2222                            }
2223                    }
2224    
2225                    List<JournalTemplate> list = q.list();
2226    
2227                    if (list.size() == 2) {
2228                            return list.get(1);
2229                    }
2230                    else {
2231                            return null;
2232                    }
2233            }
2234    
2235            /**
2236             * Returns all the journal templates that the user has permission to view where groupId = &#63;.
2237             *
2238             * @param groupId the group ID
2239             * @return the matching journal templates that the user has permission to view
2240             * @throws SystemException if a system exception occurred
2241             */
2242            public List<JournalTemplate> filterFindByGroupId(long groupId)
2243                    throws SystemException {
2244                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
2245                            QueryUtil.ALL_POS, null);
2246            }
2247    
2248            /**
2249             * Returns a range of all the journal templates that the user has permission to view where groupId = &#63;.
2250             *
2251             * <p>
2252             * 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.
2253             * </p>
2254             *
2255             * @param groupId the group ID
2256             * @param start the lower bound of the range of journal templates
2257             * @param end the upper bound of the range of journal templates (not inclusive)
2258             * @return the range of matching journal templates that the user has permission to view
2259             * @throws SystemException if a system exception occurred
2260             */
2261            public List<JournalTemplate> filterFindByGroupId(long groupId, int start,
2262                    int end) throws SystemException {
2263                    return filterFindByGroupId(groupId, start, end, null);
2264            }
2265    
2266            /**
2267             * Returns an ordered range of all the journal templates that the user has permissions to view where groupId = &#63;.
2268             *
2269             * <p>
2270             * 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.
2271             * </p>
2272             *
2273             * @param groupId the group ID
2274             * @param start the lower bound of the range of journal templates
2275             * @param end the upper bound of the range of journal templates (not inclusive)
2276             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2277             * @return the ordered range of matching journal templates that the user has permission to view
2278             * @throws SystemException if a system exception occurred
2279             */
2280            public List<JournalTemplate> filterFindByGroupId(long groupId, int start,
2281                    int end, OrderByComparator orderByComparator) throws SystemException {
2282                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2283                            return findByGroupId(groupId, start, end, orderByComparator);
2284                    }
2285    
2286                    StringBundler query = null;
2287    
2288                    if (orderByComparator != null) {
2289                            query = new StringBundler(3 +
2290                                            (orderByComparator.getOrderByFields().length * 3));
2291                    }
2292                    else {
2293                            query = new StringBundler(3);
2294                    }
2295    
2296                    if (getDB().isSupportsInlineDistinct()) {
2297                            query.append(_FILTER_SQL_SELECT_JOURNALTEMPLATE_WHERE);
2298                    }
2299                    else {
2300                            query.append(_FILTER_SQL_SELECT_JOURNALTEMPLATE_NO_INLINE_DISTINCT_WHERE_1);
2301                    }
2302    
2303                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2304    
2305                    if (!getDB().isSupportsInlineDistinct()) {
2306                            query.append(_FILTER_SQL_SELECT_JOURNALTEMPLATE_NO_INLINE_DISTINCT_WHERE_2);
2307                    }
2308    
2309                    if (orderByComparator != null) {
2310                            if (getDB().isSupportsInlineDistinct()) {
2311                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2312                                            orderByComparator);
2313                            }
2314                            else {
2315                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2316                                            orderByComparator);
2317                            }
2318                    }
2319    
2320                    else {
2321                            if (getDB().isSupportsInlineDistinct()) {
2322                                    query.append(JournalTemplateModelImpl.ORDER_BY_JPQL);
2323                            }
2324                            else {
2325                                    query.append(JournalTemplateModelImpl.ORDER_BY_SQL);
2326                            }
2327                    }
2328    
2329                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2330                                    JournalTemplate.class.getName(),
2331                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2332    
2333                    Session session = null;
2334    
2335                    try {
2336                            session = openSession();
2337    
2338                            SQLQuery q = session.createSQLQuery(sql);
2339    
2340                            if (getDB().isSupportsInlineDistinct()) {
2341                                    q.addEntity(_FILTER_ENTITY_ALIAS, JournalTemplateImpl.class);
2342                            }
2343                            else {
2344                                    q.addEntity(_FILTER_ENTITY_TABLE, JournalTemplateImpl.class);
2345                            }
2346    
2347                            QueryPos qPos = QueryPos.getInstance(q);
2348    
2349                            qPos.add(groupId);
2350    
2351                            return (List<JournalTemplate>)QueryUtil.list(q, getDialect(),
2352                                    start, end);
2353                    }
2354                    catch (Exception e) {
2355                            throw processException(e);
2356                    }
2357                    finally {
2358                            closeSession(session);
2359                    }
2360            }
2361    
2362            /**
2363             * 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;.
2364             *
2365             * @param id the primary key of the current journal template
2366             * @param groupId the group ID
2367             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2368             * @return the previous, current, and next journal template
2369             * @throws com.liferay.portlet.journal.NoSuchTemplateException if a journal template with the primary key could not be found
2370             * @throws SystemException if a system exception occurred
2371             */
2372            public JournalTemplate[] filterFindByGroupId_PrevAndNext(long id,
2373                    long groupId, OrderByComparator orderByComparator)
2374                    throws NoSuchTemplateException, SystemException {
2375                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2376                            return findByGroupId_PrevAndNext(id, groupId, orderByComparator);
2377                    }
2378    
2379                    JournalTemplate journalTemplate = findByPrimaryKey(id);
2380    
2381                    Session session = null;
2382    
2383                    try {
2384                            session = openSession();
2385    
2386                            JournalTemplate[] array = new JournalTemplateImpl[3];
2387    
2388                            array[0] = filterGetByGroupId_PrevAndNext(session, journalTemplate,
2389                                            groupId, orderByComparator, true);
2390    
2391                            array[1] = journalTemplate;
2392    
2393                            array[2] = filterGetByGroupId_PrevAndNext(session, journalTemplate,
2394                                            groupId, orderByComparator, false);
2395    
2396                            return array;
2397                    }
2398                    catch (Exception e) {
2399                            throw processException(e);
2400                    }
2401                    finally {
2402                            closeSession(session);
2403                    }
2404            }
2405    
2406            protected JournalTemplate filterGetByGroupId_PrevAndNext(Session session,
2407                    JournalTemplate journalTemplate, long groupId,
2408                    OrderByComparator orderByComparator, boolean previous) {
2409                    StringBundler query = null;
2410    
2411                    if (orderByComparator != null) {
2412                            query = new StringBundler(6 +
2413                                            (orderByComparator.getOrderByFields().length * 6));
2414                    }
2415                    else {
2416                            query = new StringBundler(3);
2417                    }
2418    
2419                    if (getDB().isSupportsInlineDistinct()) {
2420                            query.append(_FILTER_SQL_SELECT_JOURNALTEMPLATE_WHERE);
2421                    }
2422                    else {
2423                            query.append(_FILTER_SQL_SELECT_JOURNALTEMPLATE_NO_INLINE_DISTINCT_WHERE_1);
2424                    }
2425    
2426                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2427    
2428                    if (!getDB().isSupportsInlineDistinct()) {
2429                            query.append(_FILTER_SQL_SELECT_JOURNALTEMPLATE_NO_INLINE_DISTINCT_WHERE_2);
2430                    }
2431    
2432                    if (orderByComparator != null) {
2433                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2434    
2435                            if (orderByConditionFields.length > 0) {
2436                                    query.append(WHERE_AND);
2437                            }
2438    
2439                            for (int i = 0; i < orderByConditionFields.length; i++) {
2440                                    if (getDB().isSupportsInlineDistinct()) {
2441                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2442                                    }
2443                                    else {
2444                                            query.append(_ORDER_BY_ENTITY_TABLE);
2445                                    }
2446    
2447                                    query.append(orderByConditionFields[i]);
2448    
2449                                    if ((i + 1) < orderByConditionFields.length) {
2450                                            if (orderByComparator.isAscending() ^ previous) {
2451                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2452                                            }
2453                                            else {
2454                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2455                                            }
2456                                    }
2457                                    else {
2458                                            if (orderByComparator.isAscending() ^ previous) {
2459                                                    query.append(WHERE_GREATER_THAN);
2460                                            }
2461                                            else {
2462                                                    query.append(WHERE_LESSER_THAN);
2463                                            }
2464                                    }
2465                            }
2466    
2467                            query.append(ORDER_BY_CLAUSE);
2468    
2469                            String[] orderByFields = orderByComparator.getOrderByFields();
2470    
2471                            for (int i = 0; i < orderByFields.length; i++) {
2472                                    if (getDB().isSupportsInlineDistinct()) {
2473                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2474                                    }
2475                                    else {
2476                                            query.append(_ORDER_BY_ENTITY_TABLE);
2477                                    }
2478    
2479                                    query.append(orderByFields[i]);
2480    
2481                                    if ((i + 1) < orderByFields.length) {
2482                                            if (orderByComparator.isAscending() ^ previous) {
2483                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2484                                            }
2485                                            else {
2486                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2487                                            }
2488                                    }
2489                                    else {
2490                                            if (orderByComparator.isAscending() ^ previous) {
2491                                                    query.append(ORDER_BY_ASC);
2492                                            }
2493                                            else {
2494                                                    query.append(ORDER_BY_DESC);
2495                                            }
2496                                    }
2497                            }
2498                    }
2499    
2500                    else {
2501                            if (getDB().isSupportsInlineDistinct()) {
2502                                    query.append(JournalTemplateModelImpl.ORDER_BY_JPQL);
2503                            }
2504                            else {
2505                                    query.append(JournalTemplateModelImpl.ORDER_BY_SQL);
2506                            }
2507                    }
2508    
2509                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2510                                    JournalTemplate.class.getName(),
2511                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2512    
2513                    SQLQuery q = session.createSQLQuery(sql);
2514    
2515                    q.setFirstResult(0);
2516                    q.setMaxResults(2);
2517    
2518                    if (getDB().isSupportsInlineDistinct()) {
2519                            q.addEntity(_FILTER_ENTITY_ALIAS, JournalTemplateImpl.class);
2520                    }
2521                    else {
2522                            q.addEntity(_FILTER_ENTITY_TABLE, JournalTemplateImpl.class);
2523                    }
2524    
2525                    QueryPos qPos = QueryPos.getInstance(q);
2526    
2527                    qPos.add(groupId);
2528    
2529                    if (orderByComparator != null) {
2530                            Object[] values = orderByComparator.getOrderByConditionValues(journalTemplate);
2531    
2532                            for (Object value : values) {
2533                                    qPos.add(value);
2534                            }
2535                    }
2536    
2537                    List<JournalTemplate> list = q.list();
2538    
2539                    if (list.size() == 2) {
2540                            return list.get(1);
2541                    }
2542                    else {
2543                            return null;
2544                    }
2545            }
2546    
2547            /**
2548             * Returns all the journal templates where templateId = &#63;.
2549             *
2550             * @param templateId the template ID
2551             * @return the matching journal templates
2552             * @throws SystemException if a system exception occurred
2553             */
2554            public List<JournalTemplate> findByTemplateId(String templateId)
2555                    throws SystemException {
2556                    return findByTemplateId(templateId, QueryUtil.ALL_POS,
2557                            QueryUtil.ALL_POS, null);
2558            }
2559    
2560            /**
2561             * Returns a range of all the journal templates where templateId = &#63;.
2562             *
2563             * <p>
2564             * 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.
2565             * </p>
2566             *
2567             * @param templateId the template ID
2568             * @param start the lower bound of the range of journal templates
2569             * @param end the upper bound of the range of journal templates (not inclusive)
2570             * @return the range of matching journal templates
2571             * @throws SystemException if a system exception occurred
2572             */
2573            public List<JournalTemplate> findByTemplateId(String templateId, int start,
2574                    int end) throws SystemException {
2575                    return findByTemplateId(templateId, start, end, null);
2576            }
2577    
2578            /**
2579             * Returns an ordered range of all the journal templates where templateId = &#63;.
2580             *
2581             * <p>
2582             * 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.
2583             * </p>
2584             *
2585             * @param templateId the template ID
2586             * @param start the lower bound of the range of journal templates
2587             * @param end the upper bound of the range of journal templates (not inclusive)
2588             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2589             * @return the ordered range of matching journal templates
2590             * @throws SystemException if a system exception occurred
2591             */
2592            public List<JournalTemplate> findByTemplateId(String templateId, int start,
2593                    int end, OrderByComparator orderByComparator) throws SystemException {
2594                    FinderPath finderPath = null;
2595                    Object[] finderArgs = null;
2596    
2597                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2598                                    (orderByComparator == null)) {
2599                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TEMPLATEID;
2600                            finderArgs = new Object[] { templateId };
2601                    }
2602                    else {
2603                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_TEMPLATEID;
2604                            finderArgs = new Object[] { templateId, start, end, orderByComparator };
2605                    }
2606    
2607                    List<JournalTemplate> list = (List<JournalTemplate>)FinderCacheUtil.getResult(finderPath,
2608                                    finderArgs, this);
2609    
2610                    if ((list != null) && !list.isEmpty()) {
2611                            for (JournalTemplate journalTemplate : list) {
2612                                    if (!Validator.equals(templateId,
2613                                                            journalTemplate.getTemplateId())) {
2614                                            list = null;
2615    
2616                                            break;
2617                                    }
2618                            }
2619                    }
2620    
2621                    if (list == null) {
2622                            StringBundler query = null;
2623    
2624                            if (orderByComparator != null) {
2625                                    query = new StringBundler(3 +
2626                                                    (orderByComparator.getOrderByFields().length * 3));
2627                            }
2628                            else {
2629                                    query = new StringBundler(3);
2630                            }
2631    
2632                            query.append(_SQL_SELECT_JOURNALTEMPLATE_WHERE);
2633    
2634                            if (templateId == null) {
2635                                    query.append(_FINDER_COLUMN_TEMPLATEID_TEMPLATEID_1);
2636                            }
2637                            else {
2638                                    if (templateId.equals(StringPool.BLANK)) {
2639                                            query.append(_FINDER_COLUMN_TEMPLATEID_TEMPLATEID_3);
2640                                    }
2641                                    else {
2642                                            query.append(_FINDER_COLUMN_TEMPLATEID_TEMPLATEID_2);
2643                                    }
2644                            }
2645    
2646                            if (orderByComparator != null) {
2647                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2648                                            orderByComparator);
2649                            }
2650    
2651                            else {
2652                                    query.append(JournalTemplateModelImpl.ORDER_BY_JPQL);
2653                            }
2654    
2655                            String sql = query.toString();
2656    
2657                            Session session = null;
2658    
2659                            try {
2660                                    session = openSession();
2661    
2662                                    Query q = session.createQuery(sql);
2663    
2664                                    QueryPos qPos = QueryPos.getInstance(q);
2665    
2666                                    if (templateId != null) {
2667                                            qPos.add(templateId);
2668                                    }
2669    
2670                                    list = (List<JournalTemplate>)QueryUtil.list(q, getDialect(),
2671                                                    start, end);
2672                            }
2673                            catch (Exception e) {
2674                                    throw processException(e);
2675                            }
2676                            finally {
2677                                    if (list == null) {
2678                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
2679                                    }
2680                                    else {
2681                                            cacheResult(list);
2682    
2683                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
2684                                    }
2685    
2686                                    closeSession(session);
2687                            }
2688                    }
2689    
2690                    return list;
2691            }
2692    
2693            /**
2694             * Returns the first journal template in the ordered set where templateId = &#63;.
2695             *
2696             * @param templateId the template ID
2697             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2698             * @return the first matching journal template
2699             * @throws com.liferay.portlet.journal.NoSuchTemplateException if a matching journal template could not be found
2700             * @throws SystemException if a system exception occurred
2701             */
2702            public JournalTemplate findByTemplateId_First(String templateId,
2703                    OrderByComparator orderByComparator)
2704                    throws NoSuchTemplateException, SystemException {
2705                    JournalTemplate journalTemplate = fetchByTemplateId_First(templateId,
2706                                    orderByComparator);
2707    
2708                    if (journalTemplate != null) {
2709                            return journalTemplate;
2710                    }
2711    
2712                    StringBundler msg = new StringBundler(4);
2713    
2714                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2715    
2716                    msg.append("templateId=");
2717                    msg.append(templateId);
2718    
2719                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2720    
2721                    throw new NoSuchTemplateException(msg.toString());
2722            }
2723    
2724            /**
2725             * Returns the first journal template in the ordered set where templateId = &#63;.
2726             *
2727             * @param templateId the template ID
2728             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2729             * @return the first matching journal template, or <code>null</code> if a matching journal template could not be found
2730             * @throws SystemException if a system exception occurred
2731             */
2732            public JournalTemplate fetchByTemplateId_First(String templateId,
2733                    OrderByComparator orderByComparator) throws SystemException {
2734                    List<JournalTemplate> list = findByTemplateId(templateId, 0, 1,
2735                                    orderByComparator);
2736    
2737                    if (!list.isEmpty()) {
2738                            return list.get(0);
2739                    }
2740    
2741                    return null;
2742            }
2743    
2744            /**
2745             * Returns the last journal template in the ordered set where templateId = &#63;.
2746             *
2747             * @param templateId the template ID
2748             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2749             * @return the last matching journal template
2750             * @throws com.liferay.portlet.journal.NoSuchTemplateException if a matching journal template could not be found
2751             * @throws SystemException if a system exception occurred
2752             */
2753            public JournalTemplate findByTemplateId_Last(String templateId,
2754                    OrderByComparator orderByComparator)
2755                    throws NoSuchTemplateException, SystemException {
2756                    JournalTemplate journalTemplate = fetchByTemplateId_Last(templateId,
2757                                    orderByComparator);
2758    
2759                    if (journalTemplate != null) {
2760                            return journalTemplate;
2761                    }
2762    
2763                    StringBundler msg = new StringBundler(4);
2764    
2765                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2766    
2767                    msg.append("templateId=");
2768                    msg.append(templateId);
2769    
2770                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2771    
2772                    throw new NoSuchTemplateException(msg.toString());
2773            }
2774    
2775            /**
2776             * Returns the last journal template in the ordered set where templateId = &#63;.
2777             *
2778             * @param templateId the template ID
2779             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2780             * @return the last matching journal template, or <code>null</code> if a matching journal template could not be found
2781             * @throws SystemException if a system exception occurred
2782             */
2783            public JournalTemplate fetchByTemplateId_Last(String templateId,
2784                    OrderByComparator orderByComparator) throws SystemException {
2785                    int count = countByTemplateId(templateId);
2786    
2787                    List<JournalTemplate> list = findByTemplateId(templateId, count - 1,
2788                                    count, orderByComparator);
2789    
2790                    if (!list.isEmpty()) {
2791                            return list.get(0);
2792                    }
2793    
2794                    return null;
2795            }
2796    
2797            /**
2798             * Returns the journal templates before and after the current journal template in the ordered set where templateId = &#63;.
2799             *
2800             * @param id the primary key of the current journal template
2801             * @param templateId the template ID
2802             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2803             * @return the previous, current, and next journal template
2804             * @throws com.liferay.portlet.journal.NoSuchTemplateException if a journal template with the primary key could not be found
2805             * @throws SystemException if a system exception occurred
2806             */
2807            public JournalTemplate[] findByTemplateId_PrevAndNext(long id,
2808                    String templateId, OrderByComparator orderByComparator)
2809                    throws NoSuchTemplateException, SystemException {
2810                    JournalTemplate journalTemplate = findByPrimaryKey(id);
2811    
2812                    Session session = null;
2813    
2814                    try {
2815                            session = openSession();
2816    
2817                            JournalTemplate[] array = new JournalTemplateImpl[3];
2818    
2819                            array[0] = getByTemplateId_PrevAndNext(session, journalTemplate,
2820                                            templateId, orderByComparator, true);
2821    
2822                            array[1] = journalTemplate;
2823    
2824                            array[2] = getByTemplateId_PrevAndNext(session, journalTemplate,
2825                                            templateId, orderByComparator, false);
2826    
2827                            return array;
2828                    }
2829                    catch (Exception e) {
2830                            throw processException(e);
2831                    }
2832                    finally {
2833                            closeSession(session);
2834                    }
2835            }
2836    
2837            protected JournalTemplate getByTemplateId_PrevAndNext(Session session,
2838                    JournalTemplate journalTemplate, String templateId,
2839                    OrderByComparator orderByComparator, boolean previous) {
2840                    StringBundler query = null;
2841    
2842                    if (orderByComparator != null) {
2843                            query = new StringBundler(6 +
2844                                            (orderByComparator.getOrderByFields().length * 6));
2845                    }
2846                    else {
2847                            query = new StringBundler(3);
2848                    }
2849    
2850                    query.append(_SQL_SELECT_JOURNALTEMPLATE_WHERE);
2851    
2852                    if (templateId == null) {
2853                            query.append(_FINDER_COLUMN_TEMPLATEID_TEMPLATEID_1);
2854                    }
2855                    else {
2856                            if (templateId.equals(StringPool.BLANK)) {
2857                                    query.append(_FINDER_COLUMN_TEMPLATEID_TEMPLATEID_3);
2858                            }
2859                            else {
2860                                    query.append(_FINDER_COLUMN_TEMPLATEID_TEMPLATEID_2);
2861                            }
2862                    }
2863    
2864                    if (orderByComparator != null) {
2865                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2866    
2867                            if (orderByConditionFields.length > 0) {
2868                                    query.append(WHERE_AND);
2869                            }
2870    
2871                            for (int i = 0; i < orderByConditionFields.length; i++) {
2872                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2873                                    query.append(orderByConditionFields[i]);
2874    
2875                                    if ((i + 1) < orderByConditionFields.length) {
2876                                            if (orderByComparator.isAscending() ^ previous) {
2877                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2878                                            }
2879                                            else {
2880                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2881                                            }
2882                                    }
2883                                    else {
2884                                            if (orderByComparator.isAscending() ^ previous) {
2885                                                    query.append(WHERE_GREATER_THAN);
2886                                            }
2887                                            else {
2888                                                    query.append(WHERE_LESSER_THAN);
2889                                            }
2890                                    }
2891                            }
2892    
2893                            query.append(ORDER_BY_CLAUSE);
2894    
2895                            String[] orderByFields = orderByComparator.getOrderByFields();
2896    
2897                            for (int i = 0; i < orderByFields.length; i++) {
2898                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2899                                    query.append(orderByFields[i]);
2900    
2901                                    if ((i + 1) < orderByFields.length) {
2902                                            if (orderByComparator.isAscending() ^ previous) {
2903                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2904                                            }
2905                                            else {
2906                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2907                                            }
2908                                    }
2909                                    else {
2910                                            if (orderByComparator.isAscending() ^ previous) {
2911                                                    query.append(ORDER_BY_ASC);
2912                                            }
2913                                            else {
2914                                                    query.append(ORDER_BY_DESC);
2915                                            }
2916                                    }
2917                            }
2918                    }
2919    
2920                    else {
2921                            query.append(JournalTemplateModelImpl.ORDER_BY_JPQL);
2922                    }
2923    
2924                    String sql = query.toString();
2925    
2926                    Query q = session.createQuery(sql);
2927    
2928                    q.setFirstResult(0);
2929                    q.setMaxResults(2);
2930    
2931                    QueryPos qPos = QueryPos.getInstance(q);
2932    
2933                    if (templateId != null) {
2934                            qPos.add(templateId);
2935                    }
2936    
2937                    if (orderByComparator != null) {
2938                            Object[] values = orderByComparator.getOrderByConditionValues(journalTemplate);
2939    
2940                            for (Object value : values) {
2941                                    qPos.add(value);
2942                            }
2943                    }
2944    
2945                    List<JournalTemplate> list = q.list();
2946    
2947                    if (list.size() == 2) {
2948                            return list.get(1);
2949                    }
2950                    else {
2951                            return null;
2952                    }
2953            }
2954    
2955            /**
2956             * Returns all the journal templates where structureId = &#63;.
2957             *
2958             * @param structureId the structure ID
2959             * @return the matching journal templates
2960             * @throws SystemException if a system exception occurred
2961             */
2962            public List<JournalTemplate> findByStructureId(String structureId)
2963                    throws SystemException {
2964                    return findByStructureId(structureId, QueryUtil.ALL_POS,
2965                            QueryUtil.ALL_POS, null);
2966            }
2967    
2968            /**
2969             * Returns a range of all the journal templates where structureId = &#63;.
2970             *
2971             * <p>
2972             * 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.
2973             * </p>
2974             *
2975             * @param structureId the structure ID
2976             * @param start the lower bound of the range of journal templates
2977             * @param end the upper bound of the range of journal templates (not inclusive)
2978             * @return the range of matching journal templates
2979             * @throws SystemException if a system exception occurred
2980             */
2981            public List<JournalTemplate> findByStructureId(String structureId,
2982                    int start, int end) throws SystemException {
2983                    return findByStructureId(structureId, start, end, null);
2984            }
2985    
2986            /**
2987             * Returns an ordered range of all the journal templates where structureId = &#63;.
2988             *
2989             * <p>
2990             * 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.
2991             * </p>
2992             *
2993             * @param structureId the structure ID
2994             * @param start the lower bound of the range of journal templates
2995             * @param end the upper bound of the range of journal templates (not inclusive)
2996             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2997             * @return the ordered range of matching journal templates
2998             * @throws SystemException if a system exception occurred
2999             */
3000            public List<JournalTemplate> findByStructureId(String structureId,
3001                    int start, int end, OrderByComparator orderByComparator)
3002                    throws SystemException {
3003                    FinderPath finderPath = null;
3004                    Object[] finderArgs = null;
3005    
3006                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3007                                    (orderByComparator == null)) {
3008                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_STRUCTUREID;
3009                            finderArgs = new Object[] { structureId };
3010                    }
3011                    else {
3012                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_STRUCTUREID;
3013                            finderArgs = new Object[] { structureId, start, end, orderByComparator };
3014                    }
3015    
3016                    List<JournalTemplate> list = (List<JournalTemplate>)FinderCacheUtil.getResult(finderPath,
3017                                    finderArgs, this);
3018    
3019                    if ((list != null) && !list.isEmpty()) {
3020                            for (JournalTemplate journalTemplate : list) {
3021                                    if (!Validator.equals(structureId,
3022                                                            journalTemplate.getStructureId())) {
3023                                            list = null;
3024    
3025                                            break;
3026                                    }
3027                            }
3028                    }
3029    
3030                    if (list == null) {
3031                            StringBundler query = null;
3032    
3033                            if (orderByComparator != null) {
3034                                    query = new StringBundler(3 +
3035                                                    (orderByComparator.getOrderByFields().length * 3));
3036                            }
3037                            else {
3038                                    query = new StringBundler(3);
3039                            }
3040    
3041                            query.append(_SQL_SELECT_JOURNALTEMPLATE_WHERE);
3042    
3043                            if (structureId == null) {
3044                                    query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_1);
3045                            }
3046                            else {
3047                                    if (structureId.equals(StringPool.BLANK)) {
3048                                            query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_3);
3049                                    }
3050                                    else {
3051                                            query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_2);
3052                                    }
3053                            }
3054    
3055                            if (orderByComparator != null) {
3056                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3057                                            orderByComparator);
3058                            }
3059    
3060                            else {
3061                                    query.append(JournalTemplateModelImpl.ORDER_BY_JPQL);
3062                            }
3063    
3064                            String sql = query.toString();
3065    
3066                            Session session = null;
3067    
3068                            try {
3069                                    session = openSession();
3070    
3071                                    Query q = session.createQuery(sql);
3072    
3073                                    QueryPos qPos = QueryPos.getInstance(q);
3074    
3075                                    if (structureId != null) {
3076                                            qPos.add(structureId);
3077                                    }
3078    
3079                                    list = (List<JournalTemplate>)QueryUtil.list(q, getDialect(),
3080                                                    start, end);
3081                            }
3082                            catch (Exception e) {
3083                                    throw processException(e);
3084                            }
3085                            finally {
3086                                    if (list == null) {
3087                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
3088                                    }
3089                                    else {
3090                                            cacheResult(list);
3091    
3092                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
3093                                    }
3094    
3095                                    closeSession(session);
3096                            }
3097                    }
3098    
3099                    return list;
3100            }
3101    
3102            /**
3103             * Returns the first journal template in the ordered set where structureId = &#63;.
3104             *
3105             * @param structureId the structure ID
3106             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3107             * @return the first matching journal template
3108             * @throws com.liferay.portlet.journal.NoSuchTemplateException if a matching journal template could not be found
3109             * @throws SystemException if a system exception occurred
3110             */
3111            public JournalTemplate findByStructureId_First(String structureId,
3112                    OrderByComparator orderByComparator)
3113                    throws NoSuchTemplateException, SystemException {
3114                    JournalTemplate journalTemplate = fetchByStructureId_First(structureId,
3115                                    orderByComparator);
3116    
3117                    if (journalTemplate != null) {
3118                            return journalTemplate;
3119                    }
3120    
3121                    StringBundler msg = new StringBundler(4);
3122    
3123                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3124    
3125                    msg.append("structureId=");
3126                    msg.append(structureId);
3127    
3128                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3129    
3130                    throw new NoSuchTemplateException(msg.toString());
3131            }
3132    
3133            /**
3134             * Returns the first journal template in the ordered set where structureId = &#63;.
3135             *
3136             * @param structureId the structure ID
3137             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3138             * @return the first matching journal template, or <code>null</code> if a matching journal template could not be found
3139             * @throws SystemException if a system exception occurred
3140             */
3141            public JournalTemplate fetchByStructureId_First(String structureId,
3142                    OrderByComparator orderByComparator) throws SystemException {
3143                    List<JournalTemplate> list = findByStructureId(structureId, 0, 1,
3144                                    orderByComparator);
3145    
3146                    if (!list.isEmpty()) {
3147                            return list.get(0);
3148                    }
3149    
3150                    return null;
3151            }
3152    
3153            /**
3154             * Returns the last journal template in the ordered set where structureId = &#63;.
3155             *
3156             * @param structureId the structure ID
3157             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3158             * @return the last matching journal template
3159             * @throws com.liferay.portlet.journal.NoSuchTemplateException if a matching journal template could not be found
3160             * @throws SystemException if a system exception occurred
3161             */
3162            public JournalTemplate findByStructureId_Last(String structureId,
3163                    OrderByComparator orderByComparator)
3164                    throws NoSuchTemplateException, SystemException {
3165                    JournalTemplate journalTemplate = fetchByStructureId_Last(structureId,
3166                                    orderByComparator);
3167    
3168                    if (journalTemplate != null) {
3169                            return journalTemplate;
3170                    }
3171    
3172                    StringBundler msg = new StringBundler(4);
3173    
3174                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3175    
3176                    msg.append("structureId=");
3177                    msg.append(structureId);
3178    
3179                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3180    
3181                    throw new NoSuchTemplateException(msg.toString());
3182            }
3183    
3184            /**
3185             * Returns the last journal template in the ordered set where structureId = &#63;.
3186             *
3187             * @param structureId the structure ID
3188             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3189             * @return the last matching journal template, or <code>null</code> if a matching journal template could not be found
3190             * @throws SystemException if a system exception occurred
3191             */
3192            public JournalTemplate fetchByStructureId_Last(String structureId,
3193                    OrderByComparator orderByComparator) throws SystemException {
3194                    int count = countByStructureId(structureId);
3195    
3196                    List<JournalTemplate> list = findByStructureId(structureId, count - 1,
3197                                    count, orderByComparator);
3198    
3199                    if (!list.isEmpty()) {
3200                            return list.get(0);
3201                    }
3202    
3203                    return null;
3204            }
3205    
3206            /**
3207             * Returns the journal templates before and after the current journal template in the ordered set where structureId = &#63;.
3208             *
3209             * @param id the primary key of the current journal template
3210             * @param structureId the structure ID
3211             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3212             * @return the previous, current, and next journal template
3213             * @throws com.liferay.portlet.journal.NoSuchTemplateException if a journal template with the primary key could not be found
3214             * @throws SystemException if a system exception occurred
3215             */
3216            public JournalTemplate[] findByStructureId_PrevAndNext(long id,
3217                    String structureId, OrderByComparator orderByComparator)
3218                    throws NoSuchTemplateException, SystemException {
3219                    JournalTemplate journalTemplate = findByPrimaryKey(id);
3220    
3221                    Session session = null;
3222    
3223                    try {
3224                            session = openSession();
3225    
3226                            JournalTemplate[] array = new JournalTemplateImpl[3];
3227    
3228                            array[0] = getByStructureId_PrevAndNext(session, journalTemplate,
3229                                            structureId, orderByComparator, true);
3230    
3231                            array[1] = journalTemplate;
3232    
3233                            array[2] = getByStructureId_PrevAndNext(session, journalTemplate,
3234                                            structureId, orderByComparator, false);
3235    
3236                            return array;
3237                    }
3238                    catch (Exception e) {
3239                            throw processException(e);
3240                    }
3241                    finally {
3242                            closeSession(session);
3243                    }
3244            }
3245    
3246            protected JournalTemplate getByStructureId_PrevAndNext(Session session,
3247                    JournalTemplate journalTemplate, String structureId,
3248                    OrderByComparator orderByComparator, boolean previous) {
3249                    StringBundler query = null;
3250    
3251                    if (orderByComparator != null) {
3252                            query = new StringBundler(6 +
3253                                            (orderByComparator.getOrderByFields().length * 6));
3254                    }
3255                    else {
3256                            query = new StringBundler(3);
3257                    }
3258    
3259                    query.append(_SQL_SELECT_JOURNALTEMPLATE_WHERE);
3260    
3261                    if (structureId == null) {
3262                            query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_1);
3263                    }
3264                    else {
3265                            if (structureId.equals(StringPool.BLANK)) {
3266                                    query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_3);
3267                            }
3268                            else {
3269                                    query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_2);
3270                            }
3271                    }
3272    
3273                    if (orderByComparator != null) {
3274                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3275    
3276                            if (orderByConditionFields.length > 0) {
3277                                    query.append(WHERE_AND);
3278                            }
3279    
3280                            for (int i = 0; i < orderByConditionFields.length; i++) {
3281                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3282                                    query.append(orderByConditionFields[i]);
3283    
3284                                    if ((i + 1) < orderByConditionFields.length) {
3285                                            if (orderByComparator.isAscending() ^ previous) {
3286                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3287                                            }
3288                                            else {
3289                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3290                                            }
3291                                    }
3292                                    else {
3293                                            if (orderByComparator.isAscending() ^ previous) {
3294                                                    query.append(WHERE_GREATER_THAN);
3295                                            }
3296                                            else {
3297                                                    query.append(WHERE_LESSER_THAN);
3298                                            }
3299                                    }
3300                            }
3301    
3302                            query.append(ORDER_BY_CLAUSE);
3303    
3304                            String[] orderByFields = orderByComparator.getOrderByFields();
3305    
3306                            for (int i = 0; i < orderByFields.length; i++) {
3307                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3308                                    query.append(orderByFields[i]);
3309    
3310                                    if ((i + 1) < orderByFields.length) {
3311                                            if (orderByComparator.isAscending() ^ previous) {
3312                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3313                                            }
3314                                            else {
3315                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3316                                            }
3317                                    }
3318                                    else {
3319                                            if (orderByComparator.isAscending() ^ previous) {
3320                                                    query.append(ORDER_BY_ASC);
3321                                            }
3322                                            else {
3323                                                    query.append(ORDER_BY_DESC);
3324                                            }
3325                                    }
3326                            }
3327                    }
3328    
3329                    else {
3330                            query.append(JournalTemplateModelImpl.ORDER_BY_JPQL);
3331                    }
3332    
3333                    String sql = query.toString();
3334    
3335                    Query q = session.createQuery(sql);
3336    
3337                    q.setFirstResult(0);
3338                    q.setMaxResults(2);
3339    
3340                    QueryPos qPos = QueryPos.getInstance(q);
3341    
3342                    if (structureId != null) {
3343                            qPos.add(structureId);
3344                    }
3345    
3346                    if (orderByComparator != null) {
3347                            Object[] values = orderByComparator.getOrderByConditionValues(journalTemplate);
3348    
3349                            for (Object value : values) {
3350                                    qPos.add(value);
3351                            }
3352                    }
3353    
3354                    List<JournalTemplate> list = q.list();
3355    
3356                    if (list.size() == 2) {
3357                            return list.get(1);
3358                    }
3359                    else {
3360                            return null;
3361                    }
3362            }
3363    
3364            /**
3365             * Returns the journal template where smallImageId = &#63; or throws a {@link com.liferay.portlet.journal.NoSuchTemplateException} if it could not be found.
3366             *
3367             * @param smallImageId the small image ID
3368             * @return the matching journal template
3369             * @throws com.liferay.portlet.journal.NoSuchTemplateException if a matching journal template could not be found
3370             * @throws SystemException if a system exception occurred
3371             */
3372            public JournalTemplate findBySmallImageId(long smallImageId)
3373                    throws NoSuchTemplateException, SystemException {
3374                    JournalTemplate journalTemplate = fetchBySmallImageId(smallImageId);
3375    
3376                    if (journalTemplate == null) {
3377                            StringBundler msg = new StringBundler(4);
3378    
3379                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3380    
3381                            msg.append("smallImageId=");
3382                            msg.append(smallImageId);
3383    
3384                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3385    
3386                            if (_log.isWarnEnabled()) {
3387                                    _log.warn(msg.toString());
3388                            }
3389    
3390                            throw new NoSuchTemplateException(msg.toString());
3391                    }
3392    
3393                    return journalTemplate;
3394            }
3395    
3396            /**
3397             * Returns the journal template where smallImageId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
3398             *
3399             * @param smallImageId the small image ID
3400             * @return the matching journal template, or <code>null</code> if a matching journal template could not be found
3401             * @throws SystemException if a system exception occurred
3402             */
3403            public JournalTemplate fetchBySmallImageId(long smallImageId)
3404                    throws SystemException {
3405                    return fetchBySmallImageId(smallImageId, true);
3406            }
3407    
3408            /**
3409             * Returns the journal template where smallImageId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
3410             *
3411             * @param smallImageId the small image ID
3412             * @param retrieveFromCache whether to use the finder cache
3413             * @return the matching journal template, or <code>null</code> if a matching journal template could not be found
3414             * @throws SystemException if a system exception occurred
3415             */
3416            public JournalTemplate fetchBySmallImageId(long smallImageId,
3417                    boolean retrieveFromCache) throws SystemException {
3418                    Object[] finderArgs = new Object[] { smallImageId };
3419    
3420                    Object result = null;
3421    
3422                    if (retrieveFromCache) {
3423                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
3424                                            finderArgs, this);
3425                    }
3426    
3427                    if (result instanceof JournalTemplate) {
3428                            JournalTemplate journalTemplate = (JournalTemplate)result;
3429    
3430                            if ((smallImageId != journalTemplate.getSmallImageId())) {
3431                                    result = null;
3432                            }
3433                    }
3434    
3435                    if (result == null) {
3436                            StringBundler query = new StringBundler(3);
3437    
3438                            query.append(_SQL_SELECT_JOURNALTEMPLATE_WHERE);
3439    
3440                            query.append(_FINDER_COLUMN_SMALLIMAGEID_SMALLIMAGEID_2);
3441    
3442                            query.append(JournalTemplateModelImpl.ORDER_BY_JPQL);
3443    
3444                            String sql = query.toString();
3445    
3446                            Session session = null;
3447    
3448                            try {
3449                                    session = openSession();
3450    
3451                                    Query q = session.createQuery(sql);
3452    
3453                                    QueryPos qPos = QueryPos.getInstance(q);
3454    
3455                                    qPos.add(smallImageId);
3456    
3457                                    List<JournalTemplate> list = q.list();
3458    
3459                                    result = list;
3460    
3461                                    JournalTemplate journalTemplate = null;
3462    
3463                                    if (list.isEmpty()) {
3464                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
3465                                                    finderArgs, list);
3466                                    }
3467                                    else {
3468                                            journalTemplate = list.get(0);
3469    
3470                                            cacheResult(journalTemplate);
3471    
3472                                            if ((journalTemplate.getSmallImageId() != smallImageId)) {
3473                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
3474                                                            finderArgs, journalTemplate);
3475                                            }
3476                                    }
3477    
3478                                    return journalTemplate;
3479                            }
3480                            catch (Exception e) {
3481                                    throw processException(e);
3482                            }
3483                            finally {
3484                                    if (result == null) {
3485                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
3486                                                    finderArgs);
3487                                    }
3488    
3489                                    closeSession(session);
3490                            }
3491                    }
3492                    else {
3493                            if (result instanceof List<?>) {
3494                                    return null;
3495                            }
3496                            else {
3497                                    return (JournalTemplate)result;
3498                            }
3499                    }
3500            }
3501    
3502            /**
3503             * 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.
3504             *
3505             * @param groupId the group ID
3506             * @param templateId the template ID
3507             * @return the matching journal template
3508             * @throws com.liferay.portlet.journal.NoSuchTemplateException if a matching journal template could not be found
3509             * @throws SystemException if a system exception occurred
3510             */
3511            public JournalTemplate findByG_T(long groupId, String templateId)
3512                    throws NoSuchTemplateException, SystemException {
3513                    JournalTemplate journalTemplate = fetchByG_T(groupId, templateId);
3514    
3515                    if (journalTemplate == null) {
3516                            StringBundler msg = new StringBundler(6);
3517    
3518                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3519    
3520                            msg.append("groupId=");
3521                            msg.append(groupId);
3522    
3523                            msg.append(", templateId=");
3524                            msg.append(templateId);
3525    
3526                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3527    
3528                            if (_log.isWarnEnabled()) {
3529                                    _log.warn(msg.toString());
3530                            }
3531    
3532                            throw new NoSuchTemplateException(msg.toString());
3533                    }
3534    
3535                    return journalTemplate;
3536            }
3537    
3538            /**
3539             * 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.
3540             *
3541             * @param groupId the group ID
3542             * @param templateId the template ID
3543             * @return the matching journal template, or <code>null</code> if a matching journal template could not be found
3544             * @throws SystemException if a system exception occurred
3545             */
3546            public JournalTemplate fetchByG_T(long groupId, String templateId)
3547                    throws SystemException {
3548                    return fetchByG_T(groupId, templateId, true);
3549            }
3550    
3551            /**
3552             * 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.
3553             *
3554             * @param groupId the group ID
3555             * @param templateId the template ID
3556             * @param retrieveFromCache whether to use the finder cache
3557             * @return the matching journal template, or <code>null</code> if a matching journal template could not be found
3558             * @throws SystemException if a system exception occurred
3559             */
3560            public JournalTemplate fetchByG_T(long groupId, String templateId,
3561                    boolean retrieveFromCache) throws SystemException {
3562                    Object[] finderArgs = new Object[] { groupId, templateId };
3563    
3564                    Object result = null;
3565    
3566                    if (retrieveFromCache) {
3567                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_T,
3568                                            finderArgs, this);
3569                    }
3570    
3571                    if (result instanceof JournalTemplate) {
3572                            JournalTemplate journalTemplate = (JournalTemplate)result;
3573    
3574                            if ((groupId != journalTemplate.getGroupId()) ||
3575                                            !Validator.equals(templateId,
3576                                                    journalTemplate.getTemplateId())) {
3577                                    result = null;
3578                            }
3579                    }
3580    
3581                    if (result == null) {
3582                            StringBundler query = new StringBundler(4);
3583    
3584                            query.append(_SQL_SELECT_JOURNALTEMPLATE_WHERE);
3585    
3586                            query.append(_FINDER_COLUMN_G_T_GROUPID_2);
3587    
3588                            if (templateId == null) {
3589                                    query.append(_FINDER_COLUMN_G_T_TEMPLATEID_1);
3590                            }
3591                            else {
3592                                    if (templateId.equals(StringPool.BLANK)) {
3593                                            query.append(_FINDER_COLUMN_G_T_TEMPLATEID_3);
3594                                    }
3595                                    else {
3596                                            query.append(_FINDER_COLUMN_G_T_TEMPLATEID_2);
3597                                    }
3598                            }
3599    
3600                            query.append(JournalTemplateModelImpl.ORDER_BY_JPQL);
3601    
3602                            String sql = query.toString();
3603    
3604                            Session session = null;
3605    
3606                            try {
3607                                    session = openSession();
3608    
3609                                    Query q = session.createQuery(sql);
3610    
3611                                    QueryPos qPos = QueryPos.getInstance(q);
3612    
3613                                    qPos.add(groupId);
3614    
3615                                    if (templateId != null) {
3616                                            qPos.add(templateId);
3617                                    }
3618    
3619                                    List<JournalTemplate> list = q.list();
3620    
3621                                    result = list;
3622    
3623                                    JournalTemplate journalTemplate = null;
3624    
3625                                    if (list.isEmpty()) {
3626                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_T,
3627                                                    finderArgs, list);
3628                                    }
3629                                    else {
3630                                            journalTemplate = list.get(0);
3631    
3632                                            cacheResult(journalTemplate);
3633    
3634                                            if ((journalTemplate.getGroupId() != groupId) ||
3635                                                            (journalTemplate.getTemplateId() == null) ||
3636                                                            !journalTemplate.getTemplateId().equals(templateId)) {
3637                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_T,
3638                                                            finderArgs, journalTemplate);
3639                                            }
3640                                    }
3641    
3642                                    return journalTemplate;
3643                            }
3644                            catch (Exception e) {
3645                                    throw processException(e);
3646                            }
3647                            finally {
3648                                    if (result == null) {
3649                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_T,
3650                                                    finderArgs);
3651                                    }
3652    
3653                                    closeSession(session);
3654                            }
3655                    }
3656                    else {
3657                            if (result instanceof List<?>) {
3658                                    return null;
3659                            }
3660                            else {
3661                                    return (JournalTemplate)result;
3662                            }
3663                    }
3664            }
3665    
3666            /**
3667             * Returns all the journal templates where groupId = &#63; and structureId = &#63;.
3668             *
3669             * @param groupId the group ID
3670             * @param structureId the structure ID
3671             * @return the matching journal templates
3672             * @throws SystemException if a system exception occurred
3673             */
3674            public List<JournalTemplate> findByG_S(long groupId, String structureId)
3675                    throws SystemException {
3676                    return findByG_S(groupId, structureId, QueryUtil.ALL_POS,
3677                            QueryUtil.ALL_POS, null);
3678            }
3679    
3680            /**
3681             * Returns a range of all the journal templates where groupId = &#63; and structureId = &#63;.
3682             *
3683             * <p>
3684             * 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.
3685             * </p>
3686             *
3687             * @param groupId the group ID
3688             * @param structureId the structure ID
3689             * @param start the lower bound of the range of journal templates
3690             * @param end the upper bound of the range of journal templates (not inclusive)
3691             * @return the range of matching journal templates
3692             * @throws SystemException if a system exception occurred
3693             */
3694            public List<JournalTemplate> findByG_S(long groupId, String structureId,
3695                    int start, int end) throws SystemException {
3696                    return findByG_S(groupId, structureId, start, end, null);
3697            }
3698    
3699            /**
3700             * Returns an ordered range of all the journal templates where groupId = &#63; and structureId = &#63;.
3701             *
3702             * <p>
3703             * 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.
3704             * </p>
3705             *
3706             * @param groupId the group ID
3707             * @param structureId the structure ID
3708             * @param start the lower bound of the range of journal templates
3709             * @param end the upper bound of the range of journal templates (not inclusive)
3710             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3711             * @return the ordered range of matching journal templates
3712             * @throws SystemException if a system exception occurred
3713             */
3714            public List<JournalTemplate> findByG_S(long groupId, String structureId,
3715                    int start, int end, OrderByComparator orderByComparator)
3716                    throws SystemException {
3717                    FinderPath finderPath = null;
3718                    Object[] finderArgs = null;
3719    
3720                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3721                                    (orderByComparator == null)) {
3722                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S;
3723                            finderArgs = new Object[] { groupId, structureId };
3724                    }
3725                    else {
3726                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S;
3727                            finderArgs = new Object[] {
3728                                            groupId, structureId,
3729                                            
3730                                            start, end, orderByComparator
3731                                    };
3732                    }
3733    
3734                    List<JournalTemplate> list = (List<JournalTemplate>)FinderCacheUtil.getResult(finderPath,
3735                                    finderArgs, this);
3736    
3737                    if ((list != null) && !list.isEmpty()) {
3738                            for (JournalTemplate journalTemplate : list) {
3739                                    if ((groupId != journalTemplate.getGroupId()) ||
3740                                                    !Validator.equals(structureId,
3741                                                            journalTemplate.getStructureId())) {
3742                                            list = null;
3743    
3744                                            break;
3745                                    }
3746                            }
3747                    }
3748    
3749                    if (list == null) {
3750                            StringBundler query = null;
3751    
3752                            if (orderByComparator != null) {
3753                                    query = new StringBundler(4 +
3754                                                    (orderByComparator.getOrderByFields().length * 3));
3755                            }
3756                            else {
3757                                    query = new StringBundler(4);
3758                            }
3759    
3760                            query.append(_SQL_SELECT_JOURNALTEMPLATE_WHERE);
3761    
3762                            query.append(_FINDER_COLUMN_G_S_GROUPID_2);
3763    
3764                            if (structureId == null) {
3765                                    query.append(_FINDER_COLUMN_G_S_STRUCTUREID_1);
3766                            }
3767                            else {
3768                                    if (structureId.equals(StringPool.BLANK)) {
3769                                            query.append(_FINDER_COLUMN_G_S_STRUCTUREID_3);
3770                                    }
3771                                    else {
3772                                            query.append(_FINDER_COLUMN_G_S_STRUCTUREID_2);
3773                                    }
3774                            }
3775    
3776                            if (orderByComparator != null) {
3777                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3778                                            orderByComparator);
3779                            }
3780    
3781                            else {
3782                                    query.append(JournalTemplateModelImpl.ORDER_BY_JPQL);
3783                            }
3784    
3785                            String sql = query.toString();
3786    
3787                            Session session = null;
3788    
3789                            try {
3790                                    session = openSession();
3791    
3792                                    Query q = session.createQuery(sql);
3793    
3794                                    QueryPos qPos = QueryPos.getInstance(q);
3795    
3796                                    qPos.add(groupId);
3797    
3798                                    if (structureId != null) {
3799                                            qPos.add(structureId);
3800                                    }
3801    
3802                                    list = (List<JournalTemplate>)QueryUtil.list(q, getDialect(),
3803                                                    start, end);
3804                            }
3805                            catch (Exception e) {
3806                                    throw processException(e);
3807                            }
3808                            finally {
3809                                    if (list == null) {
3810                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
3811                                    }
3812                                    else {
3813                                            cacheResult(list);
3814    
3815                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
3816                                    }
3817    
3818                                    closeSession(session);
3819                            }
3820                    }
3821    
3822                    return list;
3823            }
3824    
3825            /**
3826             * Returns the first journal template in the ordered set where groupId = &#63; and structureId = &#63;.
3827             *
3828             * @param groupId the group ID
3829             * @param structureId the structure ID
3830             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3831             * @return the first matching journal template
3832             * @throws com.liferay.portlet.journal.NoSuchTemplateException if a matching journal template could not be found
3833             * @throws SystemException if a system exception occurred
3834             */
3835            public JournalTemplate findByG_S_First(long groupId, String structureId,
3836                    OrderByComparator orderByComparator)
3837                    throws NoSuchTemplateException, SystemException {
3838                    JournalTemplate journalTemplate = fetchByG_S_First(groupId,
3839                                    structureId, orderByComparator);
3840    
3841                    if (journalTemplate != null) {
3842                            return journalTemplate;
3843                    }
3844    
3845                    StringBundler msg = new StringBundler(6);
3846    
3847                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3848    
3849                    msg.append("groupId=");
3850                    msg.append(groupId);
3851    
3852                    msg.append(", structureId=");
3853                    msg.append(structureId);
3854    
3855                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3856    
3857                    throw new NoSuchTemplateException(msg.toString());
3858            }
3859    
3860            /**
3861             * Returns the first journal template in the ordered set where groupId = &#63; and structureId = &#63;.
3862             *
3863             * @param groupId the group ID
3864             * @param structureId the structure ID
3865             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3866             * @return the first matching journal template, or <code>null</code> if a matching journal template could not be found
3867             * @throws SystemException if a system exception occurred
3868             */
3869            public JournalTemplate fetchByG_S_First(long groupId, String structureId,
3870                    OrderByComparator orderByComparator) throws SystemException {
3871                    List<JournalTemplate> list = findByG_S(groupId, structureId, 0, 1,
3872                                    orderByComparator);
3873    
3874                    if (!list.isEmpty()) {
3875                            return list.get(0);
3876                    }
3877    
3878                    return null;
3879            }
3880    
3881            /**
3882             * Returns the last journal template in the ordered set where groupId = &#63; and structureId = &#63;.
3883             *
3884             * @param groupId the group ID
3885             * @param structureId the structure ID
3886             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3887             * @return the last matching journal template
3888             * @throws com.liferay.portlet.journal.NoSuchTemplateException if a matching journal template could not be found
3889             * @throws SystemException if a system exception occurred
3890             */
3891            public JournalTemplate findByG_S_Last(long groupId, String structureId,
3892                    OrderByComparator orderByComparator)
3893                    throws NoSuchTemplateException, SystemException {
3894                    JournalTemplate journalTemplate = fetchByG_S_Last(groupId, structureId,
3895                                    orderByComparator);
3896    
3897                    if (journalTemplate != null) {
3898                            return journalTemplate;
3899                    }
3900    
3901                    StringBundler msg = new StringBundler(6);
3902    
3903                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3904    
3905                    msg.append("groupId=");
3906                    msg.append(groupId);
3907    
3908                    msg.append(", structureId=");
3909                    msg.append(structureId);
3910    
3911                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3912    
3913                    throw new NoSuchTemplateException(msg.toString());
3914            }
3915    
3916            /**
3917             * Returns the last journal template in the ordered set where groupId = &#63; and structureId = &#63;.
3918             *
3919             * @param groupId the group ID
3920             * @param structureId the structure ID
3921             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3922             * @return the last matching journal template, or <code>null</code> if a matching journal template could not be found
3923             * @throws SystemException if a system exception occurred
3924             */
3925            public JournalTemplate fetchByG_S_Last(long groupId, String structureId,
3926                    OrderByComparator orderByComparator) throws SystemException {
3927                    int count = countByG_S(groupId, structureId);
3928    
3929                    List<JournalTemplate> list = findByG_S(groupId, structureId, count - 1,
3930                                    count, orderByComparator);
3931    
3932                    if (!list.isEmpty()) {
3933                            return list.get(0);
3934                    }
3935    
3936                    return null;
3937            }
3938    
3939            /**
3940             * Returns the journal templates before and after the current journal template in the ordered set where groupId = &#63; and structureId = &#63;.
3941             *
3942             * @param id the primary key of the current journal template
3943             * @param groupId the group ID
3944             * @param structureId the structure ID
3945             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3946             * @return the previous, current, and next journal template
3947             * @throws com.liferay.portlet.journal.NoSuchTemplateException if a journal template with the primary key could not be found
3948             * @throws SystemException if a system exception occurred
3949             */
3950            public JournalTemplate[] findByG_S_PrevAndNext(long id, long groupId,
3951                    String structureId, OrderByComparator orderByComparator)
3952                    throws NoSuchTemplateException, SystemException {
3953                    JournalTemplate journalTemplate = findByPrimaryKey(id);
3954    
3955                    Session session = null;
3956    
3957                    try {
3958                            session = openSession();
3959    
3960                            JournalTemplate[] array = new JournalTemplateImpl[3];
3961    
3962                            array[0] = getByG_S_PrevAndNext(session, journalTemplate, groupId,
3963                                            structureId, orderByComparator, true);
3964    
3965                            array[1] = journalTemplate;
3966    
3967                            array[2] = getByG_S_PrevAndNext(session, journalTemplate, groupId,
3968                                            structureId, orderByComparator, false);
3969    
3970                            return array;
3971                    }
3972                    catch (Exception e) {
3973                            throw processException(e);
3974                    }
3975                    finally {
3976                            closeSession(session);
3977                    }
3978            }
3979    
3980            protected JournalTemplate getByG_S_PrevAndNext(Session session,
3981                    JournalTemplate journalTemplate, long groupId, String structureId,
3982                    OrderByComparator orderByComparator, boolean previous) {
3983                    StringBundler query = null;
3984    
3985                    if (orderByComparator != null) {
3986                            query = new StringBundler(6 +
3987                                            (orderByComparator.getOrderByFields().length * 6));
3988                    }
3989                    else {
3990                            query = new StringBundler(3);
3991                    }
3992    
3993                    query.append(_SQL_SELECT_JOURNALTEMPLATE_WHERE);
3994    
3995                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
3996    
3997                    if (structureId == null) {
3998                            query.append(_FINDER_COLUMN_G_S_STRUCTUREID_1);
3999                    }
4000                    else {
4001                            if (structureId.equals(StringPool.BLANK)) {
4002                                    query.append(_FINDER_COLUMN_G_S_STRUCTUREID_3);
4003                            }
4004                            else {
4005                                    query.append(_FINDER_COLUMN_G_S_STRUCTUREID_2);
4006                            }
4007                    }
4008    
4009                    if (orderByComparator != null) {
4010                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4011    
4012                            if (orderByConditionFields.length > 0) {
4013                                    query.append(WHERE_AND);
4014                            }
4015    
4016                            for (int i = 0; i < orderByConditionFields.length; i++) {
4017                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4018                                    query.append(orderByConditionFields[i]);
4019    
4020                                    if ((i + 1) < orderByConditionFields.length) {
4021                                            if (orderByComparator.isAscending() ^ previous) {
4022                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4023                                            }
4024                                            else {
4025                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4026                                            }
4027                                    }
4028                                    else {
4029                                            if (orderByComparator.isAscending() ^ previous) {
4030                                                    query.append(WHERE_GREATER_THAN);
4031                                            }
4032                                            else {
4033                                                    query.append(WHERE_LESSER_THAN);
4034                                            }
4035                                    }
4036                            }
4037    
4038                            query.append(ORDER_BY_CLAUSE);
4039    
4040                            String[] orderByFields = orderByComparator.getOrderByFields();
4041    
4042                            for (int i = 0; i < orderByFields.length; i++) {
4043                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4044                                    query.append(orderByFields[i]);
4045    
4046                                    if ((i + 1) < orderByFields.length) {
4047                                            if (orderByComparator.isAscending() ^ previous) {
4048                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4049                                            }
4050                                            else {
4051                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4052                                            }
4053                                    }
4054                                    else {
4055                                            if (orderByComparator.isAscending() ^ previous) {
4056                                                    query.append(ORDER_BY_ASC);
4057                                            }
4058                                            else {
4059                                                    query.append(ORDER_BY_DESC);
4060                                            }
4061                                    }
4062                            }
4063                    }
4064    
4065                    else {
4066                            query.append(JournalTemplateModelImpl.ORDER_BY_JPQL);
4067                    }
4068    
4069                    String sql = query.toString();
4070    
4071                    Query q = session.createQuery(sql);
4072    
4073                    q.setFirstResult(0);
4074                    q.setMaxResults(2);
4075    
4076                    QueryPos qPos = QueryPos.getInstance(q);
4077    
4078                    qPos.add(groupId);
4079    
4080                    if (structureId != null) {
4081                            qPos.add(structureId);
4082                    }
4083    
4084                    if (orderByComparator != null) {
4085                            Object[] values = orderByComparator.getOrderByConditionValues(journalTemplate);
4086    
4087                            for (Object value : values) {
4088                                    qPos.add(value);
4089                            }
4090                    }
4091    
4092                    List<JournalTemplate> list = q.list();
4093    
4094                    if (list.size() == 2) {
4095                            return list.get(1);
4096                    }
4097                    else {
4098                            return null;
4099                    }
4100            }
4101    
4102            /**
4103             * Returns all the journal templates that the user has permission to view where groupId = &#63; and structureId = &#63;.
4104             *
4105             * @param groupId the group ID
4106             * @param structureId the structure ID
4107             * @return the matching journal templates that the user has permission to view
4108             * @throws SystemException if a system exception occurred
4109             */
4110            public List<JournalTemplate> filterFindByG_S(long groupId,
4111                    String structureId) throws SystemException {
4112                    return filterFindByG_S(groupId, structureId, QueryUtil.ALL_POS,
4113                            QueryUtil.ALL_POS, null);
4114            }
4115    
4116            /**
4117             * Returns a range of all the journal templates that the user has permission to view where groupId = &#63; and structureId = &#63;.
4118             *
4119             * <p>
4120             * 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.
4121             * </p>
4122             *
4123             * @param groupId the group ID
4124             * @param structureId the structure ID
4125             * @param start the lower bound of the range of journal templates
4126             * @param end the upper bound of the range of journal templates (not inclusive)
4127             * @return the range of matching journal templates that the user has permission to view
4128             * @throws SystemException if a system exception occurred
4129             */
4130            public List<JournalTemplate> filterFindByG_S(long groupId,
4131                    String structureId, int start, int end) throws SystemException {
4132                    return filterFindByG_S(groupId, structureId, start, end, null);
4133            }
4134    
4135            /**
4136             * Returns an ordered range of all the journal templates that the user has permissions to view where groupId = &#63; and structureId = &#63;.
4137             *
4138             * <p>
4139             * 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.
4140             * </p>
4141             *
4142             * @param groupId the group ID
4143             * @param structureId the structure ID
4144             * @param start the lower bound of the range of journal templates
4145             * @param end the upper bound of the range of journal templates (not inclusive)
4146             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4147             * @return the ordered range of matching journal templates that the user has permission to view
4148             * @throws SystemException if a system exception occurred
4149             */
4150            public List<JournalTemplate> filterFindByG_S(long groupId,
4151                    String structureId, int start, int end,
4152                    OrderByComparator orderByComparator) throws SystemException {
4153                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4154                            return findByG_S(groupId, structureId, start, end, orderByComparator);
4155                    }
4156    
4157                    StringBundler query = null;
4158    
4159                    if (orderByComparator != null) {
4160                            query = new StringBundler(4 +
4161                                            (orderByComparator.getOrderByFields().length * 3));
4162                    }
4163                    else {
4164                            query = new StringBundler(4);
4165                    }
4166    
4167                    if (getDB().isSupportsInlineDistinct()) {
4168                            query.append(_FILTER_SQL_SELECT_JOURNALTEMPLATE_WHERE);
4169                    }
4170                    else {
4171                            query.append(_FILTER_SQL_SELECT_JOURNALTEMPLATE_NO_INLINE_DISTINCT_WHERE_1);
4172                    }
4173    
4174                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
4175    
4176                    if (structureId == null) {
4177                            query.append(_FINDER_COLUMN_G_S_STRUCTUREID_1);
4178                    }
4179                    else {
4180                            if (structureId.equals(StringPool.BLANK)) {
4181                                    query.append(_FINDER_COLUMN_G_S_STRUCTUREID_3);
4182                            }
4183                            else {
4184                                    query.append(_FINDER_COLUMN_G_S_STRUCTUREID_2);
4185                            }
4186                    }
4187    
4188                    if (!getDB().isSupportsInlineDistinct()) {
4189                            query.append(_FILTER_SQL_SELECT_JOURNALTEMPLATE_NO_INLINE_DISTINCT_WHERE_2);
4190                    }
4191    
4192                    if (orderByComparator != null) {
4193                            if (getDB().isSupportsInlineDistinct()) {
4194                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4195                                            orderByComparator);
4196                            }
4197                            else {
4198                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
4199                                            orderByComparator);
4200                            }
4201                    }
4202    
4203                    else {
4204                            if (getDB().isSupportsInlineDistinct()) {
4205                                    query.append(JournalTemplateModelImpl.ORDER_BY_JPQL);
4206                            }
4207                            else {
4208                                    query.append(JournalTemplateModelImpl.ORDER_BY_SQL);
4209                            }
4210                    }
4211    
4212                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4213                                    JournalTemplate.class.getName(),
4214                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4215    
4216                    Session session = null;
4217    
4218                    try {
4219                            session = openSession();
4220    
4221                            SQLQuery q = session.createSQLQuery(sql);
4222    
4223                            if (getDB().isSupportsInlineDistinct()) {
4224                                    q.addEntity(_FILTER_ENTITY_ALIAS, JournalTemplateImpl.class);
4225                            }
4226                            else {
4227                                    q.addEntity(_FILTER_ENTITY_TABLE, JournalTemplateImpl.class);
4228                            }
4229    
4230                            QueryPos qPos = QueryPos.getInstance(q);
4231    
4232                            qPos.add(groupId);
4233    
4234                            if (structureId != null) {
4235                                    qPos.add(structureId);
4236                            }
4237    
4238                            return (List<JournalTemplate>)QueryUtil.list(q, getDialect(),
4239                                    start, end);
4240                    }
4241                    catch (Exception e) {
4242                            throw processException(e);
4243                    }
4244                    finally {
4245                            closeSession(session);
4246                    }
4247            }
4248    
4249            /**
4250             * 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;.
4251             *
4252             * @param id the primary key of the current journal template
4253             * @param groupId the group ID
4254             * @param structureId the structure ID
4255             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4256             * @return the previous, current, and next journal template
4257             * @throws com.liferay.portlet.journal.NoSuchTemplateException if a journal template with the primary key could not be found
4258             * @throws SystemException if a system exception occurred
4259             */
4260            public JournalTemplate[] filterFindByG_S_PrevAndNext(long id, long groupId,
4261                    String structureId, OrderByComparator orderByComparator)
4262                    throws NoSuchTemplateException, SystemException {
4263                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4264                            return findByG_S_PrevAndNext(id, groupId, structureId,
4265                                    orderByComparator);
4266                    }
4267    
4268                    JournalTemplate journalTemplate = findByPrimaryKey(id);
4269    
4270                    Session session = null;
4271    
4272                    try {
4273                            session = openSession();
4274    
4275                            JournalTemplate[] array = new JournalTemplateImpl[3];
4276    
4277                            array[0] = filterGetByG_S_PrevAndNext(session, journalTemplate,
4278                                            groupId, structureId, orderByComparator, true);
4279    
4280                            array[1] = journalTemplate;
4281    
4282                            array[2] = filterGetByG_S_PrevAndNext(session, journalTemplate,
4283                                            groupId, structureId, orderByComparator, false);
4284    
4285                            return array;
4286                    }
4287                    catch (Exception e) {
4288                            throw processException(e);
4289                    }
4290                    finally {
4291                            closeSession(session);
4292                    }
4293            }
4294    
4295            protected JournalTemplate filterGetByG_S_PrevAndNext(Session session,
4296                    JournalTemplate journalTemplate, long groupId, String structureId,
4297                    OrderByComparator orderByComparator, boolean previous) {
4298                    StringBundler query = null;
4299    
4300                    if (orderByComparator != null) {
4301                            query = new StringBundler(6 +
4302                                            (orderByComparator.getOrderByFields().length * 6));
4303                    }
4304                    else {
4305                            query = new StringBundler(3);
4306                    }
4307    
4308                    if (getDB().isSupportsInlineDistinct()) {
4309                            query.append(_FILTER_SQL_SELECT_JOURNALTEMPLATE_WHERE);
4310                    }
4311                    else {
4312                            query.append(_FILTER_SQL_SELECT_JOURNALTEMPLATE_NO_INLINE_DISTINCT_WHERE_1);
4313                    }
4314    
4315                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
4316    
4317                    if (structureId == null) {
4318                            query.append(_FINDER_COLUMN_G_S_STRUCTUREID_1);
4319                    }
4320                    else {
4321                            if (structureId.equals(StringPool.BLANK)) {
4322                                    query.append(_FINDER_COLUMN_G_S_STRUCTUREID_3);
4323                            }
4324                            else {
4325                                    query.append(_FINDER_COLUMN_G_S_STRUCTUREID_2);
4326                            }
4327                    }
4328    
4329                    if (!getDB().isSupportsInlineDistinct()) {
4330                            query.append(_FILTER_SQL_SELECT_JOURNALTEMPLATE_NO_INLINE_DISTINCT_WHERE_2);
4331                    }
4332    
4333                    if (orderByComparator != null) {
4334                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4335    
4336                            if (orderByConditionFields.length > 0) {
4337                                    query.append(WHERE_AND);
4338                            }
4339    
4340                            for (int i = 0; i < orderByConditionFields.length; i++) {
4341                                    if (getDB().isSupportsInlineDistinct()) {
4342                                            query.append(_ORDER_BY_ENTITY_ALIAS);
4343                                    }
4344                                    else {
4345                                            query.append(_ORDER_BY_ENTITY_TABLE);
4346                                    }
4347    
4348                                    query.append(orderByConditionFields[i]);
4349    
4350                                    if ((i + 1) < orderByConditionFields.length) {
4351                                            if (orderByComparator.isAscending() ^ previous) {
4352                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4353                                            }
4354                                            else {
4355                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4356                                            }
4357                                    }
4358                                    else {
4359                                            if (orderByComparator.isAscending() ^ previous) {
4360                                                    query.append(WHERE_GREATER_THAN);
4361                                            }
4362                                            else {
4363                                                    query.append(WHERE_LESSER_THAN);
4364                                            }
4365                                    }
4366                            }
4367    
4368                            query.append(ORDER_BY_CLAUSE);
4369    
4370                            String[] orderByFields = orderByComparator.getOrderByFields();
4371    
4372                            for (int i = 0; i < orderByFields.length; i++) {
4373                                    if (getDB().isSupportsInlineDistinct()) {
4374                                            query.append(_ORDER_BY_ENTITY_ALIAS);
4375                                    }
4376                                    else {
4377                                            query.append(_ORDER_BY_ENTITY_TABLE);
4378                                    }
4379    
4380                                    query.append(orderByFields[i]);
4381    
4382                                    if ((i + 1) < orderByFields.length) {
4383                                            if (orderByComparator.isAscending() ^ previous) {
4384                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4385                                            }
4386                                            else {
4387                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4388                                            }
4389                                    }
4390                                    else {
4391                                            if (orderByComparator.isAscending() ^ previous) {
4392                                                    query.append(ORDER_BY_ASC);
4393                                            }
4394                                            else {
4395                                                    query.append(ORDER_BY_DESC);
4396                                            }
4397                                    }
4398                            }
4399                    }
4400    
4401                    else {
4402                            if (getDB().isSupportsInlineDistinct()) {
4403                                    query.append(JournalTemplateModelImpl.ORDER_BY_JPQL);
4404                            }
4405                            else {
4406                                    query.append(JournalTemplateModelImpl.ORDER_BY_SQL);
4407                            }
4408                    }
4409    
4410                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4411                                    JournalTemplate.class.getName(),
4412                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4413    
4414                    SQLQuery q = session.createSQLQuery(sql);
4415    
4416                    q.setFirstResult(0);
4417                    q.setMaxResults(2);
4418    
4419                    if (getDB().isSupportsInlineDistinct()) {
4420                            q.addEntity(_FILTER_ENTITY_ALIAS, JournalTemplateImpl.class);
4421                    }
4422                    else {
4423                            q.addEntity(_FILTER_ENTITY_TABLE, JournalTemplateImpl.class);
4424                    }
4425    
4426                    QueryPos qPos = QueryPos.getInstance(q);
4427    
4428                    qPos.add(groupId);
4429    
4430                    if (structureId != null) {
4431                            qPos.add(structureId);
4432                    }
4433    
4434                    if (orderByComparator != null) {
4435                            Object[] values = orderByComparator.getOrderByConditionValues(journalTemplate);
4436    
4437                            for (Object value : values) {
4438                                    qPos.add(value);
4439                            }
4440                    }
4441    
4442                    List<JournalTemplate> list = q.list();
4443    
4444                    if (list.size() == 2) {
4445                            return list.get(1);
4446                    }
4447                    else {
4448                            return null;
4449                    }
4450            }
4451    
4452            /**
4453             * Returns all the journal templates.
4454             *
4455             * @return the journal templates
4456             * @throws SystemException if a system exception occurred
4457             */
4458            public List<JournalTemplate> findAll() throws SystemException {
4459                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
4460            }
4461    
4462            /**
4463             * Returns a range of all the journal templates.
4464             *
4465             * <p>
4466             * 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.
4467             * </p>
4468             *
4469             * @param start the lower bound of the range of journal templates
4470             * @param end the upper bound of the range of journal templates (not inclusive)
4471             * @return the range of journal templates
4472             * @throws SystemException if a system exception occurred
4473             */
4474            public List<JournalTemplate> findAll(int start, int end)
4475                    throws SystemException {
4476                    return findAll(start, end, null);
4477            }
4478    
4479            /**
4480             * Returns an ordered range of all the journal templates.
4481             *
4482             * <p>
4483             * 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.
4484             * </p>
4485             *
4486             * @param start the lower bound of the range of journal templates
4487             * @param end the upper bound of the range of journal templates (not inclusive)
4488             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4489             * @return the ordered range of journal templates
4490             * @throws SystemException if a system exception occurred
4491             */
4492            public List<JournalTemplate> findAll(int start, int end,
4493                    OrderByComparator orderByComparator) throws SystemException {
4494                    FinderPath finderPath = null;
4495                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
4496    
4497                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4498                                    (orderByComparator == null)) {
4499                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
4500                            finderArgs = FINDER_ARGS_EMPTY;
4501                    }
4502                    else {
4503                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
4504                            finderArgs = new Object[] { start, end, orderByComparator };
4505                    }
4506    
4507                    List<JournalTemplate> list = (List<JournalTemplate>)FinderCacheUtil.getResult(finderPath,
4508                                    finderArgs, this);
4509    
4510                    if (list == null) {
4511                            StringBundler query = null;
4512                            String sql = null;
4513    
4514                            if (orderByComparator != null) {
4515                                    query = new StringBundler(2 +
4516                                                    (orderByComparator.getOrderByFields().length * 3));
4517    
4518                                    query.append(_SQL_SELECT_JOURNALTEMPLATE);
4519    
4520                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4521                                            orderByComparator);
4522    
4523                                    sql = query.toString();
4524                            }
4525                            else {
4526                                    sql = _SQL_SELECT_JOURNALTEMPLATE.concat(JournalTemplateModelImpl.ORDER_BY_JPQL);
4527                            }
4528    
4529                            Session session = null;
4530    
4531                            try {
4532                                    session = openSession();
4533    
4534                                    Query q = session.createQuery(sql);
4535    
4536                                    if (orderByComparator == null) {
4537                                            list = (List<JournalTemplate>)QueryUtil.list(q,
4538                                                            getDialect(), start, end, false);
4539    
4540                                            Collections.sort(list);
4541                                    }
4542                                    else {
4543                                            list = (List<JournalTemplate>)QueryUtil.list(q,
4544                                                            getDialect(), start, end);
4545                                    }
4546                            }
4547                            catch (Exception e) {
4548                                    throw processException(e);
4549                            }
4550                            finally {
4551                                    if (list == null) {
4552                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
4553                                    }
4554                                    else {
4555                                            cacheResult(list);
4556    
4557                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
4558                                    }
4559    
4560                                    closeSession(session);
4561                            }
4562                    }
4563    
4564                    return list;
4565            }
4566    
4567            /**
4568             * Removes all the journal templates where uuid = &#63; from the database.
4569             *
4570             * @param uuid the uuid
4571             * @throws SystemException if a system exception occurred
4572             */
4573            public void removeByUuid(String uuid) throws SystemException {
4574                    for (JournalTemplate journalTemplate : findByUuid(uuid)) {
4575                            remove(journalTemplate);
4576                    }
4577            }
4578    
4579            /**
4580             * Removes the journal template where uuid = &#63; and groupId = &#63; from the database.
4581             *
4582             * @param uuid the uuid
4583             * @param groupId the group ID
4584             * @return the journal template that was removed
4585             * @throws SystemException if a system exception occurred
4586             */
4587            public JournalTemplate removeByUUID_G(String uuid, long groupId)
4588                    throws NoSuchTemplateException, SystemException {
4589                    JournalTemplate journalTemplate = findByUUID_G(uuid, groupId);
4590    
4591                    return remove(journalTemplate);
4592            }
4593    
4594            /**
4595             * Removes all the journal templates where uuid = &#63; and companyId = &#63; from the database.
4596             *
4597             * @param uuid the uuid
4598             * @param companyId the company ID
4599             * @throws SystemException if a system exception occurred
4600             */
4601            public void removeByUuid_C(String uuid, long companyId)
4602                    throws SystemException {
4603                    for (JournalTemplate journalTemplate : findByUuid_C(uuid, companyId)) {
4604                            remove(journalTemplate);
4605                    }
4606            }
4607    
4608            /**
4609             * Removes all the journal templates where groupId = &#63; from the database.
4610             *
4611             * @param groupId the group ID
4612             * @throws SystemException if a system exception occurred
4613             */
4614            public void removeByGroupId(long groupId) throws SystemException {
4615                    for (JournalTemplate journalTemplate : findByGroupId(groupId)) {
4616                            remove(journalTemplate);
4617                    }
4618            }
4619    
4620            /**
4621             * Removes all the journal templates where templateId = &#63; from the database.
4622             *
4623             * @param templateId the template ID
4624             * @throws SystemException if a system exception occurred
4625             */
4626            public void removeByTemplateId(String templateId) throws SystemException {
4627                    for (JournalTemplate journalTemplate : findByTemplateId(templateId)) {
4628                            remove(journalTemplate);
4629                    }
4630            }
4631    
4632            /**
4633             * Removes all the journal templates where structureId = &#63; from the database.
4634             *
4635             * @param structureId the structure ID
4636             * @throws SystemException if a system exception occurred
4637             */
4638            public void removeByStructureId(String structureId)
4639                    throws SystemException {
4640                    for (JournalTemplate journalTemplate : findByStructureId(structureId)) {
4641                            remove(journalTemplate);
4642                    }
4643            }
4644    
4645            /**
4646             * Removes the journal template where smallImageId = &#63; from the database.
4647             *
4648             * @param smallImageId the small image ID
4649             * @return the journal template that was removed
4650             * @throws SystemException if a system exception occurred
4651             */
4652            public JournalTemplate removeBySmallImageId(long smallImageId)
4653                    throws NoSuchTemplateException, SystemException {
4654                    JournalTemplate journalTemplate = findBySmallImageId(smallImageId);
4655    
4656                    return remove(journalTemplate);
4657            }
4658    
4659            /**
4660             * Removes the journal template where groupId = &#63; and templateId = &#63; from the database.
4661             *
4662             * @param groupId the group ID
4663             * @param templateId the template ID
4664             * @return the journal template that was removed
4665             * @throws SystemException if a system exception occurred
4666             */
4667            public JournalTemplate removeByG_T(long groupId, String templateId)
4668                    throws NoSuchTemplateException, SystemException {
4669                    JournalTemplate journalTemplate = findByG_T(groupId, templateId);
4670    
4671                    return remove(journalTemplate);
4672            }
4673    
4674            /**
4675             * Removes all the journal templates where groupId = &#63; and structureId = &#63; from the database.
4676             *
4677             * @param groupId the group ID
4678             * @param structureId the structure ID
4679             * @throws SystemException if a system exception occurred
4680             */
4681            public void removeByG_S(long groupId, String structureId)
4682                    throws SystemException {
4683                    for (JournalTemplate journalTemplate : findByG_S(groupId, structureId)) {
4684                            remove(journalTemplate);
4685                    }
4686            }
4687    
4688            /**
4689             * Removes all the journal templates from the database.
4690             *
4691             * @throws SystemException if a system exception occurred
4692             */
4693            public void removeAll() throws SystemException {
4694                    for (JournalTemplate journalTemplate : findAll()) {
4695                            remove(journalTemplate);
4696                    }
4697            }
4698    
4699            /**
4700             * Returns the number of journal templates where uuid = &#63;.
4701             *
4702             * @param uuid the uuid
4703             * @return the number of matching journal templates
4704             * @throws SystemException if a system exception occurred
4705             */
4706            public int countByUuid(String uuid) throws SystemException {
4707                    Object[] finderArgs = new Object[] { uuid };
4708    
4709                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
4710                                    finderArgs, this);
4711    
4712                    if (count == null) {
4713                            StringBundler query = new StringBundler(2);
4714    
4715                            query.append(_SQL_COUNT_JOURNALTEMPLATE_WHERE);
4716    
4717                            if (uuid == null) {
4718                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
4719                            }
4720                            else {
4721                                    if (uuid.equals(StringPool.BLANK)) {
4722                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
4723                                    }
4724                                    else {
4725                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
4726                                    }
4727                            }
4728    
4729                            String sql = query.toString();
4730    
4731                            Session session = null;
4732    
4733                            try {
4734                                    session = openSession();
4735    
4736                                    Query q = session.createQuery(sql);
4737    
4738                                    QueryPos qPos = QueryPos.getInstance(q);
4739    
4740                                    if (uuid != null) {
4741                                            qPos.add(uuid);
4742                                    }
4743    
4744                                    count = (Long)q.uniqueResult();
4745                            }
4746                            catch (Exception e) {
4747                                    throw processException(e);
4748                            }
4749                            finally {
4750                                    if (count == null) {
4751                                            count = Long.valueOf(0);
4752                                    }
4753    
4754                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
4755                                            finderArgs, count);
4756    
4757                                    closeSession(session);
4758                            }
4759                    }
4760    
4761                    return count.intValue();
4762            }
4763    
4764            /**
4765             * Returns the number of journal templates where uuid = &#63; and groupId = &#63;.
4766             *
4767             * @param uuid the uuid
4768             * @param groupId the group ID
4769             * @return the number of matching journal templates
4770             * @throws SystemException if a system exception occurred
4771             */
4772            public int countByUUID_G(String uuid, long groupId)
4773                    throws SystemException {
4774                    Object[] finderArgs = new Object[] { uuid, groupId };
4775    
4776                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
4777                                    finderArgs, this);
4778    
4779                    if (count == null) {
4780                            StringBundler query = new StringBundler(3);
4781    
4782                            query.append(_SQL_COUNT_JOURNALTEMPLATE_WHERE);
4783    
4784                            if (uuid == null) {
4785                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
4786                            }
4787                            else {
4788                                    if (uuid.equals(StringPool.BLANK)) {
4789                                            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
4790                                    }
4791                                    else {
4792                                            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
4793                                    }
4794                            }
4795    
4796                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
4797    
4798                            String sql = query.toString();
4799    
4800                            Session session = null;
4801    
4802                            try {
4803                                    session = openSession();
4804    
4805                                    Query q = session.createQuery(sql);
4806    
4807                                    QueryPos qPos = QueryPos.getInstance(q);
4808    
4809                                    if (uuid != null) {
4810                                            qPos.add(uuid);
4811                                    }
4812    
4813                                    qPos.add(groupId);
4814    
4815                                    count = (Long)q.uniqueResult();
4816                            }
4817                            catch (Exception e) {
4818                                    throw processException(e);
4819                            }
4820                            finally {
4821                                    if (count == null) {
4822                                            count = Long.valueOf(0);
4823                                    }
4824    
4825                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
4826                                            finderArgs, count);
4827    
4828                                    closeSession(session);
4829                            }
4830                    }
4831    
4832                    return count.intValue();
4833            }
4834    
4835            /**
4836             * Returns the number of journal templates where uuid = &#63; and companyId = &#63;.
4837             *
4838             * @param uuid the uuid
4839             * @param companyId the company ID
4840             * @return the number of matching journal templates
4841             * @throws SystemException if a system exception occurred
4842             */
4843            public int countByUuid_C(String uuid, long companyId)
4844                    throws SystemException {
4845                    Object[] finderArgs = new Object[] { uuid, companyId };
4846    
4847                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_C,
4848                                    finderArgs, this);
4849    
4850                    if (count == null) {
4851                            StringBundler query = new StringBundler(3);
4852    
4853                            query.append(_SQL_COUNT_JOURNALTEMPLATE_WHERE);
4854    
4855                            if (uuid == null) {
4856                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
4857                            }
4858                            else {
4859                                    if (uuid.equals(StringPool.BLANK)) {
4860                                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
4861                                    }
4862                                    else {
4863                                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
4864                                    }
4865                            }
4866    
4867                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
4868    
4869                            String sql = query.toString();
4870    
4871                            Session session = null;
4872    
4873                            try {
4874                                    session = openSession();
4875    
4876                                    Query q = session.createQuery(sql);
4877    
4878                                    QueryPos qPos = QueryPos.getInstance(q);
4879    
4880                                    if (uuid != null) {
4881                                            qPos.add(uuid);
4882                                    }
4883    
4884                                    qPos.add(companyId);
4885    
4886                                    count = (Long)q.uniqueResult();
4887                            }
4888                            catch (Exception e) {
4889                                    throw processException(e);
4890                            }
4891                            finally {
4892                                    if (count == null) {
4893                                            count = Long.valueOf(0);
4894                                    }
4895    
4896                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_C,
4897                                            finderArgs, count);
4898    
4899                                    closeSession(session);
4900                            }
4901                    }
4902    
4903                    return count.intValue();
4904            }
4905    
4906            /**
4907             * Returns the number of journal templates where groupId = &#63;.
4908             *
4909             * @param groupId the group ID
4910             * @return the number of matching journal templates
4911             * @throws SystemException if a system exception occurred
4912             */
4913            public int countByGroupId(long groupId) throws SystemException {
4914                    Object[] finderArgs = new Object[] { groupId };
4915    
4916                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
4917                                    finderArgs, this);
4918    
4919                    if (count == null) {
4920                            StringBundler query = new StringBundler(2);
4921    
4922                            query.append(_SQL_COUNT_JOURNALTEMPLATE_WHERE);
4923    
4924                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
4925    
4926                            String sql = query.toString();
4927    
4928                            Session session = null;
4929    
4930                            try {
4931                                    session = openSession();
4932    
4933                                    Query q = session.createQuery(sql);
4934    
4935                                    QueryPos qPos = QueryPos.getInstance(q);
4936    
4937                                    qPos.add(groupId);
4938    
4939                                    count = (Long)q.uniqueResult();
4940                            }
4941                            catch (Exception e) {
4942                                    throw processException(e);
4943                            }
4944                            finally {
4945                                    if (count == null) {
4946                                            count = Long.valueOf(0);
4947                                    }
4948    
4949                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
4950                                            finderArgs, count);
4951    
4952                                    closeSession(session);
4953                            }
4954                    }
4955    
4956                    return count.intValue();
4957            }
4958    
4959            /**
4960             * Returns the number of journal templates that the user has permission to view where groupId = &#63;.
4961             *
4962             * @param groupId the group ID
4963             * @return the number of matching journal templates that the user has permission to view
4964             * @throws SystemException if a system exception occurred
4965             */
4966            public int filterCountByGroupId(long groupId) throws SystemException {
4967                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4968                            return countByGroupId(groupId);
4969                    }
4970    
4971                    StringBundler query = new StringBundler(2);
4972    
4973                    query.append(_FILTER_SQL_COUNT_JOURNALTEMPLATE_WHERE);
4974    
4975                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
4976    
4977                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4978                                    JournalTemplate.class.getName(),
4979                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4980    
4981                    Session session = null;
4982    
4983                    try {
4984                            session = openSession();
4985    
4986                            SQLQuery q = session.createSQLQuery(sql);
4987    
4988                            q.addScalar(COUNT_COLUMN_NAME,
4989                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
4990    
4991                            QueryPos qPos = QueryPos.getInstance(q);
4992    
4993                            qPos.add(groupId);
4994    
4995                            Long count = (Long)q.uniqueResult();
4996    
4997                            return count.intValue();
4998                    }
4999                    catch (Exception e) {
5000                            throw processException(e);
5001                    }
5002                    finally {
5003                            closeSession(session);
5004                    }
5005            }
5006    
5007            /**
5008             * Returns the number of journal templates where templateId = &#63;.
5009             *
5010             * @param templateId the template ID
5011             * @return the number of matching journal templates
5012             * @throws SystemException if a system exception occurred
5013             */
5014            public int countByTemplateId(String templateId) throws SystemException {
5015                    Object[] finderArgs = new Object[] { templateId };
5016    
5017                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_TEMPLATEID,
5018                                    finderArgs, this);
5019    
5020                    if (count == null) {
5021                            StringBundler query = new StringBundler(2);
5022    
5023                            query.append(_SQL_COUNT_JOURNALTEMPLATE_WHERE);
5024    
5025                            if (templateId == null) {
5026                                    query.append(_FINDER_COLUMN_TEMPLATEID_TEMPLATEID_1);
5027                            }
5028                            else {
5029                                    if (templateId.equals(StringPool.BLANK)) {
5030                                            query.append(_FINDER_COLUMN_TEMPLATEID_TEMPLATEID_3);
5031                                    }
5032                                    else {
5033                                            query.append(_FINDER_COLUMN_TEMPLATEID_TEMPLATEID_2);
5034                                    }
5035                            }
5036    
5037                            String sql = query.toString();
5038    
5039                            Session session = null;
5040    
5041                            try {
5042                                    session = openSession();
5043    
5044                                    Query q = session.createQuery(sql);
5045    
5046                                    QueryPos qPos = QueryPos.getInstance(q);
5047    
5048                                    if (templateId != null) {
5049                                            qPos.add(templateId);
5050                                    }
5051    
5052                                    count = (Long)q.uniqueResult();
5053                            }
5054                            catch (Exception e) {
5055                                    throw processException(e);
5056                            }
5057                            finally {
5058                                    if (count == null) {
5059                                            count = Long.valueOf(0);
5060                                    }
5061    
5062                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_TEMPLATEID,
5063                                            finderArgs, count);
5064    
5065                                    closeSession(session);
5066                            }
5067                    }
5068    
5069                    return count.intValue();
5070            }
5071    
5072            /**
5073             * Returns the number of journal templates where structureId = &#63;.
5074             *
5075             * @param structureId the structure ID
5076             * @return the number of matching journal templates
5077             * @throws SystemException if a system exception occurred
5078             */
5079            public int countByStructureId(String structureId) throws SystemException {
5080                    Object[] finderArgs = new Object[] { structureId };
5081    
5082                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_STRUCTUREID,
5083                                    finderArgs, this);
5084    
5085                    if (count == null) {
5086                            StringBundler query = new StringBundler(2);
5087    
5088                            query.append(_SQL_COUNT_JOURNALTEMPLATE_WHERE);
5089    
5090                            if (structureId == null) {
5091                                    query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_1);
5092                            }
5093                            else {
5094                                    if (structureId.equals(StringPool.BLANK)) {
5095                                            query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_3);
5096                                    }
5097                                    else {
5098                                            query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_2);
5099                                    }
5100                            }
5101    
5102                            String sql = query.toString();
5103    
5104                            Session session = null;
5105    
5106                            try {
5107                                    session = openSession();
5108    
5109                                    Query q = session.createQuery(sql);
5110    
5111                                    QueryPos qPos = QueryPos.getInstance(q);
5112    
5113                                    if (structureId != null) {
5114                                            qPos.add(structureId);
5115                                    }
5116    
5117                                    count = (Long)q.uniqueResult();
5118                            }
5119                            catch (Exception e) {
5120                                    throw processException(e);
5121                            }
5122                            finally {
5123                                    if (count == null) {
5124                                            count = Long.valueOf(0);
5125                                    }
5126    
5127                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_STRUCTUREID,
5128                                            finderArgs, count);
5129    
5130                                    closeSession(session);
5131                            }
5132                    }
5133    
5134                    return count.intValue();
5135            }
5136    
5137            /**
5138             * Returns the number of journal templates where smallImageId = &#63;.
5139             *
5140             * @param smallImageId the small image ID
5141             * @return the number of matching journal templates
5142             * @throws SystemException if a system exception occurred
5143             */
5144            public int countBySmallImageId(long smallImageId) throws SystemException {
5145                    Object[] finderArgs = new Object[] { smallImageId };
5146    
5147                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_SMALLIMAGEID,
5148                                    finderArgs, this);
5149    
5150                    if (count == null) {
5151                            StringBundler query = new StringBundler(2);
5152    
5153                            query.append(_SQL_COUNT_JOURNALTEMPLATE_WHERE);
5154    
5155                            query.append(_FINDER_COLUMN_SMALLIMAGEID_SMALLIMAGEID_2);
5156    
5157                            String sql = query.toString();
5158    
5159                            Session session = null;
5160    
5161                            try {
5162                                    session = openSession();
5163    
5164                                    Query q = session.createQuery(sql);
5165    
5166                                    QueryPos qPos = QueryPos.getInstance(q);
5167    
5168                                    qPos.add(smallImageId);
5169    
5170                                    count = (Long)q.uniqueResult();
5171                            }
5172                            catch (Exception e) {
5173                                    throw processException(e);
5174                            }
5175                            finally {
5176                                    if (count == null) {
5177                                            count = Long.valueOf(0);
5178                                    }
5179    
5180                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_SMALLIMAGEID,
5181                                            finderArgs, count);
5182    
5183                                    closeSession(session);
5184                            }
5185                    }
5186    
5187                    return count.intValue();
5188            }
5189    
5190            /**
5191             * Returns the number of journal templates where groupId = &#63; and templateId = &#63;.
5192             *
5193             * @param groupId the group ID
5194             * @param templateId the template ID
5195             * @return the number of matching journal templates
5196             * @throws SystemException if a system exception occurred
5197             */
5198            public int countByG_T(long groupId, String templateId)
5199                    throws SystemException {
5200                    Object[] finderArgs = new Object[] { groupId, templateId };
5201    
5202                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_T,
5203                                    finderArgs, this);
5204    
5205                    if (count == null) {
5206                            StringBundler query = new StringBundler(3);
5207    
5208                            query.append(_SQL_COUNT_JOURNALTEMPLATE_WHERE);
5209    
5210                            query.append(_FINDER_COLUMN_G_T_GROUPID_2);
5211    
5212                            if (templateId == null) {
5213                                    query.append(_FINDER_COLUMN_G_T_TEMPLATEID_1);
5214                            }
5215                            else {
5216                                    if (templateId.equals(StringPool.BLANK)) {
5217                                            query.append(_FINDER_COLUMN_G_T_TEMPLATEID_3);
5218                                    }
5219                                    else {
5220                                            query.append(_FINDER_COLUMN_G_T_TEMPLATEID_2);
5221                                    }
5222                            }
5223    
5224                            String sql = query.toString();
5225    
5226                            Session session = null;
5227    
5228                            try {
5229                                    session = openSession();
5230    
5231                                    Query q = session.createQuery(sql);
5232    
5233                                    QueryPos qPos = QueryPos.getInstance(q);
5234    
5235                                    qPos.add(groupId);
5236    
5237                                    if (templateId != null) {
5238                                            qPos.add(templateId);
5239                                    }
5240    
5241                                    count = (Long)q.uniqueResult();
5242                            }
5243                            catch (Exception e) {
5244                                    throw processException(e);
5245                            }
5246                            finally {
5247                                    if (count == null) {
5248                                            count = Long.valueOf(0);
5249                                    }
5250    
5251                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_T, finderArgs,
5252                                            count);
5253    
5254                                    closeSession(session);
5255                            }
5256                    }
5257    
5258                    return count.intValue();
5259            }
5260    
5261            /**
5262             * Returns the number of journal templates where groupId = &#63; and structureId = &#63;.
5263             *
5264             * @param groupId the group ID
5265             * @param structureId the structure ID
5266             * @return the number of matching journal templates
5267             * @throws SystemException if a system exception occurred
5268             */
5269            public int countByG_S(long groupId, String structureId)
5270                    throws SystemException {
5271                    Object[] finderArgs = new Object[] { groupId, structureId };
5272    
5273                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_S,
5274                                    finderArgs, this);
5275    
5276                    if (count == null) {
5277                            StringBundler query = new StringBundler(3);
5278    
5279                            query.append(_SQL_COUNT_JOURNALTEMPLATE_WHERE);
5280    
5281                            query.append(_FINDER_COLUMN_G_S_GROUPID_2);
5282    
5283                            if (structureId == null) {
5284                                    query.append(_FINDER_COLUMN_G_S_STRUCTUREID_1);
5285                            }
5286                            else {
5287                                    if (structureId.equals(StringPool.BLANK)) {
5288                                            query.append(_FINDER_COLUMN_G_S_STRUCTUREID_3);
5289                                    }
5290                                    else {
5291                                            query.append(_FINDER_COLUMN_G_S_STRUCTUREID_2);
5292                                    }
5293                            }
5294    
5295                            String sql = query.toString();
5296    
5297                            Session session = null;
5298    
5299                            try {
5300                                    session = openSession();
5301    
5302                                    Query q = session.createQuery(sql);
5303    
5304                                    QueryPos qPos = QueryPos.getInstance(q);
5305    
5306                                    qPos.add(groupId);
5307    
5308                                    if (structureId != null) {
5309                                            qPos.add(structureId);
5310                                    }
5311    
5312                                    count = (Long)q.uniqueResult();
5313                            }
5314                            catch (Exception e) {
5315                                    throw processException(e);
5316                            }
5317                            finally {
5318                                    if (count == null) {
5319                                            count = Long.valueOf(0);
5320                                    }
5321    
5322                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_S, finderArgs,
5323                                            count);
5324    
5325                                    closeSession(session);
5326                            }
5327                    }
5328    
5329                    return count.intValue();
5330            }
5331    
5332            /**
5333             * Returns the number of journal templates that the user has permission to view where groupId = &#63; and structureId = &#63;.
5334             *
5335             * @param groupId the group ID
5336             * @param structureId the structure ID
5337             * @return the number of matching journal templates that the user has permission to view
5338             * @throws SystemException if a system exception occurred
5339             */
5340            public int filterCountByG_S(long groupId, String structureId)
5341                    throws SystemException {
5342                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5343                            return countByG_S(groupId, structureId);
5344                    }
5345    
5346                    StringBundler query = new StringBundler(3);
5347    
5348                    query.append(_FILTER_SQL_COUNT_JOURNALTEMPLATE_WHERE);
5349    
5350                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
5351    
5352                    if (structureId == null) {
5353                            query.append(_FINDER_COLUMN_G_S_STRUCTUREID_1);
5354                    }
5355                    else {
5356                            if (structureId.equals(StringPool.BLANK)) {
5357                                    query.append(_FINDER_COLUMN_G_S_STRUCTUREID_3);
5358                            }
5359                            else {
5360                                    query.append(_FINDER_COLUMN_G_S_STRUCTUREID_2);
5361                            }
5362                    }
5363    
5364                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5365                                    JournalTemplate.class.getName(),
5366                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5367    
5368                    Session session = null;
5369    
5370                    try {
5371                            session = openSession();
5372    
5373                            SQLQuery q = session.createSQLQuery(sql);
5374    
5375                            q.addScalar(COUNT_COLUMN_NAME,
5376                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
5377    
5378                            QueryPos qPos = QueryPos.getInstance(q);
5379    
5380                            qPos.add(groupId);
5381    
5382                            if (structureId != null) {
5383                                    qPos.add(structureId);
5384                            }
5385    
5386                            Long count = (Long)q.uniqueResult();
5387    
5388                            return count.intValue();
5389                    }
5390                    catch (Exception e) {
5391                            throw processException(e);
5392                    }
5393                    finally {
5394                            closeSession(session);
5395                    }
5396            }
5397    
5398            /**
5399             * Returns the number of journal templates.
5400             *
5401             * @return the number of journal templates
5402             * @throws SystemException if a system exception occurred
5403             */
5404            public int countAll() throws SystemException {
5405                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
5406                                    FINDER_ARGS_EMPTY, this);
5407    
5408                    if (count == null) {
5409                            Session session = null;
5410    
5411                            try {
5412                                    session = openSession();
5413    
5414                                    Query q = session.createQuery(_SQL_COUNT_JOURNALTEMPLATE);
5415    
5416                                    count = (Long)q.uniqueResult();
5417                            }
5418                            catch (Exception e) {
5419                                    throw processException(e);
5420                            }
5421                            finally {
5422                                    if (count == null) {
5423                                            count = Long.valueOf(0);
5424                                    }
5425    
5426                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
5427                                            FINDER_ARGS_EMPTY, count);
5428    
5429                                    closeSession(session);
5430                            }
5431                    }
5432    
5433                    return count.intValue();
5434            }
5435    
5436            /**
5437             * Initializes the journal template persistence.
5438             */
5439            public void afterPropertiesSet() {
5440                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
5441                                            com.liferay.portal.util.PropsUtil.get(
5442                                                    "value.object.listener.com.liferay.portlet.journal.model.JournalTemplate")));
5443    
5444                    if (listenerClassNames.length > 0) {
5445                            try {
5446                                    List<ModelListener<JournalTemplate>> listenersList = new ArrayList<ModelListener<JournalTemplate>>();
5447    
5448                                    for (String listenerClassName : listenerClassNames) {
5449                                            listenersList.add((ModelListener<JournalTemplate>)InstanceFactory.newInstance(
5450                                                            listenerClassName));
5451                                    }
5452    
5453                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
5454                            }
5455                            catch (Exception e) {
5456                                    _log.error(e);
5457                            }
5458                    }
5459            }
5460    
5461            public void destroy() {
5462                    EntityCacheUtil.removeCache(JournalTemplateImpl.class.getName());
5463                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
5464                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
5465            }
5466    
5467            @BeanReference(type = JournalArticlePersistence.class)
5468            protected JournalArticlePersistence journalArticlePersistence;
5469            @BeanReference(type = JournalArticleImagePersistence.class)
5470            protected JournalArticleImagePersistence journalArticleImagePersistence;
5471            @BeanReference(type = JournalArticleResourcePersistence.class)
5472            protected JournalArticleResourcePersistence journalArticleResourcePersistence;
5473            @BeanReference(type = JournalContentSearchPersistence.class)
5474            protected JournalContentSearchPersistence journalContentSearchPersistence;
5475            @BeanReference(type = JournalFeedPersistence.class)
5476            protected JournalFeedPersistence journalFeedPersistence;
5477            @BeanReference(type = JournalFolderPersistence.class)
5478            protected JournalFolderPersistence journalFolderPersistence;
5479            @BeanReference(type = JournalStructurePersistence.class)
5480            protected JournalStructurePersistence journalStructurePersistence;
5481            @BeanReference(type = JournalTemplatePersistence.class)
5482            protected JournalTemplatePersistence journalTemplatePersistence;
5483            @BeanReference(type = GroupPersistence.class)
5484            protected GroupPersistence groupPersistence;
5485            @BeanReference(type = ImagePersistence.class)
5486            protected ImagePersistence imagePersistence;
5487            @BeanReference(type = UserPersistence.class)
5488            protected UserPersistence userPersistence;
5489            @BeanReference(type = WebDAVPropsPersistence.class)
5490            protected WebDAVPropsPersistence webDAVPropsPersistence;
5491            @BeanReference(type = ExpandoValuePersistence.class)
5492            protected ExpandoValuePersistence expandoValuePersistence;
5493            private static final String _SQL_SELECT_JOURNALTEMPLATE = "SELECT journalTemplate FROM JournalTemplate journalTemplate";
5494            private static final String _SQL_SELECT_JOURNALTEMPLATE_WHERE = "SELECT journalTemplate FROM JournalTemplate journalTemplate WHERE ";
5495            private static final String _SQL_COUNT_JOURNALTEMPLATE = "SELECT COUNT(journalTemplate) FROM JournalTemplate journalTemplate";
5496            private static final String _SQL_COUNT_JOURNALTEMPLATE_WHERE = "SELECT COUNT(journalTemplate) FROM JournalTemplate journalTemplate WHERE ";
5497            private static final String _FINDER_COLUMN_UUID_UUID_1 = "journalTemplate.uuid IS NULL";
5498            private static final String _FINDER_COLUMN_UUID_UUID_2 = "journalTemplate.uuid = ?";
5499            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(journalTemplate.uuid IS NULL OR journalTemplate.uuid = ?)";
5500            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "journalTemplate.uuid IS NULL AND ";
5501            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "journalTemplate.uuid = ? AND ";
5502            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(journalTemplate.uuid IS NULL OR journalTemplate.uuid = ?) AND ";
5503            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "journalTemplate.groupId = ?";
5504            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "journalTemplate.uuid IS NULL AND ";
5505            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "journalTemplate.uuid = ? AND ";
5506            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(journalTemplate.uuid IS NULL OR journalTemplate.uuid = ?) AND ";
5507            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "journalTemplate.companyId = ?";
5508            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "journalTemplate.groupId = ?";
5509            private static final String _FINDER_COLUMN_TEMPLATEID_TEMPLATEID_1 = "journalTemplate.templateId IS NULL";
5510            private static final String _FINDER_COLUMN_TEMPLATEID_TEMPLATEID_2 = "journalTemplate.templateId = ?";
5511            private static final String _FINDER_COLUMN_TEMPLATEID_TEMPLATEID_3 = "(journalTemplate.templateId IS NULL OR journalTemplate.templateId = ?)";
5512            private static final String _FINDER_COLUMN_STRUCTUREID_STRUCTUREID_1 = "journalTemplate.structureId IS NULL";
5513            private static final String _FINDER_COLUMN_STRUCTUREID_STRUCTUREID_2 = "journalTemplate.structureId = ?";
5514            private static final String _FINDER_COLUMN_STRUCTUREID_STRUCTUREID_3 = "(journalTemplate.structureId IS NULL OR journalTemplate.structureId = ?)";
5515            private static final String _FINDER_COLUMN_SMALLIMAGEID_SMALLIMAGEID_2 = "journalTemplate.smallImageId = ?";
5516            private static final String _FINDER_COLUMN_G_T_GROUPID_2 = "journalTemplate.groupId = ? AND ";
5517            private static final String _FINDER_COLUMN_G_T_TEMPLATEID_1 = "journalTemplate.templateId IS NULL";
5518            private static final String _FINDER_COLUMN_G_T_TEMPLATEID_2 = "journalTemplate.templateId = ?";
5519            private static final String _FINDER_COLUMN_G_T_TEMPLATEID_3 = "(journalTemplate.templateId IS NULL OR journalTemplate.templateId = ?)";
5520            private static final String _FINDER_COLUMN_G_S_GROUPID_2 = "journalTemplate.groupId = ? AND ";
5521            private static final String _FINDER_COLUMN_G_S_STRUCTUREID_1 = "journalTemplate.structureId IS NULL";
5522            private static final String _FINDER_COLUMN_G_S_STRUCTUREID_2 = "journalTemplate.structureId = ?";
5523            private static final String _FINDER_COLUMN_G_S_STRUCTUREID_3 = "(journalTemplate.structureId IS NULL OR journalTemplate.structureId = ?)";
5524            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "journalTemplate.id_";
5525            private static final String _FILTER_SQL_SELECT_JOURNALTEMPLATE_WHERE = "SELECT DISTINCT {journalTemplate.*} FROM JournalTemplate journalTemplate WHERE ";
5526            private static final String _FILTER_SQL_SELECT_JOURNALTEMPLATE_NO_INLINE_DISTINCT_WHERE_1 =
5527                    "SELECT {JournalTemplate.*} FROM (SELECT DISTINCT journalTemplate.id_ FROM JournalTemplate journalTemplate WHERE ";
5528            private static final String _FILTER_SQL_SELECT_JOURNALTEMPLATE_NO_INLINE_DISTINCT_WHERE_2 =
5529                    ") TEMP_TABLE INNER JOIN JournalTemplate ON TEMP_TABLE.id_ = JournalTemplate.id_";
5530            private static final String _FILTER_SQL_COUNT_JOURNALTEMPLATE_WHERE = "SELECT COUNT(DISTINCT journalTemplate.id_) AS COUNT_VALUE FROM JournalTemplate journalTemplate WHERE ";
5531            private static final String _FILTER_ENTITY_ALIAS = "journalTemplate";
5532            private static final String _FILTER_ENTITY_TABLE = "JournalTemplate";
5533            private static final String _ORDER_BY_ENTITY_ALIAS = "journalTemplate.";
5534            private static final String _ORDER_BY_ENTITY_TABLE = "JournalTemplate.";
5535            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No JournalTemplate exists with the primary key ";
5536            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No JournalTemplate exists with the key {";
5537            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
5538            private static Log _log = LogFactoryUtil.getLog(JournalTemplatePersistenceImpl.class);
5539            private static JournalTemplate _nullJournalTemplate = new JournalTemplateImpl() {
5540                            @Override
5541                            public Object clone() {
5542                                    return this;
5543                            }
5544    
5545                            @Override
5546                            public CacheModel<JournalTemplate> toCacheModel() {
5547                                    return _nullJournalTemplateCacheModel;
5548                            }
5549                    };
5550    
5551            private static CacheModel<JournalTemplate> _nullJournalTemplateCacheModel = new CacheModel<JournalTemplate>() {
5552                            public JournalTemplate toEntityModel() {
5553                                    return _nullJournalTemplate;
5554                            }
5555                    };
5556    }