001    /**
002     * Copyright (c) 2000-2010 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.annotation.BeanReference;
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.SQLQuery;
027    import com.liferay.portal.kernel.dao.orm.Session;
028    import com.liferay.portal.kernel.exception.SystemException;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.util.GetterUtil;
032    import com.liferay.portal.kernel.util.InstanceFactory;
033    import com.liferay.portal.kernel.util.OrderByComparator;
034    import com.liferay.portal.kernel.util.StringBundler;
035    import com.liferay.portal.kernel.util.StringPool;
036    import com.liferay.portal.kernel.util.StringUtil;
037    import com.liferay.portal.kernel.util.Validator;
038    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
039    import com.liferay.portal.model.ModelListener;
040    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
041    import com.liferay.portal.service.persistence.BatchSessionUtil;
042    import com.liferay.portal.service.persistence.ImagePersistence;
043    import com.liferay.portal.service.persistence.ResourcePersistence;
044    import com.liferay.portal.service.persistence.UserPersistence;
045    import com.liferay.portal.service.persistence.WebDAVPropsPersistence;
046    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
047    
048    import com.liferay.portlet.expando.service.persistence.ExpandoValuePersistence;
049    import com.liferay.portlet.journal.NoSuchTemplateException;
050    import com.liferay.portlet.journal.model.JournalTemplate;
051    import com.liferay.portlet.journal.model.impl.JournalTemplateImpl;
052    import com.liferay.portlet.journal.model.impl.JournalTemplateModelImpl;
053    
054    import java.io.Serializable;
055    
056    import java.util.ArrayList;
057    import java.util.Collections;
058    import java.util.List;
059    
060    /**
061     * @author    Brian Wing Shun Chan
062     * @see       JournalTemplatePersistence
063     * @see       JournalTemplateUtil
064     * @generated
065     */
066    public class JournalTemplatePersistenceImpl extends BasePersistenceImpl<JournalTemplate>
067            implements JournalTemplatePersistence {
068            public static final String FINDER_CLASS_NAME_ENTITY = JournalTemplateImpl.class.getName();
069            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
070                    ".List";
071            public static final FinderPath FINDER_PATH_FIND_BY_UUID = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
072                            JournalTemplateModelImpl.FINDER_CACHE_ENABLED,
073                            FINDER_CLASS_NAME_LIST, "findByUuid",
074                            new String[] {
075                                    String.class.getName(),
076                                    
077                            "java.lang.Integer", "java.lang.Integer",
078                                    "com.liferay.portal.kernel.util.OrderByComparator"
079                            });
080            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
081                            JournalTemplateModelImpl.FINDER_CACHE_ENABLED,
082                            FINDER_CLASS_NAME_LIST, "countByUuid",
083                            new String[] { String.class.getName() });
084            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
085                            JournalTemplateModelImpl.FINDER_CACHE_ENABLED,
086                            FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
087                            new String[] { String.class.getName(), Long.class.getName() });
088            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
089                            JournalTemplateModelImpl.FINDER_CACHE_ENABLED,
090                            FINDER_CLASS_NAME_LIST, "countByUUID_G",
091                            new String[] { String.class.getName(), Long.class.getName() });
092            public static final FinderPath FINDER_PATH_FIND_BY_GROUPID = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
093                            JournalTemplateModelImpl.FINDER_CACHE_ENABLED,
094                            FINDER_CLASS_NAME_LIST, "findByGroupId",
095                            new String[] {
096                                    Long.class.getName(),
097                                    
098                            "java.lang.Integer", "java.lang.Integer",
099                                    "com.liferay.portal.kernel.util.OrderByComparator"
100                            });
101            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
102                            JournalTemplateModelImpl.FINDER_CACHE_ENABLED,
103                            FINDER_CLASS_NAME_LIST, "countByGroupId",
104                            new String[] { Long.class.getName() });
105            public static final FinderPath FINDER_PATH_FIND_BY_TEMPLATEID = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
106                            JournalTemplateModelImpl.FINDER_CACHE_ENABLED,
107                            FINDER_CLASS_NAME_LIST, "findByTemplateId",
108                            new String[] {
109                                    String.class.getName(),
110                                    
111                            "java.lang.Integer", "java.lang.Integer",
112                                    "com.liferay.portal.kernel.util.OrderByComparator"
113                            });
114            public static final FinderPath FINDER_PATH_COUNT_BY_TEMPLATEID = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
115                            JournalTemplateModelImpl.FINDER_CACHE_ENABLED,
116                            FINDER_CLASS_NAME_LIST, "countByTemplateId",
117                            new String[] { String.class.getName() });
118            public static final FinderPath FINDER_PATH_FETCH_BY_SMALLIMAGEID = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
119                            JournalTemplateModelImpl.FINDER_CACHE_ENABLED,
120                            FINDER_CLASS_NAME_ENTITY, "fetchBySmallImageId",
121                            new String[] { Long.class.getName() });
122            public static final FinderPath FINDER_PATH_COUNT_BY_SMALLIMAGEID = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
123                            JournalTemplateModelImpl.FINDER_CACHE_ENABLED,
124                            FINDER_CLASS_NAME_LIST, "countBySmallImageId",
125                            new String[] { Long.class.getName() });
126            public static final FinderPath FINDER_PATH_FETCH_BY_G_T = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
127                            JournalTemplateModelImpl.FINDER_CACHE_ENABLED,
128                            FINDER_CLASS_NAME_ENTITY, "fetchByG_T",
129                            new String[] { Long.class.getName(), String.class.getName() });
130            public static final FinderPath FINDER_PATH_COUNT_BY_G_T = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
131                            JournalTemplateModelImpl.FINDER_CACHE_ENABLED,
132                            FINDER_CLASS_NAME_LIST, "countByG_T",
133                            new String[] { Long.class.getName(), String.class.getName() });
134            public static final FinderPath FINDER_PATH_FIND_BY_G_S = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
135                            JournalTemplateModelImpl.FINDER_CACHE_ENABLED,
136                            FINDER_CLASS_NAME_LIST, "findByG_S",
137                            new String[] {
138                                    Long.class.getName(), String.class.getName(),
139                                    
140                            "java.lang.Integer", "java.lang.Integer",
141                                    "com.liferay.portal.kernel.util.OrderByComparator"
142                            });
143            public static final FinderPath FINDER_PATH_COUNT_BY_G_S = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
144                            JournalTemplateModelImpl.FINDER_CACHE_ENABLED,
145                            FINDER_CLASS_NAME_LIST, "countByG_S",
146                            new String[] { Long.class.getName(), String.class.getName() });
147            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
148                            JournalTemplateModelImpl.FINDER_CACHE_ENABLED,
149                            FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
150            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
151                            JournalTemplateModelImpl.FINDER_CACHE_ENABLED,
152                            FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
153    
154            public void cacheResult(JournalTemplate journalTemplate) {
155                    EntityCacheUtil.putResult(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
156                            JournalTemplateImpl.class, journalTemplate.getPrimaryKey(),
157                            journalTemplate);
158    
159                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
160                            new Object[] {
161                                    journalTemplate.getUuid(),
162                                    new Long(journalTemplate.getGroupId())
163                            }, journalTemplate);
164    
165                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
166                            new Object[] { new Long(journalTemplate.getSmallImageId()) },
167                            journalTemplate);
168    
169                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_T,
170                            new Object[] {
171                                    new Long(journalTemplate.getGroupId()),
172                                    
173                            journalTemplate.getTemplateId()
174                            }, journalTemplate);
175            }
176    
177            public void cacheResult(List<JournalTemplate> journalTemplates) {
178                    for (JournalTemplate journalTemplate : journalTemplates) {
179                            if (EntityCacheUtil.getResult(
180                                                    JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
181                                                    JournalTemplateImpl.class,
182                                                    journalTemplate.getPrimaryKey(), this) == null) {
183                                    cacheResult(journalTemplate);
184                            }
185                    }
186            }
187    
188            public void clearCache() {
189                    CacheRegistryUtil.clear(JournalTemplateImpl.class.getName());
190                    EntityCacheUtil.clearCache(JournalTemplateImpl.class.getName());
191                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
192                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
193            }
194    
195            public void clearCache(JournalTemplate journalTemplate) {
196                    EntityCacheUtil.removeResult(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
197                            JournalTemplateImpl.class, journalTemplate.getPrimaryKey());
198    
199                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
200                            new Object[] {
201                                    journalTemplate.getUuid(),
202                                    new Long(journalTemplate.getGroupId())
203                            });
204    
205                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
206                            new Object[] { new Long(journalTemplate.getSmallImageId()) });
207    
208                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_T,
209                            new Object[] {
210                                    new Long(journalTemplate.getGroupId()),
211                                    
212                            journalTemplate.getTemplateId()
213                            });
214            }
215    
216            public JournalTemplate create(long id) {
217                    JournalTemplate journalTemplate = new JournalTemplateImpl();
218    
219                    journalTemplate.setNew(true);
220                    journalTemplate.setPrimaryKey(id);
221    
222                    String uuid = PortalUUIDUtil.generate();
223    
224                    journalTemplate.setUuid(uuid);
225    
226                    return journalTemplate;
227            }
228    
229            public JournalTemplate remove(Serializable primaryKey)
230                    throws NoSuchModelException, SystemException {
231                    return remove(((Long)primaryKey).longValue());
232            }
233    
234            public JournalTemplate remove(long id)
235                    throws NoSuchTemplateException, SystemException {
236                    Session session = null;
237    
238                    try {
239                            session = openSession();
240    
241                            JournalTemplate journalTemplate = (JournalTemplate)session.get(JournalTemplateImpl.class,
242                                            new Long(id));
243    
244                            if (journalTemplate == null) {
245                                    if (_log.isWarnEnabled()) {
246                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + id);
247                                    }
248    
249                                    throw new NoSuchTemplateException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
250                                            id);
251                            }
252    
253                            return remove(journalTemplate);
254                    }
255                    catch (NoSuchTemplateException nsee) {
256                            throw nsee;
257                    }
258                    catch (Exception e) {
259                            throw processException(e);
260                    }
261                    finally {
262                            closeSession(session);
263                    }
264            }
265    
266            protected JournalTemplate removeImpl(JournalTemplate journalTemplate)
267                    throws SystemException {
268                    journalTemplate = toUnwrappedModel(journalTemplate);
269    
270                    Session session = null;
271    
272                    try {
273                            session = openSession();
274    
275                            if (journalTemplate.isCachedModel() ||
276                                            BatchSessionUtil.isEnabled()) {
277                                    Object staleObject = session.get(JournalTemplateImpl.class,
278                                                    journalTemplate.getPrimaryKeyObj());
279    
280                                    if (staleObject != null) {
281                                            session.evict(staleObject);
282                                    }
283                            }
284    
285                            session.delete(journalTemplate);
286    
287                            session.flush();
288                    }
289                    catch (Exception e) {
290                            throw processException(e);
291                    }
292                    finally {
293                            closeSession(session);
294                    }
295    
296                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
297    
298                    JournalTemplateModelImpl journalTemplateModelImpl = (JournalTemplateModelImpl)journalTemplate;
299    
300                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
301                            new Object[] {
302                                    journalTemplateModelImpl.getOriginalUuid(),
303                                    new Long(journalTemplateModelImpl.getOriginalGroupId())
304                            });
305    
306                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
307                            new Object[] {
308                                    new Long(journalTemplateModelImpl.getOriginalSmallImageId())
309                            });
310    
311                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_T,
312                            new Object[] {
313                                    new Long(journalTemplateModelImpl.getOriginalGroupId()),
314                                    
315                            journalTemplateModelImpl.getOriginalTemplateId()
316                            });
317    
318                    EntityCacheUtil.removeResult(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
319                            JournalTemplateImpl.class, journalTemplate.getPrimaryKey());
320    
321                    return journalTemplate;
322            }
323    
324            public JournalTemplate updateImpl(
325                    com.liferay.portlet.journal.model.JournalTemplate journalTemplate,
326                    boolean merge) throws SystemException {
327                    journalTemplate = toUnwrappedModel(journalTemplate);
328    
329                    boolean isNew = journalTemplate.isNew();
330    
331                    JournalTemplateModelImpl journalTemplateModelImpl = (JournalTemplateModelImpl)journalTemplate;
332    
333                    if (Validator.isNull(journalTemplate.getUuid())) {
334                            String uuid = PortalUUIDUtil.generate();
335    
336                            journalTemplate.setUuid(uuid);
337                    }
338    
339                    Session session = null;
340    
341                    try {
342                            session = openSession();
343    
344                            BatchSessionUtil.update(session, journalTemplate, merge);
345    
346                            journalTemplate.setNew(false);
347                    }
348                    catch (Exception e) {
349                            throw processException(e);
350                    }
351                    finally {
352                            closeSession(session);
353                    }
354    
355                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
356    
357                    EntityCacheUtil.putResult(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
358                            JournalTemplateImpl.class, journalTemplate.getPrimaryKey(),
359                            journalTemplate);
360    
361                    if (!isNew &&
362                                    (!Validator.equals(journalTemplate.getUuid(),
363                                            journalTemplateModelImpl.getOriginalUuid()) ||
364                                    (journalTemplate.getGroupId() != journalTemplateModelImpl.getOriginalGroupId()))) {
365                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
366                                    new Object[] {
367                                            journalTemplateModelImpl.getOriginalUuid(),
368                                            new Long(journalTemplateModelImpl.getOriginalGroupId())
369                                    });
370                    }
371    
372                    if (isNew ||
373                                    (!Validator.equals(journalTemplate.getUuid(),
374                                            journalTemplateModelImpl.getOriginalUuid()) ||
375                                    (journalTemplate.getGroupId() != journalTemplateModelImpl.getOriginalGroupId()))) {
376                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
377                                    new Object[] {
378                                            journalTemplate.getUuid(),
379                                            new Long(journalTemplate.getGroupId())
380                                    }, journalTemplate);
381                    }
382    
383                    if (!isNew &&
384                                    (journalTemplate.getSmallImageId() != journalTemplateModelImpl.getOriginalSmallImageId())) {
385                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
386                                    new Object[] {
387                                            new Long(journalTemplateModelImpl.getOriginalSmallImageId())
388                                    });
389                    }
390    
391                    if (isNew ||
392                                    (journalTemplate.getSmallImageId() != journalTemplateModelImpl.getOriginalSmallImageId())) {
393                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
394                                    new Object[] { new Long(journalTemplate.getSmallImageId()) },
395                                    journalTemplate);
396                    }
397    
398                    if (!isNew &&
399                                    ((journalTemplate.getGroupId() != journalTemplateModelImpl.getOriginalGroupId()) ||
400                                    !Validator.equals(journalTemplate.getTemplateId(),
401                                            journalTemplateModelImpl.getOriginalTemplateId()))) {
402                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_T,
403                                    new Object[] {
404                                            new Long(journalTemplateModelImpl.getOriginalGroupId()),
405                                            
406                                    journalTemplateModelImpl.getOriginalTemplateId()
407                                    });
408                    }
409    
410                    if (isNew ||
411                                    ((journalTemplate.getGroupId() != journalTemplateModelImpl.getOriginalGroupId()) ||
412                                    !Validator.equals(journalTemplate.getTemplateId(),
413                                            journalTemplateModelImpl.getOriginalTemplateId()))) {
414                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_T,
415                                    new Object[] {
416                                            new Long(journalTemplate.getGroupId()),
417                                            
418                                    journalTemplate.getTemplateId()
419                                    }, journalTemplate);
420                    }
421    
422                    return journalTemplate;
423            }
424    
425            protected JournalTemplate toUnwrappedModel(JournalTemplate journalTemplate) {
426                    if (journalTemplate instanceof JournalTemplateImpl) {
427                            return journalTemplate;
428                    }
429    
430                    JournalTemplateImpl journalTemplateImpl = new JournalTemplateImpl();
431    
432                    journalTemplateImpl.setNew(journalTemplate.isNew());
433                    journalTemplateImpl.setPrimaryKey(journalTemplate.getPrimaryKey());
434    
435                    journalTemplateImpl.setUuid(journalTemplate.getUuid());
436                    journalTemplateImpl.setId(journalTemplate.getId());
437                    journalTemplateImpl.setGroupId(journalTemplate.getGroupId());
438                    journalTemplateImpl.setCompanyId(journalTemplate.getCompanyId());
439                    journalTemplateImpl.setUserId(journalTemplate.getUserId());
440                    journalTemplateImpl.setUserName(journalTemplate.getUserName());
441                    journalTemplateImpl.setCreateDate(journalTemplate.getCreateDate());
442                    journalTemplateImpl.setModifiedDate(journalTemplate.getModifiedDate());
443                    journalTemplateImpl.setTemplateId(journalTemplate.getTemplateId());
444                    journalTemplateImpl.setStructureId(journalTemplate.getStructureId());
445                    journalTemplateImpl.setName(journalTemplate.getName());
446                    journalTemplateImpl.setDescription(journalTemplate.getDescription());
447                    journalTemplateImpl.setXsl(journalTemplate.getXsl());
448                    journalTemplateImpl.setLangType(journalTemplate.getLangType());
449                    journalTemplateImpl.setCacheable(journalTemplate.isCacheable());
450                    journalTemplateImpl.setSmallImage(journalTemplate.isSmallImage());
451                    journalTemplateImpl.setSmallImageId(journalTemplate.getSmallImageId());
452                    journalTemplateImpl.setSmallImageURL(journalTemplate.getSmallImageURL());
453    
454                    return journalTemplateImpl;
455            }
456    
457            public JournalTemplate findByPrimaryKey(Serializable primaryKey)
458                    throws NoSuchModelException, SystemException {
459                    return findByPrimaryKey(((Long)primaryKey).longValue());
460            }
461    
462            public JournalTemplate findByPrimaryKey(long id)
463                    throws NoSuchTemplateException, SystemException {
464                    JournalTemplate journalTemplate = fetchByPrimaryKey(id);
465    
466                    if (journalTemplate == null) {
467                            if (_log.isWarnEnabled()) {
468                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + id);
469                            }
470    
471                            throw new NoSuchTemplateException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
472                                    id);
473                    }
474    
475                    return journalTemplate;
476            }
477    
478            public JournalTemplate fetchByPrimaryKey(Serializable primaryKey)
479                    throws SystemException {
480                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
481            }
482    
483            public JournalTemplate fetchByPrimaryKey(long id) throws SystemException {
484                    JournalTemplate journalTemplate = (JournalTemplate)EntityCacheUtil.getResult(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
485                                    JournalTemplateImpl.class, id, this);
486    
487                    if (journalTemplate == null) {
488                            Session session = null;
489    
490                            try {
491                                    session = openSession();
492    
493                                    journalTemplate = (JournalTemplate)session.get(JournalTemplateImpl.class,
494                                                    new Long(id));
495                            }
496                            catch (Exception e) {
497                                    throw processException(e);
498                            }
499                            finally {
500                                    if (journalTemplate != null) {
501                                            cacheResult(journalTemplate);
502                                    }
503    
504                                    closeSession(session);
505                            }
506                    }
507    
508                    return journalTemplate;
509            }
510    
511            public List<JournalTemplate> findByUuid(String uuid)
512                    throws SystemException {
513                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
514            }
515    
516            public List<JournalTemplate> findByUuid(String uuid, int start, int end)
517                    throws SystemException {
518                    return findByUuid(uuid, start, end, null);
519            }
520    
521            public List<JournalTemplate> findByUuid(String uuid, int start, int end,
522                    OrderByComparator orderByComparator) throws SystemException {
523                    Object[] finderArgs = new Object[] {
524                                    uuid,
525                                    
526                                    String.valueOf(start), String.valueOf(end),
527                                    String.valueOf(orderByComparator)
528                            };
529    
530                    List<JournalTemplate> list = (List<JournalTemplate>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_UUID,
531                                    finderArgs, this);
532    
533                    if (list == null) {
534                            Session session = null;
535    
536                            try {
537                                    session = openSession();
538    
539                                    StringBundler query = null;
540    
541                                    if (orderByComparator != null) {
542                                            query = new StringBundler(3 +
543                                                            (orderByComparator.getOrderByFields().length * 3));
544                                    }
545                                    else {
546                                            query = new StringBundler(3);
547                                    }
548    
549                                    query.append(_SQL_SELECT_JOURNALTEMPLATE_WHERE);
550    
551                                    if (uuid == null) {
552                                            query.append(_FINDER_COLUMN_UUID_UUID_1);
553                                    }
554                                    else {
555                                            if (uuid.equals(StringPool.BLANK)) {
556                                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
557                                            }
558                                            else {
559                                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
560                                            }
561                                    }
562    
563                                    if (orderByComparator != null) {
564                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
565                                                    orderByComparator);
566                                    }
567    
568                                    else {
569                                            query.append(JournalTemplateModelImpl.ORDER_BY_JPQL);
570                                    }
571    
572                                    String sql = query.toString();
573    
574                                    Query q = session.createQuery(sql);
575    
576                                    QueryPos qPos = QueryPos.getInstance(q);
577    
578                                    if (uuid != null) {
579                                            qPos.add(uuid);
580                                    }
581    
582                                    list = (List<JournalTemplate>)QueryUtil.list(q, getDialect(),
583                                                    start, end);
584                            }
585                            catch (Exception e) {
586                                    throw processException(e);
587                            }
588                            finally {
589                                    if (list == null) {
590                                            list = new ArrayList<JournalTemplate>();
591                                    }
592    
593                                    cacheResult(list);
594    
595                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_UUID, finderArgs,
596                                            list);
597    
598                                    closeSession(session);
599                            }
600                    }
601    
602                    return list;
603            }
604    
605            public JournalTemplate findByUuid_First(String uuid,
606                    OrderByComparator orderByComparator)
607                    throws NoSuchTemplateException, SystemException {
608                    List<JournalTemplate> list = findByUuid(uuid, 0, 1, orderByComparator);
609    
610                    if (list.isEmpty()) {
611                            StringBundler msg = new StringBundler(4);
612    
613                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
614    
615                            msg.append("uuid=");
616                            msg.append(uuid);
617    
618                            msg.append(StringPool.CLOSE_CURLY_BRACE);
619    
620                            throw new NoSuchTemplateException(msg.toString());
621                    }
622                    else {
623                            return list.get(0);
624                    }
625            }
626    
627            public JournalTemplate findByUuid_Last(String uuid,
628                    OrderByComparator orderByComparator)
629                    throws NoSuchTemplateException, SystemException {
630                    int count = countByUuid(uuid);
631    
632                    List<JournalTemplate> list = findByUuid(uuid, count - 1, count,
633                                    orderByComparator);
634    
635                    if (list.isEmpty()) {
636                            StringBundler msg = new StringBundler(4);
637    
638                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
639    
640                            msg.append("uuid=");
641                            msg.append(uuid);
642    
643                            msg.append(StringPool.CLOSE_CURLY_BRACE);
644    
645                            throw new NoSuchTemplateException(msg.toString());
646                    }
647                    else {
648                            return list.get(0);
649                    }
650            }
651    
652            public JournalTemplate[] findByUuid_PrevAndNext(long id, String uuid,
653                    OrderByComparator orderByComparator)
654                    throws NoSuchTemplateException, SystemException {
655                    JournalTemplate journalTemplate = findByPrimaryKey(id);
656    
657                    Session session = null;
658    
659                    try {
660                            session = openSession();
661    
662                            JournalTemplate[] array = new JournalTemplateImpl[3];
663    
664                            array[0] = getByUuid_PrevAndNext(session, journalTemplate, uuid,
665                                            orderByComparator, true);
666    
667                            array[1] = journalTemplate;
668    
669                            array[2] = getByUuid_PrevAndNext(session, journalTemplate, uuid,
670                                            orderByComparator, false);
671    
672                            return array;
673                    }
674                    catch (Exception e) {
675                            throw processException(e);
676                    }
677                    finally {
678                            closeSession(session);
679                    }
680            }
681    
682            protected JournalTemplate getByUuid_PrevAndNext(Session session,
683                    JournalTemplate journalTemplate, String uuid,
684                    OrderByComparator orderByComparator, boolean previous) {
685                    StringBundler query = null;
686    
687                    if (orderByComparator != null) {
688                            query = new StringBundler(6 +
689                                            (orderByComparator.getOrderByFields().length * 6));
690                    }
691                    else {
692                            query = new StringBundler(3);
693                    }
694    
695                    query.append(_SQL_SELECT_JOURNALTEMPLATE_WHERE);
696    
697                    if (uuid == null) {
698                            query.append(_FINDER_COLUMN_UUID_UUID_1);
699                    }
700                    else {
701                            if (uuid.equals(StringPool.BLANK)) {
702                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
703                            }
704                            else {
705                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
706                            }
707                    }
708    
709                    if (orderByComparator != null) {
710                            String[] orderByFields = orderByComparator.getOrderByFields();
711    
712                            if (orderByFields.length > 0) {
713                                    query.append(WHERE_AND);
714                            }
715    
716                            for (int i = 0; i < orderByFields.length; i++) {
717                                    query.append(_ORDER_BY_ENTITY_ALIAS);
718                                    query.append(orderByFields[i]);
719    
720                                    if ((i + 1) < orderByFields.length) {
721                                            if (orderByComparator.isAscending() ^ previous) {
722                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
723                                            }
724                                            else {
725                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
726                                            }
727                                    }
728                                    else {
729                                            if (orderByComparator.isAscending() ^ previous) {
730                                                    query.append(WHERE_GREATER_THAN);
731                                            }
732                                            else {
733                                                    query.append(WHERE_LESSER_THAN);
734                                            }
735                                    }
736                            }
737    
738                            query.append(ORDER_BY_CLAUSE);
739    
740                            for (int i = 0; i < orderByFields.length; i++) {
741                                    query.append(_ORDER_BY_ENTITY_ALIAS);
742                                    query.append(orderByFields[i]);
743    
744                                    if ((i + 1) < orderByFields.length) {
745                                            if (orderByComparator.isAscending() ^ previous) {
746                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
747                                            }
748                                            else {
749                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
750                                            }
751                                    }
752                                    else {
753                                            if (orderByComparator.isAscending() ^ previous) {
754                                                    query.append(ORDER_BY_ASC);
755                                            }
756                                            else {
757                                                    query.append(ORDER_BY_DESC);
758                                            }
759                                    }
760                            }
761                    }
762    
763                    else {
764                            query.append(JournalTemplateModelImpl.ORDER_BY_JPQL);
765                    }
766    
767                    String sql = query.toString();
768    
769                    Query q = session.createQuery(sql);
770    
771                    q.setFirstResult(0);
772                    q.setMaxResults(2);
773    
774                    QueryPos qPos = QueryPos.getInstance(q);
775    
776                    if (uuid != null) {
777                            qPos.add(uuid);
778                    }
779    
780                    if (orderByComparator != null) {
781                            Object[] values = orderByComparator.getOrderByValues(journalTemplate);
782    
783                            for (Object value : values) {
784                                    qPos.add(value);
785                            }
786                    }
787    
788                    List<JournalTemplate> list = q.list();
789    
790                    if (list.size() == 2) {
791                            return list.get(1);
792                    }
793                    else {
794                            return null;
795                    }
796            }
797    
798            public JournalTemplate findByUUID_G(String uuid, long groupId)
799                    throws NoSuchTemplateException, SystemException {
800                    JournalTemplate journalTemplate = fetchByUUID_G(uuid, groupId);
801    
802                    if (journalTemplate == null) {
803                            StringBundler msg = new StringBundler(6);
804    
805                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
806    
807                            msg.append("uuid=");
808                            msg.append(uuid);
809    
810                            msg.append(", groupId=");
811                            msg.append(groupId);
812    
813                            msg.append(StringPool.CLOSE_CURLY_BRACE);
814    
815                            if (_log.isWarnEnabled()) {
816                                    _log.warn(msg.toString());
817                            }
818    
819                            throw new NoSuchTemplateException(msg.toString());
820                    }
821    
822                    return journalTemplate;
823            }
824    
825            public JournalTemplate fetchByUUID_G(String uuid, long groupId)
826                    throws SystemException {
827                    return fetchByUUID_G(uuid, groupId, true);
828            }
829    
830            public JournalTemplate fetchByUUID_G(String uuid, long groupId,
831                    boolean retrieveFromCache) throws SystemException {
832                    Object[] finderArgs = new Object[] { uuid, groupId };
833    
834                    Object result = null;
835    
836                    if (retrieveFromCache) {
837                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
838                                            finderArgs, this);
839                    }
840    
841                    if (result == null) {
842                            Session session = null;
843    
844                            try {
845                                    session = openSession();
846    
847                                    StringBundler query = new StringBundler(4);
848    
849                                    query.append(_SQL_SELECT_JOURNALTEMPLATE_WHERE);
850    
851                                    if (uuid == null) {
852                                            query.append(_FINDER_COLUMN_UUID_G_UUID_1);
853                                    }
854                                    else {
855                                            if (uuid.equals(StringPool.BLANK)) {
856                                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
857                                            }
858                                            else {
859                                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
860                                            }
861                                    }
862    
863                                    query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
864    
865                                    query.append(JournalTemplateModelImpl.ORDER_BY_JPQL);
866    
867                                    String sql = query.toString();
868    
869                                    Query q = session.createQuery(sql);
870    
871                                    QueryPos qPos = QueryPos.getInstance(q);
872    
873                                    if (uuid != null) {
874                                            qPos.add(uuid);
875                                    }
876    
877                                    qPos.add(groupId);
878    
879                                    List<JournalTemplate> list = q.list();
880    
881                                    result = list;
882    
883                                    JournalTemplate journalTemplate = null;
884    
885                                    if (list.isEmpty()) {
886                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
887                                                    finderArgs, list);
888                                    }
889                                    else {
890                                            journalTemplate = list.get(0);
891    
892                                            cacheResult(journalTemplate);
893    
894                                            if ((journalTemplate.getUuid() == null) ||
895                                                            !journalTemplate.getUuid().equals(uuid) ||
896                                                            (journalTemplate.getGroupId() != groupId)) {
897                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
898                                                            finderArgs, journalTemplate);
899                                            }
900                                    }
901    
902                                    return journalTemplate;
903                            }
904                            catch (Exception e) {
905                                    throw processException(e);
906                            }
907                            finally {
908                                    if (result == null) {
909                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
910                                                    finderArgs, new ArrayList<JournalTemplate>());
911                                    }
912    
913                                    closeSession(session);
914                            }
915                    }
916                    else {
917                            if (result instanceof List<?>) {
918                                    return null;
919                            }
920                            else {
921                                    return (JournalTemplate)result;
922                            }
923                    }
924            }
925    
926            public List<JournalTemplate> findByGroupId(long groupId)
927                    throws SystemException {
928                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
929            }
930    
931            public List<JournalTemplate> findByGroupId(long groupId, int start, int end)
932                    throws SystemException {
933                    return findByGroupId(groupId, start, end, null);
934            }
935    
936            public List<JournalTemplate> findByGroupId(long groupId, int start,
937                    int end, OrderByComparator orderByComparator) throws SystemException {
938                    Object[] finderArgs = new Object[] {
939                                    groupId,
940                                    
941                                    String.valueOf(start), String.valueOf(end),
942                                    String.valueOf(orderByComparator)
943                            };
944    
945                    List<JournalTemplate> list = (List<JournalTemplate>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
946                                    finderArgs, this);
947    
948                    if (list == null) {
949                            Session session = null;
950    
951                            try {
952                                    session = openSession();
953    
954                                    StringBundler query = null;
955    
956                                    if (orderByComparator != null) {
957                                            query = new StringBundler(3 +
958                                                            (orderByComparator.getOrderByFields().length * 3));
959                                    }
960                                    else {
961                                            query = new StringBundler(3);
962                                    }
963    
964                                    query.append(_SQL_SELECT_JOURNALTEMPLATE_WHERE);
965    
966                                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
967    
968                                    if (orderByComparator != null) {
969                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
970                                                    orderByComparator);
971                                    }
972    
973                                    else {
974                                            query.append(JournalTemplateModelImpl.ORDER_BY_JPQL);
975                                    }
976    
977                                    String sql = query.toString();
978    
979                                    Query q = session.createQuery(sql);
980    
981                                    QueryPos qPos = QueryPos.getInstance(q);
982    
983                                    qPos.add(groupId);
984    
985                                    list = (List<JournalTemplate>)QueryUtil.list(q, getDialect(),
986                                                    start, end);
987                            }
988                            catch (Exception e) {
989                                    throw processException(e);
990                            }
991                            finally {
992                                    if (list == null) {
993                                            list = new ArrayList<JournalTemplate>();
994                                    }
995    
996                                    cacheResult(list);
997    
998                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
999                                            finderArgs, list);
1000    
1001                                    closeSession(session);
1002                            }
1003                    }
1004    
1005                    return list;
1006            }
1007    
1008            public JournalTemplate findByGroupId_First(long groupId,
1009                    OrderByComparator orderByComparator)
1010                    throws NoSuchTemplateException, SystemException {
1011                    List<JournalTemplate> list = findByGroupId(groupId, 0, 1,
1012                                    orderByComparator);
1013    
1014                    if (list.isEmpty()) {
1015                            StringBundler msg = new StringBundler(4);
1016    
1017                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1018    
1019                            msg.append("groupId=");
1020                            msg.append(groupId);
1021    
1022                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1023    
1024                            throw new NoSuchTemplateException(msg.toString());
1025                    }
1026                    else {
1027                            return list.get(0);
1028                    }
1029            }
1030    
1031            public JournalTemplate findByGroupId_Last(long groupId,
1032                    OrderByComparator orderByComparator)
1033                    throws NoSuchTemplateException, SystemException {
1034                    int count = countByGroupId(groupId);
1035    
1036                    List<JournalTemplate> list = findByGroupId(groupId, count - 1, count,
1037                                    orderByComparator);
1038    
1039                    if (list.isEmpty()) {
1040                            StringBundler msg = new StringBundler(4);
1041    
1042                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1043    
1044                            msg.append("groupId=");
1045                            msg.append(groupId);
1046    
1047                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1048    
1049                            throw new NoSuchTemplateException(msg.toString());
1050                    }
1051                    else {
1052                            return list.get(0);
1053                    }
1054            }
1055    
1056            public JournalTemplate[] findByGroupId_PrevAndNext(long id, long groupId,
1057                    OrderByComparator orderByComparator)
1058                    throws NoSuchTemplateException, SystemException {
1059                    JournalTemplate journalTemplate = findByPrimaryKey(id);
1060    
1061                    Session session = null;
1062    
1063                    try {
1064                            session = openSession();
1065    
1066                            JournalTemplate[] array = new JournalTemplateImpl[3];
1067    
1068                            array[0] = getByGroupId_PrevAndNext(session, journalTemplate,
1069                                            groupId, orderByComparator, true);
1070    
1071                            array[1] = journalTemplate;
1072    
1073                            array[2] = getByGroupId_PrevAndNext(session, journalTemplate,
1074                                            groupId, orderByComparator, false);
1075    
1076                            return array;
1077                    }
1078                    catch (Exception e) {
1079                            throw processException(e);
1080                    }
1081                    finally {
1082                            closeSession(session);
1083                    }
1084            }
1085    
1086            protected JournalTemplate getByGroupId_PrevAndNext(Session session,
1087                    JournalTemplate journalTemplate, long groupId,
1088                    OrderByComparator orderByComparator, boolean previous) {
1089                    StringBundler query = null;
1090    
1091                    if (orderByComparator != null) {
1092                            query = new StringBundler(6 +
1093                                            (orderByComparator.getOrderByFields().length * 6));
1094                    }
1095                    else {
1096                            query = new StringBundler(3);
1097                    }
1098    
1099                    query.append(_SQL_SELECT_JOURNALTEMPLATE_WHERE);
1100    
1101                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1102    
1103                    if (orderByComparator != null) {
1104                            String[] orderByFields = orderByComparator.getOrderByFields();
1105    
1106                            if (orderByFields.length > 0) {
1107                                    query.append(WHERE_AND);
1108                            }
1109    
1110                            for (int i = 0; i < orderByFields.length; i++) {
1111                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1112                                    query.append(orderByFields[i]);
1113    
1114                                    if ((i + 1) < orderByFields.length) {
1115                                            if (orderByComparator.isAscending() ^ previous) {
1116                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1117                                            }
1118                                            else {
1119                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1120                                            }
1121                                    }
1122                                    else {
1123                                            if (orderByComparator.isAscending() ^ previous) {
1124                                                    query.append(WHERE_GREATER_THAN);
1125                                            }
1126                                            else {
1127                                                    query.append(WHERE_LESSER_THAN);
1128                                            }
1129                                    }
1130                            }
1131    
1132                            query.append(ORDER_BY_CLAUSE);
1133    
1134                            for (int i = 0; i < orderByFields.length; i++) {
1135                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1136                                    query.append(orderByFields[i]);
1137    
1138                                    if ((i + 1) < orderByFields.length) {
1139                                            if (orderByComparator.isAscending() ^ previous) {
1140                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1141                                            }
1142                                            else {
1143                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1144                                            }
1145                                    }
1146                                    else {
1147                                            if (orderByComparator.isAscending() ^ previous) {
1148                                                    query.append(ORDER_BY_ASC);
1149                                            }
1150                                            else {
1151                                                    query.append(ORDER_BY_DESC);
1152                                            }
1153                                    }
1154                            }
1155                    }
1156    
1157                    else {
1158                            query.append(JournalTemplateModelImpl.ORDER_BY_JPQL);
1159                    }
1160    
1161                    String sql = query.toString();
1162    
1163                    Query q = session.createQuery(sql);
1164    
1165                    q.setFirstResult(0);
1166                    q.setMaxResults(2);
1167    
1168                    QueryPos qPos = QueryPos.getInstance(q);
1169    
1170                    qPos.add(groupId);
1171    
1172                    if (orderByComparator != null) {
1173                            Object[] values = orderByComparator.getOrderByValues(journalTemplate);
1174    
1175                            for (Object value : values) {
1176                                    qPos.add(value);
1177                            }
1178                    }
1179    
1180                    List<JournalTemplate> list = q.list();
1181    
1182                    if (list.size() == 2) {
1183                            return list.get(1);
1184                    }
1185                    else {
1186                            return null;
1187                    }
1188            }
1189    
1190            public List<JournalTemplate> filterFindByGroupId(long groupId)
1191                    throws SystemException {
1192                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1193                            QueryUtil.ALL_POS, null);
1194            }
1195    
1196            public List<JournalTemplate> filterFindByGroupId(long groupId, int start,
1197                    int end) throws SystemException {
1198                    return filterFindByGroupId(groupId, start, end, null);
1199            }
1200    
1201            public List<JournalTemplate> filterFindByGroupId(long groupId, int start,
1202                    int end, OrderByComparator orderByComparator) throws SystemException {
1203                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1204                            return findByGroupId(groupId, start, end, orderByComparator);
1205                    }
1206    
1207                    Session session = null;
1208    
1209                    try {
1210                            session = openSession();
1211    
1212                            StringBundler query = null;
1213    
1214                            if (orderByComparator != null) {
1215                                    query = new StringBundler(3 +
1216                                                    (orderByComparator.getOrderByFields().length * 3));
1217                            }
1218                            else {
1219                                    query = new StringBundler(3);
1220                            }
1221    
1222                            query.append(_FILTER_SQL_SELECT_JOURNALTEMPLATE_WHERE);
1223    
1224                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1225    
1226                            if (orderByComparator != null) {
1227                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1228                                            orderByComparator);
1229                            }
1230    
1231                            else {
1232                                    query.append(JournalTemplateModelImpl.ORDER_BY_JPQL);
1233                            }
1234    
1235                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1236                                            JournalTemplate.class.getName(), _FILTER_COLUMN_PK,
1237                                            _FILTER_COLUMN_USERID, groupId);
1238    
1239                            SQLQuery q = session.createSQLQuery(sql);
1240    
1241                            q.addEntity(_FILTER_ENTITY_ALIAS, JournalTemplateImpl.class);
1242    
1243                            QueryPos qPos = QueryPos.getInstance(q);
1244    
1245                            qPos.add(groupId);
1246    
1247                            return (List<JournalTemplate>)QueryUtil.list(q, getDialect(),
1248                                    start, end);
1249                    }
1250                    catch (Exception e) {
1251                            throw processException(e);
1252                    }
1253                    finally {
1254                            closeSession(session);
1255                    }
1256            }
1257    
1258            public List<JournalTemplate> findByTemplateId(String templateId)
1259                    throws SystemException {
1260                    return findByTemplateId(templateId, QueryUtil.ALL_POS,
1261                            QueryUtil.ALL_POS, null);
1262            }
1263    
1264            public List<JournalTemplate> findByTemplateId(String templateId, int start,
1265                    int end) throws SystemException {
1266                    return findByTemplateId(templateId, start, end, null);
1267            }
1268    
1269            public List<JournalTemplate> findByTemplateId(String templateId, int start,
1270                    int end, OrderByComparator orderByComparator) throws SystemException {
1271                    Object[] finderArgs = new Object[] {
1272                                    templateId,
1273                                    
1274                                    String.valueOf(start), String.valueOf(end),
1275                                    String.valueOf(orderByComparator)
1276                            };
1277    
1278                    List<JournalTemplate> list = (List<JournalTemplate>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_TEMPLATEID,
1279                                    finderArgs, this);
1280    
1281                    if (list == null) {
1282                            Session session = null;
1283    
1284                            try {
1285                                    session = openSession();
1286    
1287                                    StringBundler query = null;
1288    
1289                                    if (orderByComparator != null) {
1290                                            query = new StringBundler(3 +
1291                                                            (orderByComparator.getOrderByFields().length * 3));
1292                                    }
1293                                    else {
1294                                            query = new StringBundler(3);
1295                                    }
1296    
1297                                    query.append(_SQL_SELECT_JOURNALTEMPLATE_WHERE);
1298    
1299                                    if (templateId == null) {
1300                                            query.append(_FINDER_COLUMN_TEMPLATEID_TEMPLATEID_1);
1301                                    }
1302                                    else {
1303                                            if (templateId.equals(StringPool.BLANK)) {
1304                                                    query.append(_FINDER_COLUMN_TEMPLATEID_TEMPLATEID_3);
1305                                            }
1306                                            else {
1307                                                    query.append(_FINDER_COLUMN_TEMPLATEID_TEMPLATEID_2);
1308                                            }
1309                                    }
1310    
1311                                    if (orderByComparator != null) {
1312                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1313                                                    orderByComparator);
1314                                    }
1315    
1316                                    else {
1317                                            query.append(JournalTemplateModelImpl.ORDER_BY_JPQL);
1318                                    }
1319    
1320                                    String sql = query.toString();
1321    
1322                                    Query q = session.createQuery(sql);
1323    
1324                                    QueryPos qPos = QueryPos.getInstance(q);
1325    
1326                                    if (templateId != null) {
1327                                            qPos.add(templateId);
1328                                    }
1329    
1330                                    list = (List<JournalTemplate>)QueryUtil.list(q, getDialect(),
1331                                                    start, end);
1332                            }
1333                            catch (Exception e) {
1334                                    throw processException(e);
1335                            }
1336                            finally {
1337                                    if (list == null) {
1338                                            list = new ArrayList<JournalTemplate>();
1339                                    }
1340    
1341                                    cacheResult(list);
1342    
1343                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_TEMPLATEID,
1344                                            finderArgs, list);
1345    
1346                                    closeSession(session);
1347                            }
1348                    }
1349    
1350                    return list;
1351            }
1352    
1353            public JournalTemplate findByTemplateId_First(String templateId,
1354                    OrderByComparator orderByComparator)
1355                    throws NoSuchTemplateException, SystemException {
1356                    List<JournalTemplate> list = findByTemplateId(templateId, 0, 1,
1357                                    orderByComparator);
1358    
1359                    if (list.isEmpty()) {
1360                            StringBundler msg = new StringBundler(4);
1361    
1362                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1363    
1364                            msg.append("templateId=");
1365                            msg.append(templateId);
1366    
1367                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1368    
1369                            throw new NoSuchTemplateException(msg.toString());
1370                    }
1371                    else {
1372                            return list.get(0);
1373                    }
1374            }
1375    
1376            public JournalTemplate findByTemplateId_Last(String templateId,
1377                    OrderByComparator orderByComparator)
1378                    throws NoSuchTemplateException, SystemException {
1379                    int count = countByTemplateId(templateId);
1380    
1381                    List<JournalTemplate> list = findByTemplateId(templateId, count - 1,
1382                                    count, orderByComparator);
1383    
1384                    if (list.isEmpty()) {
1385                            StringBundler msg = new StringBundler(4);
1386    
1387                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1388    
1389                            msg.append("templateId=");
1390                            msg.append(templateId);
1391    
1392                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1393    
1394                            throw new NoSuchTemplateException(msg.toString());
1395                    }
1396                    else {
1397                            return list.get(0);
1398                    }
1399            }
1400    
1401            public JournalTemplate[] findByTemplateId_PrevAndNext(long id,
1402                    String templateId, OrderByComparator orderByComparator)
1403                    throws NoSuchTemplateException, SystemException {
1404                    JournalTemplate journalTemplate = findByPrimaryKey(id);
1405    
1406                    Session session = null;
1407    
1408                    try {
1409                            session = openSession();
1410    
1411                            JournalTemplate[] array = new JournalTemplateImpl[3];
1412    
1413                            array[0] = getByTemplateId_PrevAndNext(session, journalTemplate,
1414                                            templateId, orderByComparator, true);
1415    
1416                            array[1] = journalTemplate;
1417    
1418                            array[2] = getByTemplateId_PrevAndNext(session, journalTemplate,
1419                                            templateId, orderByComparator, false);
1420    
1421                            return array;
1422                    }
1423                    catch (Exception e) {
1424                            throw processException(e);
1425                    }
1426                    finally {
1427                            closeSession(session);
1428                    }
1429            }
1430    
1431            protected JournalTemplate getByTemplateId_PrevAndNext(Session session,
1432                    JournalTemplate journalTemplate, String templateId,
1433                    OrderByComparator orderByComparator, boolean previous) {
1434                    StringBundler query = null;
1435    
1436                    if (orderByComparator != null) {
1437                            query = new StringBundler(6 +
1438                                            (orderByComparator.getOrderByFields().length * 6));
1439                    }
1440                    else {
1441                            query = new StringBundler(3);
1442                    }
1443    
1444                    query.append(_SQL_SELECT_JOURNALTEMPLATE_WHERE);
1445    
1446                    if (templateId == null) {
1447                            query.append(_FINDER_COLUMN_TEMPLATEID_TEMPLATEID_1);
1448                    }
1449                    else {
1450                            if (templateId.equals(StringPool.BLANK)) {
1451                                    query.append(_FINDER_COLUMN_TEMPLATEID_TEMPLATEID_3);
1452                            }
1453                            else {
1454                                    query.append(_FINDER_COLUMN_TEMPLATEID_TEMPLATEID_2);
1455                            }
1456                    }
1457    
1458                    if (orderByComparator != null) {
1459                            String[] orderByFields = orderByComparator.getOrderByFields();
1460    
1461                            if (orderByFields.length > 0) {
1462                                    query.append(WHERE_AND);
1463                            }
1464    
1465                            for (int i = 0; i < orderByFields.length; i++) {
1466                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1467                                    query.append(orderByFields[i]);
1468    
1469                                    if ((i + 1) < orderByFields.length) {
1470                                            if (orderByComparator.isAscending() ^ previous) {
1471                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1472                                            }
1473                                            else {
1474                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1475                                            }
1476                                    }
1477                                    else {
1478                                            if (orderByComparator.isAscending() ^ previous) {
1479                                                    query.append(WHERE_GREATER_THAN);
1480                                            }
1481                                            else {
1482                                                    query.append(WHERE_LESSER_THAN);
1483                                            }
1484                                    }
1485                            }
1486    
1487                            query.append(ORDER_BY_CLAUSE);
1488    
1489                            for (int i = 0; i < orderByFields.length; i++) {
1490                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1491                                    query.append(orderByFields[i]);
1492    
1493                                    if ((i + 1) < orderByFields.length) {
1494                                            if (orderByComparator.isAscending() ^ previous) {
1495                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1496                                            }
1497                                            else {
1498                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1499                                            }
1500                                    }
1501                                    else {
1502                                            if (orderByComparator.isAscending() ^ previous) {
1503                                                    query.append(ORDER_BY_ASC);
1504                                            }
1505                                            else {
1506                                                    query.append(ORDER_BY_DESC);
1507                                            }
1508                                    }
1509                            }
1510                    }
1511    
1512                    else {
1513                            query.append(JournalTemplateModelImpl.ORDER_BY_JPQL);
1514                    }
1515    
1516                    String sql = query.toString();
1517    
1518                    Query q = session.createQuery(sql);
1519    
1520                    q.setFirstResult(0);
1521                    q.setMaxResults(2);
1522    
1523                    QueryPos qPos = QueryPos.getInstance(q);
1524    
1525                    if (templateId != null) {
1526                            qPos.add(templateId);
1527                    }
1528    
1529                    if (orderByComparator != null) {
1530                            Object[] values = orderByComparator.getOrderByValues(journalTemplate);
1531    
1532                            for (Object value : values) {
1533                                    qPos.add(value);
1534                            }
1535                    }
1536    
1537                    List<JournalTemplate> list = q.list();
1538    
1539                    if (list.size() == 2) {
1540                            return list.get(1);
1541                    }
1542                    else {
1543                            return null;
1544                    }
1545            }
1546    
1547            public JournalTemplate findBySmallImageId(long smallImageId)
1548                    throws NoSuchTemplateException, SystemException {
1549                    JournalTemplate journalTemplate = fetchBySmallImageId(smallImageId);
1550    
1551                    if (journalTemplate == null) {
1552                            StringBundler msg = new StringBundler(4);
1553    
1554                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1555    
1556                            msg.append("smallImageId=");
1557                            msg.append(smallImageId);
1558    
1559                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1560    
1561                            if (_log.isWarnEnabled()) {
1562                                    _log.warn(msg.toString());
1563                            }
1564    
1565                            throw new NoSuchTemplateException(msg.toString());
1566                    }
1567    
1568                    return journalTemplate;
1569            }
1570    
1571            public JournalTemplate fetchBySmallImageId(long smallImageId)
1572                    throws SystemException {
1573                    return fetchBySmallImageId(smallImageId, true);
1574            }
1575    
1576            public JournalTemplate fetchBySmallImageId(long smallImageId,
1577                    boolean retrieveFromCache) throws SystemException {
1578                    Object[] finderArgs = new Object[] { smallImageId };
1579    
1580                    Object result = null;
1581    
1582                    if (retrieveFromCache) {
1583                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
1584                                            finderArgs, this);
1585                    }
1586    
1587                    if (result == null) {
1588                            Session session = null;
1589    
1590                            try {
1591                                    session = openSession();
1592    
1593                                    StringBundler query = new StringBundler(3);
1594    
1595                                    query.append(_SQL_SELECT_JOURNALTEMPLATE_WHERE);
1596    
1597                                    query.append(_FINDER_COLUMN_SMALLIMAGEID_SMALLIMAGEID_2);
1598    
1599                                    query.append(JournalTemplateModelImpl.ORDER_BY_JPQL);
1600    
1601                                    String sql = query.toString();
1602    
1603                                    Query q = session.createQuery(sql);
1604    
1605                                    QueryPos qPos = QueryPos.getInstance(q);
1606    
1607                                    qPos.add(smallImageId);
1608    
1609                                    List<JournalTemplate> list = q.list();
1610    
1611                                    result = list;
1612    
1613                                    JournalTemplate journalTemplate = null;
1614    
1615                                    if (list.isEmpty()) {
1616                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
1617                                                    finderArgs, list);
1618                                    }
1619                                    else {
1620                                            journalTemplate = list.get(0);
1621    
1622                                            cacheResult(journalTemplate);
1623    
1624                                            if ((journalTemplate.getSmallImageId() != smallImageId)) {
1625                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
1626                                                            finderArgs, journalTemplate);
1627                                            }
1628                                    }
1629    
1630                                    return journalTemplate;
1631                            }
1632                            catch (Exception e) {
1633                                    throw processException(e);
1634                            }
1635                            finally {
1636                                    if (result == null) {
1637                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
1638                                                    finderArgs, new ArrayList<JournalTemplate>());
1639                                    }
1640    
1641                                    closeSession(session);
1642                            }
1643                    }
1644                    else {
1645                            if (result instanceof List<?>) {
1646                                    return null;
1647                            }
1648                            else {
1649                                    return (JournalTemplate)result;
1650                            }
1651                    }
1652            }
1653    
1654            public JournalTemplate findByG_T(long groupId, String templateId)
1655                    throws NoSuchTemplateException, SystemException {
1656                    JournalTemplate journalTemplate = fetchByG_T(groupId, templateId);
1657    
1658                    if (journalTemplate == null) {
1659                            StringBundler msg = new StringBundler(6);
1660    
1661                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1662    
1663                            msg.append("groupId=");
1664                            msg.append(groupId);
1665    
1666                            msg.append(", templateId=");
1667                            msg.append(templateId);
1668    
1669                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1670    
1671                            if (_log.isWarnEnabled()) {
1672                                    _log.warn(msg.toString());
1673                            }
1674    
1675                            throw new NoSuchTemplateException(msg.toString());
1676                    }
1677    
1678                    return journalTemplate;
1679            }
1680    
1681            public JournalTemplate fetchByG_T(long groupId, String templateId)
1682                    throws SystemException {
1683                    return fetchByG_T(groupId, templateId, true);
1684            }
1685    
1686            public JournalTemplate fetchByG_T(long groupId, String templateId,
1687                    boolean retrieveFromCache) throws SystemException {
1688                    Object[] finderArgs = new Object[] { groupId, templateId };
1689    
1690                    Object result = null;
1691    
1692                    if (retrieveFromCache) {
1693                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_T,
1694                                            finderArgs, this);
1695                    }
1696    
1697                    if (result == null) {
1698                            Session session = null;
1699    
1700                            try {
1701                                    session = openSession();
1702    
1703                                    StringBundler query = new StringBundler(4);
1704    
1705                                    query.append(_SQL_SELECT_JOURNALTEMPLATE_WHERE);
1706    
1707                                    query.append(_FINDER_COLUMN_G_T_GROUPID_2);
1708    
1709                                    if (templateId == null) {
1710                                            query.append(_FINDER_COLUMN_G_T_TEMPLATEID_1);
1711                                    }
1712                                    else {
1713                                            if (templateId.equals(StringPool.BLANK)) {
1714                                                    query.append(_FINDER_COLUMN_G_T_TEMPLATEID_3);
1715                                            }
1716                                            else {
1717                                                    query.append(_FINDER_COLUMN_G_T_TEMPLATEID_2);
1718                                            }
1719                                    }
1720    
1721                                    query.append(JournalTemplateModelImpl.ORDER_BY_JPQL);
1722    
1723                                    String sql = query.toString();
1724    
1725                                    Query q = session.createQuery(sql);
1726    
1727                                    QueryPos qPos = QueryPos.getInstance(q);
1728    
1729                                    qPos.add(groupId);
1730    
1731                                    if (templateId != null) {
1732                                            qPos.add(templateId);
1733                                    }
1734    
1735                                    List<JournalTemplate> list = q.list();
1736    
1737                                    result = list;
1738    
1739                                    JournalTemplate journalTemplate = null;
1740    
1741                                    if (list.isEmpty()) {
1742                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_T,
1743                                                    finderArgs, list);
1744                                    }
1745                                    else {
1746                                            journalTemplate = list.get(0);
1747    
1748                                            cacheResult(journalTemplate);
1749    
1750                                            if ((journalTemplate.getGroupId() != groupId) ||
1751                                                            (journalTemplate.getTemplateId() == null) ||
1752                                                            !journalTemplate.getTemplateId().equals(templateId)) {
1753                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_T,
1754                                                            finderArgs, journalTemplate);
1755                                            }
1756                                    }
1757    
1758                                    return journalTemplate;
1759                            }
1760                            catch (Exception e) {
1761                                    throw processException(e);
1762                            }
1763                            finally {
1764                                    if (result == null) {
1765                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_T,
1766                                                    finderArgs, new ArrayList<JournalTemplate>());
1767                                    }
1768    
1769                                    closeSession(session);
1770                            }
1771                    }
1772                    else {
1773                            if (result instanceof List<?>) {
1774                                    return null;
1775                            }
1776                            else {
1777                                    return (JournalTemplate)result;
1778                            }
1779                    }
1780            }
1781    
1782            public List<JournalTemplate> findByG_S(long groupId, String structureId)
1783                    throws SystemException {
1784                    return findByG_S(groupId, structureId, QueryUtil.ALL_POS,
1785                            QueryUtil.ALL_POS, null);
1786            }
1787    
1788            public List<JournalTemplate> findByG_S(long groupId, String structureId,
1789                    int start, int end) throws SystemException {
1790                    return findByG_S(groupId, structureId, start, end, null);
1791            }
1792    
1793            public List<JournalTemplate> findByG_S(long groupId, String structureId,
1794                    int start, int end, OrderByComparator orderByComparator)
1795                    throws SystemException {
1796                    Object[] finderArgs = new Object[] {
1797                                    groupId, structureId,
1798                                    
1799                                    String.valueOf(start), String.valueOf(end),
1800                                    String.valueOf(orderByComparator)
1801                            };
1802    
1803                    List<JournalTemplate> list = (List<JournalTemplate>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_S,
1804                                    finderArgs, this);
1805    
1806                    if (list == null) {
1807                            Session session = null;
1808    
1809                            try {
1810                                    session = openSession();
1811    
1812                                    StringBundler query = null;
1813    
1814                                    if (orderByComparator != null) {
1815                                            query = new StringBundler(4 +
1816                                                            (orderByComparator.getOrderByFields().length * 3));
1817                                    }
1818                                    else {
1819                                            query = new StringBundler(4);
1820                                    }
1821    
1822                                    query.append(_SQL_SELECT_JOURNALTEMPLATE_WHERE);
1823    
1824                                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
1825    
1826                                    if (structureId == null) {
1827                                            query.append(_FINDER_COLUMN_G_S_STRUCTUREID_1);
1828                                    }
1829                                    else {
1830                                            if (structureId.equals(StringPool.BLANK)) {
1831                                                    query.append(_FINDER_COLUMN_G_S_STRUCTUREID_3);
1832                                            }
1833                                            else {
1834                                                    query.append(_FINDER_COLUMN_G_S_STRUCTUREID_2);
1835                                            }
1836                                    }
1837    
1838                                    if (orderByComparator != null) {
1839                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1840                                                    orderByComparator);
1841                                    }
1842    
1843                                    else {
1844                                            query.append(JournalTemplateModelImpl.ORDER_BY_JPQL);
1845                                    }
1846    
1847                                    String sql = query.toString();
1848    
1849                                    Query q = session.createQuery(sql);
1850    
1851                                    QueryPos qPos = QueryPos.getInstance(q);
1852    
1853                                    qPos.add(groupId);
1854    
1855                                    if (structureId != null) {
1856                                            qPos.add(structureId);
1857                                    }
1858    
1859                                    list = (List<JournalTemplate>)QueryUtil.list(q, getDialect(),
1860                                                    start, end);
1861                            }
1862                            catch (Exception e) {
1863                                    throw processException(e);
1864                            }
1865                            finally {
1866                                    if (list == null) {
1867                                            list = new ArrayList<JournalTemplate>();
1868                                    }
1869    
1870                                    cacheResult(list);
1871    
1872                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_S, finderArgs,
1873                                            list);
1874    
1875                                    closeSession(session);
1876                            }
1877                    }
1878    
1879                    return list;
1880            }
1881    
1882            public JournalTemplate findByG_S_First(long groupId, String structureId,
1883                    OrderByComparator orderByComparator)
1884                    throws NoSuchTemplateException, SystemException {
1885                    List<JournalTemplate> list = findByG_S(groupId, structureId, 0, 1,
1886                                    orderByComparator);
1887    
1888                    if (list.isEmpty()) {
1889                            StringBundler msg = new StringBundler(6);
1890    
1891                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1892    
1893                            msg.append("groupId=");
1894                            msg.append(groupId);
1895    
1896                            msg.append(", structureId=");
1897                            msg.append(structureId);
1898    
1899                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1900    
1901                            throw new NoSuchTemplateException(msg.toString());
1902                    }
1903                    else {
1904                            return list.get(0);
1905                    }
1906            }
1907    
1908            public JournalTemplate findByG_S_Last(long groupId, String structureId,
1909                    OrderByComparator orderByComparator)
1910                    throws NoSuchTemplateException, SystemException {
1911                    int count = countByG_S(groupId, structureId);
1912    
1913                    List<JournalTemplate> list = findByG_S(groupId, structureId, count - 1,
1914                                    count, orderByComparator);
1915    
1916                    if (list.isEmpty()) {
1917                            StringBundler msg = new StringBundler(6);
1918    
1919                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1920    
1921                            msg.append("groupId=");
1922                            msg.append(groupId);
1923    
1924                            msg.append(", structureId=");
1925                            msg.append(structureId);
1926    
1927                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1928    
1929                            throw new NoSuchTemplateException(msg.toString());
1930                    }
1931                    else {
1932                            return list.get(0);
1933                    }
1934            }
1935    
1936            public JournalTemplate[] findByG_S_PrevAndNext(long id, long groupId,
1937                    String structureId, OrderByComparator orderByComparator)
1938                    throws NoSuchTemplateException, SystemException {
1939                    JournalTemplate journalTemplate = findByPrimaryKey(id);
1940    
1941                    Session session = null;
1942    
1943                    try {
1944                            session = openSession();
1945    
1946                            JournalTemplate[] array = new JournalTemplateImpl[3];
1947    
1948                            array[0] = getByG_S_PrevAndNext(session, journalTemplate, groupId,
1949                                            structureId, orderByComparator, true);
1950    
1951                            array[1] = journalTemplate;
1952    
1953                            array[2] = getByG_S_PrevAndNext(session, journalTemplate, groupId,
1954                                            structureId, orderByComparator, false);
1955    
1956                            return array;
1957                    }
1958                    catch (Exception e) {
1959                            throw processException(e);
1960                    }
1961                    finally {
1962                            closeSession(session);
1963                    }
1964            }
1965    
1966            protected JournalTemplate getByG_S_PrevAndNext(Session session,
1967                    JournalTemplate journalTemplate, long groupId, String structureId,
1968                    OrderByComparator orderByComparator, boolean previous) {
1969                    StringBundler query = null;
1970    
1971                    if (orderByComparator != null) {
1972                            query = new StringBundler(6 +
1973                                            (orderByComparator.getOrderByFields().length * 6));
1974                    }
1975                    else {
1976                            query = new StringBundler(3);
1977                    }
1978    
1979                    query.append(_SQL_SELECT_JOURNALTEMPLATE_WHERE);
1980    
1981                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
1982    
1983                    if (structureId == null) {
1984                            query.append(_FINDER_COLUMN_G_S_STRUCTUREID_1);
1985                    }
1986                    else {
1987                            if (structureId.equals(StringPool.BLANK)) {
1988                                    query.append(_FINDER_COLUMN_G_S_STRUCTUREID_3);
1989                            }
1990                            else {
1991                                    query.append(_FINDER_COLUMN_G_S_STRUCTUREID_2);
1992                            }
1993                    }
1994    
1995                    if (orderByComparator != null) {
1996                            String[] orderByFields = orderByComparator.getOrderByFields();
1997    
1998                            if (orderByFields.length > 0) {
1999                                    query.append(WHERE_AND);
2000                            }
2001    
2002                            for (int i = 0; i < orderByFields.length; i++) {
2003                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2004                                    query.append(orderByFields[i]);
2005    
2006                                    if ((i + 1) < orderByFields.length) {
2007                                            if (orderByComparator.isAscending() ^ previous) {
2008                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2009                                            }
2010                                            else {
2011                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2012                                            }
2013                                    }
2014                                    else {
2015                                            if (orderByComparator.isAscending() ^ previous) {
2016                                                    query.append(WHERE_GREATER_THAN);
2017                                            }
2018                                            else {
2019                                                    query.append(WHERE_LESSER_THAN);
2020                                            }
2021                                    }
2022                            }
2023    
2024                            query.append(ORDER_BY_CLAUSE);
2025    
2026                            for (int i = 0; i < orderByFields.length; i++) {
2027                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2028                                    query.append(orderByFields[i]);
2029    
2030                                    if ((i + 1) < orderByFields.length) {
2031                                            if (orderByComparator.isAscending() ^ previous) {
2032                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2033                                            }
2034                                            else {
2035                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2036                                            }
2037                                    }
2038                                    else {
2039                                            if (orderByComparator.isAscending() ^ previous) {
2040                                                    query.append(ORDER_BY_ASC);
2041                                            }
2042                                            else {
2043                                                    query.append(ORDER_BY_DESC);
2044                                            }
2045                                    }
2046                            }
2047                    }
2048    
2049                    else {
2050                            query.append(JournalTemplateModelImpl.ORDER_BY_JPQL);
2051                    }
2052    
2053                    String sql = query.toString();
2054    
2055                    Query q = session.createQuery(sql);
2056    
2057                    q.setFirstResult(0);
2058                    q.setMaxResults(2);
2059    
2060                    QueryPos qPos = QueryPos.getInstance(q);
2061    
2062                    qPos.add(groupId);
2063    
2064                    if (structureId != null) {
2065                            qPos.add(structureId);
2066                    }
2067    
2068                    if (orderByComparator != null) {
2069                            Object[] values = orderByComparator.getOrderByValues(journalTemplate);
2070    
2071                            for (Object value : values) {
2072                                    qPos.add(value);
2073                            }
2074                    }
2075    
2076                    List<JournalTemplate> list = q.list();
2077    
2078                    if (list.size() == 2) {
2079                            return list.get(1);
2080                    }
2081                    else {
2082                            return null;
2083                    }
2084            }
2085    
2086            public List<JournalTemplate> filterFindByG_S(long groupId,
2087                    String structureId) throws SystemException {
2088                    return filterFindByG_S(groupId, structureId, QueryUtil.ALL_POS,
2089                            QueryUtil.ALL_POS, null);
2090            }
2091    
2092            public List<JournalTemplate> filterFindByG_S(long groupId,
2093                    String structureId, int start, int end) throws SystemException {
2094                    return filterFindByG_S(groupId, structureId, start, end, null);
2095            }
2096    
2097            public List<JournalTemplate> filterFindByG_S(long groupId,
2098                    String structureId, int start, int end,
2099                    OrderByComparator orderByComparator) throws SystemException {
2100                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2101                            return findByG_S(groupId, structureId, start, end, orderByComparator);
2102                    }
2103    
2104                    Session session = null;
2105    
2106                    try {
2107                            session = openSession();
2108    
2109                            StringBundler query = null;
2110    
2111                            if (orderByComparator != null) {
2112                                    query = new StringBundler(4 +
2113                                                    (orderByComparator.getOrderByFields().length * 3));
2114                            }
2115                            else {
2116                                    query = new StringBundler(4);
2117                            }
2118    
2119                            query.append(_FILTER_SQL_SELECT_JOURNALTEMPLATE_WHERE);
2120    
2121                            query.append(_FINDER_COLUMN_G_S_GROUPID_2);
2122    
2123                            if (structureId == null) {
2124                                    query.append(_FINDER_COLUMN_G_S_STRUCTUREID_1);
2125                            }
2126                            else {
2127                                    if (structureId.equals(StringPool.BLANK)) {
2128                                            query.append(_FINDER_COLUMN_G_S_STRUCTUREID_3);
2129                                    }
2130                                    else {
2131                                            query.append(_FINDER_COLUMN_G_S_STRUCTUREID_2);
2132                                    }
2133                            }
2134    
2135                            if (orderByComparator != null) {
2136                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2137                                            orderByComparator);
2138                            }
2139    
2140                            else {
2141                                    query.append(JournalTemplateModelImpl.ORDER_BY_JPQL);
2142                            }
2143    
2144                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2145                                            JournalTemplate.class.getName(), _FILTER_COLUMN_PK,
2146                                            _FILTER_COLUMN_USERID, groupId);
2147    
2148                            SQLQuery q = session.createSQLQuery(sql);
2149    
2150                            q.addEntity(_FILTER_ENTITY_ALIAS, JournalTemplateImpl.class);
2151    
2152                            QueryPos qPos = QueryPos.getInstance(q);
2153    
2154                            qPos.add(groupId);
2155    
2156                            if (structureId != null) {
2157                                    qPos.add(structureId);
2158                            }
2159    
2160                            return (List<JournalTemplate>)QueryUtil.list(q, getDialect(),
2161                                    start, end);
2162                    }
2163                    catch (Exception e) {
2164                            throw processException(e);
2165                    }
2166                    finally {
2167                            closeSession(session);
2168                    }
2169            }
2170    
2171            public List<JournalTemplate> findAll() throws SystemException {
2172                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2173            }
2174    
2175            public List<JournalTemplate> findAll(int start, int end)
2176                    throws SystemException {
2177                    return findAll(start, end, null);
2178            }
2179    
2180            public List<JournalTemplate> findAll(int start, int end,
2181                    OrderByComparator orderByComparator) throws SystemException {
2182                    Object[] finderArgs = new Object[] {
2183                                    String.valueOf(start), String.valueOf(end),
2184                                    String.valueOf(orderByComparator)
2185                            };
2186    
2187                    List<JournalTemplate> list = (List<JournalTemplate>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
2188                                    finderArgs, this);
2189    
2190                    if (list == null) {
2191                            Session session = null;
2192    
2193                            try {
2194                                    session = openSession();
2195    
2196                                    StringBundler query = null;
2197                                    String sql = null;
2198    
2199                                    if (orderByComparator != null) {
2200                                            query = new StringBundler(2 +
2201                                                            (orderByComparator.getOrderByFields().length * 3));
2202    
2203                                            query.append(_SQL_SELECT_JOURNALTEMPLATE);
2204    
2205                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2206                                                    orderByComparator);
2207    
2208                                            sql = query.toString();
2209                                    }
2210                                    else {
2211                                            sql = _SQL_SELECT_JOURNALTEMPLATE.concat(JournalTemplateModelImpl.ORDER_BY_JPQL);
2212                                    }
2213    
2214                                    Query q = session.createQuery(sql);
2215    
2216                                    if (orderByComparator == null) {
2217                                            list = (List<JournalTemplate>)QueryUtil.list(q,
2218                                                            getDialect(), start, end, false);
2219    
2220                                            Collections.sort(list);
2221                                    }
2222                                    else {
2223                                            list = (List<JournalTemplate>)QueryUtil.list(q,
2224                                                            getDialect(), start, end);
2225                                    }
2226                            }
2227                            catch (Exception e) {
2228                                    throw processException(e);
2229                            }
2230                            finally {
2231                                    if (list == null) {
2232                                            list = new ArrayList<JournalTemplate>();
2233                                    }
2234    
2235                                    cacheResult(list);
2236    
2237                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
2238    
2239                                    closeSession(session);
2240                            }
2241                    }
2242    
2243                    return list;
2244            }
2245    
2246            public void removeByUuid(String uuid) throws SystemException {
2247                    for (JournalTemplate journalTemplate : findByUuid(uuid)) {
2248                            remove(journalTemplate);
2249                    }
2250            }
2251    
2252            public void removeByUUID_G(String uuid, long groupId)
2253                    throws NoSuchTemplateException, SystemException {
2254                    JournalTemplate journalTemplate = findByUUID_G(uuid, groupId);
2255    
2256                    remove(journalTemplate);
2257            }
2258    
2259            public void removeByGroupId(long groupId) throws SystemException {
2260                    for (JournalTemplate journalTemplate : findByGroupId(groupId)) {
2261                            remove(journalTemplate);
2262                    }
2263            }
2264    
2265            public void removeByTemplateId(String templateId) throws SystemException {
2266                    for (JournalTemplate journalTemplate : findByTemplateId(templateId)) {
2267                            remove(journalTemplate);
2268                    }
2269            }
2270    
2271            public void removeBySmallImageId(long smallImageId)
2272                    throws NoSuchTemplateException, SystemException {
2273                    JournalTemplate journalTemplate = findBySmallImageId(smallImageId);
2274    
2275                    remove(journalTemplate);
2276            }
2277    
2278            public void removeByG_T(long groupId, String templateId)
2279                    throws NoSuchTemplateException, SystemException {
2280                    JournalTemplate journalTemplate = findByG_T(groupId, templateId);
2281    
2282                    remove(journalTemplate);
2283            }
2284    
2285            public void removeByG_S(long groupId, String structureId)
2286                    throws SystemException {
2287                    for (JournalTemplate journalTemplate : findByG_S(groupId, structureId)) {
2288                            remove(journalTemplate);
2289                    }
2290            }
2291    
2292            public void removeAll() throws SystemException {
2293                    for (JournalTemplate journalTemplate : findAll()) {
2294                            remove(journalTemplate);
2295                    }
2296            }
2297    
2298            public int countByUuid(String uuid) throws SystemException {
2299                    Object[] finderArgs = new Object[] { uuid };
2300    
2301                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
2302                                    finderArgs, this);
2303    
2304                    if (count == null) {
2305                            Session session = null;
2306    
2307                            try {
2308                                    session = openSession();
2309    
2310                                    StringBundler query = new StringBundler(2);
2311    
2312                                    query.append(_SQL_COUNT_JOURNALTEMPLATE_WHERE);
2313    
2314                                    if (uuid == null) {
2315                                            query.append(_FINDER_COLUMN_UUID_UUID_1);
2316                                    }
2317                                    else {
2318                                            if (uuid.equals(StringPool.BLANK)) {
2319                                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
2320                                            }
2321                                            else {
2322                                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
2323                                            }
2324                                    }
2325    
2326                                    String sql = query.toString();
2327    
2328                                    Query q = session.createQuery(sql);
2329    
2330                                    QueryPos qPos = QueryPos.getInstance(q);
2331    
2332                                    if (uuid != null) {
2333                                            qPos.add(uuid);
2334                                    }
2335    
2336                                    count = (Long)q.uniqueResult();
2337                            }
2338                            catch (Exception e) {
2339                                    throw processException(e);
2340                            }
2341                            finally {
2342                                    if (count == null) {
2343                                            count = Long.valueOf(0);
2344                                    }
2345    
2346                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
2347                                            finderArgs, count);
2348    
2349                                    closeSession(session);
2350                            }
2351                    }
2352    
2353                    return count.intValue();
2354            }
2355    
2356            public int countByUUID_G(String uuid, long groupId)
2357                    throws SystemException {
2358                    Object[] finderArgs = new Object[] { uuid, groupId };
2359    
2360                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
2361                                    finderArgs, this);
2362    
2363                    if (count == null) {
2364                            Session session = null;
2365    
2366                            try {
2367                                    session = openSession();
2368    
2369                                    StringBundler query = new StringBundler(3);
2370    
2371                                    query.append(_SQL_COUNT_JOURNALTEMPLATE_WHERE);
2372    
2373                                    if (uuid == null) {
2374                                            query.append(_FINDER_COLUMN_UUID_G_UUID_1);
2375                                    }
2376                                    else {
2377                                            if (uuid.equals(StringPool.BLANK)) {
2378                                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
2379                                            }
2380                                            else {
2381                                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
2382                                            }
2383                                    }
2384    
2385                                    query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
2386    
2387                                    String sql = query.toString();
2388    
2389                                    Query q = session.createQuery(sql);
2390    
2391                                    QueryPos qPos = QueryPos.getInstance(q);
2392    
2393                                    if (uuid != null) {
2394                                            qPos.add(uuid);
2395                                    }
2396    
2397                                    qPos.add(groupId);
2398    
2399                                    count = (Long)q.uniqueResult();
2400                            }
2401                            catch (Exception e) {
2402                                    throw processException(e);
2403                            }
2404                            finally {
2405                                    if (count == null) {
2406                                            count = Long.valueOf(0);
2407                                    }
2408    
2409                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
2410                                            finderArgs, count);
2411    
2412                                    closeSession(session);
2413                            }
2414                    }
2415    
2416                    return count.intValue();
2417            }
2418    
2419            public int countByGroupId(long groupId) throws SystemException {
2420                    Object[] finderArgs = new Object[] { groupId };
2421    
2422                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
2423                                    finderArgs, this);
2424    
2425                    if (count == null) {
2426                            Session session = null;
2427    
2428                            try {
2429                                    session = openSession();
2430    
2431                                    StringBundler query = new StringBundler(2);
2432    
2433                                    query.append(_SQL_COUNT_JOURNALTEMPLATE_WHERE);
2434    
2435                                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2436    
2437                                    String sql = query.toString();
2438    
2439                                    Query q = session.createQuery(sql);
2440    
2441                                    QueryPos qPos = QueryPos.getInstance(q);
2442    
2443                                    qPos.add(groupId);
2444    
2445                                    count = (Long)q.uniqueResult();
2446                            }
2447                            catch (Exception e) {
2448                                    throw processException(e);
2449                            }
2450                            finally {
2451                                    if (count == null) {
2452                                            count = Long.valueOf(0);
2453                                    }
2454    
2455                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
2456                                            finderArgs, count);
2457    
2458                                    closeSession(session);
2459                            }
2460                    }
2461    
2462                    return count.intValue();
2463            }
2464    
2465            public int filterCountByGroupId(long groupId) throws SystemException {
2466                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2467                            return countByGroupId(groupId);
2468                    }
2469    
2470                    Session session = null;
2471    
2472                    try {
2473                            session = openSession();
2474    
2475                            StringBundler query = new StringBundler(2);
2476    
2477                            query.append(_FILTER_SQL_COUNT_JOURNALTEMPLATE_WHERE);
2478    
2479                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2480    
2481                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2482                                            JournalTemplate.class.getName(), _FILTER_COLUMN_PK,
2483                                            _FILTER_COLUMN_USERID, groupId);
2484    
2485                            SQLQuery q = session.createSQLQuery(sql);
2486    
2487                            q.addScalar(COUNT_COLUMN_NAME,
2488                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2489    
2490                            QueryPos qPos = QueryPos.getInstance(q);
2491    
2492                            qPos.add(groupId);
2493    
2494                            Long count = (Long)q.uniqueResult();
2495    
2496                            return count.intValue();
2497                    }
2498                    catch (Exception e) {
2499                            throw processException(e);
2500                    }
2501                    finally {
2502                            closeSession(session);
2503                    }
2504            }
2505    
2506            public int countByTemplateId(String templateId) throws SystemException {
2507                    Object[] finderArgs = new Object[] { templateId };
2508    
2509                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_TEMPLATEID,
2510                                    finderArgs, this);
2511    
2512                    if (count == null) {
2513                            Session session = null;
2514    
2515                            try {
2516                                    session = openSession();
2517    
2518                                    StringBundler query = new StringBundler(2);
2519    
2520                                    query.append(_SQL_COUNT_JOURNALTEMPLATE_WHERE);
2521    
2522                                    if (templateId == null) {
2523                                            query.append(_FINDER_COLUMN_TEMPLATEID_TEMPLATEID_1);
2524                                    }
2525                                    else {
2526                                            if (templateId.equals(StringPool.BLANK)) {
2527                                                    query.append(_FINDER_COLUMN_TEMPLATEID_TEMPLATEID_3);
2528                                            }
2529                                            else {
2530                                                    query.append(_FINDER_COLUMN_TEMPLATEID_TEMPLATEID_2);
2531                                            }
2532                                    }
2533    
2534                                    String sql = query.toString();
2535    
2536                                    Query q = session.createQuery(sql);
2537    
2538                                    QueryPos qPos = QueryPos.getInstance(q);
2539    
2540                                    if (templateId != null) {
2541                                            qPos.add(templateId);
2542                                    }
2543    
2544                                    count = (Long)q.uniqueResult();
2545                            }
2546                            catch (Exception e) {
2547                                    throw processException(e);
2548                            }
2549                            finally {
2550                                    if (count == null) {
2551                                            count = Long.valueOf(0);
2552                                    }
2553    
2554                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_TEMPLATEID,
2555                                            finderArgs, count);
2556    
2557                                    closeSession(session);
2558                            }
2559                    }
2560    
2561                    return count.intValue();
2562            }
2563    
2564            public int countBySmallImageId(long smallImageId) throws SystemException {
2565                    Object[] finderArgs = new Object[] { smallImageId };
2566    
2567                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_SMALLIMAGEID,
2568                                    finderArgs, this);
2569    
2570                    if (count == null) {
2571                            Session session = null;
2572    
2573                            try {
2574                                    session = openSession();
2575    
2576                                    StringBundler query = new StringBundler(2);
2577    
2578                                    query.append(_SQL_COUNT_JOURNALTEMPLATE_WHERE);
2579    
2580                                    query.append(_FINDER_COLUMN_SMALLIMAGEID_SMALLIMAGEID_2);
2581    
2582                                    String sql = query.toString();
2583    
2584                                    Query q = session.createQuery(sql);
2585    
2586                                    QueryPos qPos = QueryPos.getInstance(q);
2587    
2588                                    qPos.add(smallImageId);
2589    
2590                                    count = (Long)q.uniqueResult();
2591                            }
2592                            catch (Exception e) {
2593                                    throw processException(e);
2594                            }
2595                            finally {
2596                                    if (count == null) {
2597                                            count = Long.valueOf(0);
2598                                    }
2599    
2600                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_SMALLIMAGEID,
2601                                            finderArgs, count);
2602    
2603                                    closeSession(session);
2604                            }
2605                    }
2606    
2607                    return count.intValue();
2608            }
2609    
2610            public int countByG_T(long groupId, String templateId)
2611                    throws SystemException {
2612                    Object[] finderArgs = new Object[] { groupId, templateId };
2613    
2614                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_T,
2615                                    finderArgs, this);
2616    
2617                    if (count == null) {
2618                            Session session = null;
2619    
2620                            try {
2621                                    session = openSession();
2622    
2623                                    StringBundler query = new StringBundler(3);
2624    
2625                                    query.append(_SQL_COUNT_JOURNALTEMPLATE_WHERE);
2626    
2627                                    query.append(_FINDER_COLUMN_G_T_GROUPID_2);
2628    
2629                                    if (templateId == null) {
2630                                            query.append(_FINDER_COLUMN_G_T_TEMPLATEID_1);
2631                                    }
2632                                    else {
2633                                            if (templateId.equals(StringPool.BLANK)) {
2634                                                    query.append(_FINDER_COLUMN_G_T_TEMPLATEID_3);
2635                                            }
2636                                            else {
2637                                                    query.append(_FINDER_COLUMN_G_T_TEMPLATEID_2);
2638                                            }
2639                                    }
2640    
2641                                    String sql = query.toString();
2642    
2643                                    Query q = session.createQuery(sql);
2644    
2645                                    QueryPos qPos = QueryPos.getInstance(q);
2646    
2647                                    qPos.add(groupId);
2648    
2649                                    if (templateId != null) {
2650                                            qPos.add(templateId);
2651                                    }
2652    
2653                                    count = (Long)q.uniqueResult();
2654                            }
2655                            catch (Exception e) {
2656                                    throw processException(e);
2657                            }
2658                            finally {
2659                                    if (count == null) {
2660                                            count = Long.valueOf(0);
2661                                    }
2662    
2663                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_T, finderArgs,
2664                                            count);
2665    
2666                                    closeSession(session);
2667                            }
2668                    }
2669    
2670                    return count.intValue();
2671            }
2672    
2673            public int filterCountByG_T(long groupId, String templateId)
2674                    throws SystemException {
2675                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2676                            return countByG_T(groupId, templateId);
2677                    }
2678    
2679                    Session session = null;
2680    
2681                    try {
2682                            session = openSession();
2683    
2684                            StringBundler query = new StringBundler(3);
2685    
2686                            query.append(_FILTER_SQL_COUNT_JOURNALTEMPLATE_WHERE);
2687    
2688                            query.append(_FINDER_COLUMN_G_T_GROUPID_2);
2689    
2690                            if (templateId == null) {
2691                                    query.append(_FINDER_COLUMN_G_T_TEMPLATEID_1);
2692                            }
2693                            else {
2694                                    if (templateId.equals(StringPool.BLANK)) {
2695                                            query.append(_FINDER_COLUMN_G_T_TEMPLATEID_3);
2696                                    }
2697                                    else {
2698                                            query.append(_FINDER_COLUMN_G_T_TEMPLATEID_2);
2699                                    }
2700                            }
2701    
2702                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2703                                            JournalTemplate.class.getName(), _FILTER_COLUMN_PK,
2704                                            _FILTER_COLUMN_USERID, groupId);
2705    
2706                            SQLQuery q = session.createSQLQuery(sql);
2707    
2708                            q.addScalar(COUNT_COLUMN_NAME,
2709                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2710    
2711                            QueryPos qPos = QueryPos.getInstance(q);
2712    
2713                            qPos.add(groupId);
2714    
2715                            if (templateId != null) {
2716                                    qPos.add(templateId);
2717                            }
2718    
2719                            Long count = (Long)q.uniqueResult();
2720    
2721                            return count.intValue();
2722                    }
2723                    catch (Exception e) {
2724                            throw processException(e);
2725                    }
2726                    finally {
2727                            closeSession(session);
2728                    }
2729            }
2730    
2731            public int countByG_S(long groupId, String structureId)
2732                    throws SystemException {
2733                    Object[] finderArgs = new Object[] { groupId, structureId };
2734    
2735                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_S,
2736                                    finderArgs, this);
2737    
2738                    if (count == null) {
2739                            Session session = null;
2740    
2741                            try {
2742                                    session = openSession();
2743    
2744                                    StringBundler query = new StringBundler(3);
2745    
2746                                    query.append(_SQL_COUNT_JOURNALTEMPLATE_WHERE);
2747    
2748                                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
2749    
2750                                    if (structureId == null) {
2751                                            query.append(_FINDER_COLUMN_G_S_STRUCTUREID_1);
2752                                    }
2753                                    else {
2754                                            if (structureId.equals(StringPool.BLANK)) {
2755                                                    query.append(_FINDER_COLUMN_G_S_STRUCTUREID_3);
2756                                            }
2757                                            else {
2758                                                    query.append(_FINDER_COLUMN_G_S_STRUCTUREID_2);
2759                                            }
2760                                    }
2761    
2762                                    String sql = query.toString();
2763    
2764                                    Query q = session.createQuery(sql);
2765    
2766                                    QueryPos qPos = QueryPos.getInstance(q);
2767    
2768                                    qPos.add(groupId);
2769    
2770                                    if (structureId != null) {
2771                                            qPos.add(structureId);
2772                                    }
2773    
2774                                    count = (Long)q.uniqueResult();
2775                            }
2776                            catch (Exception e) {
2777                                    throw processException(e);
2778                            }
2779                            finally {
2780                                    if (count == null) {
2781                                            count = Long.valueOf(0);
2782                                    }
2783    
2784                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_S, finderArgs,
2785                                            count);
2786    
2787                                    closeSession(session);
2788                            }
2789                    }
2790    
2791                    return count.intValue();
2792            }
2793    
2794            public int filterCountByG_S(long groupId, String structureId)
2795                    throws SystemException {
2796                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2797                            return countByG_S(groupId, structureId);
2798                    }
2799    
2800                    Session session = null;
2801    
2802                    try {
2803                            session = openSession();
2804    
2805                            StringBundler query = new StringBundler(3);
2806    
2807                            query.append(_FILTER_SQL_COUNT_JOURNALTEMPLATE_WHERE);
2808    
2809                            query.append(_FINDER_COLUMN_G_S_GROUPID_2);
2810    
2811                            if (structureId == null) {
2812                                    query.append(_FINDER_COLUMN_G_S_STRUCTUREID_1);
2813                            }
2814                            else {
2815                                    if (structureId.equals(StringPool.BLANK)) {
2816                                            query.append(_FINDER_COLUMN_G_S_STRUCTUREID_3);
2817                                    }
2818                                    else {
2819                                            query.append(_FINDER_COLUMN_G_S_STRUCTUREID_2);
2820                                    }
2821                            }
2822    
2823                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2824                                            JournalTemplate.class.getName(), _FILTER_COLUMN_PK,
2825                                            _FILTER_COLUMN_USERID, groupId);
2826    
2827                            SQLQuery q = session.createSQLQuery(sql);
2828    
2829                            q.addScalar(COUNT_COLUMN_NAME,
2830                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2831    
2832                            QueryPos qPos = QueryPos.getInstance(q);
2833    
2834                            qPos.add(groupId);
2835    
2836                            if (structureId != null) {
2837                                    qPos.add(structureId);
2838                            }
2839    
2840                            Long count = (Long)q.uniqueResult();
2841    
2842                            return count.intValue();
2843                    }
2844                    catch (Exception e) {
2845                            throw processException(e);
2846                    }
2847                    finally {
2848                            closeSession(session);
2849                    }
2850            }
2851    
2852            public int countAll() throws SystemException {
2853                    Object[] finderArgs = new Object[0];
2854    
2855                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2856                                    finderArgs, this);
2857    
2858                    if (count == null) {
2859                            Session session = null;
2860    
2861                            try {
2862                                    session = openSession();
2863    
2864                                    Query q = session.createQuery(_SQL_COUNT_JOURNALTEMPLATE);
2865    
2866                                    count = (Long)q.uniqueResult();
2867                            }
2868                            catch (Exception e) {
2869                                    throw processException(e);
2870                            }
2871                            finally {
2872                                    if (count == null) {
2873                                            count = Long.valueOf(0);
2874                                    }
2875    
2876                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
2877                                            count);
2878    
2879                                    closeSession(session);
2880                            }
2881                    }
2882    
2883                    return count.intValue();
2884            }
2885    
2886            public void afterPropertiesSet() {
2887                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2888                                            com.liferay.portal.util.PropsUtil.get(
2889                                                    "value.object.listener.com.liferay.portlet.journal.model.JournalTemplate")));
2890    
2891                    if (listenerClassNames.length > 0) {
2892                            try {
2893                                    List<ModelListener<JournalTemplate>> listenersList = new ArrayList<ModelListener<JournalTemplate>>();
2894    
2895                                    for (String listenerClassName : listenerClassNames) {
2896                                            listenersList.add((ModelListener<JournalTemplate>)InstanceFactory.newInstance(
2897                                                            listenerClassName));
2898                                    }
2899    
2900                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2901                            }
2902                            catch (Exception e) {
2903                                    _log.error(e);
2904                            }
2905                    }
2906            }
2907    
2908            @BeanReference(type = JournalArticlePersistence.class)
2909            protected JournalArticlePersistence journalArticlePersistence;
2910            @BeanReference(type = JournalArticleImagePersistence.class)
2911            protected JournalArticleImagePersistence journalArticleImagePersistence;
2912            @BeanReference(type = JournalArticleResourcePersistence.class)
2913            protected JournalArticleResourcePersistence journalArticleResourcePersistence;
2914            @BeanReference(type = JournalContentSearchPersistence.class)
2915            protected JournalContentSearchPersistence journalContentSearchPersistence;
2916            @BeanReference(type = JournalFeedPersistence.class)
2917            protected JournalFeedPersistence journalFeedPersistence;
2918            @BeanReference(type = JournalStructurePersistence.class)
2919            protected JournalStructurePersistence journalStructurePersistence;
2920            @BeanReference(type = JournalTemplatePersistence.class)
2921            protected JournalTemplatePersistence journalTemplatePersistence;
2922            @BeanReference(type = ImagePersistence.class)
2923            protected ImagePersistence imagePersistence;
2924            @BeanReference(type = ResourcePersistence.class)
2925            protected ResourcePersistence resourcePersistence;
2926            @BeanReference(type = UserPersistence.class)
2927            protected UserPersistence userPersistence;
2928            @BeanReference(type = WebDAVPropsPersistence.class)
2929            protected WebDAVPropsPersistence webDAVPropsPersistence;
2930            @BeanReference(type = ExpandoValuePersistence.class)
2931            protected ExpandoValuePersistence expandoValuePersistence;
2932            private static final String _SQL_SELECT_JOURNALTEMPLATE = "SELECT journalTemplate FROM JournalTemplate journalTemplate";
2933            private static final String _SQL_SELECT_JOURNALTEMPLATE_WHERE = "SELECT journalTemplate FROM JournalTemplate journalTemplate WHERE ";
2934            private static final String _SQL_COUNT_JOURNALTEMPLATE = "SELECT COUNT(journalTemplate) FROM JournalTemplate journalTemplate";
2935            private static final String _SQL_COUNT_JOURNALTEMPLATE_WHERE = "SELECT COUNT(journalTemplate) FROM JournalTemplate journalTemplate WHERE ";
2936            private static final String _FINDER_COLUMN_UUID_UUID_1 = "journalTemplate.uuid IS NULL";
2937            private static final String _FINDER_COLUMN_UUID_UUID_2 = "journalTemplate.uuid = ?";
2938            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(journalTemplate.uuid IS NULL OR journalTemplate.uuid = ?)";
2939            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "journalTemplate.uuid IS NULL AND ";
2940            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "journalTemplate.uuid = ? AND ";
2941            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(journalTemplate.uuid IS NULL OR journalTemplate.uuid = ?) AND ";
2942            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "journalTemplate.groupId = ?";
2943            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "journalTemplate.groupId = ?";
2944            private static final String _FINDER_COLUMN_TEMPLATEID_TEMPLATEID_1 = "journalTemplate.templateId IS NULL";
2945            private static final String _FINDER_COLUMN_TEMPLATEID_TEMPLATEID_2 = "journalTemplate.templateId = ?";
2946            private static final String _FINDER_COLUMN_TEMPLATEID_TEMPLATEID_3 = "(journalTemplate.templateId IS NULL OR journalTemplate.templateId = ?)";
2947            private static final String _FINDER_COLUMN_SMALLIMAGEID_SMALLIMAGEID_2 = "journalTemplate.smallImageId = ?";
2948            private static final String _FINDER_COLUMN_G_T_GROUPID_2 = "journalTemplate.groupId = ? AND ";
2949            private static final String _FINDER_COLUMN_G_T_TEMPLATEID_1 = "journalTemplate.templateId IS NULL";
2950            private static final String _FINDER_COLUMN_G_T_TEMPLATEID_2 = "journalTemplate.templateId = ?";
2951            private static final String _FINDER_COLUMN_G_T_TEMPLATEID_3 = "(journalTemplate.templateId IS NULL OR journalTemplate.templateId = ?)";
2952            private static final String _FINDER_COLUMN_G_S_GROUPID_2 = "journalTemplate.groupId = ? AND ";
2953            private static final String _FINDER_COLUMN_G_S_STRUCTUREID_1 = "journalTemplate.structureId IS NULL";
2954            private static final String _FINDER_COLUMN_G_S_STRUCTUREID_2 = "journalTemplate.structureId = ?";
2955            private static final String _FINDER_COLUMN_G_S_STRUCTUREID_3 = "(journalTemplate.structureId IS NULL OR journalTemplate.structureId = ?)";
2956            private static final String _FILTER_SQL_SELECT_JOURNALTEMPLATE_WHERE = "SELECT DISTINCT {journalTemplate.*} FROM JournalTemplate journalTemplate WHERE ";
2957            private static final String _FILTER_SQL_COUNT_JOURNALTEMPLATE_WHERE = "SELECT COUNT(DISTINCT journalTemplate.id) AS COUNT_VALUE FROM JournalTemplate journalTemplate WHERE ";
2958            private static final String _FILTER_COLUMN_PK = "journalTemplate.id";
2959            private static final String _FILTER_COLUMN_USERID = "journalTemplate.userId";
2960            private static final String _FILTER_ENTITY_ALIAS = "journalTemplate";
2961            private static final String _ORDER_BY_ENTITY_ALIAS = "journalTemplate.";
2962            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No JournalTemplate exists with the primary key ";
2963            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No JournalTemplate exists with the key {";
2964            private static Log _log = LogFactoryUtil.getLog(JournalTemplatePersistenceImpl.class);
2965    }