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