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