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