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