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