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