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