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