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