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