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