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