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