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