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