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