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