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