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