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